From d568842d7c834a366e257713749be77816db8cd1 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 30 Apr 2018 17:49:23 +0100 Subject: [PATCH] Wither Assault (I don't like it at all) --- .../src/mineplex/core/game/kit/GameKit.java | 5 +- .../game/arcade/game/games/micro/Micro.java | 2 +- .../game/games/wither/PlayerCopyWither.java | 26 +-- .../arcade/game/games/wither/WitherGame.java | 201 +++--------------- .../game/games/wither/kit/KitHumanMedic.java | 2 - .../arcade/kit/perks/PerkWitherArrows.java | 11 +- .../arcade/kit/perks/PerkWitherAttack.java | 110 +++++----- .../arcade/kit/perks/PerkWitherMinion.java | 113 +++++----- 8 files changed, 169 insertions(+), 301 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java b/Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java index edac7d52e..fb17dba95 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/game/kit/GameKit.java @@ -3886,8 +3886,9 @@ public enum GameKit }, new KitEntityData<> ( - Wither.class, - createColoured(Material.SKULL_ITEM, (byte) 2) + Skeleton.class, + createColoured(Material.SKULL_ITEM, (byte) 1), + SkeletonType.WITHER.ordinal() ) ), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java index 6d5aaf6c3..3d44f72b4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/micro/Micro.java @@ -50,7 +50,7 @@ public class Micro extends TeamGame "Be the " + C.cYellow + "Last Team" + C.Reset + " standing!" }; private static final long BARRIER_TIME = TimeUnit.SECONDS.toMillis(10); - private static final long CHEAT_TIME = TimeUnit.SECONDS.toMillis(5); + private static final long CHEAT_TIME = TimeUnit.SECONDS.toMillis(4); private final Set _glass = new HashSet<>(); private final Map _teamCenters = new HashMap<>(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/PlayerCopyWither.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/PlayerCopyWither.java index 41da8752e..9fd5ae2b2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/PlayerCopyWither.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/PlayerCopyWither.java @@ -11,37 +11,29 @@ import nautilus.game.arcade.game.Game; public class PlayerCopyWither { - private Game Host; + + private final Skeleton _ent; + private final Player _owner; - private Skeleton _ent; - private Player _owner; - - public PlayerCopyWither(Game host, Player owner, ChatColor nameColor) + PlayerCopyWither(Game host, Player owner, ChatColor nameColor) { - Host = host; - _owner = owner; - - Host.CreatureAllowOverride = true; + + host.CreatureAllowOverride = true; _ent = owner.getWorld().spawn(owner.getLocation(), Skeleton.class); - Host.CreatureAllowOverride = false; + host.CreatureAllowOverride = false; UtilEnt.ghost(_ent, true, false); - - UtilEnt.vegetate(_ent); + UtilEnt.vegetate(_ent, true); //Armor _ent.getEquipment().setArmorContents(owner.getInventory().getArmorContents()); _ent.setCustomName(C.cWhite + C.Bold + C.Scramble + "XX" + ChatColor.RESET + " " + nameColor + owner.getName() + " " + C.cWhite + C.Bold + C.Scramble + "XX"); _ent.setCustomNameVisible(true); - - //Disguise -// DisguisePlayer disguise = new DisguisePlayer(_ent, ((CraftPlayer)owner).getProfile()); -// Host.Manager.GetDisguise().disguise(disguise); } - public LivingEntity GetEntity() + public LivingEntity GetEntity() { return _ent; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java index 2c7dbbc05..6fd1c3ca5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/WitherGame.java @@ -4,7 +4,10 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -53,6 +56,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.condition.Condition.ConditionType; import mineplex.minecraft.game.core.damage.CustomDamageEvent; + import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.GameType; import nautilus.game.arcade.events.GameStateChangeEvent; @@ -75,24 +79,19 @@ import nautilus.game.arcade.stats.TeamKillsStatTracker; public class WitherGame extends TeamGame implements IBlockRestorer { + + private static final double WITHER_FACTOR = 2.5; + private static final long GAME_TIMEOUT = TimeUnit.MINUTES.toMillis(5); + private GameTeam _runners; private GameTeam _withers; - - private double _witherFactor = 2.5; - + private int _yLimit = 0; private int _maxY; - - private long _gameTime = 300000; - - private HashMap _doubles = new HashMap(); - - // private int _livesPerPlayer = 3; - // private HashMap _lives = new HashMap(); - - private HashSet _blocks = new HashSet(); - private ArrayList _locationsOfBlocks = new ArrayList(); + private final Map _doubles = new HashMap<>(); + private final Set _blocks = new HashSet<>(); + private final List _locationsOfBlocks = new ArrayList<>(); public WitherGame(ArcadeManager manager) { @@ -118,29 +117,28 @@ public class WitherGame extends TeamGame implements IBlockRestorer C.cRed + "Withers" + C.cWhite + " Kill all the Humans within 5 Minutes", }); - this.DeathOut = true; - this.DamageTeamSelf = false; - this.DamageSelf = false; - this.DeathSpectateSecs = 4; - this.HungerSet = 20; - this.WorldBoundaryKill = false; + DeathOut = true; + DamageTeamSelf = false; + DamageSelf = false; + DeathSpectateSecs = 4; + HungerSet = 20; + WorldBoundaryKill = false; //Customizing for the Editor kit - this.BlockBreak = true; - this.BlockPlace = true; - this.ItemPickup = true; + BlockBreak = true; + BlockPlace = true; + ItemPickup = true; - this.KitRegisterState = GameState.Prepare; + KitRegisterState = GameState.Prepare; - this.InventoryClick = false; - this.InventoryOpenBlock = false; + InventoryClick = false; + InventoryOpenBlock = false; _help = new String[] { "Blocks placed by an Editor can be passed by other humans by " + C.cDGreen + "Right-clicking the block", "Withers are too powerful to be killed. Hiding is the only option!", "Medics are a valuable asset. Stick with them and keep them safe!", - }; @@ -219,7 +217,7 @@ public class WitherGame extends TeamGame implements IBlockRestorer return; // Enough Withers - if (_withers.GetPlayers(true).size() * _witherFactor >= _runners + if (_withers.GetPlayers(true).size() * WITHER_FACTOR >= _runners .GetPlayers(true).size()) return; @@ -227,28 +225,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer setWither(player, true); } -// @EventHandler -// public void assignCompassOnStart(GameStateChangeEvent event) -// { -// if (event.GetState() != GameState.Live) -// return; -// -// for (Player players : _withers.GetPlayers(true)) -// { -// ItemStack compass = new ItemBuilder(Material.COMPASS, 1).build(); -// -// ItemMeta im = compass.getItemMeta(); -// im.setLore(new ArrayList(Arrays.asList( -// F.item("A compass that trigger"), -// F.item("your ability to track humans!")))); -// im.setDisplayName(F.name("Scent Trigger")); -// -// compass.setItemMeta(im); -// -// players.getInventory().setItem(7, compass); -// } -// } - // Cancel wither shooting in waiting lobby @EventHandler public void onWitherSkullFire(ProjectileLaunchEvent event) @@ -381,8 +357,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer public void setWither(Player player, boolean forced) { - // _lives.remove(player); - SetPlayerTeam(player, _withers, true); // Kit @@ -408,27 +382,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer } } - // @EventHandler - // public void playerLoseLife(final PlayerDeathOutEvent event) - // { - // Player player = event.GetPlayer(); - // - // if (_lives.containsKey(player)) - // { - // int lives = _lives.get(player); - // - // if (lives <= 1) - // return; - // - // _lives.put(player, lives - 1); - // - // UtilPlayer.message(player, F.main("Game", "You have " + F.elem(C.cGreen + - // C.Bold + lives + " Lives Remaining") + ".")); - // - // event.setCancelled(true); - // } - // } - @EventHandler public void gameStart(GameStateChangeEvent event) { @@ -466,26 +419,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer } - // @EventHandler - // public void playerLivesDisplay(PlayerKitGiveEvent event) - // { - // if (!_runners.HasPlayer(event.GetPlayer())) - // return; - // - // //Player Lives - // if (!_lives.containsKey(event.GetPlayer())) - // _lives.put(event.GetPlayer(), _livesPerPlayer); - // - // int lives = _lives.get(event.GetPlayer()); - // - // if (lives <= 0) - // return; - // - // event.GetPlayer().getInventory().setItem(8, - // ItemStackFactory.Instance.CreateStack(Material.BONE, (byte)0, lives, - // C.cGreen + C.Bold + lives + " Lives Remaining")); - // } - @Override public void EndCheck() { @@ -502,7 +435,7 @@ public class WitherGame extends TeamGame implements IBlockRestorer GameTeam winner = null; // Wither Win - if (UtilTime.elapsed(this.GetStateTime(), _gameTime)) + if (UtilTime.elapsed(this.GetStateTime(), GAME_TIMEOUT)) winner = _runners; // Runner Win @@ -542,36 +475,20 @@ public class WitherGame extends TeamGame implements IBlockRestorer if (event.getType() != UpdateType.FAST) return; - - // int lives = 0; - // for (int i : _lives.values()) - // lives += i; - // Wipe Last Scoreboard.reset(); Scoreboard.writeNewLine(); Scoreboard.write(_runners.GetColor() + C.Bold + _runners.GetName()); - Scoreboard.write(_runners.GetColor() + "" - + _runners.GetPlayers(true).size() + " Players"); + Scoreboard.write(_runners.GetColor() + "" + _runners.GetPlayers(true).size() + " Players"); Scoreboard.writeNewLine(); Scoreboard.write(_withers.GetColor() + C.Bold + _withers.GetName()); - Scoreboard.write(_withers.GetColor() + "" - + _withers.GetPlayers(true).size() + " Players"); - - // Scoreboard.WriteBlank(); - // Scoreboard.Write(C.cYellow + C.Bold + "Humans Alive"); - // Scoreboard.Write(lives + " / " + (_lives.size() * _livesPerPlayer)); + Scoreboard.write(_withers.GetColor() + "" + _withers.GetPlayers(true).size() + " Players"); Scoreboard.writeNewLine(); Scoreboard.write(C.cYellow + C.Bold + "Time Left"); - Scoreboard.write(UtilTime.MakeStr( - Math.max( - 0, - _gameTime - - (System.currentTimeMillis() - this - .GetStateTime())), 1)); + Scoreboard.write(UtilTime.MakeStr(Math.max(0, GAME_TIMEOUT - (System.currentTimeMillis() - GetStateTime())), 1)); Scoreboard.draw(); } @@ -598,7 +515,7 @@ public class WitherGame extends TeamGame implements IBlockRestorer public int getRequiredWithers() { - return (int) (GetPlayers(true).size() / _witherFactor); + return (int) (GetPlayers(true).size() / WITHER_FACTOR); } @EventHandler @@ -620,15 +537,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer double distanceToGround = player.getLocation().distance(new Location(_spawn.getWorld(), player.getLocation().getX(), _spawn.getY(), player.getLocation().getZ())); double speed; - if (distanceToGround < 8) - { - speed = 0.16; - } - else - { - speed = 0.09 - (_yLimit - player.getLocation().getY()) * 0.006; - } - if (distanceToGround < 4) { speed = 0.016; @@ -662,10 +570,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer continue; UtilAction.velocity(player, vec, 0.6, false, 0, 0.4, 10, true); - - // if (player.getLocation().getY() < _yLimit + 6) - // UtilAction.velocity(player, new Vector(0, 1, 0), 0.6, false, 0, - // 0, 10, true); } } @@ -684,11 +588,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer else if (!isInsideMap(block.getLocation())) blockIter.remove(); - - // else if (UtilAlg.inBoundingBox(block.getLocation(), _safeA, - // _safeB) || UtilAlg.inBoundingBox(block.getLocation(), _spawnA, - // _spawnB)) - // blockIter.remove(); } for (Block block : blocks) @@ -717,32 +616,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer } } - // @EventHandler - // public void cleanLives(PlayerQuitEvent event) - // { - // _lives.remove(event.getPlayer()); - // } - - // @EventHandler - // public void livesUpdate(UpdateEvent event) - // { - // if (!IsLive()) - // return; - // - // if (event.getType() != UpdateType.FASTER) - // return; - // - // Iterator playerIter = _lives.keySet().iterator(); - // - // while (playerIter.hasNext()) - // { - // Player player = playerIter.next(); - // - // if (!player.isOnline() || !_runners.HasPlayer(player)) - // playerIter.remove(); - // } - // } - @EventHandler public void arrowDamage(CustomDamageEvent event) { @@ -921,20 +794,6 @@ public class WitherGame extends TeamGame implements IBlockRestorer Bukkit.getPluginManager().callEvent(new HumanReviveEvent(thrower, copy.GetPlayer())); } - - // Revive a player -// for (Player player : GetPlayers(true)) -// { -// GameTeam otherTeam = GetTeam(player); -// if (otherTeam == null || !otherTeam.equals(throwerTeam)) -// continue; -// -// if (UtilMath.offset(player.getLocation().add(0, 1, 0), event -// .getEntity().getLocation()) > 3) -// continue; -// -// playerIn(player, null, thrower); -// } } @EventHandler diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/kit/KitHumanMedic.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/kit/KitHumanMedic.java index db9e50fdf..dd48c1493 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/kit/KitHumanMedic.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wither/kit/KitHumanMedic.java @@ -29,8 +29,6 @@ public class KitHumanMedic extends Kit private static final ItemStack[] PLAYER_ITEMS = { ItemStackFactory.Instance.CreateStack(Material.STONE_AXE), - ItemStackFactory.Instance.CreateStack(Material.STONE_PICKAXE), - ItemStackFactory.Instance.CreateStack(Material.STONE_SPADE), new ItemBuilder(Material.POTION).setAmount(2).setData((short) 16429).setTitle(C.Reset + "Revival Potion").build(), ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP), ItemStackFactory.Instance.CreateStack(Material.MUSHROOM_SOUP), diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherArrows.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherArrows.java index 07249f73d..1a8df0655 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherArrows.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherArrows.java @@ -1,6 +1,7 @@ package nautilus.game.arcade.kit.perks; import java.util.Iterator; +import java.util.Map; import java.util.WeakHashMap; import org.bukkit.Sound; @@ -10,16 +11,18 @@ import org.bukkit.event.EventHandler; import mineplex.core.common.util.C; import mineplex.core.common.util.UtilParticle; -import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; +import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; + import nautilus.game.arcade.kit.Perk; public class PerkWitherArrows extends Perk { - private WeakHashMap _proj = new WeakHashMap(); + + private final Map _proj = new WeakHashMap<>(); public PerkWitherArrows() { @@ -32,8 +35,10 @@ public class PerkWitherArrows extends Perk @EventHandler public void shoot(UpdateEvent event) { - if (event.getType() != UpdateType.TICK) + if (event.getType() != UpdateType.TICK || !Manager.GetGame().IsLive()) + { return; + } for (Player player : Manager.GetGame().GetPlayers(true)) { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherAttack.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherAttack.java index 8609bcaac..75db3d6f3 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherAttack.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherAttack.java @@ -12,6 +12,7 @@ import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilEvent; import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilGear; +import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.UtilParticle.ParticleType; import mineplex.core.common.util.UtilParticle.ViewDist; @@ -21,15 +22,19 @@ import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; + import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.perks.data.IBlockRestorer; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Skeleton; import org.bukkit.entity.WitherSkull; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -40,74 +45,74 @@ import org.bukkit.event.player.PlayerInteractEvent; public class PerkWitherAttack extends Perk { private ArrayList _active = new ArrayList(); - - public PerkWitherAttack() + + public PerkWitherAttack() { - super("Wither Skull", new String[] - { - C.cYellow + "Left-Click" + C.cGray + " with Gold Sword to use " + C.cGreen + "Wither Skull" + super("Wither Skull", new String[] + { + C.cYellow + "Left-Click" + C.cGray + " with Gold Sword to use " + C.cGreen + "Wither Skull" }); } - - + + @EventHandler public void Activate(PlayerInteractEvent event) { if (event.isCancelled()) return; - + if (!UtilEvent.isAction(event, ActionType.L)) return; - + Player player = event.getPlayer(); - + if (!Kit.HasKit(player)) return; - + if (!UtilGear.isMat(event.getPlayer().getItemInHand(), Material.GOLD_SWORD)) return; - + if (!Recharge.Instance.use(player, GetName(), 2000, true, true)) return; - + //Fire _active.add(player.launchProjectile(WitherSkull.class)); - + //Sound player.getWorld().playSound(player.getLocation(), Sound.WITHER_SHOOT, 1f, 1f); - + //Inform UtilPlayer.message(player, F.main("Game", "You used " + F.skill(GetName()) + ".")); } - + @EventHandler public void explode(EntityExplodeEvent event) { if (!_active.contains(event.getEntity())) return; - + event.setCancelled(true); - - WitherSkull skull = (WitherSkull)event.getEntity(); - + + WitherSkull skull = (WitherSkull) event.getEntity(); + UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, skull.getLocation(), 0, 0, 0, 0, 1, ViewDist.MAX, UtilServer.getPlayers()); - + explode(skull); } - + @EventHandler - public void clean(UpdateEvent event) + public void clean(UpdateEvent event) { if (event.getType() != UpdateType.FAST) return; Iterator skullIterator = _active.iterator(); - + while (skullIterator.hasNext()) { WitherSkull skull = skullIterator.next(); - + if (!skull.isValid()) { skullIterator.remove(); @@ -116,21 +121,21 @@ public class PerkWitherAttack extends Perk } } } - + @EventHandler(priority = EventPriority.LOWEST) public void ExplodeDamage(CustomDamageEvent event) { if (event.IsCancelled()) return; - + if (event.GetProjectile() != null && event.GetProjectile() instanceof WitherSkull) event.SetCancelled("Wither Skull Cancel"); } - - private void explode(WitherSkull skull) - { - double scale = 0.4 + 0.6 * Math.min(1, skull.getTicksLived()/20d); - + + private void explode(WitherSkull skull) + { + double scale = 0.4 + 0.6 * Math.min(1, skull.getTicksLived() / 20d); + //Players HashMap players = UtilPlayer.getInRadius(skull.getLocation(), 7); for (Player player : players.keySet()) @@ -139,32 +144,39 @@ public class PerkWitherAttack extends Perk continue; //Damage Event - Manager.GetDamage().NewDamageEvent(player, (LivingEntity)skull.getShooter(), null, + Manager.GetDamage().NewDamageEvent(player, (LivingEntity) skull.getShooter(), null, DamageCause.CUSTOM, 2 + 10 * players.get(player) * scale, true, true, false, - UtilEnt.getName((LivingEntity)skull.getShooter()), GetName()); + UtilEnt.getName((LivingEntity) skull.getShooter()), GetName()); } - + //Blocks Set blocks = UtilBlock.getInRadius(skull.getLocation(), 4d).keySet(); - - Iterator blockIterator = blocks.iterator(); - while (blockIterator.hasNext()) + + blocks.removeIf(block -> { - Block block = blockIterator.next(); - - if (block.isLiquid()) - blockIterator.remove(); - - else if (block.getRelative(BlockFace.UP).isLiquid()) - blockIterator.remove(); - } + if (block.isLiquid() || block.getRelative(BlockFace.UP).isLiquid()) + { + return true; + } + + Location location = block.getLocation(); + + for (Entity entity : block.getWorld().getEntitiesByClass(Skeleton.class)) + { + if (UtilMath.offsetSquared(location, entity.getLocation()) < 9) + { + return true; + } + } + + return false; + }); if (Manager.GetGame() != null && Manager.GetGame() instanceof IBlockRestorer) { - ((IBlockRestorer)Manager.GetGame()).addBlocks(blocks); + ((IBlockRestorer) Manager.GetGame()).addBlocks(blocks); } - - + Manager.GetExplosion().BlockExplosion(blocks, skull.getLocation(), false); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherMinion.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherMinion.java index c0131bc41..b0747f158 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherMinion.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkWitherMinion.java @@ -1,21 +1,19 @@ package nautilus.game.arcade.kit.perks; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.WeakHashMap; +import java.util.HashMap; +import java.util.Map; import org.bukkit.ChatColor; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.Sound; -import org.bukkit.entity.Arrow; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; -import org.bukkit.entity.Skeleton.SkeletonType; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.entity.EntityTargetEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; @@ -26,26 +24,28 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEvent; +import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.common.util.UtilGear; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilEvent.ActionType; import mineplex.core.itemstack.ItemStackFactory; import mineplex.core.recharge.Recharge; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.minecraft.game.core.damage.CustomDamageEvent; + import nautilus.game.arcade.game.GameTeam; import nautilus.game.arcade.kit.Perk; -public class PerkWitherMinion extends Perk +public class PerkWitherMinion extends Perk { - private ArrayList _ents = new ArrayList(); - - public PerkWitherMinion() + + private final Map _minions = new HashMap<>(); + + public PerkWitherMinion() { - super("Wither Minions", new String[] + super("Wither Minions", new String[] { - C.cYellow + "Left-Click" + C.cGray + " with Diamond Sword to use " + C.cGreen + "Wither Minions" + C.cYellow + "Left-Click" + C.cGray + " with Diamond Sword to use " + C.cGreen + "Wither Minions" }); } @@ -75,96 +75,97 @@ public class PerkWitherMinion extends Perk event.setCancelled(true); Manager.GetGame().CreatureAllowOverride = true; - - for (int i=0 ; i<2 ; i++) + + for (int i = 0; i < 2; i++) { Skeleton skel = player.getWorld().spawn(player.getEyeLocation(), Skeleton.class); - _ents.add(skel); - - skel.getEquipment().setHelmet(ItemStackFactory.Instance.CreateStack(Material.SKULL_ITEM, (byte)1, 1)); - + _minions.put(skel, player); + + skel.getEquipment().setHelmet(ItemStackFactory.Instance.CreateStack(Material.SKULL_ITEM, (byte) 1, 1)); + ItemStack armor = new ItemStack(Material.LEATHER_CHESTPLATE); - LeatherArmorMeta meta = (LeatherArmorMeta)armor.getItemMeta(); + LeatherArmorMeta meta = (LeatherArmorMeta) armor.getItemMeta(); meta.setColor(Color.BLACK); armor.setItemMeta(meta); skel.getEquipment().setChestplate(armor); - + Manager.GetCondition().Factory().Invisible("Skeleton", skel, skel, 9999, 0, false, false, false); Manager.GetCondition().Factory().Speed("Skeleton", skel, skel, 9999, 0, false, false, false); - + Vector random = new Vector(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5); random.normalize(); random.multiply(0.1); - - UtilAction.velocity(skel, player.getLocation().getDirection().add(random), 1 + Math.random() * 0.4, false, 0, 0.2, 10, false); + + UtilAction.velocity(skel, player.getLocation().getDirection().add(random), 1 + Math.random() * 0.4, false, 0, 0.2, 10, false); } Manager.GetGame().CreatureAllowOverride = false; - + //Inform UtilPlayer.message(player, F.main("Game", "You used " + F.skill(GetName()) + ".")); //Effect player.getWorld().playSound(player.getLocation(), Sound.WITHER_HURT, 2f, 0.6f); } - - @EventHandler(priority = EventPriority.LOWEST) - public void witherFallCancel(CustomDamageEvent event) + + @EventHandler(priority = EventPriority.HIGH) + public void minionDamage(CustomDamageEvent event) { if (event.IsCancelled()) + { return; - - if (event.GetCause() != DamageCause.FALL) - return; - - if (!_ents.contains(event.GetDamageeEntity())) - return; - - event.SetCancelled("Minion Fall Damage"); + } + + LivingEntity damagee = event.GetDamageeEntity(), damager = event.GetDamagerEntity(true); + + if (event.GetCause() == DamageCause.FALL && _minions.containsKey(damagee)) + { + event.SetCancelled("Minion Fall Damage"); + } + else if (_minions.containsKey(damager)) + { + event.SetDamager(_minions.get(damager)); + } } - + @EventHandler public void entityTarget(EntityTargetEvent event) { if (getWitherTeam() == null) return; - + if (getWitherTeam().GetPlayers(true).contains(event.getTarget())) event.setCancelled(true); } - + @EventHandler - public void update(UpdateEvent event) + public void update(UpdateEvent event) { if (event.getType() != UpdateType.TICK) return; - - Iterator skelIter = _ents.iterator(); - - while (skelIter.hasNext()) + + _minions.keySet().removeIf(skel -> { - Skeleton skel = skelIter.next(); - if (!skel.isValid() || skel.getTicksLived() > 300 || skel.getLocation().getY() < 0) { skel.remove(); - skelIter.remove(); + return true; } - else + + if (skel.getTarget() == null) { - if (skel.getTarget() == null) - { - skel.setTarget(UtilPlayer.getClosest(skel.getLocation(), getWitherTeam().GetPlayers(true))); - } + skel.setTarget(UtilPlayer.getClosest(skel.getLocation(), getWitherTeam().GetPlayers(true))); } - } + + return false; + }); } - - public GameTeam getWitherTeam() + + private GameTeam getWitherTeam() { if (Manager.GetGame() == null) return null; - + return Manager.GetGame().GetTeam(ChatColor.RED); } }