public static Object armorstandCreation(Location location, Entity entity, ServerMob serverMob) { try { Object armorstand = entity.getWorld().spawnEntity(entity.getLocation().clone().add(0, ((LivingEntity) entity).getEyeHeight() - (entity instanceof Wither ? 0.15 : 0.3), 0), EntityType.valueOf("ARMOR_STAND")); armorstand.getClass().getMethod("setVisible", boolean.class).invoke(armorstand, false); armorstand.getClass().getMethod("setCustomNameVisible", boolean.class).invoke(armorstand, true); armorstand.getClass().getMethod("setGravity", boolean.class).invoke(armorstand, false); armorstand.getClass().getMethod("setBasePlate", boolean.class).invoke(armorstand, false); armorstand.getClass().getMethod("setSmall", boolean.class).invoke(armorstand, true); armorstand.getClass().getMethod("setCanPickupItems", boolean.class).invoke(armorstand, false); return armorstand; }catch (Exception ex) { ex.printStackTrace(); } return null; }
@EventHandler(priority=EventPriority.LOWEST) public void onEntityChangeBlock(EntityChangeBlockEvent e) { if (e.getEntity() instanceof FallingBlock) { if (Variables.blocks.contains(e.getEntity().getUniqueId())) { e.setCancelled(true); e.getEntity().remove(); } } else if (e.getEntity() instanceof Wither) { SlimefunItem item = BlockStorage.check(e.getBlock()); if (item != null) { if (item.getName().equals("WITHER_PROOF_OBSIDIAN")) e.setCancelled(true); if (item.getName().equals("WITHER_PROOF_GLASS")) e.setCancelled(true); } } }
@Override public Relation compare(final DamageCause dc, final EntityData e) { switch (dc) { case ENTITY_ATTACK: return Relation.get(e.isSupertypeOf(EntityData.fromClass(Entity.class))); case PROJECTILE: return Relation.get(e.isSupertypeOf(EntityData.fromClass(Projectile.class))); case WITHER: return Relation.get(e.isSupertypeOf(EntityData.fromClass(Wither.class))); case FALLING_BLOCK: return Relation.get(e.isSupertypeOf(EntityData.fromClass(FallingBlock.class))); //$CASES-OMITTED$ default: return Relation.NOT_EQUAL; } }
@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.LOWEST) public void onEntityChangeBlock(EntityChangeBlockEvent e) { if (e.getEntity() instanceof FallingBlock) { if (Variables.blocks.contains(e.getEntity().getUniqueId())) { e.setCancelled(true); e.getEntity().remove(); } } else if (e.getEntity() instanceof Wither) { SlimefunItem item = BlockStorage.check(e.getBlock()); if (item != null) { if (item.getID().equals("WITHER_PROOF_OBSIDIAN")) e.setCancelled(true); if (item.getID().equals("WITHER_PROOF_GLASS")) e.setCancelled(true); } } }
public void announce(String message, AnnouncementType at, Player[] players) throws IllegalArgumentException { if(at == AnnouncementType.BOSS_HEALTH) { for(Player p : players) { final Wither w = (Wither) p.getWorld().spawnEntity(p.getLocation(), EntityType.WITHER); final Location l = w.getLocation(); w.setCustomName(message); plugin.getServer().getScheduler().runTaskLater(plugin, new BukkitRunnable() { public void run() { w.remove(); } }, 500); plugin.getServer().getScheduler().runTaskTimer(plugin, new BukkitRunnable() { public void run() { w.teleport(l); } }, 0, 1); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onWitherChangeBlock(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); if (entity instanceof Wither || entity instanceof EnderDragon) { event.setCancelled(true); } }
@EventHandler public void onEntityDamageByEntityListener(EntityDamageByEntityEvent e) { User user = null; if (e.getDamager() instanceof Player) { user = MWAPI.getUserHandler().findById(e.getDamager().getUniqueId()); } else if (e.getDamager() instanceof Projectile) { Projectile p = (Projectile) e.getDamager(); if (p.getShooter() instanceof Player) { user = MWAPI.getUserHandler().findById(((Player) p.getShooter()).getUniqueId()); } } if (user == null || !user.isPlaying()) return; if (e.getEntity() instanceof Wither) { Wither wither = (Wither) e.getEntity(); if (((BasicWither) user.getGame().getTeam(user).getWither()).getWither().getEntityId().equals(wither.getUniqueId())) { e.setCancelled(true); } } else if (e.getEntity() instanceof Player) { User target = MWAPI.getUserHandler().findById(e.getEntity().getUniqueId()); if (target.getGame().getTeam(target).getTeamColor() == user.getGame().getTeam(user).getTeamColor()) { 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); } } }
@EventHandler public void onTargeting(EntityTargetLivingEntityEvent e) { if (!witherEnabled || e == null || e.isCancelled() || !plugin.isSkyAssociatedWorld(e.getEntity().getWorld())) { return; } if (e.getEntity() instanceof Wither && e.getTarget() != null) { handleWitherRampage(e, (Wither) e.getEntity(), e.getTarget().getLocation()); } }
@EventHandler public void onWitherSkullExplosion(EntityDamageByEntityEvent e) { if (!witherEnabled || e == null || !(e.getEntity() instanceof WitherSkull) || !plugin.isSkyAssociatedWorld(e.getEntity().getWorld())) { return; } // Find owner ProjectileSource shooter = ((WitherSkull) e.getEntity()).getShooter(); if (shooter instanceof Wither) { handleWitherRampage(e, (Wither) shooter, e.getDamager().getLocation()); } }
private void handleWitherRampage(Cancellable e, Wither shooter, Location targetLocation) { String islandName = getOwningIsland(shooter); String targetIsland = WorldGuardHandler.getIslandNameAt(targetLocation); if (targetIsland == null || !targetIsland.equals(islandName)) { e.setCancelled(true); checkWitherLeash(shooter, islandName); } }
private void checkWitherLeash(Wither shooter, String islandName) { String currentIsland = WorldGuardHandler.getIslandNameAt(shooter.getLocation()); if (currentIsland == null || !currentIsland.equals(islandName)) { shooter.remove(); IslandInfo islandInfo = plugin.getIslandInfo(islandName); if (islandInfo != null) { islandInfo.sendMessageToOnlineMembers(I18nUtil.tr("\u00a7cWither Despawned!\u00a7e It wandered too far from your island.")); } } }
private String getOwningIsland(Wither wither) { if (wither.hasMetadata("fromIsland")) { return wither.getMetadata("fromIsland").get(0).asString(); } try { Object[] parse = new MessageFormat(I18nUtil.marktr("{0}''s Wither")).parse(wither.getCustomName()); if (parse != null && parse.length == 1 && parse[0] instanceof String) { return (String) parse[0]; } } catch (ParseException e) { // Ignore } return null; }
@EventHandler public void onMobSpawn(CreatureSpawnEvent event) { LivingEntity mob = event.getEntity(); if (mob instanceof Wither) { if (NoWither.getWitherSetting()) { //TODO display message to player event.setCancelled(true); NoWither.log("Wither spawn averted"); } } }
@EventHandler public void disableExplosionWithers(EntityExplodeEvent e) { if(e.getEntity() instanceof WitherSkull) { e.setCancelled(true); } else if(e.getEntity() instanceof Wither) { e.setCancelled(true); } }
/** * Deal with pre-explosions */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void WitherExplode(ExplosionPrimeEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } // Only cover withers in the island world if (!Util.inWorld(e.getEntity()) || e.getEntity() == null) { return; } // The wither or wither skulls can both blow up if (e.getEntityType() == EntityType.WITHER) { //plugin.getLogger().info("DEBUG: Wither"); // Check the location if (mobSpawnInfo.containsKey(e.getEntity())) { // We know about this wither if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this wither"); } if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getEntity().getLocation())) { // Cancel the explosion if (DEBUG) { plugin.getLogger().info("DEBUG: cancelling wither pre-explosion"); } e.setCancelled(true); } } // Testing only e.setCancelled(true); } if (e.getEntityType() == EntityType.WITHER_SKULL) { //plugin.getLogger().info("DEBUG: Wither skull"); // Get shooter Projectile projectile = (Projectile)e.getEntity(); if (projectile.getShooter() instanceof Wither) { //plugin.getLogger().info("DEBUG: shooter is wither"); Wither wither = (Wither)projectile.getShooter(); // Check the location if (mobSpawnInfo.containsKey(wither)) { // We know about this wither if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this wither"); } if (!mobSpawnInfo.get(wither).inIslandSpace(e.getEntity().getLocation())) { // Cancel the explosion if (DEBUG) { plugin.getLogger().info("DEBUG: cancel wither skull explosion"); } e.setCancelled(true); } } } } }
public CanaryWither(net.canarymod.api.entity.living.monster.Wither entity) { super(entity); }
/** * Deal with pre-explosions */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void WitherExplode(ExplosionPrimeEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } // Only cover withers in the island world if (!IslandGuard.inWorld(e.getEntity()) || e.getEntity() == null) { return; } // The wither or wither skulls can both blow up if (e.getEntityType() == EntityType.WITHER) { //plugin.getLogger().info("DEBUG: Wither"); // Check the location if (mobSpawnInfo.containsKey(e.getEntity().getUniqueId())) { // We know about this wither if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this wither"); } if (!mobSpawnInfo.get(e.getEntity()).inIslandSpace(e.getEntity().getLocation())) { // Cancel the explosion if (DEBUG) { plugin.getLogger().info("DEBUG: cancelling wither pre-explosion"); } e.setCancelled(true); } } // Testing only e.setCancelled(true); } if (e.getEntityType() == EntityType.WITHER_SKULL) { //plugin.getLogger().info("DEBUG: Wither skull"); // Get shooter Projectile projectile = (Projectile)e.getEntity(); if (projectile.getShooter() instanceof Wither) { //plugin.getLogger().info("DEBUG: shooter is wither"); Wither wither = (Wither)projectile.getShooter(); // Check the location if (mobSpawnInfo.containsKey(wither.getUniqueId())) { // We know about this wither if (DEBUG) { plugin.getLogger().info("DEBUG: We know about this wither"); } if (!mobSpawnInfo.get(wither.getUniqueId()).inIslandSpace(e.getEntity().getLocation())) { // Cancel the explosion if (DEBUG) { plugin.getLogger().info("DEBUG: cancel wither skull explosion"); } e.setCancelled(true); } } } } }
public RemoteWither(int inID, EntityManager inManager) { super(inID, RemoteEntityType.Wither, inManager); }
@EventHandler public void disableExplosionWither(EntityExplodeEvent e) { if(e.getEntity() instanceof Wither) { e.setCancelled(true); } }