Commit
- Added ItemLore property - added <&sc> tag to return semicolons magically - adjusted how special/control symbols are handled to avoid errors / hack risks
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package net.aufdemrand.denizen.objects.properties.Item; | ||
|
||
|
||
import net.aufdemrand.denizen.objects.Element; | ||
import net.aufdemrand.denizen.objects.dItem; | ||
import net.aufdemrand.denizen.objects.dList; | ||
import net.aufdemrand.denizen.objects.dObject; | ||
import net.aufdemrand.denizen.objects.properties.Property; | ||
import net.aufdemrand.denizen.tags.Attribute; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ItemLore implements Property { | ||
|
||
public static boolean describes(dObject item) { | ||
return item instanceof dItem | ||
&& ((dItem) item).getItemStack().hasItemMeta() | ||
&& ((dItem) item).getItemStack().getItemMeta().hasLore(); | ||
} | ||
|
||
public static ItemLore getFrom(dObject _item) { | ||
if (!describes(_item)) return null; | ||
else return new ItemLore((dItem)_item); | ||
} | ||
|
||
|
||
private ItemLore(dItem _item) { | ||
item = _item; | ||
} | ||
|
||
dItem item; | ||
|
||
@Override | ||
public String getAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) return "null"; | ||
|
||
// <--[tag] | ||
// @attribute <i@item.lore> | ||
// @returns dList | ||
// @description | ||
// Returns lore as a dList. Excludes the custom-script-id lore. | ||
// To get that information, use <i@item.scriptname>. | ||
// --> | ||
if (attribute.startsWith("lore")) { | ||
List<String> loreList = new ArrayList<String>(); | ||
for (String itemLore : item.getItemStack().getItemMeta().getLore()) { | ||
if (!itemLore.startsWith(dItem.itemscriptIdentifier)) { | ||
loreList.add(itemLore); | ||
} | ||
} | ||
return new dList(loreList).getAttribute(attribute.fulfill(1)); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public String getPropertyString() { | ||
StringBuilder output = new StringBuilder(); | ||
for (String itemLore : item.getItemStack().getItemMeta().getLore()) { | ||
if (!itemLore.startsWith(dItem.itemscriptIdentifier)) { | ||
output.append(itemLore).append("|"); | ||
} | ||
} | ||
return (output.length() == 0) ? "": output.substring(0, output.length() - 1); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "lore"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,23 @@ public void registerCoreTags() { | |
denizen.getServer().getPluginManager().registerEvents(this, denizen); | ||
} | ||
|
||
// INTERNAL MAPPING NOTE: | ||
// 0x01: < | ||
// 0x02: > | ||
// 0x04: Exclusively For Utilities.talkToNPC() | ||
// 0x05: | | ||
// 0x2011: ; | ||
|
||
public static String CleanOutput(String input) { | ||
return input.replace((char)0x01, '<').replace((char)0x02, '>') | ||
/*.replace((char)0x2011, ';')*/.replace(dList.internal_escape_char, '|'); | ||
} | ||
|
||
public static String CleanOutputFully(String input) { | ||
return input.replace((char)0x01, '<').replace((char)0x02, '>') | ||
.replace((char)0x2011, ';').replace(dList.internal_escape_char, '|'); | ||
} | ||
|
||
@EventHandler | ||
public void fetchObject(ReplaceableTagEvent event) { | ||
if (!event.getName().contains("@")) return; | ||
|
@@ -114,9 +131,7 @@ public static String tag(dPlayer player, dNPC npc, String arg, boolean instant, | |
// Find location of the first tag | ||
int[] positions = locateTag(arg); | ||
if (positions == null) { | ||
// Unescape internal escape codes. | ||
arg = arg.replace((char)0x01, '<').replace((char)0x02, '>').replace(dList.internal_escape, "|"); | ||
return arg; | ||
return CleanOutput(arg); | ||
} | ||
|
||
int failsafe = 0; | ||
|
@@ -144,10 +159,7 @@ public static String tag(dPlayer player, dNPC npc, String arg, boolean instant, | |
positions = locateTag(arg); | ||
} while (positions != null || failsafe < 50); | ||
|
||
// Unescape internal escape codes. | ||
arg = arg.replace((char)0x01, '<').replace((char)0x02, '>').replace(dList.internal_escape, "|"); | ||
|
||
return arg; | ||
return CleanOutput(arg); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Morphan1
Contributor
|
||
} | ||
|
||
// Match all < > brackets that don't contain < > inside them | ||
|
What is up with this, when do we need to call it, and why two versions?