diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java index ddaf85fe4..78c8bd6a4 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/stats/DeathBomberStatTracker.java @@ -1,23 +1,29 @@ package nautilus.game.arcade.stats; -import mineplex.core.common.util.UtilPlayer; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; -import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; -import nautilus.game.arcade.game.Game; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.inventory.ItemStack; - import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; +import mineplex.minecraft.game.core.combat.CombatComponent; +import mineplex.minecraft.game.core.combat.event.CombatDeathEvent; + +import nautilus.game.arcade.game.Game; + public class DeathBomberStatTracker extends StatTracker { - private int _required; + + private final int _required; private final Map _killCount = new HashMap<>(); public DeathBomberStatTracker(Game game, int requiredKills) @@ -30,29 +36,39 @@ public class DeathBomberStatTracker extends StatTracker @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onCombatDeath(CombatDeathEvent event) { - if (getGame().GetState() != Game.GameState.Live) + if (!getGame().IsLive()) + { return; + } - if (event.GetLog().GetKiller() == null) + CombatComponent killerComp = event.GetLog().GetKiller();; + + if (killerComp == null || !killerComp.IsPlayer()) + { return; + } if (!event.GetLog().GetKiller().IsPlayer()) return; - Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName()); + Player killer = UtilPlayer.searchExact(killerComp.GetName()); + if (killer == null) + { return; + } - if (event.GetLog().GetPlayer() == null) - return; - - if (!event.GetLog().GetPlayer().IsPlayer()) + if (event.GetLog().GetPlayer() == null || !event.GetLog().GetPlayer().IsPlayer()) + { return; + } Player killed = UtilPlayer.searchExact(event.GetLog().GetPlayer().GetName()); if(killer.equals(killed)) + { return; + } if (event.GetLog().GetKiller() != null && event.GetLog().GetKiller().GetReason().contains("Throwing TNT")) { @@ -61,38 +77,53 @@ public class DeathBomberStatTracker extends StatTracker count = (count == null ? 0 : count) + 1; System.out.println("Death Bomber: " + killer.getName() + " " + count); - + _killCount.put(killer.getUniqueId(), count); if (count >= _required) + { addStat(killer, "DeathBomber", 1, true, false); + } } } @EventHandler public void removeFakeThrowingTNT(UpdateEvent event) { - if (event.getType() != UpdateType.FAST) + if (event.getType() != UpdateType.FAST || !getGame().IsLive()) { return; } for (Player player : getGame().GetPlayers(true)) { - ItemStack[] contents = player.getInventory().getContents(); - int i = 0; + Inventory inventory = player.getInventory(); + ItemStack[] contents = inventory.getContents(); - for (ItemStack itemStack : contents) + for (int i = 0; i < contents.length; i++) { - if (itemStack == null || itemStack.getItemMeta() == null || itemStack.getItemMeta().getDisplayName() == null) + ItemStack itemStack = contents[i]; + + if (itemStack == null || itemStack.getType() == Material.TNT) { continue; } - if (itemStack.getItemMeta().getDisplayName().contains("Throwing TNT") && itemStack.getType() != Material.TNT) + ItemMeta itemMeta = itemStack.getItemMeta(); + + if (itemMeta == null || itemMeta.getDisplayName() == null) { - player.getInventory().setItem(i, null); + continue; } + + String displayName = itemMeta.getDisplayName(); + + if (displayName == null || !displayName.contains("Throwing TNT")) + { + continue; + } + + inventory.setItem(i, null); } } }