diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 6834ed751..5021741d3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -444,7 +444,7 @@ public class ClansManager extends MiniClientPlugin implements IRelat _scoreboard = new ClansScoreboardManager(plugin, this, _warManager, _worldEvent, _tutorial, clientManager, donationManager); _clanDataAccess = new ClansDataAccessLayer(this, _scoreboard); - new HelmetPacketManager(); + HelmetPacketManager.getInstance(); _bannerManager = new BannerManager(plugin); _goldManager = new GoldManager(this, _clientManager, donationManager, _clanDataAccess); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/HelmetPacketManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/HelmetPacketManager.java index 88069707e..a32871e94 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/HelmetPacketManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/HelmetPacketManager.java @@ -1,6 +1,5 @@ package mineplex.game.clans.clans; -import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; @@ -16,9 +15,9 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.packethandler.IPacketHandler; import net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment; -import net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot; /** * Handler for custom helmet display packets @@ -26,25 +25,13 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot; public class HelmetPacketManager implements Listener { private static final net.minecraft.server.v1_8_R3.ItemStack MELON = CraftItemStack.asNMSCopy(new ItemStack(Material.MELON_BLOCK)); - private Field _itemField; - private static HelmetPacketManager Instance; + private static final HelmetPacketManager Instance = new HelmetPacketManager(); + private final Map _handlers = new HashMap<>(); - - public HelmetPacketManager() + + private HelmetPacketManager() { - try - { - _itemField = PacketPlayOutSetSlot.class.getDeclaredField("c"); - _itemField.setAccessible(true); - - Bukkit.getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin()); - } - catch (Exception e) - { - e.printStackTrace(); - } - - Instance = this; + UtilServer.RegisterEvents(this); } /** @@ -116,9 +103,10 @@ public class HelmetPacketManager implements Listener @EventHandler public void onQuit(PlayerQuitEvent event) { - if (_handlers.containsKey(event.getPlayer())) + IPacketHandler handler = _handlers.remove(event.getPlayer()); + if (handler != null) { - ClansManager.getInstance().getPacketHandler().removePacketHandler(_handlers.remove(event.getPlayer())); + ClansManager.getInstance().getPacketHandler().removePacketHandler(handler); } } } \ No newline at end of file