From 170606e5cdf4cdb349d957259220b76ad6da8da3 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Sat, 7 Dec 2019 06:59:20 -0800 Subject: [PATCH] more aggressive inventory tracking --- .../denizen/objects/InventoryTag.java | 24 +++++++++---------- .../core/InventoryScriptContainer.java | 2 +- .../core/InventoryScriptHelper.java | 10 -------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java index 13c0ef2934..94c337636d 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java @@ -180,11 +180,6 @@ public static InventoryTag mirrorBukkitInventory(Inventory inventory) { if (result != null) { return result; } - // Scripts have priority over notables - String scriptResult = InventoryScriptHelper.tempInventoryScripts.get(inventory); - if (scriptResult != null) { - return new InventoryTag(inventory).setIdentifiers("script", scriptResult); - } // Use the map to get notable inventories String title = NMSHandler.getInstance().getTitle(inventory); result = InventoryScriptHelper.notableInventories.get(title); @@ -332,17 +327,19 @@ public static InventoryTag valueOf(String string, PlayerTag player, NPCTag npc, } if (ScriptRegistry.containsScript(string, InventoryScriptContainer.class)) { - return ScriptRegistry.getScriptContainerAs(string, InventoryScriptContainer.class) - .getInventoryFrom(player, npc); + return ScriptRegistry.getScriptContainerAs(string, InventoryScriptContainer.class).getInventoryFrom(player, npc); } - if (NotableManager.isSaved(string) && NotableManager.isType(string, InventoryTag.class)) { - return (InventoryTag) NotableManager.getSavedObject(string); + Notable noted = NotableManager.getSavedObject(string); + if (noted instanceof InventoryTag) { + return (InventoryTag) noted; } for (String idType : idTypes) { if (string.equalsIgnoreCase(idType)) { - return new InventoryTag(string); + InventoryTag result = new InventoryTag(string); + trackTemporaryInventory(result); + return result; } } @@ -376,7 +373,7 @@ public static boolean matches(String arg) { return true; } - if (NotableManager.isSaved(tid) && NotableManager.isType(tid, InventoryTag.class)) { + if (NotableManager.isType(tid, InventoryTag.class)) { return true; } @@ -679,8 +676,9 @@ else if (getIdType().equals("enderchest")) { } } else if (getIdType().equals("script")) { - if (InventoryScriptHelper.tempInventoryScripts.containsKey(inventory)) { - idHolder = InventoryScriptHelper.tempInventoryScripts.get(inventory); + InventoryTag tracked = InventoryTrackerSystem.retainedInventoryLinks.get(inventory); + if (tracked != null) { + idHolder = tracked.idHolder; return; } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/containers/core/InventoryScriptContainer.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/containers/core/InventoryScriptContainer.java index 1c1e111ed9..234b1d5c1e 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/containers/core/InventoryScriptContainer.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/containers/core/InventoryScriptContainer.java @@ -263,7 +263,7 @@ else if (ItemTag.matches(item)) { } if (inventory != null) { - InventoryScriptHelper.tempInventoryScripts.put(inventory.getInventory(), getName()); + InventoryTag.trackTemporaryInventory(inventory); inventory.scriptName = getName(); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/containers/core/InventoryScriptHelper.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/containers/core/InventoryScriptHelper.java index c41a404166..bc818e07ea 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/containers/core/InventoryScriptHelper.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/containers/core/InventoryScriptHelper.java @@ -7,7 +7,6 @@ import com.denizenscript.denizen.objects.InventoryTag; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.PlayerInventory; @@ -21,7 +20,6 @@ public class InventoryScriptHelper implements Listener { public static Map inventory_scripts = new ConcurrentHashMap<>(8, 0.9f, 1); public static Map notableInventories = new HashMap<>(); - public static Map tempInventoryScripts = new HashMap<>(); public InventoryScriptHelper() { DenizenAPI.getCurrentInstance().getServer().getPluginManager() @@ -51,12 +49,4 @@ public void onPlayerLogin(PlayerLoginEvent event) { ImprovedOfflinePlayer.offlineEnderChests.remove(uuid); } } - - @EventHandler - public void onInventoryClose(InventoryCloseEvent event) { - Inventory inventory = event.getInventory(); - if (tempInventoryScripts.containsKey(inventory) && inventory.getViewers().isEmpty()) { - tempInventoryScripts.remove(inventory); - } - } }