From 41b7e4bf380aa94f396d5386c322cb6d84ee6a79 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 1 May 2017 14:26:41 +0100 Subject: [PATCH] Fix Zombie's Deaths Grasp hitting spectating players --- .../game/games/smash/kits/KitEnderman.java | 86 ++++++++----------- .../perks/creeper/PerkCreeperExplode.java | 3 +- .../arcade/kit/perks/PerkDeathsGrasp.java | 2 +- 3 files changed, 37 insertions(+), 54 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitEnderman.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitEnderman.java index 43137cfb9..ab333d936 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitEnderman.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/kits/KitEnderman.java @@ -1,23 +1,11 @@ package nautilus.game.arcade.game.games.smash.kits; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; - -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.inventory.ItemStack; - import mineplex.core.common.util.C; import mineplex.core.common.util.UtilInv; +import mineplex.core.disguise.disguises.DisguiseBase; import mineplex.core.disguise.disguises.DisguiseEnderman; import mineplex.core.itemstack.ItemStackFactory; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.damage.CustomDamageEvent; import nautilus.game.arcade.ArcadeManager; import nautilus.game.arcade.game.Game.GameState; import nautilus.game.arcade.game.games.smash.perks.PerkSmashStats; @@ -31,6 +19,13 @@ import nautilus.game.arcade.kit.Perk; import nautilus.game.arcade.kit.perks.PerkDoubleJump; import nautilus.game.arcade.kit.perks.event.PerkBlockGrabEvent; import nautilus.game.arcade.kit.perks.event.PerkBlockThrowEvent; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; public class KitEnderman extends SmashKit { @@ -82,8 +77,6 @@ public class KitEnderman extends SmashKit }; - public HashMap _disguises = new HashMap(); - public KitEnderman(ArcadeManager manager) { super(manager, "Enderman", KitAvailability.Gem, 3000, PERKS, EntityType.ENDERMAN, IN_HAND, DisguiseEnderman.class); @@ -93,9 +86,7 @@ public class KitEnderman extends SmashKit public void GiveItems(Player player) { disguise(player); - - _disguises.put(player, (DisguiseEnderman) Manager.GetDisguise().getActiveDisguise(player)); - + UtilInv.Clear(player); player.getInventory().addItem(PLAYER_ITEMS[0], PLAYER_ITEMS[1]); @@ -111,54 +102,45 @@ public class KitEnderman extends SmashKit @EventHandler public void BlockGrab(PerkBlockGrabEvent event) { - SetBlock(_disguises.get(event.GetPlayer()), event.GetId(), event.GetData()); + setBlock(event.GetPlayer(), event.GetId(), event.GetData()); } @EventHandler public void BlockThrow(PerkBlockThrowEvent event) { - SetBlock(_disguises.get(event.GetPlayer()), 0, (byte) 0); + setBlock(event.GetPlayer(), 0, (byte) 0); } @EventHandler public void Death(PlayerDeathEvent event) { - SetBlock(_disguises.get(event.getEntity()), 0, (byte) 0); - } - - public void SetBlock(DisguiseEnderman disguise, int id, byte data) - { - if (disguise == null) - { - return; - } - - disguise.SetCarriedId(id); - disguise.SetCarriedData(data); - - Manager.GetDisguise().updateDisguise(disguise); + setBlock(event.getEntity(), 0, (byte) 0); } @EventHandler - public void cleanDisguises(UpdateEvent event) + public void damage(CustomDamageEvent event) { - if (event.getType() != UpdateType.FAST) - { - return; - } - - for (Iterator> iterator = _disguises.entrySet().iterator(); iterator.hasNext();) - { - Entry current = iterator.next(); + Player player = event.GetDamageePlayer(); + DisguiseBase disguise = Manager.GetDisguise().getActiveDisguise(player); - if (!Manager.GetDisguise().isDisguised(current.getKey())) - { - iterator.remove(); - } - else if (Manager.GetDisguise().getActiveDisguise(current.getKey()) != current.getValue()) - { - iterator.remove(); - } + if (player != null && disguise != null && disguise instanceof DisguiseEnderman) + { + // Endermen drop their held block when damaged. This means the client renders it this way, so we need to resend the correct data on the next tick. + Manager.runSyncLater(() -> Manager.GetDisguise().updateDisguise(disguise), 1); + } + } + + public void setBlock(Player player, int id, byte data) + { + DisguiseBase disguise = Manager.GetDisguise().getActiveDisguise(player); + + if (player != null && disguise != null && disguise instanceof DisguiseEnderman) + { + DisguiseEnderman disguiseEnderman = (DisguiseEnderman) disguise; + disguiseEnderman.SetCarriedId(id); + disguiseEnderman.SetCarriedData(data); + + Manager.GetDisguise().updateDisguise(disguiseEnderman); } } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/creeper/PerkCreeperExplode.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/creeper/PerkCreeperExplode.java index d43b21e62..34f3764a5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/creeper/PerkCreeperExplode.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/smash/perks/creeper/PerkCreeperExplode.java @@ -138,7 +138,8 @@ public class PerkCreeperExplode extends SmashPerk UtilAction.zeroVelocity(player); // Sound - player.getWorld().playSound(player.getLocation(), Sound.CREEPER_HISS, (float) (0.5 + elapsed), (float) (0.5 + elapsed)); + float volume = (float) 0.5F + elapsed / 1000F; + player.getWorld().playSound(player.getLocation(), Sound.CREEPER_HISS, volume, volume); IncreaseSize(player); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDeathsGrasp.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDeathsGrasp.java index c57a8ceba..5b2cfef50 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDeathsGrasp.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkDeathsGrasp.java @@ -129,7 +129,7 @@ public class PerkDeathsGrasp extends Perk List team = TeamSuperSmash.getTeam(Manager, player, true); for (Player other : Manager.GetGame().GetPlayers(true)) { - if(team.contains(other)) + if(UtilPlayer.isSpectator(player) || team.contains(other)) { continue; }