org.bukkit.entity.Monster Java Examples
The following examples show how to use
org.bukkit.entity.Monster.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LivingEntityShopListener.java From Shopkeepers with GNU General Public License v3.0 | 6 votes |
@EventHandler(ignoreCancelled = true) void onEntityDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); // block damaging of shopkeepers if (plugin.isShopkeeper(entity)) { event.setCancelled(true); if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent evt = (EntityDamageByEntityEvent) event; if (evt.getDamager() instanceof Monster) { Monster monster = (Monster) evt.getDamager(); // reset target, future targeting should get prevented somewhere else: if (entity.equals(monster.getTarget())) { monster.setTarget(null); } } } } }
Example #2
Source File: MobListener.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onChunkLoad(ChunkLoadEvent event) { for (Entity e : event.getChunk().getEntities()) { if (e instanceof Monster) { e.remove(); return; } if (e instanceof IronGolem) { e.remove(); return; } } }
Example #3
Source File: EntityRemoveListener.java From StackMob-3 with GNU General Public License v3.0 | 6 votes |
private void cleanupEntity(Entity entity) { // Check if entity is a mob, since they despawn on chunk unload. if (entity instanceof Monster) { sm.getCache().remove(entity.getUniqueId()); StackTools.removeSize(entity); return; } // Add to storage if (StackTools.hasValidData(entity)) { int stackSize = StackTools.getSize(entity); StackTools.removeSize(entity); if (stackSize <= 1 && stackSize != GlobalValues.NO_STACKING) { return; } if (sm.getCustomConfig().getBoolean("remove-chunk-unload")) { entity.remove(); return; } sm.getCache().put(entity.getUniqueId(), stackSize); } }
Example #4
Source File: LimitLogic.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
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; }
Example #5
Source File: EntityEventHandler.java From GriefDefender with MIT License | 6 votes |
private boolean isEntityProtected(Entity entity) { if (entity.getType() == null) { if (entity instanceof Monster) { return false; } return true; } // ignore monsters final String name = entity.getType().getName() == null ? entity.getType().name().toLowerCase() : entity.getType().getName(); final GDEntityType type = EntityTypeRegistryModule.getInstance().getById(name).orElse(null); if (type == null) { return true; } final String creatureType = type.getEnumCreatureTypeId(); if (creatureType == null) { return true; } if (creatureType.contains("monster")) { return false; } return true; }
Example #6
Source File: EntityCustomNbtInjectorTest.java From Item-NBT-API with MIT License | 6 votes |
@Override public void test() throws Exception { if(!NBTInjector.isInjected())return; if (!Bukkit.getWorlds().isEmpty()) { World world = Bukkit.getWorlds().get(0); try { if (!world.getEntitiesByClasses(Animals.class, Monster.class).isEmpty()) { Entity ent = world.getEntitiesByClasses(Animals.class, Monster.class).iterator().next(); ent = NBTInjector.patchEntity(ent); NBTCompound comp = NBTInjector.getNbtData(ent); comp.setString("Hello", "World"); NBTEntity nbtent = new NBTEntity(ent); if (!nbtent.toString().contains("__extraData:{Hello:\"World\"}")) { throw new NbtApiException("Custom Data did not save to the Entity!"); } comp.removeKey("Hello"); } } catch (Exception ex) { throw new NbtApiException("Wasn't able to use NBTEntities!", ex); } } }
Example #7
Source File: EntityCustomNbtPersistentTest.java From Item-NBT-API with MIT License | 6 votes |
@Override public void test() throws Exception { if(MinecraftVersion.getVersion().getVersionId() < MinecraftVersion.MC1_14_R1.getVersionId())return; if (!Bukkit.getWorlds().isEmpty()) { World world = Bukkit.getWorlds().get(0); try { if (!world.getEntitiesByClasses(Animals.class, Monster.class).isEmpty()) { Entity ent = world.getEntitiesByClasses(Animals.class, Monster.class).iterator().next(); NBTEntity nbtEnt = new NBTEntity(ent); NBTCompound comp = nbtEnt.getPersistentDataContainer(); comp.setString("Hello", "World"); NBTEntity nbtent = new NBTEntity(ent); if (!nbtent.toString().contains("Hello:\"World\"")) { throw new NbtApiException("Custom Data did not save to the Entity!"); } comp.removeKey("Hello"); } } catch (Exception ex) { throw new NbtApiException("Wasn't able to use NBTEntities!", ex); } } }
Example #8
Source File: WorldManager.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
/** * Removes all unnamed {@link Monster}'s at the given {@link Location}. * @param target Location to remove unnamed monsters. */ public void removeCreatures(@Nullable final Location target) { if (!Settings.island_removeCreaturesByTeleport || target == null || target.getWorld() == null) { return; } final int px = target.getBlockX(); final int py = target.getBlockY(); final int pz = target.getBlockZ(); for (int x = -1; x <= 1; ++x) { for (int z = -1; z <= 1; ++z) { Chunk chunk = target.getWorld().getChunkAt( new Location(target.getWorld(), (px + x * 16), py, (pz + z * 16))); Arrays.stream(chunk.getEntities()) .filter(entity -> entity instanceof Monster) .filter(entity -> entity.getCustomName() == null) .forEach(Entity::remove); } } }
Example #9
Source File: LimitLogic.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
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; }
Example #10
Source File: GridManager.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * Removes monsters around location l * * @param l location */ public void removeMobs(final Location l) { if (!inWorld(l)) { return; } //plugin.getLogger().info("DEBUG: removing mobs"); // Don't remove mobs if at spawn if (this.isAtSpawn(l)) { //plugin.getLogger().info("DEBUG: at spawn!"); return; } final int px = l.getBlockX(); final int py = l.getBlockY(); final int pz = l.getBlockZ(); for (int x = -1; x <= 1; x++) { for (int z = -1; z <= 1; z++) { final Chunk c = l.getWorld().getChunkAt(new Location(l.getWorld(), px + x * 16, py, pz + z * 16)); if (c.isLoaded()) { for (final Entity e : c.getEntities()) { //plugin.getLogger().info("DEBUG: " + e.getType()); // Don't remove if the entity is an NPC or has a name tag if (e.getCustomName() != null || e.hasMetadata("NPC")) continue; if (e instanceof Monster && !Settings.mobWhiteList.contains(e.getType())) { e.remove(); } } } } } }
Example #11
Source File: AcidTask.java From askyblock with GNU General Public License v2.0 | 5 votes |
/** * Runs repeating tasks to deliver acid damage to mobs, etc. * @param plugin - ASkyBlock plugin object - ASkyBlock plugin */ public AcidTask(final ASkyBlock plugin) { this.plugin = plugin; // Initialize water item list itemsInWater = new HashSet<>(); // This part will kill monsters if they fall into the water // because it // is acid if (Settings.mobAcidDamage > 0D || Settings.animalAcidDamage > 0D) { plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, () -> { List<Entity> entList = ASkyBlock.getIslandWorld().getEntities(); for (Entity current : entList) { if (plugin.isOnePointEight() && current instanceof Guardian) { // Guardians are immune to acid too continue; } if ((current instanceof Monster) && Settings.mobAcidDamage > 0D) { if ((current.getLocation().getBlock().getType() == Material.WATER) || (current.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) { ((Monster) current).damage(Settings.mobAcidDamage); } } else if ((current instanceof Animals) && Settings.animalAcidDamage > 0D) { if ((current.getLocation().getBlock().getType() == Material.WATER) || (current.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) { if (!current.getType().equals(EntityType.CHICKEN) || Settings.damageChickens) { ((Animals) current).damage(Settings.animalAcidDamage); } } } } }, 0L, 20L); } runAcidItemRemovalTask(); }
Example #12
Source File: GriefEvents.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private void cancelMobDamage(EntityDamageByEntityEvent event) { if (killAnimalsEnabled && event.getEntity() instanceof Animals) { event.setCancelled(true); } else if (killMonstersEnabled && event.getEntity() instanceof Monster) { event.setCancelled(true); } }
Example #13
Source File: GameArena.java From ZombieEscape with GNU General Public License v2.0 | 5 votes |
/** * 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(); } } }
Example #14
Source File: BukkitFightListener.java From Parties with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onEntityDieKill(EntityDeathEvent event) { if (BukkitConfigParties.KILLS_ENABLE && event.getEntity().getKiller() != null) { Player killer = event.getEntity().getKiller(); PartyPlayerImpl ppKiller = plugin.getPlayerManager().getPlayer(killer.getUniqueId()); if (!ppKiller.getPartyName().isEmpty()) { PartyImpl party = plugin.getPartyManager().getParty(ppKiller.getPartyName()); boolean gotKill = false; if (BukkitConfigParties.KILLS_MOB_HOSTILE && event.getEntity() instanceof Monster) gotKill = true; else if (BukkitConfigParties.KILLS_MOB_NEUTRAL && event.getEntity() instanceof Animals) gotKill = true; else if (BukkitConfigParties.KILLS_MOB_PLAYERS && event.getEntity() instanceof Player) gotKill = true; if (gotKill) { party.setKills(party.getKills() + 1); party.updateParty(); plugin.getLoggerManager().logDebug(PartiesConstants.DEBUG_KILL_ADD .replace("{party}", party.getName()) .replace("{player}", killer.getName()), true); } } } }
Example #15
Source File: TargetEvent.java From StackMob-3 with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onEntityTarget(EntityTargetLivingEntityEvent event) { if(event.getTarget() instanceof Player && event.getEntity() instanceof Monster){ if(StackTools.hasSizeMoreThanOne(event.getEntity())){ if(!sm.getCustomConfig().getStringList("no-targeting.types-blacklist") .contains(event.getEntityType().toString())) { event.setCancelled(true); } } } }
Example #16
Source File: StackTools.java From StackMob-3 with GNU General Public License v3.0 | 5 votes |
public static void setSize(Entity entity, int newSize){ currentEntities.put(entity.getUniqueId(), newSize); if (!(entity instanceof Monster)) { if (newSize <= 1 && newSize != GlobalValues.NO_STACKING) { persistentEntities.remove(entity.getUniqueId()); return; } persistentEntities.add(entity.getUniqueId()); } }
Example #17
Source File: LifeskillingListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
/** * Killing mobs gives enhancement stone. * * @param e */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onKilling(EntityDeathEvent e) { // If the killed entity is a monster if (e.getEntity() instanceof Monster) { if (e.getEntity().getKiller() instanceof Player) { Player player = e.getEntity().getKiller(); if (DropManager.killingChance > random.nextDouble()) { DropManager.randomDrop(player, DropManager.killingLootTable); } } } }
Example #18
Source File: EntityListener.java From Guilds with MIT License | 5 votes |
/** * Handles extra XP dropped from mobs * * @param event */ @EventHandler public void onMobDeath(EntityDeathEvent event) { if (!(event.getEntity() instanceof Monster)) return; Monster monster = (Monster) event.getEntity(); Player killer = monster.getKiller(); if (killer == null) return; Guild guild = guildHandler.getGuild(killer); if (guild == null) { return; } double xp = event.getDroppedExp(); double multiplier = guild.getTier().getMobXpMultiplier(); event.setDroppedExp((int) Math.round(xp * multiplier)); }
Example #19
Source File: EntityUtilTest.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
@Test public void testGetEntity() { List<Entity> testList = new ArrayList<>(); ArmorStand fakeArmorStand = mock(ArmorStand.class); Cow fakeCow = mock(Cow.class); Evoker fakeEvoker = mock(Evoker.class); Guardian fakeGuardian = mock(Guardian.class); Pig fakePig = mock(Pig.class); PigZombie fakePigZombie = mock(PigZombie.class); Pillager fakePillager = mock(Pillager.class); Sheep fakeSheep = mock(Sheep.class); Skeleton fakeSkeleton = mock(Skeleton.class); Turtle fakeTurtle = mock(Turtle.class); Villager fakeVillager = mock(Villager.class); WanderingTrader fakeWanderingTrader = mock(WanderingTrader.class); testList.add(fakeArmorStand); testList.add(fakeCow); testList.add(fakeEvoker); testList.add(fakeGuardian); testList.add(fakePig); testList.add(fakePigZombie); testList.add(fakePillager); testList.add(fakeSheep); testList.add(fakeSkeleton); testList.add(fakeTurtle); testList.add(fakeVillager); testList.add(fakeWanderingTrader); List<Sheep> sheepList = EntityUtil.getEntity(testList, Sheep.class); assertEquals(1, sheepList.size()); assertEquals(fakeSheep, sheepList.get(0)); List<Animals> animalsList = EntityUtil.getAnimals(testList); assertEquals(4, animalsList.size()); assertTrue(animalsList.contains(fakeCow)); assertTrue(animalsList.contains(fakePig)); assertTrue(animalsList.contains(fakeSheep)); assertTrue(animalsList.contains(fakeTurtle)); List<Monster> monsterList = EntityUtil.getMonsters(testList); assertEquals(5, monsterList.size()); assertTrue(monsterList.contains(fakeEvoker)); assertTrue(monsterList.contains(fakeGuardian)); assertTrue(monsterList.contains(fakePigZombie)); assertTrue(monsterList.contains(fakePillager)); assertTrue(monsterList.contains(fakeSkeleton)); List<NPC> npcList = EntityUtil.getNPCs(testList); assertEquals(2, npcList.size()); assertTrue(npcList.contains(fakeVillager)); assertTrue(npcList.contains(fakeWanderingTrader)); }
Example #20
Source File: MobkillingTaskType.java From Quests with MIT License | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onMobKill(EntityDeathEvent event) { Player killer = event.getEntity().getKiller(); //The killer is a player Entity mob = event.getEntity(); if (mob == null || mob instanceof Player) { return; } if (killer == null) { return; } QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(killer.getUniqueId(), true); QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile(); for (Quest quest : super.getRegisteredQuests()) { if (questProgressFile.hasStartedQuest(quest)) { QuestProgress questProgress = questProgressFile.getQuestProgress(quest); for (Task task : quest.getTasksOfType(super.getType())) { TaskProgress taskProgress = questProgress.getTaskProgress(task.getId()); if (taskProgress.isCompleted()) { continue; } boolean hostilitySpecified = false; boolean hostile = false; if (task.getConfigValue("hostile") != null) { hostilitySpecified = true; hostile = (boolean) task.getConfigValue("hostile"); } if (hostilitySpecified) { if (!hostile && !(mob instanceof Animals)) { continue; } else if (hostile && !(mob instanceof Monster)) { continue; } } int mobKillsNeeded = (int) task.getConfigValue("amount"); int progressKills; if (taskProgress.getProgress() == null) { progressKills = 0; } else { progressKills = (int) taskProgress.getProgress(); } taskProgress.setProgress(progressKills + 1); if (((int) taskProgress.getProgress()) >= mobKillsNeeded) { taskProgress.setCompleted(true); } } } } }
Example #21
Source File: IslandGuard1_9.java From askyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onLingeringPotionDamage(final EntityDamageByEntityEvent e) { if (!IslandGuard.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())) { return; } Island island = plugin.getGrid().getIslandAt(e.getEntity().getLocation()); boolean inNether = false; if (e.getEntity().getWorld().equals(ASkyBlock.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.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker))) { return; } e.setCancelled(true); return; } // Establish whether PVP is allowed or not. boolean pvp = false; if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) { pvp = true; } // Players being hurt PvP if (e.getEntity() instanceof Player) { if (pvp) { } else { e.setCancelled(true); } } } }
Example #22
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 4 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onFishing(final PlayerFishEvent e) { if (DEBUG) { plugin.getLogger().info("Player fish event " + e.getEventName()); plugin.getLogger().info("Player fish event " + e.getCaught()); } if (e.getCaught() == null) return; Player p = e.getPlayer(); if (!inWorld(p)) { return; } if (p.isOp() || VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.bypassprotect")) { // You can do anything if you are Op of have the bypass return; } // Handle rods Island island = plugin.getGrid().getProtectedIslandAt(e.getCaught().getLocation()); // PVP check if (e.getCaught() instanceof Player) { // Check if this is the player who is holding the rod if (e.getCaught().equals(e.getPlayer())) { if (DEBUG) plugin.getLogger().info("DEBUG: player cught themselves!"); return; } if (island == null && (e.getCaught().getWorld().getEnvironment().equals(Environment.NORMAL) && !Settings.defaultWorldSettings.get(SettingsFlag.PVP)) || ((e.getCaught().getWorld().getEnvironment().equals(Environment.NETHER) && !Settings.defaultWorldSettings.get(SettingsFlag.NETHER_PVP)))) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).targetInNoPVPArea); e.setCancelled(true); e.getHook().remove(); return; } if (island != null && ((e.getCaught().getWorld().getEnvironment().equals(Environment.NORMAL) && !island.getIgsFlag(SettingsFlag.PVP)) || (e.getCaught().getWorld().getEnvironment().equals(Environment.NETHER) && !island.getIgsFlag(SettingsFlag.NETHER_PVP)))) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).targetInNoPVPArea); e.setCancelled(true); e.getHook().remove(); return; } } if (!plugin.getGrid().playerIsOnIsland(e.getPlayer())) { if (e.getCaught() instanceof Animals) { if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MOBS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected); e.setCancelled(true); e.getHook().remove(); return; } if (island != null) { if ((!island.getIgsFlag(SettingsFlag.HURT_MOBS) && !island.getMembers().contains(p.getUniqueId()))) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected); e.setCancelled(true); e.getHook().remove(); return; } } } // Monster protection if (e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) { if (island == null && !Settings.defaultWorldSettings.get(SettingsFlag.HURT_MONSTERS)) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected); e.setCancelled(true); e.getHook().remove(); return; } if (island != null) { if ((!island.getIgsFlag(SettingsFlag.HURT_MONSTERS) && !island.getMembers().contains(p.getUniqueId()))) { Util.sendMessage(e.getPlayer(), ChatColor.RED + plugin.myLocale(e.getPlayer().getUniqueId()).islandProtected); e.setCancelled(true); e.getHook().remove(); } } } } }
Example #23
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Checks for splash damage. If there is any to any affected entity and it's not allowed, it won't work on any of them. * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onSplashPotionSplash(final PotionSplashEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); plugin.getLogger().info("splash entity = " + e.getEntity()); plugin.getLogger().info("splash entity type = " + e.getEntityType()); plugin.getLogger().info("splash affected entities = " + e.getAffectedEntities()); //plugin.getLogger().info("splash hit entity = " + e.getHitEntity()); } if (!IslandGuard.inWorld(e.getEntity().getLocation())) { return; } // Try to get the shooter Projectile projectile = e.getEntity(); if (DEBUG) plugin.getLogger().info("splash shooter = " + projectile.getShooter()); if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) { Player attacker = (Player)projectile.getShooter(); // Run through all the affected entities for (LivingEntity entity: e.getAffectedEntities()) { if (DEBUG) plugin.getLogger().info("DEBUG: affected splash entity = " + entity); // Self damage if (attacker.equals(entity)) { if (DEBUG) plugin.getLogger().info("DEBUG: Self damage from splash potion!"); continue; } Island island = plugin.getGrid().getIslandAt(entity.getLocation()); boolean inNether = false; if (entity.getWorld().equals(ASkyBlock.getNetherWorld())) { inNether = true; } // Monsters being hurt if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) { // Normal island check if (island != null && island.getMembers().contains(attacker.getUniqueId())) { // Members always allowed continue; } if (actionAllowed(attacker, entity.getLocation(), SettingsFlag.HURT_MONSTERS)) { continue; } // Not allowed Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected); e.setCancelled(true); return; } // Mobs being hurt if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman || entity instanceof Villager) { if (island != null && (island.getIgsFlag(SettingsFlag.HURT_MOBS) || island.getMembers().contains(attacker.getUniqueId()))) { continue; } if (DEBUG) plugin.getLogger().info("DEBUG: Mobs not allowed to be hurt. Blocking"); Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).islandProtected); e.setCancelled(true); return; } // Establish whether PVP is allowed or not. boolean pvp = false; if ((inNether && island != null && island.getIgsFlag(SettingsFlag.NETHER_PVP) || (!inNether && island != null && island.getIgsFlag(SettingsFlag.PVP)))) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); pvp = true; } // Players being hurt PvP if (entity instanceof Player) { if (pvp) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); } else { if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed"); Util.sendMessage(attacker, ChatColor.RED + plugin.myLocale(attacker.getUniqueId()).targetInNoPVPArea); e.setCancelled(true); return; } } } } }
Example #24
Source File: EntityLimits.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Prevents mobs spawning naturally at spawn or in an island * * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onNaturalMobSpawn(final CreatureSpawnEvent e) { // if grid is not loaded yet, return. if (plugin.getGrid() == null) { return; } // If not in the right world, return if (!IslandGuard.inWorld(e.getEntity())) { return; } // Deal with natural spawning if (e.getSpawnReason().equals(SpawnReason.NATURAL) || e.getSpawnReason().equals(SpawnReason.CHUNK_GEN) || e.getSpawnReason().equals(SpawnReason.DEFAULT) || e.getSpawnReason().equals(SpawnReason.MOUNT) || e.getSpawnReason().equals(SpawnReason.JOCKEY) || e.getSpawnReason().equals(SpawnReason.NETHER_PORTAL)) { if (e.getEntity() instanceof Monster || e.getEntity() instanceof Slime) { if (!actionAllowed(e.getLocation(), SettingsFlag.MONSTER_SPAWN)) { if (DEBUG3) plugin.getLogger().info("Natural monster spawn cancelled."); // Mobs not allowed to spawn e.setCancelled(true); return; } } else if (e.getEntity() instanceof Animals) { if (!actionAllowed(e.getLocation(), SettingsFlag.MOB_SPAWN)) { // Animals are not allowed to spawn if (DEBUG2) plugin.getLogger().info("Natural animal spawn cancelled."); e.setCancelled(true); return; } } } if (DEBUG2) { plugin.getLogger().info("Mob spawn allowed " + e.getEventName()); plugin.getLogger().info(e.getSpawnReason().toString()); plugin.getLogger().info(e.getEntityType().toString()); } }