/** * Prevents visitors picking items from riding horses or other inventories * @param event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onHorseInventoryClick(InventoryClickEvent event) { if (DEBUG) plugin.getLogger().info("DEBUG: horse and llama inventory click"); if (event.getInventory().getHolder() == null) { return; } // World check if (!Util.inWorld(event.getWhoClicked())) { return; } if (event.getInventory().getHolder() instanceof Animals) { if (actionAllowed((Player)event.getWhoClicked(), event.getWhoClicked().getLocation(), SettingsFlag.MOUNT_INVENTORY)) { return; } // Elsewhere - not allowed Util.sendMessage(event.getWhoClicked(), plugin.getLocale(event.getWhoClicked().getUniqueId()).get("island.protected")); event.setCancelled(true); } }
@EventHandler public void onFakeEntityDamageByEntityEvent(FakeEntityDamageByEntityEvent e){ RedProtect.get().logger.debug("Mcmmo FakeEntityDamageByEntityEvent event."); if (e.getDamager() instanceof Player){ Player p = (Player) e.getDamager(); Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation()); if (e.getEntity() instanceof Animals){ if (r != null && !r.canInteractPassives(p)){ RPLang.sendMessage(p, "entitylistener.region.cantpassive"); e.setCancelled(true); } } if (e.getEntity() instanceof Player){ if (r != null && !r.canPVP(p, (Player)e.getEntity())){ RPLang.sendMessage(p, "entitylistener.region.cantpvp"); e.setCancelled(true); } } } }
@EventHandler public void onFakeEntityDamageEvent(FakeEntityDamageEvent e){ RedProtect.get().logger.debug("Mcmmo FakeEntityDamageEvent event."); Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation()); if (e.getEntity() instanceof Animals){ if (r != null && !r.getFlagBool("passives")){ e.setCancelled(true); } } if (e.getEntity() instanceof Player){ Player p = (Player) e.getEntity(); if (r != null && !r.canPVP(p, null)){ e.setCancelled(true); } } }
@EventHandler public void onInteractEvent(PlayerInteractEntityEvent e){ RedProtect.get().logger.debug("RPEntityListener - Is PlayerInteractEntityEvent"); if (e.isCancelled()) { return; } Player p = e.getPlayer(); if (p == null){ return; } Location l = e.getRightClicked().getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); Entity et = e.getRightClicked(); if (r != null && !r.canInteractPassives(p) && (et instanceof Animals || et instanceof Villager || et instanceof Golem)) { if (et instanceof Tameable){ Tameable tam = (Tameable) et; if (tam.isTamed() && tam.getOwner() != null && tam.getOwner().getName().equals(p.getName())){ return; } } e.setCancelled(true); RPLang.sendMessage(p, "entitylistener.region.cantinteract"); } }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityDamage(EntityDamageEvent e) { Region r = RedProtect.get().rm.getTopRegion(e.getEntity().getLocation()); if (r != null){ return; } Entity ent = e.getEntity(); if (ent instanceof LivingEntity && !(ent instanceof Monster)){ if (RPConfig.getGlobalFlagBool(ent.getWorld().getName()+".invincible")){ if (ent instanceof Animals){ ((Animals)ent).setTarget(null); } e.setCancelled(true); } } }
/** * Protects animals on a beacon from damage * @param event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEntityDamage(final EntityDamageEvent event) { World world = event.getEntity().getWorld(); if (!world.equals(getBeaconzWorld())) { return; } //getLogger().info("DEBUG: " + event.getEntityType()); if (!(event.getEntity() instanceof Animals || event.getEntity() instanceof LeashHitch)) { return; } // Check beacon defense BeaconObj beacon = getRegister().getBeaconAt(event.getEntity().getLocation()); if (beacon != null) { event.setCancelled(true); } }
public CreatureType getCreatureType(EntityType entityType) { if (Monster.class.isAssignableFrom(entityType.getEntityClass()) || WaterMob.class.isAssignableFrom(entityType.getEntityClass()) || Slime.class.isAssignableFrom(entityType.getEntityClass()) || Ghast.class.isAssignableFrom(entityType.getEntityClass()) ) { return CreatureType.MONSTER; } else if (Animals.class.isAssignableFrom(entityType.getEntityClass())) { return CreatureType.ANIMAL; } else if (Villager.class.isAssignableFrom(entityType.getEntityClass())) { return CreatureType.VILLAGER; } else if (Golem.class.isAssignableFrom(entityType.getEntityClass())) { return CreatureType.GOLEM; } return CreatureType.UNKNOWN; }
/** * Prevents visitors picking items from riding horses or other inventories * @param event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onHorseInventoryClick(InventoryClickEvent event) { if (DEBUG) plugin.getLogger().info("DEBUG: horse and llama inventory click"); if (event.getInventory().getHolder() == null) { return; } // World check if (!inWorld(event.getWhoClicked())) { return; } if (event.getInventory().getHolder() instanceof Animals) { if (actionAllowed((Player)event.getWhoClicked(), event.getWhoClicked().getLocation(), SettingsFlag.HORSE_INVENTORY)) { return; } // Elsewhere - not allowed Util.sendMessage(event.getWhoClicked(), ChatColor.RED + plugin.myLocale(event.getWhoClicked().getUniqueId()).islandProtected); event.setCancelled(true); return; } }
public void handle(CommandInfo commandInfo) { final Player player = (Player) commandInfo.getSender(); if (teleportQueue.containsKey(player) && teleportQueue.get(player) instanceof Animals) { StableMaster.commandQueue.remove(player); Animals animal = (Animals) teleportQueue.get(player); removeFromQueue(player); // Horses duplicate with cross world teleports... if (animal.getLocation().getWorld() != (player).getLocation().getWorld()) { new LangString("command.teleport.cross-world").send(player); return; } new TeleportEval(animal, player).runTask(StableMaster.getPlugin()); } else { StableMaster.commandQueue.put(player, this); teleportQueue.put(player, true); new LangString("punch-animal").send(player); } }
@EventHandler(ignoreCancelled = true) public void onEntityTame(EntityTameEvent event) { // Return if the damaged entity is not a tameable entity. if (!(event.getEntity() instanceof Tameable)) return; Player player = (Player) event.getOwner(); Animals animal = (Animals) event.getEntity(); String name = animal.getType().name().toLowerCase(); // Don't cancel if the player has the appropriate permission if (player.hasPermission("stablemaster.tame." + name)) return; event.setCancelled(true); new LangString("error.cannot-tame", getAnimal(animal.getType())).send(player); }
@Override public void onTick(ChunkLocation cl) { int ni = rand.nextInt(4); EntityType toSpawn = possibleToSpawn[ni]; Entity[] ents = cl.getChunk().getEntities(); if(ents.length > Feudalism.getConfiguration().getPastureEntityLimit()) { return; } for (Entity enty : ents) { System.out.println(enty.getType()); if (enty instanceof Animals) { Location locy = enty.getLocation(); for (int i = 1; i <= Feudalism.getConfiguration().getPastureSpawningAnimals(); i++) { locy.getWorld().spawnEntity(locy, toSpawn); } return; } } }
public void startLoveMode(Animals animal) { EntityAnimal entity = getEntityAnimal(animal); EntityHuman human = null; try { Class<?> c = EntityAnimal.class; Field bx = c.getDeclaredField("bx"); bx.setAccessible(true); bx.setInt(entity, 600); Field by = c.getDeclaredField("by"); by.setAccessible(true); by.set(entity, human); entity.breedItem = null; entity.world.broadcastEntityEffect(entity, (byte)18); } catch (Exception x) { throw new RuntimeException(x.toString()); } }
public void startLoveMode(Animals animal) { EntityAnimal entity = getEntityAnimal(animal); EntityHuman human = null; try { Class<?> c = EntityAnimal.class; Field bx = c.getDeclaredField("bw"); bx.setAccessible(true); bx.setInt(entity, 600); Field by = c.getDeclaredField("bx"); by.setAccessible(true); by.set(entity, human); entity.breedItem = null; entity.world.broadcastEntityEffect(entity, (byte)18); } catch (Exception x) { throw new RuntimeException(x.toString()); } }
@SuppressWarnings("deprecation") public static Class<? extends net.minecraft.server.v1_7_R1.Entity> getNmsEntityClass(final Class<? extends LivingEntity> entityClass) throws IllegalArgumentException { if(entityClass==null) throw new IllegalArgumentException("entityClass must not be null"); if(entityClass==HumanEntity.class || entityClass==Player.class) return net.minecraft.server.v1_7_R1.EntityHuman.class; if(entityClass==Monster.class) return net.minecraft.server.v1_7_R1.EntityMonster.class; if(entityClass==Creature.class) return net.minecraft.server.v1_7_R1.EntityCreature.class; if(entityClass==Animals.class) return net.minecraft.server.v1_7_R1.EntityAnimal.class; if(entityClass==LivingEntity.class) return net.minecraft.server.v1_7_R1.EntityLiving.class; for(EntityType entityType: EntityType.values()) { if(entityType.getEntityClass()==null || entityType.getTypeId()==-1) continue; if(entityClass.equals(entityType.getEntityClass())) { return getNmsEntityClass(entityType); } } throw new IllegalArgumentException("Class "+entityClass.getSimpleName()+" is not resolvable to an EntityType"); }
/** * Prevents mobs spawning at spawn or in an island * * @param e */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onMobSpawn(final CreatureSpawnEvent e) { if (DEBUG2) { plugin.getLogger().info("on Mob spawn" + e.getEventName()); } // if grid is not loaded yet, return. if (plugin.getIslands() == null) { return; } // If not in the right world, return if (!Util.inWorld(e.getEntity())) { return; } // Deal with natural spawning if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) { if (!actionAllowed(e.getLocation(), SettingsFlag.MONSTER_SPAWN)) { if (DEBUG2) plugin.getLogger().info("Natural monster spawn cancelled."); // Mobs not allowed to spawn e.setCancelled(true); return; } } if (e.getEntity() instanceof Animals) { if (!actionAllowed(e.getLocation(), SettingsFlag.ANIMAL_SPAWN)) { // Animals are not allowed to spawn if (DEBUG2) plugin.getLogger().info("Natural animal spawn cancelled."); e.setCancelled(true); } } }
private void exterminate(){ world.getEntities().forEach(e -> { if (e instanceof Monster || e instanceof Animals){ LivingEntity le = (LivingEntity)e; le.damage(le.getMaxHealth()); } if (e instanceof Item){ e.remove(); } }); }
public WorldInfo(World world) { this.worldName = world.getName(); this.totalOnline = world.getPlayers().size(); for (Entity entity : world.getEntities()) { this.totalEntity++; if (entity instanceof Animals) { this.totalAnimals++; } else if (entity instanceof Monster) { this.totalMonsters++; } else if (entity instanceof Item) { this.totalDropItem++; } } for (Chunk loadedChunk : world.getLoadedChunks()) { this.totalChunk++; for (BlockState tiles : loadedChunk.getTileEntities()) { this.totalTiles++; if (tiles instanceof Hopper) { this.totalHopper++; } else if (tiles instanceof Chest) { this.totalChest++; } else if (tiles instanceof Dispenser) { this.totalDispenser++; } else if (tiles instanceof Dropper) { this.totalDropper++; } else if (tiles instanceof BrewingStand) { this.totalBrewingStand++; } } } }
@EventHandler() public void onEntityDamage(EntityDamageByEntityEvent e) { if (!ClaimChunk.getInstance().getChunkHandler().isClaimed(e.getEntity().getLocation().getChunk())) { return; } if (e.getDamager() instanceof Player && e.getEntity() instanceof Animals) ChunkHelper.cancelAnimalDamage((Player) e.getDamager(), e.getDamager().getLocation().getChunk(), e); }
@EventHandler(priority = EventPriority.LOWEST) public void onEntityDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); DamageCause cause = event.getCause(); if(cause == DamageCause.ENTITY_ATTACK || cause == DamageCause.PROJECTILE) { EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent)event; Entity attacker = event2.getDamager(); if(attacker != null && attacker.getType() == EntityType.PLAYER) return; if(attacker instanceof Projectile) { ProjectileSource source = ((Projectile)attacker).getShooter(); if(source != null && source instanceof Player) return; } } if(entity instanceof Animals || entity instanceof WaterMob || entity.getType() == EntityType.VILLAGER || entity.getCustomName() != null) { Flag flag = this.GetFlagInstanceAtLocation(entity.getLocation(), null); if(flag == null) return; event.setCancelled(true); } }
@EventHandler public void onEntityKill(EntityDeathEvent e) { if (!instance.dropFromMobs) return; Player p = e.getEntity().getKiller(); LivingEntity entity = e.getEntity(); if (p == null && instance.requirePlayerKill) return; if (!instance.limitWorlds.isEmpty() && !instance.limitWorlds.contains(entity.getWorld().getName())) return; if (!instance.limitRegions.isEmpty() && !a(entity.getLocation(), instance.limitRegions)) return; boolean isBaby = entity instanceof Animals && !((Animals) entity).isAdult(); boolean isSpawner = entity.hasMetadata("isSpawnerMob"); int looting = p.getInventory().getItemInMainHand() == null ? 0 : p.getInventory().getItemInMainHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_MOBS); double lootExtraChance = instance.lootingEffectiveness * looting; for (MysteryBag bag : instance.cheezBags.values()) { if (bag.willDrop(entity, lootExtraChance, isBaby, isSpawner)) { MysteryBagDropEvent event = new MysteryBagDropEvent(p, entity, bag.getBagItem()); instance.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) return; ItemStack drop = event.getItem(); if (instance.lootingSensitiveAmount) { drop.setAmount(drop.getAmount() * (1 + instance.random.nextInt(looting + 1))); } if (MysteryBags.instance().overrideDrops) { entity.getWorld().dropItem(entity.getLocation(), drop); } else { e.getDrops().add(drop); } } } }
/** * {@inheritDoc} */ public ColorMenu(Plot plot, Animals entity) { super(plot, entity); ItemStack color = new ItemStack(Material.CONCRETE_POWDER, 1, (short) 1); ItemMeta colorMeta = color.getItemMeta(); colorMeta.setDisplayName(ChatColor.GREEN + "Change the color of the entity"); color.setItemMeta(colorMeta); insertItem(color, event -> { new ColorSelectionMenu(entity).open((Player) event.getWhoClicked()); event.setCancelled(true); }, 0); }
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { RedProtect.get().logger.debug("RPGlobalListener - Is CreatureSpawnEvent event! Cancelled? " + event.isCancelled()); if (event.isCancelled()) { return; } Entity e = event.getEntity(); if (e == null) { return; } Location l = event.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l); if (r != null){ return; } if (e instanceof Wither && event.getSpawnReason().equals(SpawnReason.BUILD_WITHER) && !RPConfig.getGlobalFlagBool(e.getWorld().getName()+".spawn-wither")){ event.setCancelled(true); return; } if (e instanceof Monster && !RPConfig.getGlobalFlagBool(e.getWorld().getName()+".spawn-monsters")) { if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CHUNK_GEN) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.DEFAULT)) { event.setCancelled(true); return; } } if ((e instanceof Animals || e instanceof Villager || e instanceof Golem) && !RPConfig.getGlobalFlagBool(e.getWorld().getName()+".spawn-passives")) { if (event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.CHUNK_GEN) || event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.DEFAULT)) { event.setCancelled(true); } } }
/** * Initializes the game state, and sets up defaults */ public void startGame() { Bukkit.getPluginManager().callEvent(new GameStartEvent()); final String MAPS_PATH = PLUGIN.getConfiguration().getSettingsConfig().getString("MapsPath"); final String ARENAS_PATH = PLUGIN.getConfiguration().getSettingsConfig().getString("ArenasPath"); this.mapSelection = VOTE_MANAGER.getWinningMap(); this.gameFile = new GameFile(ARENAS_PATH, mapSelection + ".yml"); this.arenaWorld = Bukkit.createWorld(new WorldCreator(MAPS_PATH + gameFile.getConfig().getString("World"))); this.arenaWorld.setSpawnFlags(false, false); this.arenaWorld.setGameRuleValue("doMobSpawning", "false"); this.spawns = gameFile.getLocations(arenaWorld, "Spawns"); this.doors = gameFile.getDoors(arenaWorld); this.checkpoints = gameFile.getCheckpoints(arenaWorld); this.nukeRoom = gameFile.getLocation(arenaWorld, "Nukeroom"); this.handleStart(); VOTE_MANAGER.resetVotes(); Bukkit.getConsoleSender().sendMessage(Utils.color("&6Start game method")); // Clear entities for (Entity entity : arenaWorld.getEntities()) { if (!(entity instanceof Player) && (entity instanceof Animals || entity instanceof Monster)) { entity.remove(); } } }
/** * Projects animals on beacons * @param event */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onEntityDamage(final EntityDamageByEntityEvent event) { World world = event.getEntity().getWorld(); if (!world.equals(getBeaconzWorld())) { return; } //getLogger().info("DEBUG: " + event.getEventName()); if (!(event.getEntity() instanceof Animals)) { return; } //getLogger().info("DEBUG: animals being hurt by " + event.getDamager()); // Check beacon defense BeaconObj beacon = getRegister().getBeaconAt(event.getEntity().getLocation()); if (beacon != null && beacon.getOwnership() != null) { //getLogger().info("DEBUG: beacon found"); if (event.getDamager() instanceof Player) { //getLogger().info("DEBUG: damager is player"); // Prevent enemies from hurting animals on beacons Player player = (Player)event.getDamager(); Game game = getGameMgr().getGame(player.getLocation()); if (game != null) { Team team = game.getScorecard().getTeam(player); if (!beacon.getOwnership().equals(team)) { player.sendMessage(ChatColor.RED + Lang.triangleThisBelongsTo.replace("[team]", beacon.getOwnership().getDisplayName())); event.setCancelled(true); return; } } } else { //getLogger().info("DEBUG: Damager is not player"); event.setCancelled(true); } } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onMobSpawn(final CreatureSpawnEvent e) { if (DEBUG) { getLogger().info(e.getEventName()); } // If not at spawn, return, or if grid is not loaded yet. if (!getGameMgr().getLobby().contains(e.getLocation())) { return; } if (!Settings.allowLobbyEggs && (e.getSpawnReason().equals(SpawnReason.SPAWNER_EGG) || e.getSpawnReason().equals(SpawnReason.EGG))) { e.setCancelled(true); return; } // Deal with mobs if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) { if (!Settings.allowLobbyMobSpawn) { // Mobs not allowed to spawn e.setCancelled(true); return; } } // If animals can spawn, check if the spawning is natural, or // egg-induced if (e.getEntity() instanceof Animals) { if (!Settings.allowLobbyAnimalSpawn) { // Animals are not allowed to spawn e.setCancelled(true); return; } } }
public CreatureType getCreatureType(LivingEntity creature) { if (creature instanceof Monster || creature instanceof WaterMob || creature instanceof Slime || creature instanceof Ghast) { return CreatureType.MONSTER; } else if (creature instanceof Animals) { return CreatureType.ANIMAL; } else if (creature instanceof Villager) { return CreatureType.VILLAGER; } else if (creature instanceof Golem) { return CreatureType.GOLEM; } return CreatureType.UNKNOWN; }
@EventHandler public void onFeedEvent(PlayerInteractEntityEvent event) { Player player = event.getPlayer(); if (player == null || event.isCancelled() || !plugin.isSkyWorld(player.getWorld())) { return; // Bail out, we don't care } if (Animals.class.isAssignableFrom(event.getRightClicked().getType().getEntityClass()) && player.getItemInHand() != null) { if (isFodder(event.getRightClicked(), player.getItemInHand())) { checkLimits(event, event.getRightClicked().getType(), player.getLocation()); if (event.isCancelled()) { plugin.notifyPlayer(player, tr("\u00a7cYou have reached your spawn-limit for your island.")); } } } }
private void cancelMobDamage(EntityDamageByEntityEvent event) { if (killAnimalsEnabled && event.getEntity() instanceof Animals) { event.setCancelled(true); } else if (killMonstersEnabled && event.getEntity() instanceof Monster) { event.setCancelled(true); } }
/** * On creature spawn. * * @param event the event */ @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onCreatureSpawn(CreatureSpawnEvent event) { IDummyLand land = Factoid.getThisPlugin().iLands().getLandOrOutsideArea(event.getEntity().getLocation()); if ((event.getEntity() instanceof Animals && land.getFlagAndInherit(FlagList.ANIMAL_SPAWN.getFlagType()).getValueBoolean() == false) || ((event.getEntity() instanceof Monster || event.getEntity() instanceof Slime || event.getEntity() instanceof Flying) && land.getFlagAndInherit(FlagList.MOB_SPAWN.getFlagType()).getValueBoolean() == false)) { event.setCancelled(true); } }
public void handleInteract(Stable stable, Player player, Tameable animal) { final Animals a = (Animals) animal; // Storing location new LangString("command.teleport.location-saved").send(player); StableMaster.teleportChunk.add(a.getLocation().getChunk()); StableMaster.commandQueue.put(player, this); teleportQueue.put(player, a); }
public void handleInteract(Stable stable, Player player, Tameable animal) { OfflinePlayer newOwner = giveQueue.get(player); removeFromQueue(player); if (animal instanceof AbstractHorse) { AbstractHorse horse = (AbstractHorse) animal; Stable newStable = StableMaster.getStable(newOwner); stable.removeHorse(horse); newStable.addHorse(horse); } animal.setOwner(newOwner); new LangString("command.give.given", getAnimal(((Animals) animal).getType()), newOwner.getName()).send(player); }
public void handleInteract(Stable stable, Player player, Tameable animal) { final Animals a = (Animals) animal; final ConfigurationSection config = StableMaster.getPlugin().getConfig().getConfigurationSection("command.rename"); String name = renameQueue.get(player); removeFromQueue(player); a.setCustomName(name); a.setCustomNameVisible(config.getBoolean("name-always-visible")); new LangString("command.rename.renamed", getAnimal(a.getType()), name).send(player); }
@Test public void checkEntities() { List<Entity> entities = world.getEntities(); // All of the entities should be an instance of Entity assertEquals(14, filter(entities, instanceOf(Entity.class)).size()); assertEquals(12, filter(entities, instanceOf(LivingEntity.class)).size()); assertEquals(7, filter(entities, instanceOf(HumanEntity.class)).size()); assertEquals(5, filter(entities, instanceOf(Player.class)).size()); assertEquals(2, filter(entities, instanceOf(Animals.class)).size()); }
@Test public void checkEntitiesByClassCounts() { // This is the same as above actually assertEquals(14, world.getEntitiesByClass(Entity.class).size()); assertEquals(12, world.getEntitiesByClass(LivingEntity.class).size()); assertEquals(7, world.getEntitiesByClass(HumanEntity.class).size()); assertEquals(5, world.getEntitiesByClass(Player.class).size()); assertEquals(2, world.getEntitiesByClass(Animals.class).size()); }
@Test public void checkEntitiesByClassType() { // Test result types checkEntityTypes(world.getEntitiesByClass(Entity.class), Entity.class); checkEntityTypes(world.getEntitiesByClass(LivingEntity.class), LivingEntity.class); checkEntityTypes(world.getEntitiesByClass(HumanEntity.class), HumanEntity.class); checkEntityTypes(world.getEntitiesByClass(Player.class), Player.class); checkEntityTypes(world.getEntitiesByClass(Animals.class), Animals.class); }
/** * Restore region from disk. * * @param loadSpeed The speed that the region is loaded and restored. * * @return A future to receive the results of the restore operation. * * @throws IOException */ public IFuture restoreData(LoadSpeed loadSpeed) throws IOException { Collection<IChunkCoords> chunks = getChunkCoords(); if (chunks.size() == 0) return new FutureAgent().cancel("No chunks to restore."); if (isSaving()) return new FutureAgent().cancel("Region is still saving."); if (isRestoring()) return new FutureAgent().cancel("Region is still restoring."); if (!canRestore()) return new FutureAgent().cancel("Region cannot restore without restore files."); _isRestoring = true; onPreRestore(); removeEntities(Item.class, Monster.class, Animals.class); removeEntities(SerializableFurnitureEntity.getFurnitureClasses()); IRegionFileData fileData = new WorldBuilder(getPlugin(), getWorld()); return getFileFormat() .getLoader(this, getFileFactory()) .load(LoadType.MISMATCHED, loadSpeed, fileData) .onStatus(new FutureSubscriber() { @Override public void on(FutureStatus status, @Nullable CharSequence message) { _isRestoring = false; onRestoreComplete(); } }); }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) { if (DEBUG) { plugin.getLogger().info("1.9 lingering potion damage " + e.getEventName()); plugin.getLogger().info("1.9 lingering potion entity = " + e.getEntity()); plugin.getLogger().info("1.9 lingering potion entity type = " + e.getEntityType()); plugin.getLogger().info("1.9 lingering potion cause = " + e.getCause()); plugin.getLogger().info("1.9 lingering potion damager = " + e.getDamager()); } if (!Util.inWorld(e.getEntity().getLocation())) { return; } if (e.getEntity() == null || e.getEntity().getUniqueId() == null) { return; } if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) { UUID attacker = thrownPotions.get(e.getDamager().getEntityId()); // Self damage if (attacker.equals(e.getEntity().getUniqueId())) { if (DEBUG) plugin.getLogger().info("DEBUG: Self damage from lingering potion!"); return; } Island island = plugin.getIslands().getIslandAt(e.getEntity().getLocation()); boolean inNether = false; if (e.getEntity().getWorld().equals(IslandWorld.getNetherWorld())) { inNether = true; } // Monsters being hurt if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime || e.getEntity() instanceof Squid) { // Normal island check if (island != null && island.getMembers().contains(attacker)) { // Members always allowed return; } if (actionAllowed(attacker, e.getEntity().getLocation(), SettingsFlag.HURT_MONSTERS)) { return; } // Not allowed e.setCancelled(true); return; } // Mobs being hurt if (e.getEntity() instanceof Animals || e.getEntity() instanceof IronGolem || e.getEntity() instanceof Snowman || e.getEntity() instanceof Villager) { if (island != null && (island.getFlag(SettingsFlag.HURT_ANIMALS) || island.getMembers().contains(attacker))) { return; } if (DEBUG) plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking"); e.setCancelled(true); return; } // Establish whether PVP is allowed or not. boolean pvp = false; if ((inNether && island != null && island.getFlag(SettingsFlag.PVP_NETHER) || (!inNether && island != null && island.getFlag(SettingsFlag.PVP_OVERWORLD)))) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); pvp = true; } // Players being hurt PvP if (e.getEntity() instanceof Player) { if (!pvp) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed"); e.setCancelled(true); } } } }
@EventHandler public void onSpawn(EntitySpawnEvent e) { if (e.getEntity() instanceof Animals) e.setCancelled(true); }
public boolean isAnimal(Entity e){ return e instanceof Animals; }