final Location location = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); final Entity[] entities = new CommandTarget(sender, args[0]).getMatched(location); targets = new ArrayList<>(); final Player player = Bukkit.getPlayerExact(playerPattern); return false; } else { currentLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); currentLocation = new Location(world, 0, 0, 0); spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); } else { sender.sendMessage(ChatColor.RED target.setBedSpawnLocation(spawnLocation, true); sender.sendMessage("Set " + target.getName() + "'s spawn point to " + spawnLocation.getBlockX() + ", " + spawnLocation.getBlockY() + ", " + spawnLocation.getBlockZ() + ".");
@Override protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) { BlockFace facing = BlockDispenser.getFacing(block); Location targetLocation = block.getLocation().clone() .add(facing.getModX(), facing.getModY(), facing.getModZ()); for (Entity entity : targetLocation.getWorld().getNearbyEntities(targetLocation, 3, 3, 3)) { switch (entity.getType()) { case PLAYER: case ARMOR_STAND: && player.getEyeLocation().getBlockZ() == targetLocation.getZ()); if ((targetLocationTest1 || targetLocationTest2)) { return ((GlowInventory) ((Player) player).getInventory()) .tryToFillSlots(stack, 36, 40);
private GlowItem getFirstDroppedItem(Location location) { for (Entity entity : location.getChunk().getEntities()) { if (location.getBlockX() != entity.getLocation().getBlockX() || location.getBlockY() != entity.getLocation().getBlockY() || location.getBlockZ() != entity.getLocation().getBlockZ()) { continue; } if (entity.getType() != EntityType.DROPPED_ITEM) { continue; } return ((GlowItem) entity); } return null; }
/** * Gets the name of an entity. * * @param entity an entity * @return the first of the following that exists and is non-empty: {@code * entity.getCustomName()}, {@code entity.getName()}, {@code * entity.getType().getName()} */ public static String getName(Entity entity) { String customName = entity.getCustomName(); if (customName != null && !customName.isEmpty()) { return customName; } String name = entity.getName(); if (name == null || name.isEmpty()) { name = entity.getType().getName(); } return name; }
targets = new CommandTarget(sender, args[0]).getMatched(location); } else { Player targetPlayer = Bukkit.getPlayerExact(args[0]); if (targetPlayer != null) { location = targetPlayer.getLocation(); String yaw = args[4]; String pitch = args[5]; targetLocation = CommandUtils.getRotation(target.getLocation(), yaw, pitch); } else { targetLocation.setYaw(target.getLocation().getYaw()); targetLocation.setPitch(target.getLocation().getPitch()); target.teleport(targetLocation); sender.sendMessage( "Teleported " + target.getName() + " to " + targetLocation.getX() + " " + targetLocation.getY() + " " + targetLocation.getZ());
for (Entity entity : source.getWorld().getEntities()) { if (entity.getLocation().distanceSquared(source) < minRadius) { continue; if (!(maxRadius == 0 || entity.getLocation().distanceSquared(source) < maxRadius)) { continue; if (!types.contains(entity.getType())) { continue; if (getX() != null && getX() != entity.getLocation().getBlockX()) { continue; if (getY() != null && getY() != entity.getLocation().getBlockY()) { continue; if (getZ() != null && getZ() != entity.getLocation().getBlockZ()) { continue; if (gameModes != null && entity.getType() != EntityType.PLAYER) { continue; if (maxLevel != null && entity.getType() != EntityType.PLAYER) { continue; if (minLevel != null && entity.getType() != EntityType.PLAYER) { continue;
private static ArmorStand getArmorStand(Block b) { Location l = new Location(b.getWorld(), b.getX() + 0.5, b.getY() - 0.7F, b.getZ() + 0.5); for (Entity n: l.getChunk().getEntities()) { if (n instanceof ArmorStand) { if (n.getCustomName() != null && l.distanceSquared(n.getLocation()) < 0.4D) return (ArmorStand) n; } } ArmorStand hologram = ArmorStandFactory.createHidden(l); return hologram; }
/** * Checks whether the entity is within the specified distance from the block. * * @param entity the entity * @param block the block * @param x maximum distance on x axis * @param y maximum distance on y axis * @param z maximum distance on z axis * @return Whether the entity is within distance */ private boolean isWithinDistance(Entity entity, Block block, int x, int y, int z) { Location loc = entity.getLocation(); return Math.abs(loc.getX() - block.getX()) <= x && Math.abs(loc.getY() - block.getY()) <= y && Math.abs(loc.getZ() - block.getZ()) <= z; } }
spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); } else { sender.sendMessage(ChatColor.RED return false; } else { senderLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); senderLocation = new Location(world, 0, 0, 0); if (spawnLocation.getBlockY() < 0) { sender.sendMessage(ChatColor.RED + "The y coordinate (" + spawnLocation.getBlockY() + ") is too small, it must be at least 0."); return false; } else if (spawnLocation.getBlockY() > world.getMaxHeight()) { sender.sendMessage(ChatColor.RED + "'" + spawnLocation.getBlockY() + "' is too high for the current world. Max value is '" + world.getMaxHeight() + "'."); return false; world.setSpawnLocation(spawnLocation.getBlockX(), spawnLocation.getBlockY(), spawnLocation.getBlockZ()); sender.sendMessage(
/** * Fires a snowball from the NPC at a target. */ public void fireSnowball(Location target) { sentinel.swingWeapon(); sentinel.stats_snowballsThrown++; sentinel.faceLocation(target); Vector forward = getLivingEntity().getEyeLocation().getDirection(); Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(sentinel.firingMinimumRange())); Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.SNOWBALL); ((Projectile) ent).setShooter(getLivingEntity()); ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(2.0))); // TODO: Fiddle with '2.0'. }
public static void swingOffhand(Entity entity, int range) { int rangeSquared = range * range; String worldName = entity.getWorld().getName(); Location center = entity.getLocation(); for (Player player : Bukkit.getOnlinePlayers()) { if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > rangeSquared) { continue; } swingOffhand(player, entity); } }
public boolean run( CommandSender sender, Command cmd, String label, String[] args, Player player) { Chunk c = player.getLocation().getChunk(); for (World w : Bukkit.getWorlds()) { List<Entity> entities = w.getEntities(); int killed = 0; for (Entity entity : entities) { if (entity instanceof Player) { } else if (entity.getLocation().getChunk().getX() == c.getX() && entity.getLocation().getChunk().getZ() == c.getZ()) { killed = killed + 1; entity.remove(); System.out.println("[butcher] removed " + entity.getName()); } } player.sendMessage(ChatColor.GREEN + "Killed " + killed + " entities on " + w.getName()); } return false; } }
double modX = random.nextDouble() - 0.5; double modZ = random.nextDouble() - 0.5; Location xpLocation = new Location(world, location.getBlockX() + 0.5 + modX, location.getY(), location.getBlockZ() + 0.5 + modZ); GlowExperienceOrb orb = (GlowExperienceOrb) world orb.setSourceEntityId(this.getUniqueId()); if (getLastDamager() != null) { orb.setTriggerEntityId(getLastDamager().getUniqueId());
@EventHandler(ignoreCancelled = true) public void onCompanionEntityClick(PlayerInteractEntityEvent event) { UUID uuid = event.getPlayer().getUniqueId(); ResultSetAntiBuild rs = new ResultSetAntiBuild(plugin, uuid); if (!rs.resultSet() || !plugin.getTrackerKeeper().getAntiBuild().containsKey(rs.getTardis_id())) { return; } Vector v = event.getRightClicked().getLocation().toVector(); TARDISAntiBuild tab = plugin.getTrackerKeeper().getAntiBuild().get(rs.getTardis_id()); if (v.isInAABB(tab.getMin(), tab.getMax())) { event.setCancelled(true); TARDISMessage.send(event.getPlayer(), "ANTIBUILD_TIMELORD", tab.getTimelord()); } }
GlowWorld world = (GlowWorld) location.getWorld(); setBlockOnFire(block); for (int i = 0; i < 4; i++) { int x = location.getBlockX() - 1 + ThreadLocalRandom.current().nextInt(3); int z = location.getBlockZ() - 1 + ThreadLocalRandom.current().nextInt(3); int y = location.getBlockY() - 1 + ThreadLocalRandom.current().nextInt(3); block = world.getBlockAt(x, y, z); if (entity.isDead()) { continue; .damage(5, this, EntityDamageEvent.DamageCause.LIGHTNING); entity.setFireTicks(entity.getMaxFireTicks());
@Override public void run() { if (Bukkit.getPlayer(uuid) == null) Bukkit.getScheduler().cancelTask(id); else if (Bukkit.getPlayer(uuid).isDead()) Bukkit.getScheduler().cancelTask(id); else if (!Bukkit.getPlayer(uuid).isSneaking()) Bukkit.getScheduler().cancelTask(id); else { for (Entity item: Bukkit.getPlayer(uuid).getNearbyEntities(6D, 6D, 6D)) { if (item instanceof Item) { if (!item.hasMetadata("no_pickup") && ((Item) item).getPickupDelay() <= 0) { item.teleport(Bukkit.getPlayer(uuid).getEyeLocation()); Bukkit.getPlayer(uuid).getWorld().playSound(Bukkit.getPlayer(uuid).getEyeLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 5L, 2L); } } } } }
@EventHandler(priority = EventPriority.LOW) public void onEntityDamage(EntityDamageByEntityEvent e) { if (e.getCause() != DamageCause.ENTITY_EXPLOSION) { return; } String l = e.getDamager().getLocation().getWorld().getName(); if (l.contains("TARDIS") || l.equals(plugin.getConfig().getString("creation.default_world_name"))) { e.setCancelled(true); } } }
protected void teleportTo(Entity sourceEntity, Entity targetEntity) { Location targetLocation = targetEntity.getLocation(); // Try to place you in front of the other player, and facing them BlockFace targetFacing = getFacing(targetEntity.getLocation()); Location candidate = findPlaceToStand(targetLocation.getBlock().getRelative(targetFacing).getRelative(targetFacing).getLocation(), 4, 4); if (candidate != null) { candidate.setPitch(0); candidate.setYaw(360 - targetLocation.getYaw()); targetLocation = candidate; } sourceEntity.teleport(targetLocation); }
private List<Entity> getJunkTravellers() { // spawn an entity Entity orb = junkLoc.getWorld().spawnEntity(junkLoc, EntityType.EXPERIENCE_ORB); List<Entity> ents = orb.getNearbyEntities(4.0, 4.0, 4.0); orb.remove(); return ents; }