Skip to content

Commit

Permalink
fix note remove calling wrong method
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 8, 2021
1 parent 2de6936 commit 4f15e69
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
Expand Up @@ -182,6 +182,7 @@ public void makeUnique(String id) {
noteName = id;
}

@Override
public void forget() {
flagTracker = null;
NotableManager.remove(this);
Expand Down
Expand Up @@ -132,6 +132,7 @@ public static String getSaved(LocationTag location) {
return NotableManager.getSavedId(location);
}

@Override
public void forget() {
NotableManager.remove(this);
}
Expand Down
Expand Up @@ -62,25 +62,27 @@ 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;
}

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);
}
Expand Down
Expand Up @@ -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());
}
Expand All @@ -72,7 +70,6 @@ else if (arg.matches("remove")) {
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("id")) {
throw new InvalidArgumentsException("Must specify an id");
}
Expand All @@ -82,60 +79,47 @@ 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 {
Debug.echoDebug(scriptEntry, id.asString() + " is not saved");
}
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);
}

}
}

0 comments on commit 4f15e69

Please sign in to comment.