Skip to content

Commit

Permalink
item lore: don't apply redundant escapes on modern lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 23, 2020
1 parent 2e58edf commit ab19097
Showing 1 changed file with 20 additions and 23 deletions.
Expand Up @@ -13,9 +13,6 @@
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.List;

public class ItemLore implements Property {

public static boolean describes(ObjectTag item) {
Expand Down Expand Up @@ -64,19 +61,11 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
// @mechanism ItemTag.lore
// @group properties
// @description
// Returns lore as a ListTag. Excludes the custom-script-id lore.
// To get that information, use <ItemTag.scriptname>.
// Returns lore as a ListTag.
// -->
if (attribute.startsWith("lore")) {
if (hasLore()) {
List<String> loreList = new ArrayList<>();
for (String itemLore : item.getItemStack().getItemMeta().getLore()) {
if (!itemLore.startsWith(ItemTag.itemscriptIdentifier)
&& !itemLore.startsWith(ItemScriptHelper.ItemScriptHashID)) {
loreList.add(itemLore);
}
}
return new ListTag(loreList).getObjectAttribute(attribute.fulfill(1));
return getLoreList().getObjectAttribute(attribute.fulfill(1));
}
}

Expand All @@ -96,17 +85,22 @@ public ObjectTag getObjectAttribute(Attribute attribute) {
return null;
}

public ListTag getLoreList() {
ListTag output = new ListTag();
for (String itemLore : item.getItemStack().getItemMeta().getLore()) {
if (!itemLore.startsWith(ItemTag.itemscriptIdentifier)
&& !itemLore.startsWith(ItemScriptHelper.ItemScriptHashID)) {
output.add(itemLore);
}
}
return output;
}

@Override
public String getPropertyString() {
if (hasLore()) {
StringBuilder output = new StringBuilder();
for (String itemLore : item.getItemStack().getItemMeta().getLore()) {
if (!itemLore.startsWith(ItemTag.itemscriptIdentifier)
&& !itemLore.startsWith(ItemScriptHelper.ItemScriptHashID)) {
output.append(EscapeTagBase.escape(itemLore)).append("|");
}
}
return (output.length() == 0) ? null : output.substring(0, output.length() - 1);
ListTag output = getLoreList();
return (output.size() == 0) ? null : output.identify();
}
else {
return null;
Expand All @@ -127,7 +121,6 @@ public void adjust(Mechanism mechanism) {
// @input ListTag
// @description
// Sets the item's lore.
// See <@link language Property Escaping>
// @tags
// <ItemTag.lore>
// -->
Expand All @@ -141,7 +134,11 @@ public void adjust(Mechanism mechanism) {
}
}
for (int i = 0; i < lore.size(); i++) {
lore.set(i, CoreUtilities.clearNBSPs(EscapeTagBase.unEscape(lore.get(i))));
String loreLine = lore.get(i);
if (lore.wasLegacy) {
loreLine = EscapeTagBase.unEscape(loreLine);
}
lore.set(i, CoreUtilities.clearNBSPs(loreLine));
}
meta.setLore(lore);
item.getItemStack().setItemMeta(meta);
Expand Down

0 comments on commit ab19097

Please sign in to comment.