Skip to content

Commit

Permalink
Add separate readSingleTag method
Browse files Browse the repository at this point in the history
Better tag control for the TagManager, yay!
  • Loading branch information
mcmonkey4eva committed Oct 19, 2014
1 parent 24bbf3c commit 343ac36
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/main/java/net/aufdemrand/denizen/tags/TagManager.java
Expand Up @@ -169,6 +169,26 @@ public void fetchObject(ReplaceableTagEvent event) {
}
}

public static String readSingleTag(String str, TagContext context) {
ReplaceableTagEvent event = new ReplaceableTagEvent(context.player, context.npc, str, context.entry);
if (event.isInstant() != context.instant) {
// Not the right type of tag, escape the brackets so it doesn't get parsed again
return String.valueOf((char)0x01) + str + String.valueOf((char)0x02);
} else {
// Call Event
Bukkit.getServer().getPluginManager().callEvent(event);
if ((!event.replaced() && event.getAlternative() != null)
|| (event.getReplaced().equals("null") && event.hasAlternative()))
event.setReplaced(event.getAlternative());
if (context.debug)
dB.echoDebug(context.entry, "Filled tag <" + event.toString() + "> with '" +
event.getReplaced() + "'.");
if (!event.replaced())
dB.echoError(context.entry != null ? context.entry.getResidingQueue(): null, "Tag '" + event.getReplaced() + "' is invalid!");
return escapeOutput(event.getReplaced());
}
}


public static String tag(dPlayer player, dNPC npc, String arg) {
return tag(player, npc, arg, false, null);
Expand Down Expand Up @@ -212,28 +232,11 @@ public static String tag(String arg, TagContext context) {
do {
// Just in case, do-loops make me nervous, but does implement a limit of 25 tags per argument.
failsafe++;
ReplaceableTagEvent event;
if (positions == null) break;
else {
String oriarg = arg.substring(positions[0] + 1, positions[1]);
event = new ReplaceableTagEvent(context.player, context.npc, oriarg, context.entry);
if (event.isInstant() != context.instant) {
// Not the right type of tag, escape the brackets so it doesn't get parsed again
arg = arg.substring(0, positions[0]) + String.valueOf((char)0x01)
+ escapeOutput(event.getReplaced()) + String.valueOf((char)0x02) + arg.substring(positions[1] + 1, arg.length());
} else {
// Call Event
Bukkit.getServer().getPluginManager().callEvent(event);
if ((!event.replaced() && event.getAlternative() != null)
|| (event.getReplaced().equals("null") && event.hasAlternative()))
event.setReplaced(event.getAlternative());
if (context.debug)
dB.echoDebug(context.entry, "Filled tag <" + event.toString() + "> with '" +
event.getReplaced() + "'.");
if (!event.replaced())
dB.echoError(context.entry != null ? context.entry.getResidingQueue(): null, "Tag '" + event.getReplaced() + "' is invalid!");
arg = arg.substring(0, positions[0]) + escapeOutput(event.getReplaced()) + arg.substring(positions[1] + 1, arg.length());
}
String replaced = readSingleTag(oriarg, context);
arg = arg.substring(0, positions[0]) + replaced + arg.substring(positions[1] + 1, arg.length());
}
// Find new tag
positions = locateTag(arg);
Expand Down

0 comments on commit 343ac36

Please sign in to comment.