@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { if (event == null || event.isCancelled() || event.getLocation() == null || !plugin.isSkyWorld(event.getLocation().getWorld())) { return; // Bail out, we don't care } if (!event.isCancelled() && ADMIN_INITIATED.contains(event.getSpawnReason())) { return; // Allow it, the above method would have blocked it if it should be blocked. } checkLimits(event, event.getEntity().getType(), event.getLocation()); if (!event.isCancelled() && event.getEntity() instanceof Squid) { Location loc = event.getLocation(); int z = loc.getBlockZ(); int x = loc.getBlockX(); if (loc.getWorld().getBiome(x, z) == Biome.DEEP_OCEAN && LocationUtil.findRoofBlock(loc).getType() == Material.PRISMARINE) { loc.getWorld().spawnEntity(loc, EntityType.GUARDIAN); event.setCancelled(true); } } if (!event.isCancelled() && event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.BUILD_WITHER && event.getEntity() instanceof Wither) { IslandInfo islandInfo = plugin.getIslandInfo(event.getLocation()); if (islandInfo != null && islandInfo.getLeader() != null) { event.getEntity().setCustomName(I18nUtil.tr("{0}''s Wither", islandInfo.getLeader())); event.getEntity().setMetadata("fromIsland", new FixedMetadataValue(plugin, islandInfo.getName())); } } }
@EventHandler(priority = EventPriority.MONITOR) public void squidLoot(EntityDeathEvent e) { EntityDamageEvent ede = e.getEntity().getLastDamageCause(); if (!(ede instanceof EntityDamageByEntityEvent)) return; EntityDamageByEntityEvent edbee = (EntityDamageByEntityEvent) ede; Entity damager = edbee.getDamager(); if (!Config.useSquidLoot || r.nextInt(100) > Config.squidLootChance || !(damager instanceof Player)) return; Player p = (Player) damager; Entity ent = e.getEntity(); if (!(ent instanceof Squid)) return; Squid squid = (Squid) ent; if (!RUtils.isInInfectedWorld(squid) || !RUtils.isInInfectedWorld(p)) return; List<String> lootSets = Config.squidLootSets; if (lootSets.isEmpty()) return; String lootSet = lootSets.get(r.nextInt(lootSets.size())); final LootChest lc = LootChest.getLootChest(lootSet); if (lc == null) return; Location l = squid.getLocation(); World w = l.getWorld(); for (ItemStack drop : lc.getRandomLoot()) w.dropItemNaturally(l, drop); }
@EventHandler(priority = EventPriority.MONITOR) public void onProjectileHit(ProjectileHitEvent event) { Projectile proj = event.getEntity(); if (proj == null) return; UUID projId = proj.getUniqueId(); if (squidEggIds.contains(projId)) { squidEggIds.remove(projId); Squid squid = (Squid) proj.getWorld().spawn(proj.getLocation(), EntityType.SQUID.getEntityClass()); proj.remove(); squidMobIds.add(squid.getUniqueId()); } }
@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(ignoreCancelled = true, priority = EventPriority.HIGH) public void onCreatureSpawn(CreatureSpawnEvent event) { if (event.getEntity() instanceof Squid) { event.setCancelled(true); } }
public CanarySquid(net.canarymod.api.entity.living.animal.Squid entity) { super(entity); }
@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 (!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())) { if (DEBUG) plugin.getLogger().info("DEBUG: Self damage from lingering potion!"); 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; } 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.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 (e.getEntity() instanceof Player) { if (pvp) { if (DEBUG) plugin.getLogger().info("DEBUG: PVP allowed"); return; } else { if (DEBUG) plugin.getLogger().info("DEBUG: PVP not allowed"); e.setCancelled(true); return; } } } }