From 4f15e69d54b7e853435c995eb6590cf9a2a81830 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Mon, 8 Mar 2021 07:37:17 -0800 Subject: [PATCH] fix note remove calling wrong method --- .../denizen/objects/InventoryTag.java | 1 + .../denizen/objects/LocationTag.java | 1 + .../objects/notable/NotableManager.java | 12 ++++++---- .../scripts/commands/core/NoteCommand.java | 24 ++++--------------- 4 files changed, 13 insertions(+), 25 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 c6a55bec70..37c7929b15 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/InventoryTag.java @@ -182,6 +182,7 @@ public void makeUnique(String id) { noteName = id; } + @Override public void forget() { flagTracker = null; NotableManager.remove(this); diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java index 2e926cc67f..1f502dbef7 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java @@ -132,6 +132,7 @@ public static String getSaved(LocationTag location) { return NotableManager.getSavedId(location); } + @Override public void forget() { NotableManager.remove(this); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/objects/notable/NotableManager.java b/plugin/src/main/java/com/denizenscript/denizen/objects/notable/NotableManager.java index fbc8d3b43e..e9f246a13c 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/objects/notable/NotableManager.java +++ b/plugin/src/main/java/com/denizenscript/denizen/objects/notable/NotableManager.java @@ -62,17 +62,19 @@ public static void saveAs(Notable object, String id) { if (object == null) { return; } - notableObjects.put(CoreUtilities.toLowerCase(id), object); - reverseObjects.put(object, CoreUtilities.toLowerCase(id)); + id = CoreUtilities.toLowerCase(id); + notableObjects.put(id, object); + reverseObjects.put(object, id); notesByType.get(object.getClass()).add(object); } public static Notable remove(String id) { - Notable obj = notableObjects.get(CoreUtilities.toLowerCase(id)); + id = CoreUtilities.toLowerCase(id); + Notable obj = notableObjects.get(id); if (obj == null) { return null; } - notableObjects.remove(CoreUtilities.toLowerCase(id)); + notableObjects.remove(id); reverseObjects.remove(obj); notesByType.get(obj.getClass()).remove(obj); return obj; @@ -80,7 +82,7 @@ public static Notable remove(String id) { public static void remove(Notable obj) { String id = reverseObjects.get(obj); - notableObjects.remove(CoreUtilities.toLowerCase(id)); + notableObjects.remove(id); reverseObjects.remove(obj); notesByType.get(obj.getClass()).remove(obj); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/core/NoteCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/core/NoteCommand.java index d4d40f5765..ce785db6f2 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/core/NoteCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/core/NoteCommand.java @@ -56,9 +56,7 @@ public NoteCommand() { @Override public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException { - for (Argument arg : scriptEntry.getProcessedArgs()) { - if (arg.matchesPrefix("as", "i", "id")) { scriptEntry.addObject("id", arg.asElement()); } @@ -72,7 +70,6 @@ else if (arg.matches("remove")) { arg.reportUnhandled(); } } - if (!scriptEntry.hasObject("id")) { throw new InvalidArgumentsException("Must specify an id"); } @@ -82,24 +79,20 @@ else if (arg.matches("remove")) { if (!scriptEntry.hasObject("remove")) { scriptEntry.addObject("remove", new ElementTag(false)); } - } @Override public void execute(ScriptEntry scriptEntry) { - String object = (String) scriptEntry.getObject("object"); ElementTag id = scriptEntry.getElement("id"); ElementTag remove = scriptEntry.getElement("remove"); - if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), ArgumentHelper.debugObj("object", object) + id.debug() + remove.debug()); - } - if (remove.asBoolean()) { - if (NotableManager.remove(id.asString()) != null) { + Notable note = NotableManager.getSavedObject(id.asString()); + if (note != null) { + note.forget(); Debug.echoDebug(scriptEntry, "notable '" + id.asString() + "' removed"); } else { @@ -107,35 +100,26 @@ public void execute(ScriptEntry scriptEntry) { } return; } - String object_type = CoreUtilities.toLowerCase(object.split("@")[0]); Class object_class = ObjectFetcher.getObjectClass(object_type); - if (object_class == null) { Debug.echoError(scriptEntry.getResidingQueue(), "Invalid object type! Could not fetch '" + object_type + "'!"); return; } - ObjectTag arg; try { - if (!ObjectFetcher.checkMatch(object_class, object)) { - Debug.echoError(scriptEntry.getResidingQueue(), "'" + object - + "' is an invalid " + object_class.getSimpleName() + "."); + Debug.echoError(scriptEntry.getResidingQueue(), "'" + object + "' is an invalid " + object_class.getSimpleName() + "."); return; } - arg = ObjectFetcher.getObjectFrom(object_class, object, scriptEntry.entryData.getTagContext()); - if (arg instanceof Notable) { ((Notable) arg).makeUnique(id.asString()); } - } catch (Exception e) { Debug.echoError(scriptEntry.getResidingQueue(), "Uh oh! Report this to the Denizen developers! Err: NoteCommandObjectReflection"); Debug.echoError(scriptEntry.getResidingQueue(), e); } - } }