public static void walkToPlayer(Entity e, Player p) { // Tamed animals already handle their own following if (e instanceof Tameable) { if (((Tameable) e).isTamed()) { return; } } if (e.getPassenger() instanceof Player) { return; } // Moving the dragon is too buggy if (e instanceof EnderDragon) { return; } // Once this is set we can't unset it. //((Creature)e).setTarget(p); // If the pet is too far just teleport instead of attempt navigation if (e.getLocation().distance(p.getLocation()) > 20) { e.teleport(p); } else { Navigation n = ((CraftLivingEntity) e).getHandle().getNavigation(); n.a(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 0.30f); } }
@Override public void run() { // Ender dragon was not found. Forcibly respawn it if (world.getEntitiesByClass(EnderDragon.class).size() == 0) { this.plugin.getLogger().warning("Something went wrong! Had to forcibly reset dragon battle..."); this.battle.resetBattleState(); this.removeCrystals(); plugin.getDEDManager().getWorldWrapper(world).startRespawn(0); return; } // Ensure all crystals are not invulnerable this.world.getEntitiesByClass(EnderCrystal.class).forEach(c -> { c.setInvulnerable(false); c.setBeamTarget(null); }); }
@EventHandler public void onPlayerSwitchWorlds(PlayerChangedWorldEvent event) { World world = event.getPlayer().getWorld(); if (world.getEnvironment() != Environment.THE_END) return; EndWorldWrapper worldWrapper = manager.getWorldWrapper(world); // Start the respawn countdown if joining an empty world if (plugin.getConfig().getBoolean("respawn-on-join", false)) { if (world.getPlayers().size() > 1 || worldWrapper.isRespawnInProgress() || world.getEntitiesByClass(EnderDragon.class).size() == 0) return; manager.getWorldWrapper(world).startRespawn(RespawnType.JOIN); } // Reset end crystal states just in case something went awry if (!worldWrapper.isRespawnInProgress()) { world.getEntitiesByClass(EnderCrystal.class).forEach(e -> { e.setInvulnerable(false); e.setBeamTarget(null); }); } }
@EventHandler public void onDragonDeath(EntityDeathEvent event) { if (!(event.getEntity() instanceof EnderDragon)) return; EnderDragon dragon = (EnderDragon) event.getEntity(); DragonBattle dragonBattle = plugin.getNMSAbstract().getEnderDragonBattleFromDragon(dragon); World world = event.getEntity().getWorld(); EndWorldWrapper worldWrapper = plugin.getDEDManager().getWorldWrapper(world); BattleStateChangeEvent bscEventCrystals = new BattleStateChangeEvent(dragonBattle, dragon, BattleState.BATTLE_COMMENCED, BattleState.BATTLE_END); Bukkit.getPluginManager().callEvent(bscEventCrystals); new BukkitRunnable() { @Override public void run() { if (plugin.getNMSAbstract().getEnderDragonDeathAnimationTime(dragon) >= 185) { // Dragon is dead at 200 new DragonDeathRunnable(plugin, worldWrapper, dragon); this.cancel(); } } }.runTaskTimer(plugin, 0L, 1L); }
/** * Apply this templates data to an EnderDragonBattle object * * @param nmsAbstract an instance of the NMSAbstract interface * @param dragon the dragon to modify * @param battle the battle to modify */ public void applyToBattle(NMSAbstract nmsAbstract, EnderDragon dragon, DragonBattle battle) { Validate.notNull(nmsAbstract, "Instance of NMSAbstract cannot be null. See DragonEggDrop#getNMSAbstract()"); Validate.notNull(dragon, "Ender Dragon cannot be null"); Validate.notNull(battle, "Instance of DragonBattle cannot be null"); if (name != null) { dragon.setCustomName(name); battle.setBossBarTitle(name); } battle.setBossBarStyle(barStyle, barColour); this.attributes.forEach((a, v) -> { AttributeInstance attribute = dragon.getAttribute(a); if (attribute != null) { attribute.setBaseValue(v); } }); // Set health... max health attribute doesn't do that for me. -,- if (attributes.containsKey(Attribute.GENERIC_MAX_HEALTH)) { dragon.setHealth(attributes.get(Attribute.GENERIC_MAX_HEALTH)); } }
@SuppressWarnings("deprecation") public void onDragonCreatesPortal(EntityCreatePortalEvent event) { if (event.isCancelled()) return; Entity entity = event.getEntity(); if (!(entity instanceof EnderDragon)) return; log("The dragon has been killed!"); Location enderEggLoc = entity.getLocation(); if (enderEggLoc != null) { End.getBlockAt(enderEggLoc).setTypeId(122); } else { log("Failed to process portal, cancelling event anyway!"); } event.setCancelled(true); }
public RemoteEnderDragon(int inID, RemoteEnderDragonEntity inEntity, EntityManager inManager) { super(inID, RemoteEntityType.EnderDragon, inManager); this.m_entity = inEntity; Bukkit.getPluginManager().registerEvents(new Listener() { @EventHandler public void onEntityExplode(EntityExplodeEvent event) { if(event.getEntity() instanceof EnderDragon) { if(event.getEntity() == getBukkitEntity() && !shouldDestroyBlocks()) event.setCancelled(true); } else if(event.getEntity() instanceof ComplexEntityPart) { if(((ComplexEntityPart)event.getEntity()).getParent() == getBukkitEntity() && !shouldDestroyBlocks()) event.setCancelled(true); } } }, this.m_manager.getPlugin() ); }
/** * Remove the unloaded EnderDragons from the loaded set * * @param event a Chunk Unload Event */ @EventHandler(priority = EventPriority.NORMAL) public void onEndChunkUnload(final ChunkUnloadEvent event) { if (event.getWorld().getEnvironment() == Environment.THE_END) { final String worldName = event.getWorld().getName(); final EndWorldHandler handler = this.plugin.getHandler(StringUtil.toLowerCamelCase(worldName)); if (handler != null) { EndChunk chunk = handler.getChunks().getChunk(event.getChunk()); if (chunk == null) { chunk = handler.getChunks().addChunk(event.getChunk()); } for (final Entity e : event.getChunk().getEntities()) { if (e.getType() == EntityType.ENDER_DRAGON) { final EnderDragon ed = (EnderDragon)e; handler.getLoadedDragons().remove(ed.getUniqueId()); chunk.incrementSavedDragons(); } } } } }
@Override public void run() { boolean found = false; final Iterator<UUID> it = this.handler.getLoadedDragons().iterator(); final Collection<EnderDragon> dragons = this.handler.getEndWorld().getEntitiesByClass(EnderDragon.class); while (it.hasNext()) { final UUID id = it.next(); for (final EnderDragon ed : dragons) { if (id == ed.getUniqueId()) { found = true; break; } } if (!found) { // This EnderDragon was deleted some other way than after his death, forget about him this.handler.getDragons().remove(id); it.remove(); for (final String line : this.message) { this.handler.getPlugin().getLogger().warning(line); } } found = false; } }
public ControllableEnderDragonBase(int id, EntityManager manager) { super(id, ControllableEntityType.ENDERDRAGON, manager); Bukkit.getPluginManager().registerEvents(new Listener() { @EventHandler public void onEntityExplode(EntityExplodeEvent event) { if (!shouldDestroyBlocks()) { Entity entity = event.getEntity(); if (entity instanceof EnderDragon && entity.equals(getBukkitEntity())) { event.setCancelled(true); } else if (entity instanceof ComplexEntityPart && ((ComplexEntityPart) entity).getParent().equals(getBukkitEntity())) { event.setCancelled(true); } } } }, EntityAPI.getCore()); }
@EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH) public void onEntityExplode(EntityExplodeEvent event) { event.blockList().clear(); if (event.getEntity() instanceof EnderDragon) { event.setCancelled(true); } }
@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); } }
private void readTempData(File file) { try (FileReader reader = new FileReader(tempDataFile)) { JsonObject root = GSON.fromJson(reader, JsonObject.class); if (root == null) return; for (Entry<String, JsonElement> entry : root.entrySet()) { World world = Bukkit.getWorld(entry.getKey()); if (world == null) return; EndWorldWrapper wrapper = dedManager.getWorldWrapper(world); JsonObject element = entry.getValue().getAsJsonObject(); if (element.has("respawnTime")) { if (wrapper.isRespawnInProgress()) wrapper.stopRespawn(); wrapper.startRespawn(element.get("respawnTime").getAsInt()); } Collection<EnderDragon> dragons = world.getEntitiesByClass(EnderDragon.class); if (element.has("activeTemplate") && !dragons.isEmpty()) { DragonTemplate template = dedManager.getTemplate(element.get("activeTemplate").getAsString()); if (template == null) return; wrapper.setActiveBattle(template); template.applyToBattle(nmsAbstract, Iterables.get(dragons, 0), nmsAbstract.getEnderDragonBattleFromWorld(world)); } } } catch (IOException | JsonParseException e) { e.printStackTrace(); } }
@Override public DragonBattle getEnderDragonBattleFromDragon(EnderDragon dragon) { if (dragon == null) return null; EntityEnderDragon nmsDragon = ((CraftEnderDragon) dragon).getHandle(); return new DragonBattle1_10_R1(nmsDragon.cZ()); }
@Override public boolean hasBeenPreviouslyKilled(EnderDragon dragon) { if (dragon == null) return false; EnderDragonBattle battle = ((DragonBattle1_10_R1) this.getEnderDragonBattleFromDragon(dragon)).getHandle(); return battle.d(); }
@Override public int getEnderDragonDeathAnimationTime(EnderDragon dragon) { if (dragon == null) return -1; EntityEnderDragon nmsDragon = ((CraftEnderDragon) dragon).getHandle(); return nmsDragon.bH; }
@Override public DragonBattle getEnderDragonBattleFromDragon(EnderDragon dragon) { if (dragon == null) return null; EntityEnderDragon nmsDragon = ((CraftEnderDragon) dragon).getHandle(); return new DragonBattle1_12_R1(nmsDragon.df()); }
@Override public boolean hasBeenPreviouslyKilled(EnderDragon dragon) { if (dragon == null) return false; EnderDragonBattle battle = ((DragonBattle1_12_R1) this.getEnderDragonBattleFromDragon(dragon)).getHandle(); return battle.d(); }
@Override public DragonBattle getEnderDragonBattleFromDragon(EnderDragon dragon) { if (dragon == null) return null; EntityEnderDragon nmsDragon = ((CraftEnderDragon) dragon).getHandle(); return new DragonBattle1_9_R2(nmsDragon.cV()); }
@Override public boolean hasBeenPreviouslyKilled(EnderDragon dragon) { if (dragon == null) return false; EnderDragonBattle battle = ((DragonBattle1_9_R2) this.getEnderDragonBattleFromDragon(dragon)).getHandle(); return battle.d(); }
@Override public int getEnderDragonDeathAnimationTime(EnderDragon dragon) { if (dragon == null) return -1; EntityEnderDragon nmsDragon = ((CraftEnderDragon) dragon).getHandle(); return nmsDragon.bG; }
@Override public DragonBattle getEnderDragonBattleFromDragon(EnderDragon dragon) { if (dragon == null) return null; EntityEnderDragon nmsDragon = ((CraftEnderDragon) dragon).getHandle(); return new DragonBattle1_9_R1(nmsDragon.cU()); }
@Override public boolean hasBeenPreviouslyKilled(EnderDragon dragon) { if (dragon == null) return false; EnderDragonBattle battle = ((DragonBattle1_9_R1) this.getEnderDragonBattleFromDragon(dragon)).getHandle(); return battle.d(); }
@Override public int getEnderDragonDeathAnimationTime(EnderDragon dragon) { if (dragon == null) return -1; EntityEnderDragon nmsDragon = ((CraftEnderDragon) dragon).getHandle(); return nmsDragon.bF; }
@Override public DragonBattle getEnderDragonBattleFromDragon(EnderDragon dragon) { if (dragon == null) return null; EntityEnderDragon nmsDragon = ((CraftEnderDragon) dragon).getHandle(); return new DragonBattle1_11_R1(nmsDragon.db()); }
@Override public boolean hasBeenPreviouslyKilled(EnderDragon dragon) { if (dragon == null) return false; EnderDragonBattle battle = ((DragonBattle1_11_R1) this.getEnderDragonBattleFromDragon(dragon)).getHandle(); return battle.d(); }
/** * Commence the Dragon's respawning processes in this world * * @param type the type that triggered this dragon respawn */ public void startRespawn(RespawnType type) { Validate.notNull(type, "Cannot respawn a dragon under a null respawn type"); boolean dragonExists = !this.getWorld().getEntitiesByClasses(EnderDragon.class).isEmpty(); if (dragonExists || respawnInProgress || respawnTask != null) return; FileConfiguration config = plugin.getConfig(); int respawnDelay = (type == RespawnType.JOIN ? config.getInt("join-respawn-delay", 60) : config.getInt("death-respawn-delay", 300)); this.respawnTask = new RespawnRunnable(plugin, getWorld(), respawnDelay); this.respawnTask.runTaskTimer(plugin, 0, 20); this.respawnInProgress = true; }
/** * Commence the Dragon's respawning processes in this world based * on provided values rather than configured ones. * * @param respawnDelay the time until the dragon respawns */ public void startRespawn(int respawnDelay) { if (respawnDelay < 0) respawnDelay = 0; boolean dragonExists = !this.getWorld().getEntitiesByClass(EnderDragon.class).isEmpty(); if (dragonExists || respawnInProgress || respawnTask != null) return; this.respawnTask = new RespawnRunnable(plugin, getWorld(), respawnDelay); this.respawnTask.runTaskTimer(plugin, 0, 20); this.respawnInProgress = true; }
@EventHandler public void onPlayerJoin(PlayerJoinEvent event) { // Version notification Player player = event.getPlayer(); if (player.isOp() && plugin.isNewVersionAvailable()) { this.plugin.sendMessage(player, ChatColor.GRAY + "A new version is available for download (Version " + this.plugin.getNewVersion() + "). " + RESOURCE_PAGE); } World world = player.getWorld(); if (world.getEnvironment() != Environment.THE_END) return; EndWorldWrapper worldWrapper = manager.getWorldWrapper(world); // Reset end crystal states just in case something went awry if (!worldWrapper.isRespawnInProgress()) { world.getEntitiesByClass(EnderCrystal.class).forEach(e -> { e.setInvulnerable(false); e.setBeamTarget(null); }); } // Dragon respawn logic if (!plugin.getConfig().getBoolean("respawn-on-join", false)) return; if (!world.getPlayers().isEmpty() || manager.getWorldWrapper(world).isRespawnInProgress() || world.getEntitiesByClass(EnderDragon.class).size() == 0) return; manager.getWorldWrapper(world).startRespawn(RespawnType.JOIN); }
@EventHandler public void onCreatureSpawn(CreatureSpawnEvent event) { if (!(event.getEntity() instanceof EnderDragon)) return; EnderDragon dragon = (EnderDragon) event.getEntity(); if (dragon.getWorld().getEnvironment() != Environment.THE_END) return; DragonBattle dragonBattle = plugin.getNMSAbstract().getEnderDragonBattleFromDragon(dragon); EndWorldWrapper world = plugin.getDEDManager().getWorldWrapper(dragon.getWorld()); if (plugin.getConfig().getBoolean("strict-countdown") && world.isRespawnInProgress()) { world.stopRespawn(); } DragonTemplate template = plugin.getDEDManager().getRandomTemplate(); if (template != null) { template.applyToBattle(plugin.getNMSAbstract(), dragon, dragonBattle); world.setActiveBattle(template); if (template.shouldAnnounceRespawn()) { Bukkit.getOnlinePlayers().forEach(p -> p.sendMessage( ChatColor.DARK_GRAY + "[" + ChatColor.RED.toString() + ChatColor.BOLD + "!!!" + ChatColor.DARK_GRAY + "] " + template.getName() + ChatColor.DARK_GRAY + " has respawned in the end!") ); } } BattleStateChangeEvent bscEventCrystals = new BattleStateChangeEvent(dragonBattle, dragon, BattleState.DRAGON_RESPAWNING, BattleState.BATTLE_COMMENCED); Bukkit.getPluginManager().callEvent(bscEventCrystals); }
@EventHandler public void onAttemptRespawn(PlayerInteractEvent event) { Player player = event.getPlayer(); ItemStack item = event.getItem(); if (item == null || item.getType() != Material.END_CRYSTAL) return; if (plugin.getConfig().getBoolean("allow-crystal-respawns")) return; World world = player.getWorld(); EndWorldWrapper worldWrapper = plugin.getDEDManager().getWorldWrapper(world); if (worldWrapper.isRespawnInProgress() || !world.getEntitiesByClass(EnderDragon.class).isEmpty()) { Set<EnderCrystal> crystals = PortalCrystal.getAllSpawnedCrystals(world); // Check for 3 crystals because PlayerInteractEvent is fired first if (crystals.size() < 3) return; for (EnderCrystal crystal : crystals) { crystal.getLocation().getBlock().setType(Material.AIR); // Remove fire world.dropItem(crystal.getLocation(), END_CRYSTAL_ITEM); crystal.remove(); } plugin.getNMSAbstract().sendActionBar(ChatColor.RED + "You cannot manually respawn a dragon!", player); player.sendMessage(ChatColor.RED + "You cannot manually respawn a dragon!"); event.setCancelled(true); } }
@SuppressWarnings("null") @Override public boolean check(final Event evt) { final EntityDamageEvent e = (EntityDamageEvent) evt; if (!checkType(e.getEntity())) return false; if (e instanceof EntityDamageByEntityEvent && ((EntityDamageByEntityEvent) e).getDamager() instanceof EnderDragon && ((EntityDamageByEntityEvent) e).getEntity() instanceof EnderDragon) return false; return checkDamage(e); }
@EventHandler void onEntityDeath(EntityDeathEvent e){ Entity entity = e.getEntity(); if(e.getEntity().getKiller() instanceof Player && entity instanceof EnderDragon){ for(String msg : Main.getInstance().getConfig().getStringList("NovoDestemido")){ msg = msg.replace("&", "�").replace("{player}", e.getEntity().getKiller().getName()); Bukkit.broadcastMessage(msg); } setDestemido(e.getEntity().getKiller()); } }
@Override public boolean effect(Event event, Player player) { // List<String> lore = e.getBow().getItemMeta().getLore(); // if(!lore.contains(placeHolder)) { // for(int i = descriptionSize; i != 0; i--) // lore.remove(i); // e.getProjectile().setMetadata("ce." + this.getOriginalName(), new FixedMetadataValue(main, writeType(lore))); // player.setMetadata("ce.CanUnleashBeasts", null); // } else // e.getProjectile().setMetadata("ce." + this.getOriginalName(), null); if(event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; if(e.getDamager() != player) return false; Entity ent = e.getEntity(); Location loc = ent.getLocation(); World w = ent.getWorld(); if(ent instanceof Silverfish || ent instanceof EnderDragon || ent instanceof Spider || ent instanceof Slime || ent instanceof Ghast || ent instanceof MagmaCube || ent instanceof CaveSpider || (ent instanceof Wolf && ((Wolf) ent).isAngry()) || ent instanceof PigZombie) { e.setDamage(e.getDamage()*DamageMultiplication); w.playEffect(loc, Effect.SMOKE, 50); w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 50); EffectManager.playSound(loc, "BLOCK_PISTON_RETRACT", 1.3f, 3f); return true; } else if (ent instanceof Player) { for(int i = 0; i < MaximumMobs; i++) { if(rand.nextInt(100) < MobAppearanceChance) { w.spawnEntity(loc, rand.nextInt(2) == 1 ? EntityType.SPIDER : EntityType.SLIME); w.playEffect(loc, Effect.MOBSPAWNER_FLAMES, 30); w.playEffect(loc, Effect.SMOKE, 30); EffectManager.playSound(loc, "BLOCK_ANVIL_BREAK", 0.3f, 0.1f); } } } } return false; }
/** * Counts: * - EnderDragons * - EnderCrystals */ private void countEntities() { this.plugin.getLogger().info("Counting existing EDs in " + this.endWorld.getName() + "..."); for (final EndChunk c : this.chunks.getSafeChunksList()) { if (this.endWorld.isChunkLoaded(c.getX(), c.getZ())) { final Chunk chunk = this.endWorld.getChunkAt(c.getX(), c.getZ()); for (final Entity e : chunk.getEntities()) { if (e.getType() == EntityType.ENDER_DRAGON) { final EnderDragon ed = (EnderDragon)e; if (!this.dragons.containsKey(ed.getUniqueId())) { ed.setMaxHealth(this.config.getEdHealth()); ed.setHealth(ed.getMaxHealth()); this.dragons.put(ed.getUniqueId(), new HashMap<String, Double>()); this.loadedDragons.add(ed.getUniqueId()); } } else if (e.getType() == EntityType.ENDER_CRYSTAL) { c.addCrystalLocation(e); } } } else { this.endWorld.loadChunk(c.getX(), c.getZ()); c.resetSavedDragons(); this.endWorld.unloadChunkRequest(c.getX(), c.getZ()); } } this.plugin.getLogger().info("Done, " + this.getNumberOfAliveEnderDragons() + " EnderDragon(s) found."); }
@Override public EnderDragon getParent() { return (EnderDragon) super.getParent(); }
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onEntityPortal(EntityPortalEvent event) { if (event.getEntity() instanceof EnderDragon) { event.setCancelled(true); } }