Skip to content

Commit

Permalink
fix some old-style registerTags problems
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 20, 2019
1 parent fcab826 commit f11f34d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2436,18 +2436,6 @@ public static void registerTag(String name, TagRunnable.ObjectForm runnable) {
registeredObjectTags.put(name, runnable);
}

public static void registerTag(String name, final TagRunnable runnable) {
if (runnable.name == null) {
runnable.name = name;
}
registerTag(name, new TagRunnable.ObjectForm() {
@Override
public ObjectTag run(Attribute attribute, ObjectTag object) {
return new ElementTag(runnable.run(attribute, object)).getObjectAttribute(attribute);
}
});
}

@Override
public <T extends ObjectTag> T asObjectType(Class<T> type, TagContext context) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public String debuggable() {
for (ObjectTag item : objectForms) {
debugText.append(item.debuggable()).append(" <G>|<Y> ");
}
return debugText.substring(0, debugText.length() - 1);
return debugText.substring(0, debugText.length() - " <G>|<Y> ".length());
}

public String flag = null;
Expand Down Expand Up @@ -1970,18 +1970,6 @@ public static void registerTag(String name, TagRunnable.ObjectForm runnable) {
registeredObjectTags.put(name, runnable);
}

public static void registerTag(String name, final TagRunnable runnable) {
if (runnable.name == null) {
runnable.name = name;
}
registerTag(name, new TagRunnable.ObjectForm() {
@Override
public ObjectTag run(Attribute attribute, ObjectTag object) {
return new ElementTag(runnable.run(attribute, object)).getObjectAttribute(attribute);
}
});
}

private static String parseString(ListTag obj, String spacer) {

StringBuilder dScriptArg = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ public static void registerTags() {
// @description
// Returns the id of the queue.
// -->
registerTag("id", new TagRunnable() {
registerTag("id", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return new ElementTag(((QueueTag) object).queue.id).getAttribute(attribute.fulfill(1));
public ObjectTag run(Attribute attribute, ObjectTag object) {
return new ElementTag(((QueueTag) object).queue.id).getObjectAttribute(attribute.fulfill(1));
}
});

Expand All @@ -136,10 +136,10 @@ public String run(Attribute attribute, ObjectTag object) {
// @description
// Returns the number of script entries in the queue.
// -->
registerTag("size", new TagRunnable() {
registerTag("size", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return new ElementTag(((QueueTag) object).queue.script_entries.size()).getAttribute(attribute.fulfill(1));
public ObjectTag run(Attribute attribute, ObjectTag object) {
return new ElementTag(((QueueTag) object).queue.script_entries.size()).getObjectAttribute(attribute.fulfill(1));
}
});

Expand All @@ -149,10 +149,10 @@ public String run(Attribute attribute, ObjectTag object) {
// @description
// Returns the time this queue started as a duration.
// -->
registerTag("start_time", new TagRunnable() {
registerTag("start_time", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return new DurationTag(((QueueTag) object).queue.startTimeMilli / 50).getAttribute(attribute.fulfill(1));
public ObjectTag run(Attribute attribute, ObjectTag object) {
return new DurationTag(((QueueTag) object).queue.startTimeMilli / 50).getObjectAttribute(attribute.fulfill(1));
}
});

Expand All @@ -162,11 +162,11 @@ public String run(Attribute attribute, ObjectTag object) {
// @description
// Returns the time this queue has ran for (the length of time between now and when the queue started) as a duration.
// -->
registerTag("time_ran", new TagRunnable() {
registerTag("time_ran", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
public ObjectTag run(Attribute attribute, ObjectTag object) {
long timeNano = System.nanoTime() - ((QueueTag) object).queue.startTime;
return new DurationTag(timeNano / (1000000 * 1000.0)).getAttribute(attribute.fulfill(1));
return new DurationTag(timeNano / (1000000 * 1000.0)).getObjectAttribute(attribute.fulfill(1));
}
});

Expand All @@ -176,9 +176,9 @@ public String run(Attribute attribute, ObjectTag object) {
// @description
// Returns 'stopping', 'running', 'paused', or 'unknown'.
// -->
registerTag("state", new TagRunnable() {
registerTag("state", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
public ObjectTag run(Attribute attribute, ObjectTag object) {
String state;
if ((object instanceof Delayable) && ((Delayable) object).isPaused()) {
state = "paused";
Expand All @@ -192,7 +192,7 @@ else if (((QueueTag) object).queue.is_stopping) {
else {
state = "unknown";
}
return new ElementTag(state).getAttribute(attribute.fulfill(1));
return new ElementTag(state).getObjectAttribute(attribute.fulfill(1));
}
});

Expand All @@ -202,13 +202,13 @@ else if (((QueueTag) object).queue.is_stopping) {
// @description
// Returns the script that started this queue.
// -->
registerTag("script", new TagRunnable() {
registerTag("script", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
public ObjectTag run(Attribute attribute, ObjectTag object) {
if (((QueueTag) object).queue.script == null) {
return null;
}
return ((QueueTag) object).queue.script.getAttribute(attribute.fulfill(1));
return ((QueueTag) object).queue.script.getObjectAttribute(attribute.fulfill(1));
}
});

Expand All @@ -218,9 +218,9 @@ public String run(Attribute attribute, ObjectTag object) {
// @description
// Returns a list of commands waiting in the queue.
// -->
registerTag("commands", new TagRunnable() {
registerTag("commands", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
public ObjectTag run(Attribute attribute, ObjectTag object) {
ListTag commands = new ListTag();
for (ScriptEntry entry : ((QueueTag) object).queue.script_entries) {
StringBuilder sb = new StringBuilder();
Expand All @@ -230,7 +230,7 @@ public String run(Attribute attribute, ObjectTag object) {
}
commands.add(sb.substring(0, sb.length() - 1));
}
return commands.getAttribute(attribute.fulfill(1));
return commands.getObjectAttribute(attribute.fulfill(1));
}
});

Expand All @@ -240,10 +240,10 @@ public String run(Attribute attribute, ObjectTag object) {
// @description
// Returns the names of all definitions that were passed to the current queue.
// -->
registerTag("definitions", new TagRunnable() {
registerTag("definitions", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
return new ListTag(((QueueTag) object).queue.getAllDefinitions().keySet()).getAttribute(attribute.fulfill(1));
public ObjectTag run(Attribute attribute, ObjectTag object) {
return new ListTag(((QueueTag) object).queue.getAllDefinitions().keySet()).getObjectAttribute(attribute.fulfill(1));
}
});

Expand Down Expand Up @@ -272,14 +272,14 @@ public ObjectTag run(Attribute attribute, ObjectTag object) {
// Returns the values that have been determined via <@link command Determine>
// for this queue, or null if there is none.
// -->
registerTag("determination", new TagRunnable() {
registerTag("determination", new TagRunnable.ObjectForm() {
@Override
public String run(Attribute attribute, ObjectTag object) {
public ObjectTag run(Attribute attribute, ObjectTag object) {
if (((QueueTag) object).queue.determinations == null) {
return null;
}
else {
return ((QueueTag) object).queue.determinations.getAttribute(attribute.fulfill(1));
return ((QueueTag) object).queue.determinations.getObjectAttribute(attribute.fulfill(1));
}
}
});
Expand All @@ -304,15 +304,6 @@ public ObjectTag run(Attribute attribute, ObjectTag object) {
});
}

public static HashMap<String, TagRunnable> registeredTags = new HashMap<>();

public static void registerTag(String name, TagRunnable runnable) {
if (runnable.name == null) {
runnable.name = name;
}
registeredTags.put(name, runnable);
}

public static HashMap<String, TagRunnable.ObjectForm> registeredObjectTags = new HashMap<>();

public static void registerTag(String name, TagRunnable.ObjectForm runnable) {
Expand Down Expand Up @@ -358,15 +349,6 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
return otr.run(attribute, this);
}

TagRunnable tr = registeredTags.get(attrLow);
if (tr != null) {
if (!tr.name.equals(attrLow)) {
Debug.echoError(attribute.getScriptEntry() != null ? attribute.getScriptEntry().getResidingQueue() : null,
"Using deprecated form of tag '" + tr.name + "': '" + attrLow + "'.");
}
return new ElementTag(tr.run(attribute, this));
}

ObjectTag returned = CoreUtilities.autoPropertyTagObject(this, attribute);
if (returned != null) {
return returned;
Expand Down

0 comments on commit f11f34d

Please sign in to comment.