Skip to content

Commit

Permalink
more aggressive inventory tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 7, 2019
1 parent 950711b commit 170606e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
Expand Up @@ -263,7 +263,7 @@ else if (ItemTag.matches(item)) {
}

if (inventory != null) {
InventoryScriptHelper.tempInventoryScripts.put(inventory.getInventory(), getName());
InventoryTag.trackTemporaryInventory(inventory);
inventory.scriptName = getName();
}

Expand Down
Expand Up @@ -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;
Expand All @@ -21,7 +20,6 @@ public class InventoryScriptHelper implements Listener {

public static Map<String, InventoryScriptContainer> inventory_scripts = new ConcurrentHashMap<>(8, 0.9f, 1);
public static Map<String, InventoryTag> notableInventories = new HashMap<>();
public static Map<Inventory, String> tempInventoryScripts = new HashMap<>();

public InventoryScriptHelper() {
DenizenAPI.getCurrentInstance().getServer().getPluginManager()
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 170606e

Please sign in to comment.