Skip to content

Commit

Permalink
More TagManager cleaning
Browse files Browse the repository at this point in the history
Closer and closer to being able to move coreward
  • Loading branch information
mcmonkey4eva committed Dec 13, 2014
1 parent e0b1454 commit 8f0cc96
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 38 deletions.
Expand Up @@ -369,7 +369,7 @@ public ScriptEntry trackObject(String key) {
/////////

@Override
public boolean shouldDebug() throws Exception {
public boolean shouldDebug() {
if (script != null && script.getContainer() != null)
return script.getContainer().shouldDebug();
else
Expand Down
Expand Up @@ -7,6 +7,7 @@

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dNPC;
Expand Down Expand Up @@ -99,8 +100,14 @@ public boolean execute(ScriptEntry scriptEntry) {
// Throw exception if arguments are required for this command, but not supplied.
if (command.getOptions().REQUIRED_ARGS > scriptEntry.getArguments().size()) throw new InvalidArgumentsException("");

if (scriptEntry.has_tags)
scriptEntry.setArguments(TagManager.fillArguments(scriptEntry.getArguments(), scriptEntry, true)); // Replace tags
if (scriptEntry.has_tags) {
scriptEntry.setArguments(TagManager.fillArguments(scriptEntry.getArguments(),
new BukkitTagContext(scriptEntry != null ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(): null,
scriptEntry != null ? ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(): null,
true, scriptEntry, scriptEntry != null ? scriptEntry.shouldDebug(): true,
scriptEntry != null ? scriptEntry.getScript(): null
))); // Replace tags
}

/* If using NPC:# or PLAYER:Name arguments, these need to be changed out immediately because...
* 1) Denizen/Player flags need the desired NPC/PLAYER before parseArgs's getFilledArguments() so that
Expand Down Expand Up @@ -201,7 +208,12 @@ else if (arg.matchesPrefix("save") && !if_ignore) {
scriptEntry.setArguments(newArgs);

// Now process non-instant tags.
scriptEntry.setArguments(TagManager.fillArguments(scriptEntry.getArguments(), scriptEntry, false));
scriptEntry.setArguments(TagManager.fillArguments(scriptEntry.getArguments(),
new BukkitTagContext(scriptEntry != null ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(): null,
scriptEntry != null ? ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(): null,
false, scriptEntry, scriptEntry != null ? scriptEntry.shouldDebug(): true,
scriptEntry != null ? scriptEntry.getScript(): null
))); // Replace tags

// Parse the rest of the arguments for execution.
command.parseArgs(scriptEntry);
Expand Down
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.exceptions.ScriptEntryCreationException;
Expand Down Expand Up @@ -156,8 +157,7 @@ else if (callback != null && callback.asBoolean()) {
data.instaTicks = 0;
}
data.LastChecked = System.currentTimeMillis();
if (TagManager.tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
data.value, false, scriptEntry).equalsIgnoreCase("true")) {
if (TagManager.tag(data.value, new BukkitTagContext(scriptEntry, false)).equalsIgnoreCase("true")) {
dB.echoDebug(scriptEntry, dB.DebugElement.Header, "While loop " + data.index);
scriptEntry.getResidingQueue().addDefinition("loop_index", String.valueOf(data.index));
ArrayList<ScriptEntry> bracedCommands = BracedCommand.getBracedCommands(scriptEntry.getOwner()).get("WHILE");
Expand Down Expand Up @@ -199,9 +199,9 @@ else if (callback != null && callback.asBoolean()) {
// Report to dB
dB.report(scriptEntry, getName(), value.debug());

if (!TagManager.tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(),
value.asString(), false, scriptEntry).equalsIgnoreCase("true"))
if (TagManager.tag(value.asString(), new BukkitTagContext(scriptEntry, false)).equalsIgnoreCase("true")) {
return;
}

WhileData datum = new WhileData();
datum.index = 1;
Expand Down
Expand Up @@ -8,6 +8,7 @@
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.nbt.LeatherColorer;
Expand Down Expand Up @@ -109,7 +110,7 @@ public ItemScriptContainer(YamlConfiguration configurationSection, String script

// Process all tags in list
for (int n = 0; n < recipeList.size(); n++) {
recipeList.set(n, TagManager.tag(player, npc, recipeList.get(n), false, null, dB.shouldDebug(this), new dScript(this)));
recipeList.set(n, TagManager.tag(recipeList.get(n), new BukkitTagContext(player, npc, false, null, dB.shouldDebug(this), new dScript(this))));
}

// Store every ingredient in a dList
Expand Down Expand Up @@ -162,7 +163,7 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {
}
// Check validity of material
if (contains("MATERIAL")){
String material = TagManager.tag(player, npc, getString("MATERIAL"), false, null, debug, new dScript(this));
String material = TagManager.tag(getString("MATERIAL"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
if (material.startsWith("m@"))
material = material.substring(2);
stack = dItem.valueOf(material);
Expand All @@ -184,20 +185,20 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {

// Set Display Name
if (contains("DISPLAY NAME")){
String displayName = TagManager.tag(player, npc, getString("DISPLAY NAME"), false, null, debug, new dScript(this));
String displayName = TagManager.tag(getString("DISPLAY NAME"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
meta.setDisplayName(displayName);
}

// Set if the object is bound to the player
if (contains("BOUND")) {
bound = Boolean.valueOf(TagManager.tag(player, npc, getString("BOUND"), false, null, debug, new dScript(this)));
bound = Boolean.valueOf(TagManager.tag(getString("BOUND"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this))));
}

// Set Lore
if (contains("LORE")) {

for (String l : getStringList("LORE")){
l = TagManager.tag(player, npc, l, false, null, debug, new dScript(this));
l = TagManager.tag(l, new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
lore.add(l);
}
}
Expand All @@ -209,7 +210,7 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {
if (contains("ENCHANTMENTS")) {
for (String enchantment : getStringList("ENCHANTMENTS")) {

enchantment = TagManager.tag(player, npc, enchantment, false, null, debug, new dScript(this));
enchantment = TagManager.tag(enchantment, new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
try {
// Build enchantment context
int level = 1;
Expand All @@ -232,14 +233,14 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {
// Set Color
if (contains("COLOR"))
{
String color = TagManager.tag(player, npc, getString("COLOR"), false, null, debug, new dScript(this));
String color = TagManager.tag(getString("COLOR"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this)));
LeatherColorer.colorArmor(stack, color);
}

// Set Book
if (contains("BOOK")) {
BookScriptContainer book = ScriptRegistry
.getScriptContainer(TagManager.tag(player, npc, getString("BOOK"), false, null, debug, new dScript(this)).replace("s@", ""));
.getScriptContainer(TagManager.tag(getString("BOOK"), new BukkitTagContext(player, npc, false, null, debug, new dScript(this))).replace("s@", ""));

stack = book.writeBookTo(stack, player, npc);
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/aufdemrand/denizen/tags/Attribute.java
Expand Up @@ -143,10 +143,8 @@ public String getContext(int attribute) {

if (contextMatcher.find()) {
String tagged = TagManager.cleanOutputFully(TagManager.tag(
scriptEntry != null ? ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(): null,
scriptEntry != null ? ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(): null,
text.substring(contextMatcher.start() + 1,
contextMatcher.end() - 1), false, getScriptEntry()));
text.substring(contextMatcher.start() + 1, contextMatcher.end() - 1),
new BukkitTagContext(scriptEntry, false)));
contexts.set(attribute - 1, tagged);
original_contexts.set(attribute - 1 + fulfilled, tagged);
return tagged;
Expand Down
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.tags;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dScript;
Expand All @@ -18,4 +19,12 @@ public BukkitTagContext(dPlayer player, dNPC npc, boolean instant, ScriptEntry e
this.entry = entry;
this.script = script;
}

public BukkitTagContext(ScriptEntry entry, boolean instant) {
super(instant, entry != null ? entry.shouldDebug(): true);
this.entry = entry;
player = entry != null ? ((BukkitScriptEntryData)entry.entryData).getPlayer(): null;
npc = entry != null ? ((BukkitScriptEntryData)entry.entryData).getNPC(): null;
script = entry != null ? entry.getScript(): null;
}
}
Expand Up @@ -243,8 +243,10 @@ public String getValue() {
if (value_tagged)
return value;
value_tagged = true;
value = TagManager.cleanOutputFully(TagManager.tag(
getPlayer(), getNPC(), value, false, getScriptEntry()));
value = TagManager.cleanOutputFully(TagManager.tag(value,
new BukkitTagContext(getPlayer(), getNPC(), false, getScriptEntry(),
getScriptEntry() != null ? getScriptEntry().shouldDebug() : true,
getScript())));
return value;
}

Expand All @@ -258,8 +260,10 @@ public String getAlternative() {
if (alternative_tagged)
return alternative;
alternative_tagged = true;
alternative = TagManager.cleanOutputFully(TagManager.tag(
getPlayer(), getNPC(), alternative, false, getScriptEntry()));
alternative = TagManager.cleanOutputFully(TagManager.tag(alternative,
new BukkitTagContext(getPlayer(), getNPC(), false, getScriptEntry(),
getScriptEntry() != null ? getScriptEntry().shouldDebug(): true,
getScript())));
return alternative;
}

Expand Down
17 changes: 5 additions & 12 deletions src/main/java/net/aufdemrand/denizen/tags/TagManager.java
Expand Up @@ -298,11 +298,6 @@ public static String tag(dPlayer player, dNPC npc, String arg, boolean instant,
}
}

@Deprecated // TODO: Delete all usages
public static String tag(dPlayer player, dNPC npc, String arg, boolean instant, ScriptEntry scriptEntry, boolean debug, dScript script) {
return tag(arg, new BukkitTagContext(player, npc, instant, scriptEntry, debug, script));
}

public static String tag(String arg, TagContext context) {
if (arg == null) return null;

Expand Down Expand Up @@ -360,11 +355,7 @@ else if (arg.charAt(i) == '>') {
else return null;
}

public static List<String> fillArguments(List<String> args, ScriptEntry scriptEntry) {
return fillArguments(args, scriptEntry, false);
}

public static List<String> fillArguments(List<String> args, ScriptEntry scriptEntry, boolean instant) {
public static List<String> fillArguments(List<String> args, TagContext context) {
List<String> filledArgs = new ArrayList<String>();

int nested_level = 0;
Expand All @@ -375,9 +366,11 @@ public static List<String> fillArguments(List<String> args, ScriptEntry scriptEn
if (argument.equals("}")) nested_level--;
// If this argument isn't nested, fill the tag.
if (nested_level < 1) {
filledArgs.add(tag(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData)scriptEntry.entryData).getNPC(), argument, instant, scriptEntry));
filledArgs.add(tag(argument, context));
}
else {
filledArgs.add(argument);
}
else filledArgs.add(argument);
}
}
return filledArgs;
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/net/aufdemrand/denizen/tags/core/ParseTags.java
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.Denizen;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.ReplaceableTagEvent;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.scripts.ScriptEntry;
Expand Down Expand Up @@ -32,8 +33,10 @@ public void parseTags(ReplaceableTagEvent event) {
return;
}
ScriptEntry se = event.getAttributes().getScriptEntry();
String read = TagManager.tag((se != null ?((BukkitScriptEntryData)se.entryData).getPlayer(): null),
(se != null ?((BukkitScriptEntryData)se.entryData).getNPC(): null), TagManager.cleanOutputFully(event.getValue()), false, se);
String read = TagManager.tag(TagManager.cleanOutputFully(event.getValue()), new BukkitTagContext(
(se != null ?((BukkitScriptEntryData)se.entryData).getPlayer(): null),
(se != null ?((BukkitScriptEntryData)se.entryData).getNPC(): null), false, se,
se != null ? se.shouldDebug(): true, se != null ? se.getScript(): null));
event.setReplaced(new Element(read).getAttribute(event.getAttributes().fulfill(1)));
}
}
Expand Down

0 comments on commit 8f0cc96

Please sign in to comment.