@Override public Extent getExtent() { org.bukkit.entity.Entity entity = entityRef.get(); if (entity != null) { return BukkitAdapter.adapt(entity.getWorld()); } else { return NullWorld.getInstance(); } }
/** * Returns the world that the given command sender is referring to when not specifying one. * * @param sender a command sender * @return the command sender's world if the sender is a block or entity, or the default world * otherwise */ public static GlowWorld getWorld(CommandSender sender) { if (sender instanceof ConsoleCommandSender) { return getDefaultWorld(); } else if (sender instanceof Entity) { return (GlowWorld) ((Entity) sender).getWorld(); } else if (sender instanceof BlockCommandSender) { return (GlowWorld) ((BlockCommandSender) sender).getBlock().getWorld(); } return getDefaultWorld(); }
/** * Gets the world in which the entity moved * * @return Last and current Entity World */ public World getWorld() { return this.entity.getWorld(); }
public static Object getEntityTrackerEntry(Entity target) throws Exception { Object world = getWorldServer(target.getWorld()); Object tracker = trackerField.get(world); Object trackedEntities = entitiesField.get(tracker); return ihmGet.invoke(trackedEntities, target.getEntityId()); }
public void watch(Entity entity) { if (entity == null) return; if (worldName != null && !entity.getWorld().getName().equals(worldName)) return; if (worldName == null) worldName = entity.getWorld().getName(); if (!entity.hasMetadata("MagicBlockList")) { setUndoList(plugin, entity, this); } modifiedTime = System.currentTimeMillis(); }
/** * Gets the tracker entry of the entity specified * * @param entity to get it for * @return entity tracker entry, or null if none is set */ public static Object getTrackerEntry(org.bukkit.entity.Entity entity) { return getTracker(entity.getWorld()).getEntry(entity); }
/** * Sets a new entity tracker entry for the entity specified * * @param entity to set it for * @param entityTrackerEntry to set to (can be null to remove only) * @return the previous tracker entry for the entity, or null if there was none */ public static Object setTrackerEntry(org.bukkit.entity.Entity entity, Object entityTrackerEntry) { return getTracker(entity.getWorld()).setEntry(entity, entityTrackerEntry); }
public static DMob getByEntity(Entity entity) { DGameWorld gameWorld = DGameWorld.getByWorld(entity.getWorld()); for (DMob dMob : gameWorld.getDMobs()) { if (dMob.entity == entity) { return dMob; } } return null; }
private static Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) { if (world != null) { return world.getSpawnLocation(); } else { // add 0.5 to x and z to center people // (spawn location is stored as int meaning that you would spawn in the corner of a block) return e.getWorld().getSpawnLocation().add(.5, 0, .5); } }
/** * Gets all the entities nearby an entity * * @param entity to get the nearby entities of * @param radX to look for entities * @param radY to look for entities * @param radZ to look for entities * @return A (referenced) list of entities nearby */ public static List<org.bukkit.entity.Entity> getNearbyEntities(org.bukkit.entity.Entity entity, double radX, double radY, double radZ) { return CommonNMS.getEntities(entity.getWorld(), entity, CommonNMS.getNative(entity).boundingBox.grow(radX, radY, radZ)); }
Entity arrow = event.getEntity(); Vector velocity = arrow.getVelocity(); Item item = arrow.getWorld().dropItem(arrow.getLocation(), ItemStack); item.setVelocity(velocity);
@EventHandler public void onEntityCombust(EntityCombustEvent event) { DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); if (gameWorld != null) { event.setCancelled(true); } }
@Override public Block apply(PathEntry input) { return npc.getEntity().getWorld().getBlockAt(input.vector.getBlockX(), input.vector.getBlockY(), input.vector.getBlockZ()); } });
@EventHandler public void onEntityCombustByEntity(EntityCombustByEntityEvent event) { DGameWorld gameWorld = DGameWorld.getByWorld(event.getEntity().getWorld()); if (gameWorld != null) { if (event.isCancelled()) { event.setCancelled(false); } } }
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); } }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPotionEffect(EntityPotionEffectEvent event) { if (event.getCause() == EntityPotionEffectEvent.Cause.CONDUIT) { WorldConfiguration config = getWorldConfig(BukkitAdapter.adapt(event.getEntity().getWorld())); if (config.disableConduitEffects) { event.setCancelled(true); } } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityRegainHealth(EntityRegainHealthEvent event) { Entity ent = event.getEntity(); World world = ent.getWorld(); ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(world)); if (wcfg.disableHealthRegain) { event.setCancelled(true); return; } }
/** * Allows or prevents enderman griefing */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEndermanGrief(final EntityChangeBlockEvent e) { if (!(e.getEntity() instanceof Enderman) || !getIWM().inWorld(e.getEntity().getLocation())) { return; } if (!Flags.ENDERMAN_GRIEFING.isSetForWorld(e.getEntity().getWorld())) { e.setCancelled(true); } }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityInteract(EntityInteractEvent event) { Entity entity = event.getEntity(); Block block = event.getBlock(); ConfigurationManager cfg = WorldGuard.getInstance().getPlatform().getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(BukkitAdapter.adapt(entity.getWorld())); if (block.getType() == Material.FARMLAND) { if (/* entity instanceof Creature && // catch for any entity (not thrown for players) */ wcfg.disableCreatureCropTrampling) { event.setCancelled(true); } } }