From 54064e40e81337e19f689c052758de37c11c0af0 Mon Sep 17 00:00:00 2001 From: mcmonkey4eva Date: Mon, 25 Nov 2013 16:19:11 -0800 Subject: [PATCH] Add <&bs> - backslash tag I had to rewrite a bitttt of the character escaping to allow this to work, but it seems to all be fine. Also fixed a tiny mislabeled tag meta. --- .../java/net/aufdemrand/denizen/objects/dLocation.java | 4 ++-- .../java/net/aufdemrand/denizen/tags/TagManager.java | 7 +++---- .../java/net/aufdemrand/denizen/tags/core/TextTags.java | 9 +++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java index ea0caad343..db2d7d0f9a 100644 --- a/src/main/java/net/aufdemrand/denizen/objects/dLocation.java +++ b/src/main/java/net/aufdemrand/denizen/objects/dLocation.java @@ -400,9 +400,9 @@ public String getAttribute(Attribute attribute) { // <--[tag] // @attribute - // @returns Element + // @returns dMaterial // @description - // Returns the Bukkit material name of the block at the location. + // Returns the material of the block at the location. // --> if (attribute.startsWith("material")) return dMaterial.getMaterialFrom(getBlock().getType(), getBlock().getData()).getAttribute(attribute.fulfill(1)); diff --git a/src/main/java/net/aufdemrand/denizen/tags/TagManager.java b/src/main/java/net/aufdemrand/denizen/tags/TagManager.java index 93395e725b..6b9d3fc844 100644 --- a/src/main/java/net/aufdemrand/denizen/tags/TagManager.java +++ b/src/main/java/net/aufdemrand/denizen/tags/TagManager.java @@ -106,11 +106,12 @@ public static String tag(dPlayer player, dNPC npc, String arg, boolean instant, // confirm there are/is a replaceable TAG(s), if not, return the arg. if (arg.indexOf('>') == -1 || arg.length() < 3) return arg; + if (!instant) arg = arg.replace("\\<", String.valueOf((char)0x01)).replace("\\>", String.valueOf((char)0x02)); + // Find location of the first tag int[] positions = locateTag(arg); if (positions == null) { - // Un-escape \<, \> - if (!instant) arg = arg.replace("\\<", "<").replace("\\>", ">"); + arg = arg.replace((char)0x01, '<').replace((char)0x02, '>').replace(dList.internal_escape, "|"); return arg; } @@ -142,8 +143,6 @@ public static String tag(dPlayer player, dNPC npc, String arg, boolean instant, // Return argument with replacements arg = arg.replace((char)0x01, '<').replace((char)0x02, '>').replace(dList.internal_escape, "|"); - // Un-escape \< \>'s - if (!instant) arg = arg.replace("\\<", "<").replace("\\>", ">"); return arg; } diff --git a/src/main/java/net/aufdemrand/denizen/tags/core/TextTags.java b/src/main/java/net/aufdemrand/denizen/tags/core/TextTags.java index 4ba4fe70ca..229026420a 100644 --- a/src/main/java/net/aufdemrand/denizen/tags/core/TextTags.java +++ b/src/main/java/net/aufdemrand/denizen/tags/core/TextTags.java @@ -540,6 +540,15 @@ else if (event.getName().equalsIgnoreCase("<")) else if (event.getName().equalsIgnoreCase(">")) event.setReplaced(new Element(String.valueOf((char)0x02)).getAttribute(attribute.fulfill(1))); + // <--[tag] + // @attribute <&bs> + // @returns Element + // @description + // Returns a backslash symbol: \ + // --> + else if (event.getName().equalsIgnoreCase("&bs")) + event.setReplaced(new Element("\\").getAttribute(attribute.fulfill(1))); + } }