Skip to content

Commit

Permalink
Make TagContext abstract
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 12, 2015
1 parent f3f605e commit 2f93af6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,9 @@ else if (arg.indexOf('@') == 2) {
* flag.getLast().asString()
*/
public abstract String getLastEntryFromFlag(String flag);

/**
* Return a valid tag context object based on the given ScriptEntry object.
*/
public TagContext getTagContext(ScriptEntry entry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.scripts.queues.ScriptQueue;
import net.aufdemrand.denizencore.tags.TagContext;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
Expand Down Expand Up @@ -121,7 +122,7 @@ public static boolean checkMatch(Class<? extends dObject> dClass, String value)

@Deprecated
public static <T extends dObject> T getObjectFrom(Class<T> dClass, String value) {
return getObjectFrom(dClass, value, new TagContext(false, false, null));
return getObjectFrom(dClass, value, DenizenCore.getImplementation().getTagContext(null));
}

public static List<String> separateProperties(String input) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/aufdemrand/denizencore/objects/dScript.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ public String getAttribute(Attribute attribute) {
each = "null";
}
// TODO
list.add(TagManager.tag(each.toString(), new TagContext(false, true, attribute.getScriptEntry())));
list.add(TagManager.tag(each.toString(), DenizenCore.getImplementation().getTagContext(attribute.getScriptEntry())));
}
return list.getAttribute(attribute.fulfill(1));

}
// TODO
else {
return new Element(TagManager.tag(obj.toString(), new TagContext(false, true, attribute.getScriptEntry())))
return new Element(TagManager.tag(obj.toString(), DenizenCore.getImplementation().getTagContext(attribute.getScriptEntry())))
.getAttribute(attribute.fulfill(1));
}
}
Expand Down Expand Up @@ -342,14 +342,14 @@ public String getAttribute(Attribute attribute) {
each = "null";
}
// TODO
list.add(TagManager.tag(each.toString(), new TagContext(false, false, attribute.getScriptEntry())));
list.add(TagManager.tag(each.toString(), DenizenCore.getImplementation().getTagContext(attribute.getScriptEntry())));
}
return list.getAttribute(attribute.fulfill(1));

}
// TODO
else {
return new Element(TagManager.tag(obj.toString(), new TagContext(false, false, attribute.getScriptEntry())))
return new Element(TagManager.tag(obj.toString(), DenizenCore.getImplementation().getTagContext(attribute.getScriptEntry())))
.getAttribute(attribute.fulfill(1));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public boolean execute(ScriptEntry scriptEntry) {

// Save the scriptentry if needed later for fetching scriptentry context
if (arg.matchesPrefix("save") && !if_ignore) {
String saveName = TagManager.tag(arg.getValue(), new TagContext(false, scriptEntry.shouldDebug(), scriptEntry));
String saveName = TagManager.tag(arg.getValue(), DenizenCore.getImplementation().getTagContext(scriptEntry));
dB.echoDebug(scriptEntry, "...remembering this script entry as '" + saveName + "'!");
scriptEntry.getResidingQueue().holdScriptEntry(saveName, scriptEntry);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aufdemrand/denizencore/tags/Attribute.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.aufdemrand.denizencore.tags;

import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.utilities.CoreUtilities;

Expand Down Expand Up @@ -143,7 +144,7 @@ public String getContext(int attribute) {
if (contextMatcher.find()) {
String tagged = TagManager.cleanOutputFully(TagManager.tag(
text.substring(contextMatcher.start() + 1, contextMatcher.end() - 1),
new TagContext(false, scriptEntry == null || scriptEntry.shouldDebug(), scriptEntry)));
DenizenCore.getImplementation().getTagContext(scriptEntry)));
contexts.set(attribute - 1, tagged);
original_contexts.set(attribute - 1 + fulfilled, tagged);
return tagged;
Expand Down
24 changes: 2 additions & 22 deletions src/main/java/net/aufdemrand/denizencore/tags/TagContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,19 @@
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.ScriptEntryData;

public class TagContext { // TODO: make abstract?
public abstract class TagContext {
public final boolean instant;
public final boolean debug;
public final ScriptEntry entry;
public final dScript script;

/**
* TODO: NEVER CALL DIRECTLY
*/
public TagContext( boolean instant, boolean debug, ScriptEntry entry) {
this.instant = instant;
this.debug = debug;
this.entry = entry;
this.script = null;
}

/**
* TODO: NEVER CALL DIRECTLY
*/
public TagContext(boolean instant, boolean debug, ScriptEntry entry, dScript script) {
this.instant = instant;
this.debug = debug;
this.entry = entry;
this.script = script;
}

// TODO: IMPLEMENT IN BUKKIT

/**
* Must implement.
*/
public ScriptEntryData getScriptEntryData() {
return null;
}
public abstract ScriptEntryData getScriptEntryData();
}

0 comments on commit 2f93af6

Please sign in to comment.