Added unregister method to AuthMeInventoryPacketAdapter class.

more reload compatibility.
This commit is contained in:
DNx5 2015-11-26 03:40:30 +07:00
parent 2162a4abe4
commit 25ed44f801
3 changed files with 43 additions and 24 deletions

View File

@ -691,7 +691,7 @@ public class AuthMe extends JavaPlugin {
} }
} else { } else {
if (inventoryProtector != null) { if (inventoryProtector != null) {
ProtocolLibrary.getProtocolManager().removePacketListener(inventoryProtector); inventoryProtector.unregister();
inventoryProtector = null; inventoryProtector = null;
} }
} }

View File

@ -78,6 +78,10 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
ProtocolLibrary.getProtocolManager().addPacketListener(this); ProtocolLibrary.getProtocolManager().addPacketListener(this);
} }
public void unregister() {
ProtocolLibrary.getProtocolManager().removePacketListener(this);
}
/** /**
* Method sendInventoryPacket. * Method sendInventoryPacket.
* *
@ -87,7 +91,7 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS); 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); inventoryPacket.getIntegers().write(0, PLAYER_INVENTORY);
ItemStack[] playerCrafting = new ItemStack[CRAFTING_SIZE]; ItemStack[] playerCrafting = new ItemStack[CRAFTING_SIZE];
@ -95,21 +99,21 @@ public class AuthMeInventoryPacketAdapter extends PacketAdapter {
ItemStack[] armorContents = player.getInventory().getArmorContents(); ItemStack[] armorContents = player.getInventory().getArmorContents();
ItemStack[] mainInventory = player.getInventory().getContents(); ItemStack[] mainInventory = player.getInventory().getContents();
//bukkit saves the armor in reversed order // bukkit saves the armor in reversed order
Collections.reverse(Arrays.asList(armorContents)); 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[] hotbar = Arrays.copyOfRange(mainInventory, 0, HOTBAR_SIZE);
ItemStack[] storedInventory = Arrays.copyOfRange(mainInventory, HOTBAR_SIZE, mainInventory.length); 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; int inventorySize = playerCrafting.length + armorContents.length + mainInventory.length;
ItemStack[] completeInventory = new ItemStack[inventorySize]; ItemStack[] completeInventory = new ItemStack[inventorySize];
System.arraycopy(playerCrafting, 0, completeInventory, 0, playerCrafting.length); System.arraycopy(playerCrafting, 0, completeInventory, 0, playerCrafting.length);
System.arraycopy(armorContents, 0, completeInventory, playerCrafting.length, armorContents.length); System.arraycopy(armorContents, 0, completeInventory, playerCrafting.length, armorContents.length);
//storedInventory and hotbar // storedInventory and hotbar
System.arraycopy(storedInventory, 0, completeInventory System.arraycopy(storedInventory, 0, completeInventory
, playerCrafting.length + armorContents.length, storedInventory.length); , playerCrafting.length + armorContents.length, storedInventory.length);
System.arraycopy(hotbar, 0, completeInventory System.arraycopy(hotbar, 0, completeInventory

View File

@ -36,18 +36,24 @@ public class AuthMeServerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onServerPing(ServerListPingEvent event) { public void onServerPing(ServerListPingEvent event) {
if (!Settings.enableProtection) if (!Settings.enableProtection) {
return; 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()); String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
} else { if (!Settings.countriesBlacklist.isEmpty()) {
event.setMotd(m.send("country_banned")[0]); 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) @EventHandler(priority = EventPriority.HIGHEST)
public void onPluginDisable(PluginDisableEvent event) { public void onPluginDisable(PluginDisableEvent event) {
// Make sure the plugin instance isn't null
if (event.getPlugin() == null) {
return;
}
// Get the plugin instance // Get the plugin instance
Plugin pluginInstance = event.getPlugin(); Plugin pluginInstance = event.getPlugin();
// Make sure the plugin instance isn't null
if (pluginInstance == null)
return;
// Make sure it's not this plugin itself // Make sure it's not this plugin itself
if (pluginInstance.equals(this.plugin)) if (pluginInstance.equals(this.plugin)) {
return; return;
}
// Call the onPluginDisable method in the permissions manager // Call the onPluginDisable method in the permissions manager
this.plugin.getPermissionsManager().onPluginDisable(event); this.plugin.getPermissionsManager().onPluginDisable(event);
@ -91,6 +99,7 @@ public class AuthMeServerListener implements Listener {
if (pluginName.equalsIgnoreCase("CombatTagPlus")) { if (pluginName.equalsIgnoreCase("CombatTagPlus")) {
plugin.combatTagPlus = null; plugin.combatTagPlus = null;
ConsoleLogger.info("CombatTagPlus has been disabled, unhook!"); ConsoleLogger.info("CombatTagPlus has been disabled, unhook!");
return;
} }
if (pluginName.equalsIgnoreCase("ProtocolLib")) { if (pluginName.equalsIgnoreCase("ProtocolLib")) {
plugin.inventoryProtector = null; plugin.inventoryProtector = null;
@ -109,12 +118,18 @@ public class AuthMeServerListener implements Listener {
this.plugin.getPermissionsManager().onPluginEnable(event); this.plugin.getPermissionsManager().onPluginEnable(event);
String pluginName = event.getPlugin().getName(); String pluginName = event.getPlugin().getName();
if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) if (pluginName.equalsIgnoreCase("Essentials") || pluginName.equalsIgnoreCase("EssentialsSpawn")) {
plugin.checkEssentials(); plugin.checkEssentials();
if (pluginName.equalsIgnoreCase("Multiverse-Core")) return;
}
if (pluginName.equalsIgnoreCase("Multiverse-Core")) {
plugin.checkMultiverse(); plugin.checkMultiverse();
if (pluginName.equalsIgnoreCase("CombatTagPlus")) return;
}
if (pluginName.equalsIgnoreCase("CombatTagPlus")) {
plugin.checkCombatTagPlus(); plugin.checkCombatTagPlus();
return;
}
if (pluginName.equalsIgnoreCase("ProtocolLib")) { if (pluginName.equalsIgnoreCase("ProtocolLib")) {
plugin.checkProtocolLib(); plugin.checkProtocolLib();
} }