Improve HelmetPacketManager's code (trimming unnecessary fields, handling instancing in a more immutable manner, replacing the Map containsKey + remove with a remove + a null check)
This commit is contained in:
parent
9f37e937fa
commit
0949ceadd3
@ -444,7 +444,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> 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);
|
||||
|
@ -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<Player, IPacketHandler> _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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user