Skip to content

Commit

Permalink
Work towards removing outdated TagManager usages
Browse files Browse the repository at this point in the history
With the intent of empowering the core
  • Loading branch information
mcmonkey4eva committed Dec 13, 2014
1 parent c93d3f3 commit 1b5f53e
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 56 deletions.
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.events.bukkit.ScriptReloadEvent;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
Expand Down Expand Up @@ -44,10 +45,12 @@ public String getConstant(String name) {

getAssignmentConstants();

if (constants.containsKey(name.toLowerCase()))
return TagManager.tag(null, DenizenAPI.getDenizenNPC(npc), constants.get(name.toLowerCase()), false);
if (constants.containsKey(name.toLowerCase())) // TODO: shouldDebug
return TagManager.tag(constants.get(name.toLowerCase()),
new BukkitTagContext(null, DenizenAPI.getDenizenNPC(npc), false, null, true, null));
else if (getAssignmentConstants().containsKey(name.toLowerCase()))
return TagManager.tag(null, DenizenAPI.getDenizenNPC(npc), assignmentConstants.get(name.toLowerCase()), false);
return TagManager.tag(assignmentConstants.get(name.toLowerCase()),
new BukkitTagContext(null, DenizenAPI.getDenizenNPC(npc), false, null, true, null));
return null;
}

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/net/aufdemrand/denizen/npc/traits/HealthTrait.java
Expand Up @@ -2,8 +2,10 @@

import net.aufdemrand.denizen.Settings;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizencore.tags.TagContext;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.persistence.Persist;
Expand Down Expand Up @@ -72,7 +74,8 @@ public String getRespawnLocationAsString() {
}

public Location getRespawnLocation() {
return dLocation.valueOf(TagManager.tag(null, dNPC.mirrorCitizensNPC(npc), respawnLocation));
return dLocation.valueOf(TagManager.tag(respawnLocation, new BukkitTagContext(null,
dNPC.mirrorCitizensNPC(npc), false, null, false, null)));
}

public void setRespawnable(boolean respawnable) {
Expand Down Expand Up @@ -288,9 +291,8 @@ else if (event instanceof EntityDamageByBlockEvent)
if (npc.getBukkitEntity() == null)
return;

loc = dLocation.valueOf(TagManager.tag(null,
DenizenAPI.getDenizenNPC(npc),
respawnLocation, false));
loc = dLocation.valueOf(TagManager.tag(respawnLocation, // TODO: debug option?
new BukkitTagContext(null, DenizenAPI.getDenizenNPC(npc), false, null, true, null)));

if (loc == null) loc = npc.getBukkitEntity().getLocation();

Expand Down
@@ -1,5 +1,6 @@
package net.aufdemrand.denizen.npc.traits;

import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.citizensnpcs.api.persistence.Persist;
Expand Down Expand Up @@ -54,7 +55,8 @@ public void setNickname(String nickName) {
*/
public String getNickname() {
if (nickname == null || nickname.equals("")) return npc.getName();
else return TagManager.tag(null, DenizenAPI.getDenizenNPC(npc), nickname, false);
else return TagManager.tag(nickname, // TODO: debug option?
new BukkitTagContext(null, DenizenAPI.getDenizenNPC(npc), false, null, true, null));
}

/**
Expand Down
Expand Up @@ -244,7 +244,7 @@ ScriptEntrySet getSetFor(String path) {
private Boolean shouldDebug = null;

@Override
public boolean shouldDebug() throws Exception {
public boolean shouldDebug() {
if (shouldDebug == null)
shouldDebug = (!(contents.contains("DEBUG") && contents.getString("DEBUG").equalsIgnoreCase("false")));
return shouldDebug;
Expand Down
Expand Up @@ -4,6 +4,7 @@
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.objects.dItem;

Expand Down Expand Up @@ -66,7 +67,7 @@ public dItem writeBookTo(dItem book, dPlayer player, dNPC npc) {

if (contains("TITLE")) {
String title = getString("TITLE");
title = TagManager.tag(player, npc, title, false, null, dB.shouldDebug(this), new dScript(this));
title = TagManager.tag(title, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
bookInfo.setTitle(title);
}

Expand All @@ -78,15 +79,15 @@ public dItem writeBookTo(dItem book, dPlayer player, dNPC npc) {

if (contains("AUTHOR")) {
String author = getString("AUTHOR");
author = TagManager.tag(player, npc, author, false);
author = TagManager.tag(author, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
bookInfo.setAuthor(author);
}

if (contains("TEXT")) {
List<String> pages = getStringList("TEXT");

for (String page : pages) {
page = TagManager.tag(player, npc, page, false, null, dB.shouldDebug(this), new dScript(this));
page = TagManager.tag(page, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
bookInfo.addPage(page);
}
}
Expand Down
Expand Up @@ -8,6 +8,7 @@
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.scripts.queues.core.InstantQueue;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenCommand;
import net.aufdemrand.denizencore.utilities.YamlConfiguration;
Expand Down Expand Up @@ -116,11 +117,13 @@ public String getDescription() {
// Replace new lines with a space and a new line, to allow full brief descriptions in /help.
// Without this, "line<n>line"s brief description would be "lin", because who doesn't like
// random cutoff-
return TagManager.tag(null, null, getString("DESCRIPTION", "")).replace("\n", " \n");
return TagManager.tag((getString("DESCRIPTION", "")).replace("\n", " \n"), new BukkitTagContext
(null, null, false, null, false, new dScript(this)));
}

public String getUsage() {
return TagManager.tag(null, null, getString("USAGE", ""));
return TagManager.tag((getString("USAGE", "")), new BukkitTagContext
(null, null, false, null, false, new dScript(this)));
}

public List<String> getAliases() {
Expand Down
Expand Up @@ -2,8 +2,10 @@

import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.utilities.YamlConfiguration;
Expand Down Expand Up @@ -50,7 +52,8 @@ public dEntity getEntityFrom(dPlayer player, dNPC npc) {
dEntity entity = null;
try {
if (contains("ENTITY_TYPE")) {
String entityType = TagManager.tag(player, npc, getString("ENTITY_TYPE"));
String entityType = TagManager.tag((getString("ENTITY_TYPE", "")), new BukkitTagContext
(player, npc, false, null, shouldDebug(), new dScript(this)));
entity = dEntity.valueOf(entityType);
}

Expand Down
Expand Up @@ -3,8 +3,10 @@
import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.dScript;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizencore.utilities.YamlConfiguration;

Expand Down Expand Up @@ -73,14 +75,16 @@ public String getFormat() {
}

public String getFormattedText(ScriptEntry entry) {
return getFormattedText(entry.getElement("text").asString(), ((BukkitScriptEntryData)entry.entryData).getNPC(), ((BukkitScriptEntryData)entry.entryData).getPlayer());
return getFormattedText(entry.getElement("text").asString(),
((BukkitScriptEntryData)entry.entryData).getNPC(),
((BukkitScriptEntryData)entry.entryData).getPlayer());
}

public String getFormattedText(String textToReplace, dNPC npc, dPlayer player) {
String text = getFormat().replace("<text>", TagManager.escapeOutput(textToReplace));
boolean debug = true;
if (contains("DEBUG"))
debug = Boolean.valueOf(getString("DEBUG"));
return TagManager.tag(player, npc, text, false, null, debug);
return TagManager.tag(text, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
}
}
Expand Up @@ -5,12 +5,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dInventory;
import net.aufdemrand.denizen.objects.dItem;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.objects.*;
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.denizencore.utilities.YamlConfiguration;
Expand Down Expand Up @@ -134,15 +131,16 @@ public dInventory getInventoryFrom(dPlayer player, dNPC npc) {
}

inventory = new dInventory(size,
contains("TITLE") ? TagManager.tag(player, npc, getString("TITLE")) : "Chest");
contains("TITLE") ? TagManager.tag(getString("TITLE"),
new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this))) : "Chest");
inventory.setIdentifiers("script", getName());
}
}
if (contains("SLOTS")) {
ItemStack[] finalItems = new ItemStack[getSize()];
int itemsAdded = 0;
for (String items : getStringList("SLOTS")) {
items = TagManager.tag(player, npc, items);
items = TagManager.tag(items, new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
String[] itemsInLine = items.split(" ");
for (String item : itemsInLine) {
Matcher m = fromPattern.matcher(item);
Expand All @@ -153,11 +151,13 @@ public dInventory getInventoryFrom(dPlayer player, dNPC npc) {
if (contains("DEFINITIONS." + m.group(2)) &&
dItem.matches(getString("DEFINITIONS." + m.group(2)))) {
finalItems[itemsAdded] = dItem.valueOf(TagManager.tag
(player, npc, getString("DEFINITIONS." + m.group(2))))
(getString("DEFINITIONS." + m.group(2)),
new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this))))
.getItemStack();
}
else if (dItem.matches(m.group(2))) {
finalItems[itemsAdded] = dItem.valueOf(TagManager.tag(player, npc, m.group(2)))
finalItems[itemsAdded] = dItem.valueOf(TagManager.tag(m.group(2),
new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this))))
.getItemStack();
}
else {
Expand All @@ -173,7 +173,8 @@ else if (dItem.matches(m.group(2))) {
if (inventory == null) {
int size = finalItems.length%9==0?finalItems.length:Math.round(finalItems.length/9)*9;
inventory = new dInventory(size==0?9:size,
contains("TITLE") ? TagManager.tag(player, npc, getString("TITLE")) : "Chest");
contains("TITLE") ? TagManager.tag(getString("TITLE"),
new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this))) : "Chest");
}
inventory.setContents(finalItems);
}
Expand Down
Expand Up @@ -8,6 +8,7 @@
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptContainer;
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptHelper;
import net.aufdemrand.denizen.scripts.triggers.AbstractTrigger;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.Utilities;
Expand Down Expand Up @@ -212,12 +213,16 @@ public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {

// Check if the chat trigger specified in the specified id's 'trigger:' key
// matches the text the player has said
String triggerText = TagManager.tag(denizenPlayer, npc, entry.getValue());
// TODO: script arg?
String triggerText = TagManager.tag(entry.getValue(), new BukkitTagContext
(denizenPlayer, npc, false, null, false, null));
Matcher matcher = triggerPattern.matcher(triggerText);
while (matcher.find ()) {
if (!script.checkSpecificTriggerScriptRequirementsFor(ChatTrigger.class,
denizenPlayer, npc, entry.getKey())) continue;
String keyword = TagManager.tag(denizenPlayer, npc, matcher.group().replace("/", ""));
// TODO: script arg?
String keyword = TagManager.tag(matcher.group().replace("/", ""), new BukkitTagContext
(denizenPlayer, npc, false, null, false, null));
String[] split = keyword.split("\\\\\\+REPLACE:", 2);
String replace = null;
if (split.length == 2) {
Expand Down
Expand Up @@ -5,6 +5,7 @@
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptContainer;
import net.aufdemrand.denizen.scripts.triggers.AbstractTrigger;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.objects.dItem;
Expand Down Expand Up @@ -107,7 +108,9 @@ public void clickTrigger(NPCRightClickEvent event) {
// Iterate through the different id entries in the step's click trigger
for (Map.Entry<String, String> entry : idMap.entrySet()) {
// Tag the entry value to account for replaceables
String entry_value = TagManager.tag(player, npc, entry.getValue());
// TODO: script arg?
String entry_value = TagManager.tag(entry.getValue(), new BukkitTagContext
(player, npc, false, null, false, null));
// Check if the item specified in the specified id's 'trigger:' key
// matches the item that the player is holding.
dItem item = dItem.valueOf(entry_value);
Expand Down
Expand Up @@ -5,6 +5,7 @@
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptContainer;
import net.aufdemrand.denizen.scripts.containers.core.InteractScriptHelper;
import net.aufdemrand.denizen.scripts.triggers.AbstractTrigger;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.citizensnpcs.api.CitizensAPI;
Expand Down Expand Up @@ -116,7 +117,9 @@ public void damageTrigger(EntityDamageByEntityEvent event) {
// Iterate through the different id entries in the step's click trigger
for (Map.Entry<String, String> entry : idMap.entrySet()) {
// Tag the entry value to account for replaceables
String entry_value = TagManager.tag(dplayer, npc, entry.getValue());
// TODO: script arg?
String entry_value = TagManager.tag(entry.getValue(), new BukkitTagContext
(dplayer, npc, false, null, false, null));
// Check if the item specified in the specified id's 'trigger:' key
// matches the item that the player is holding.
if (dItem.valueOf(entry_value).comparesTo(dplayer.getPlayerEntity().getItemInHand()) >= 0
Expand Down
23 changes: 3 additions & 20 deletions src/main/java/net/aufdemrand/denizen/tags/TagManager.java
Expand Up @@ -287,35 +287,18 @@ public static String readSingleTag(String str, TagContext context) {
}
}


@Deprecated
public static String tag(dPlayer player, dNPC npc, String arg) {
return tag(player, npc, arg, false, null);
}

@Deprecated
public static String tag(dPlayer player, dNPC npc, String arg, boolean instant) {
return tag(player, npc, arg, instant, null);
}

@Deprecated
@Deprecated // TODO: Delete all usages
public static String tag(dPlayer player, dNPC npc, String arg, boolean instant, ScriptEntry scriptEntry) {
try {
return tag(player, npc, arg, instant, scriptEntry, dB.shouldDebug(scriptEntry));
return tag(arg, new BukkitTagContext(player, npc, instant, scriptEntry, scriptEntry.shouldDebug(), null));
}
catch (Exception e) {
dB.echoError(e);
return null;
}
}


@Deprecated
public static String tag(dPlayer player, dNPC npc, String arg, boolean instant, ScriptEntry scriptEntry, boolean debug) {
return tag(arg, new BukkitTagContext(player, npc, instant, scriptEntry, debug, scriptEntry != null ? scriptEntry.getScript(): null));
}

@Deprecated
@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));
}
Expand Down
Expand Up @@ -2,6 +2,7 @@

import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.scripts.containers.core.CommandScriptContainer;
import net.aufdemrand.denizen.tags.BukkitTagContext;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.citizensnpcs.api.CitizensAPI;
Expand Down Expand Up @@ -73,8 +74,9 @@ public boolean testPermission(CommandSender target) {
npc = dNPC.mirrorCitizensNPC(citizen);
}
// <permission> is built into Bukkit... let's keep it here
for (String line : TagManager.tag(player, npc, permissionMessage.replace("<permission>", getPermission()))
.split("\n")) {
// TODO: script arg?
for (String line : TagManager.tag(permissionMessage.replace("<permission>", getPermission()),
new BukkitTagContext(player, npc, false, null, false, null)).split("\n")) {
target.sendMessage(line);
}
}
Expand Down

0 comments on commit 1b5f53e

Please sign in to comment.