From 25ed44f801ba9e9d0c853993603a1fbcc7d7f849 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Thu, 26 Nov 2015 03:40:30 +0700 Subject: [PATCH] Added unregister method to AuthMeInventoryPacketAdapter class. more reload compatibility. --- src/main/java/fr/xephi/authme/AuthMe.java | 2 +- .../AuthMeInventoryPacketAdapter.java | 14 +++-- .../authme/listener/AuthMeServerListener.java | 51 ++++++++++++------- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 537cd1c3..fe492ff5 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -691,7 +691,7 @@ public class AuthMe extends JavaPlugin { } } else { if (inventoryProtector != null) { - ProtocolLibrary.getProtocolManager().removePacketListener(inventoryProtector); + inventoryProtector.unregister(); inventoryProtector = null; } } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java index a333dbd2..6e5e922b 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeInventoryPacketAdapter.java @@ -78,6 +78,10 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter { ProtocolLibrary.getProtocolManager().addPacketListener(this); } + public void unregister() { + ProtocolLibrary.getProtocolManager().removePacketListener(this); + } + /** * Method sendInventoryPacket. * @@ -87,7 +91,7 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter { ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS); - //we are sending our own inventory + // we are sending our own inventory inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY); ItemStack[] playerCrafting = new ItemStack[CRAFTING_SIZE]; @@ -95,21 +99,21 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter { ItemStack[] armorContents = player.getInventory().getArmorContents(); ItemStack[] mainInventory = player.getInventory().getContents(); - //bukkit saves the armor in reversed order + // bukkit saves the armor in reversed order Collections.reverse(Arrays.asList(armorContents)); - //same main inventory. The hotbar is at the beginning but it should be at the end of the array + // same main inventory. The hotbar is at the beginning but it should be at the end of the array ItemStack[] hotbar = Arrays.copyOfRange(mainInventory, 0, HOTBAR_SIZE); ItemStack[] storedInventory = Arrays.copyOfRange(mainInventory, HOTBAR_SIZE, mainInventory.length); - //concat all parts of the inventory together + // concat all parts of the inventory together int inventorySize = playerCrafting.length + armorContents.length + mainInventory.length; ItemStack[] completeInventory = new ItemStack[inventorySize]; System.arraycopy(playerCrafting, 0, completeInventory, 0, playerCrafting.length); System.arraycopy(armorContents, 0, completeInventory, playerCrafting.length, armorContents.length); - //storedInventory and hotbar + // storedInventory and hotbar System.arraycopy(storedInventory, 0, completeInventory , playerCrafting.length + armorContents.length, storedInventory.length); System.arraycopy(hotbar, 0, completeInventory diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java index 7495edf8..a5846e34 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerListener.java @@ -36,18 +36,24 @@ public class AuthMeServerListener implements Listener { */ @EventHandler(priority = EventPriority.HIGHEST) public void onServerPing(ServerListPingEvent event) { - if (!Settings.enableProtection) + if (!Settings.enableProtection) { return; - if (Settings.countries.isEmpty()) - return; - if (!Settings.countriesBlacklist.isEmpty()) { - if (Settings.countriesBlacklist.contains(GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()))) - event.setMotd(m.send("country_banned")[0]); } - if (Settings.countries.contains(GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()))) { - event.setMotd(plugin.getServer().getMotd()); - } else { - event.setMotd(m.send("country_banned")[0]); + + String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); + if (!Settings.countriesBlacklist.isEmpty()) { + if (Settings.countriesBlacklist.contains(countryCode)) { + event.setMotd(m.send("country_banned")[0]); + return; + } + } + + if (!Settings.countries.isEmpty()) { + if (Settings.countries.contains(countryCode)) { + event.setMotd(plugin.getServer().getMotd()); + } else { + event.setMotd(m.send("country_banned")[0]); + } } } @@ -58,16 +64,18 @@ public class AuthMeServerListener implements Listener { */ @EventHandler(priority = EventPriority.HIGHEST) public void onPluginDisable(PluginDisableEvent event) { + // Make sure the plugin instance isn't null + if (event.getPlugin() == null) { + return; + } + // Get the plugin instance Plugin pluginInstance = event.getPlugin(); - // Make sure the plugin instance isn't null - if (pluginInstance == null) - return; - // Make sure it's not this plugin itself - if (pluginInstance.equals(this.plugin)) + if (pluginInstance.equals(this.plugin)) { return; + } // Call the onPluginDisable method in the permissions manager this.plugin.getPermissionsManager().onPluginDisable(event); @@ -91,6 +99,7 @@ public class AuthMeServerListener implements Listener { if (pluginName.equalsIgnoreCase("CombatTagPlus")) { plugin.combatTagPlus = null; ConsoleLogger.info("CombatTagPlus has been disabled, unhook!"); + return; } if (pluginName.equalsIgnoreCase("ProtocolLib")) { plugin.inventoryProtector = null; @@ -109,12 +118,18 @@ public class AuthMeServerListener implements Listener { this.plugin.getPermissionsManager().onPluginEnable(event); String pluginName = event.getPlugin().getName(); - if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) + if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) { plugin.checkEssentials(); - if (pluginName.equalsIgnoreCase("Multiverse-Core")) + return; + } + if (pluginName.equalsIgnoreCase("Multiverse-Core")) { plugin.checkMultiverse(); - if (pluginName.equalsIgnoreCase("CombatTagPlus")) + return; + } + if (pluginName.equalsIgnoreCase("CombatTagPlus")) { plugin.checkCombatTagPlus(); + return; + } if (pluginName.equalsIgnoreCase("ProtocolLib")) { plugin.checkProtocolLib(); }