diff --git a/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java b/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java index 334e5cc..2cbdeb3 100644 --- a/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java +++ b/plugin/plugin-core/src/main/java/com/lishid/openinv/OpenInv.java @@ -38,6 +38,7 @@ import com.lishid.openinv.internal.ISpecialPlayerInventory; import com.lishid.openinv.listeners.InventoryClickListener; import com.lishid.openinv.listeners.InventoryDragListener; import com.lishid.openinv.listeners.PlayerListener; +import com.lishid.openinv.listeners.PluginListener; import com.lishid.openinv.util.Cache; import com.lishid.openinv.util.ConfigUpdater; import com.lishid.openinv.util.Function; @@ -67,7 +68,6 @@ public class OpenInv extends JavaPlugin implements IOpenInv { private final Map inventories = new HashMap(); private final Map enderChests = new HashMap(); - // TODO: handle plugin unload private final Multimap> pluginUsage = HashMultimap.create(); private final Cache playerCache = new Cache(300000L, @@ -135,6 +135,7 @@ public class OpenInv extends JavaPlugin implements IOpenInv { // Register listeners pm.registerEvents(new PlayerListener(this), this); + pm.registerEvents(new PluginListener(this), this); pm.registerEvents(new InventoryClickListener(this), this); // Bukkit will handle missing events for us, attempt to register InventoryDragEvent without a version check pm.registerEvents(new InventoryDragListener(this), this); @@ -516,6 +517,15 @@ public class OpenInv extends JavaPlugin implements IOpenInv { this.pluginUsage.remove(key, plugin.getClass()); } + /** + * Unmark any Players in use by the specified Plugin. + * + * @param plugin + */ + public void releaseAllPlayers(Plugin plugin) { + this.pluginUsage.removeAll(plugin.getClass()); + } + /** * Method for handling a Player coming online. * diff --git a/plugin/plugin-core/src/main/java/com/lishid/openinv/listeners/PluginListener.java b/plugin/plugin-core/src/main/java/com/lishid/openinv/listeners/PluginListener.java new file mode 100644 index 0000000..ea7dea8 --- /dev/null +++ b/plugin/plugin-core/src/main/java/com/lishid/openinv/listeners/PluginListener.java @@ -0,0 +1,27 @@ +package com.lishid.openinv.listeners; + +import com.lishid.openinv.OpenInv; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginDisableEvent; + +/** + * Listener for plugin-related events. + * + * @author Jikoo + */ +public class PluginListener implements Listener { + + private final OpenInv plugin; + + public PluginListener(OpenInv plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPluginDisable(PluginDisableEvent event) { + plugin.releaseAllPlayers(event.getPlugin()); + } + +}