/** * Checks if an Entity of the specified type is allowed to be a leash holder. * * @param type type of the entity which wishes to become a leash holder * @return if the type is allowed as a leash holder true, otherwise false */ public static boolean isAllowedLeashHolder(EntityType type) { return !(EntityType.ENDER_DRAGON.equals(type) || EntityType.WITHER.equals(type) || EntityType.PLAYER.equals(type) || EntityType.BAT.equals(type)); }
if (EntityType.LEASH_HITCH.equals(leashHolder.getType()) && leashHolder.leashedEntities.size() == 1) { leashHolder.remove();
/** * Prevent TNT damage from explosion * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onExplosion(final EntityExplodeEvent e) { // Remove any blocks from the explosion list if they are inside a protected area and if the entity was a TNT if (e.getEntity() != null && e.getEntityType().equals(EntityType.PRIMED_TNT) && e.blockList().removeIf(b -> getIslands().getProtectedIslandAt(b.getLocation()).map(i -> !i.isAllowed(Flags.TNT)).orElse(false))) { // If any were removed, then prevent damage too e.setCancelled(true); } }
@EventHandler public void onEntitySpawn(CreatureSpawnEvent ese) { if (BedwarsRel.getInstance().getGameManager() == null) { return; } if (ese.getLocation() == null) { return; } if (ese.getLocation().getWorld() == null) { return; } Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(ese.getLocation()); if (game == null) { return; } if (game.getState() == GameState.STOPPED) { return; } if (ese.getEntityType().equals(EntityType.CREEPER) || ese.getEntityType().equals(EntityType.CAVE_SPIDER) || ese.getEntityType().equals(EntityType.SPIDER) || ese.getEntityType().equals(EntityType.ZOMBIE) || ese.getEntityType().equals(EntityType.SKELETON) || ese.getEntityType().equals(EntityType.SILVERFISH)) { ese.setCancelled(true); } }
@EventHandler public void onEntitySpawn(CreatureSpawnEvent ese) { if (BedwarsRel.getInstance().getGameManager() == null) { return; } if (ese.getLocation() == null) { return; } if (ese.getLocation().getWorld() == null) { return; } Game game = BedwarsRel.getInstance().getGameManager().getGameByLocation(ese.getLocation()); if (game == null) { return; } if (game.getState() == GameState.STOPPED) { return; } if (ese.getEntityType().equals(EntityType.CREEPER) || ese.getEntityType().equals(EntityType.CAVE_SPIDER) || ese.getEntityType().equals(EntityType.SPIDER) || ese.getEntityType().equals(EntityType.ZOMBIE) || ese.getEntityType().equals(EntityType.SKELETON) || ese.getEntityType().equals(EntityType.SILVERFISH)) { ese.setCancelled(true); } }
switch (type) { case WOLF: if (entity.getType().equals(EntityType.WOLF) && checkConditions(playerID)) { playerData.subtract(); if (entity.getType().equals(EntityType.OCELOT) && checkConditions(playerID)) { playerData.subtract(); if (entity.getType().equals(EntityType.HORSE) && checkConditions(playerID)) { playerData.subtract();
/** * Handles placing items into ItemFrames * @param e - event */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerHitEntity(PlayerInteractEntityEvent e) { if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) { checkIsland(e, e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS); } }
@EventHandler void onInteract(PlayerInteractEntityEvent event) { if (event.getRightClicked().getType().equals(EntityType.VILLAGER)) { event.setCancelled(true);
/** * Prevents hitching * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerLeashHitch(final HangingPlaceEvent e) { if (e.getEntity() != null && e.getEntity().getType().equals(EntityType.LEASH_HITCH)) { checkIsland(e, e.getEntity().getLocation(), Flags.LEASH); } }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onSilurianSpawn(CreatureSpawnEvent event) { if (!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER)) { return; } if (!event.getLocation().getWorld().getName().equals("Siluria")) { return; } if (!event.getEntity().getType().equals(EntityType.SKELETON)) { return; } LivingEntity le = event.getEntity(); // it's a Silurian - disguise it! twaAPI.setSilurianEquipment(le, false); } }
/** * This handles end dragon spawning prevention * * @param e - event * @return true if dragon can spawn, false if not */ @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public boolean onDragonSpawn(CreatureSpawnEvent e) { if (!e.getEntityType().equals(EntityType.ENDER_DRAGON) || plugin.getIWM().isDragonSpawn(e.getEntity().getWorld())) { return true; } e.getEntity().setHealth(0); e.getEntity().remove(); e.setCancelled(true); return false; }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onDalekSpawn(CreatureSpawnEvent event) { if (!event.getSpawnReason().equals(SpawnReason.SPAWNER)) { return; } if (!event.getLocation().getWorld().getName().equals("Skaro")) { return; } if (!event.getEntity().getType().equals(EntityType.SKELETON)) { return; } LivingEntity le = event.getEntity(); // it's a Dalek - disguise it! twaAPI.setDalekEquipment(le); if (plugin.getPlanetsConfig().getBoolean("planets.Skaro.flying_daleks") && r.nextInt(100) < 10) { // make the Dalek fly EntityEquipment ee = le.getEquipment(); ee.setChestplate(new ItemStack(Material.ELYTRA, 1)); // teleport them straight up le.teleport(le.getLocation().add(0.0d, 20.0d, 0.0d)); plugin.getTardisHelper().setFallFlyingTag(le); } } }
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent ev) { if (!ev.getCause().equals(DamageCause.PROJECTILE)) { return; } if (!ev.getEntityType().equals(EntityType.PLAYER)) { return; } Player player = (Player) ev.getEntity(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } if (!isBlockerActive(player, game)) { return; } ev.setCancelled(true); }
if (type != null && type.equals(e.getType())) { specified = true; if (!negate) {
@EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent ev) { if (!ev.getCause().equals(DamageCause.PROJECTILE)) { return; } if (!ev.getEntityType().equals(EntityType.PLAYER)) { return; } Player player = (Player) ev.getEntity(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } if (!isBlockerActive(player, game)) { return; } ev.setCancelled(true); }
/** * Monitor falling blocks. * * @param event The event to watch */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onFallingBlock(EntityChangeBlockEvent event) { /* WORLD BLACKLIST CHECK */ if(WorldBlacklist.isWorldBlacklisted(event.getBlock().getWorld())) return; if (BlockUtils.shouldBeWatched(event.getBlock().getState()) && event.getEntityType().equals(EntityType.FALLING_BLOCK)) { if (event.getTo().equals(Material.AIR) && mcMMO.getPlaceStore().isTrue(event.getBlock())) { event.getEntity().setMetadata("mcMMOBlockFall", new FixedMetadataValue( plugin, event.getBlock().getLocation())); } else { List<MetadataValue> values = event.getEntity().getMetadata( "mcMMOBlockFall" ); if (!values.isEmpty()) { if (values.get(0).value() == null) return; Block spawn = ((org.bukkit.Location) values.get(0).value()).getBlock(); mcMMO.getPlaceStore().setTrue( event.getBlock() ); mcMMO.getPlaceStore().setFalse( spawn ); } } } }
/** * Prevent damage from explosion * @param e - event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onExplosion(final EntityExplodeEvent e) { if (e.getEntity() == null || !e.getEntityType().equals(EntityType.CREEPER) || !getIWM().inWorld(e.getLocation())) { return; } // If creeper damage is not allowed in world, remove it if (!Flags.CREEPER_DAMAGE.isSetForWorld(e.getLocation().getWorld())) { // If any were removed, then prevent damage too e.blockList().clear(); e.setCancelled(true); return; } // Check for griefing Creeper creeper = (Creeper)e.getEntity(); if (!Flags.CREEPER_GRIEFING.isSetForWorld(e.getLocation().getWorld()) && creeper.getTarget() instanceof Player) { Player target = (Player)creeper.getTarget(); if (!getIslands().locationIsOnIsland(target, e.getLocation())) { User user = User.getInstance(target); user.notify("protection.protected", TextVariables.DESCRIPTION, user.getTranslation(Flags.CREEPER_GRIEFING.getHintReference())); e.setCancelled(true); e.blockList().clear(); } } } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerHitEntity(PlayerInteractEntityEvent e) { // Animal riding if (e.getRightClicked() instanceof Vehicle && e.getRightClicked() instanceof Animals) { checkIsland(e, e.getRightClicked().getLocation(), Flags.RIDING); } // Villager trading if (e.getRightClicked().getType().equals(EntityType.VILLAGER)) { checkIsland(e, e.getRightClicked().getLocation(), Flags.TRADING); } // Name tags if (e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.NAME_TAG)) { checkIsland(e, e.getRightClicked().getLocation(), Flags.NAME_TAG); } } }
/** * @param event */ @EventHandler(priority = EventPriority.HIGH) public void onPlayerInteractAtEntityEvent(PlayerInteractAtEntityEvent event) { if (event.isCancelled()) { return; } Entity entity = event.getRightClicked(); Player player = event.getPlayer(); if (plugin.getSettingsManager().isBlacklistedWorld(entity.getLocation().getWorld())) { return; } if (entity.getType().equals(EntityType.ARMOR_STAND)) { if (player != null && !plugin.getPermissionsManager().has(player, "preciousstones.bypass.armor-stand-take")) { Field field = plugin.getForceFieldManager().getEnabledSourceField(entity.getLocation(), FieldFlag.PROTECT_ARMOR_STANDS); if (field != null) { if (FieldFlag.PROTECT_ARMOR_STANDS.applies(field, player)) { event.setCancelled(true); } } } } }
Entity entity = event.getRightClicked(); if (entity.getType().equals(EntityType.ITEM_FRAME)) { if (!plugin.getPermissionsManager().has(player, "preciousstones.bypass.item-frame-take")) { Field field = plugin.getForceFieldManager().getEnabledSourceField(entity.getLocation(), FieldFlag.PREVENT_ITEM_FRAME_TAKE); if (entity.getType().equals(EntityType.ARMOR_STAND)) { if (player != null && !plugin.getPermissionsManager().has(player, "preciousstones.bypass.armor-stand-take")) { Field field = plugin.getForceFieldManager().getEnabledSourceField(entity.getLocation(), FieldFlag.PROTECT_ARMOR_STANDS);