@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onItemFrameDamage(final EntityDamageByEntityEvent e) { // Check world if (!Util.inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) { return; } if (e.getDamager() instanceof Projectile) { if (DEBUG) plugin.getLogger().info("DEBUG: Projectile damage to itemframe"); // Find out who fired the arrow Projectile p = (Projectile) e.getDamager(); if (DEBUG) plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString()); if (p.getShooter() instanceof Skeleton || p.getShooter() instanceof Golem) { if (DEBUG) plugin.getLogger().info("DEBUG: Shooter is mob"); if (!Settings.allowMobDamageToItemFrames) { if (DEBUG) plugin.getLogger().info("DEBUG: Damage not allowed, cancelling"); e.setCancelled(true); } } } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onItemFrameDamage(final HangingBreakByEntityEvent e) { if (DEBUG) { plugin.getLogger().info("DEBUG: Hanging break by entity event"); plugin.getLogger().info("DEBUG: cause = " + e.getCause()); plugin.getLogger().info("DEBUG: entity = " + e.getEntity()); plugin.getLogger().info("DEBUG: remover = " + e.getRemover()); } // Check world if (!Util.inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) { return; } if (e.getRemover() instanceof Skeleton || e.getRemover() instanceof Golem) { if (DEBUG) plugin.getLogger().info("DEBUG: Remover is mob"); if (!Settings.allowMobDamageToItemFrames) { if (DEBUG) plugin.getLogger().info("DEBUG: Damage not allowed, cancelling"); 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"); } }
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; }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onItemFrameDamage(final EntityDamageByEntityEvent e) { // Check world if (!inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) { return; } if (e.getDamager() instanceof Projectile) { if (DEBUG) plugin.getLogger().info("DEBUG: Projectile damage to itemframe"); // Find out who fired the arrow Projectile p = (Projectile) e.getDamager(); if (DEBUG) plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString()); if (p.getShooter() instanceof Skeleton || p.getShooter() instanceof Golem) { if (DEBUG) plugin.getLogger().info("DEBUG: Shooter is mob"); if (!Settings.allowMobDamageToItemFrames) { if (DEBUG) plugin.getLogger().info("DEBUG: Damage not allowed, cancelling"); e.setCancelled(true); } } } }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onItemFrameDamage(final HangingBreakByEntityEvent e) { if (DEBUG) { plugin.getLogger().info("DEBUG: Hanging break by entity event"); plugin.getLogger().info("DEBUG: cause = " + e.getCause()); plugin.getLogger().info("DEBUG: entity = " + e.getEntity()); plugin.getLogger().info("DEBUG: remover = " + e.getRemover()); } // Check world if (!inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) { return; } if (e.getRemover() instanceof Skeleton || e.getRemover() instanceof Golem) { if (DEBUG) plugin.getLogger().info("DEBUG: Remover is mob"); if (!Settings.allowMobDamageToItemFrames) { if (DEBUG) plugin.getLogger().info("DEBUG: Damage not allowed, cancelling"); e.setCancelled(true); } } }
@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); } } }
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; }