diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/MorphTitan.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/MorphTitan.java index a4554c372..1396d82e3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/MorphTitan.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/MorphTitan.java @@ -2,6 +2,7 @@ package mineplex.core.gadget.gadgets; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import org.bukkit.Location; import org.bukkit.Material; @@ -41,7 +42,7 @@ import mineplex.core.updater.event.UpdateEvent; public class MorphTitan extends MorphGadget { private HashMap _targets = new HashMap(); - + public MorphTitan(GadgetManager manager) { super(manager, "Elder Guardian Morph", new String[] @@ -73,15 +74,15 @@ public class MorphTitan extends MorphGadget { this.RemoveArmor(player); Manager.getDisguiseManager().undisguise(player); - + player.setAllowFlight(false); player.setFlying(false); - + Entity ent = _targets.remove(player); if (ent != null) ent.remove(); } - + @EventHandler public void lazer(PlayerInteractEvent event) { @@ -92,102 +93,104 @@ public class MorphTitan extends MorphGadget if (!UtilEvent.isAction(event, ActionType.L)) return; - + if (!Recharge.Instance.use(player, "Guardians Laser", 4000, true, false)) return; - + DisguiseBase base = Manager.getDisguiseManager().getDisguise(player); if (base == null || !(base instanceof DisguiseGuardian)) return; - + DisguiseGuardian disguise = (DisguiseGuardian)base; - + HashSet ignore = new HashSet(); ignore.add(Material.AIR); - + Location loc = player.getTargetBlock(ignore, 64).getLocation().add(0.5, 0.5, 0.5); - + ArmorStand stand = loc.getWorld().spawn(loc, ArmorStand.class); - + stand.setVisible(false); stand.setGhost(true); stand.setGravity(false); - + _targets.put(player, stand); - + disguise.setTarget(stand.getEntityId()); Manager.getDisguiseManager().updateDisguise(disguise); - + //Fake Head UtilEnt.setFakeHead(player, true); Recharge.Instance.useForce(player, GetName() + " FakeHead", 2000); } - + @EventHandler public void lazerEnd(RechargedEvent event) { if (event.GetAbility().equals(GetName() + " FakeHead")) { UtilEnt.setFakeHead(event.GetPlayer(), false); - + //Explode ArmorStand stand = _targets.remove(event.GetPlayer()); if (stand != null) { UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, stand.getLocation(), 3f, 3f, 3f, 0, 32, ViewDist.MAX, UtilServer.getPlayers()); - + HashMap players = UtilEnt.getInRadius(stand.getLocation(), 12); for (Entity ent : players.keySet()) { if (ent instanceof Player) if (Manager.collideEvent(this, (Player)ent)) continue; - + double mult = players.get(ent); - + //Knockback UtilAction.velocity(ent, UtilAlg.getTrajectory(stand.getLocation(), ent.getLocation()), 4 * mult, false, 0, 1 + 3 * mult, 10, true); } - + //Sound stand.getWorld().playSound(stand.getLocation(), Sound.ZOMBIE_REMEDY, 6f, 0.75f); + + stand.remove(); } - + //Disguise DisguiseBase base = Manager.getDisguiseManager().getDisguise(event.GetPlayer()); if (base == null || !(base instanceof DisguiseGuardian)) return; - + DisguiseGuardian disguise = (DisguiseGuardian)base; disguise.setTarget(0); - + Manager.getDisguiseManager().updateDisguise(disguise); } } - + @EventHandler public void selfParticles(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; - + for (Player player : _targets.keySet()) { Vector dir = UtilAlg.getTrajectory( player.getLocation().add(0, 1.5, 0), _targets.get(player).getLocation()); dir.multiply(8); - + UtilParticle.PlayParticle(ParticleType.MAGIC_CRIT, - player.getLocation().add(0, 1.5, 0), - (float)dir.getX(), - (float)dir.getY(), - (float)dir.getZ(), - 1, 0, ViewDist.LONG, UtilServer.getPlayers()); - + player.getLocation().add(0, 1.5, 0), + (float)dir.getX(), + (float)dir.getY(), + (float)dir.getZ(), + 1, 0, ViewDist.LONG, UtilServer.getPlayers()); + player.playSound(player.getLocation(), Sound.FIREWORK_TWINKLE2, 2f, 2f); } } - + @EventHandler public void flight(UpdateEvent event) { @@ -198,15 +201,15 @@ public class MorphTitan extends MorphGadget { if (UtilPlayer.isSpectator(player)) continue; - + player.setAllowFlight(true); player.setFlying(true); - + if (UtilEnt.isGrounded(player)) UtilAction.velocity(player, new Vector(0,1,0)); } } - + @EventHandler public void titanOwner(PlayerJoinEvent event) { @@ -215,4 +218,24 @@ public class MorphTitan extends MorphGadget Manager.getDonationManager().Get(event.getPlayer().getName()).AddUnknownSalesPackagesOwned(GetName()); } } -} + + @EventHandler + public void clean(UpdateEvent event) + { + if (event.getType() != UpdateType.SLOW) + return; + + Iterator playerIter = _targets.keySet().iterator(); + + while (playerIter.hasNext()) + { + Player player = playerIter.next(); + + if (!player.isOnline()) + { + Entity ent = _targets.get(player); + ent.remove(); + playerIter.remove(); + } + } + }