handle lore better for tokens

This commit is contained in:
hyperdefined
2025-01-26 19:35:03 -05:00
parent 61f87a94f7
commit 9ee1f773da
3 changed files with 73 additions and 50 deletions

View File

@@ -24,6 +24,9 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -162,4 +165,34 @@ public class ConfigTools {
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
}
/**
* Get the token item's lore from config.
*
* @param tokenType The type.
* @return The lore.
*/
public List<Component> getTokenLore(String tokenType) {
List<String> raw = toolStats.config.getStringList("tokens.data." + tokenType + ".lore");
if (raw.isEmpty()) {
return Collections.emptyList();
}
List<Component> finalLore = new ArrayList<>();
for (String line : raw) {
Component component;
// if we match the old color codes, then format them as so
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(line);
Matcher colorMatcher = COLOR_CODES.matcher(line);
if (hexMatcher.find() || colorMatcher.find()) {
component = LegacyComponentSerializer.legacyAmpersand().deserialize(line);
} else {
// otherwise format them normally
component = MiniMessage.miniMessage().deserialize(line);
}
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
finalLore.add(component);
}
return finalLore;
}
}

View File

@@ -44,11 +44,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.player-kills.title");
Component lore = toolStats.configTools.format("tokens.data.player-kills.lore");
List<Component> lore = toolStats.configTools.getTokenLore("player-kills");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "player-kills");
@@ -64,11 +62,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.mob-kills.title");
Component lore = toolStats.configTools.format("tokens.data.mob-kills.lore");
List<Component> lore = toolStats.configTools.getTokenLore("mob-kills");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "mob-kills");
@@ -84,11 +80,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.blocks-mined.title");
Component lore = toolStats.configTools.format("tokens.data.blocks-mined.lore");
List<Component> lore = toolStats.configTools.getTokenLore("blocks-mined");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "blocks-mined");
@@ -104,11 +98,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.crops-mined.title");
Component lore = toolStats.configTools.format("tokens.data.crops-mined.lore");
List<Component> lore = toolStats.configTools.getTokenLore("crops-mined");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "crops-mined");
@@ -124,11 +116,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.fish-caught.title");
Component lore = toolStats.configTools.format("tokens.data.fish-caught.lore");
List<Component> lore = toolStats.configTools.getTokenLore("fight-caught");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "fish-caught");
@@ -144,11 +134,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.sheep-sheared.title");
Component lore = toolStats.configTools.format("tokens.data.sheep-sheared.lore");
List<Component> lore = toolStats.configTools.getTokenLore("sheep-sheared");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "sheep-sheared");
@@ -164,11 +152,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.damage-taken.title");
Component lore = toolStats.configTools.format("tokens.data.damage-taken.lore");
List<Component> lore = toolStats.configTools.getTokenLore("damage-taken");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "damage-taken");
@@ -184,11 +170,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.arrows-shot.title");
Component lore = toolStats.configTools.format("tokens.data.arrows-shot.lore");
List<Component> lore = toolStats.configTools.getTokenLore("arrows-shot");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "arrows-shot");
@@ -204,11 +188,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.flight-time.title");
Component lore = toolStats.configTools.format("tokens.data.flight-time.lore");
List<Component> lore = toolStats.configTools.getTokenLore("flight-time");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "flight-time");
@@ -224,11 +206,9 @@ public class TokenItems {
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.reset.title");
Component lore = toolStats.configTools.format("tokens.data.reset.lore");
List<Component> lore = toolStats.configTools.getTokenLore("reset");
tokenMeta.displayName(title);
List<Component> newLore = new ArrayList<>();
newLore.add(lore);
tokenMeta.lore(newLore);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "reset");

View File

@@ -6,43 +6,53 @@ tokens:
data:
player-kills:
title: "&7ToolStats: &8Player Kills Token"
lore: "&8Combine with a melee or ranged weapon in an anvil to track player kills."
lore:
- "&8Combine with a melee or ranged weapon in an anvil to track player kills."
levels: 1
mob-kills:
title: "&7ToolStats: &8Mob Kills Token"
lore: "&8Combine with a melee or ranged weapon in an anvil to track mob kills."
lore:
- "&8Combine with a melee or ranged weapon in an anvil to track mob kills."
levels: 1
blocks-mined:
title: "&7ToolStats: &8Blocks Mined Token"
lore: "&8Combine with a pickaxe, axe, shovel, or shears in an anvil to track blocks mined."
lore:
- "&8Combine with a pickaxe, axe, shovel, or shears in an anvil to track blocks mined."
levels: 1
crops-mined:
title: "&7ToolStats: &8Crops Mined Token"
lore: "&8Combine with a hoe in an anvil to track crops broken."
lore:
- "&8Combine with a hoe in an anvil to track crops broken."
levels: 1
fish-caught:
title: "&7ToolStats: &8Fish Caught Token"
lore: "&8Combine with a fishing rod in an anvil to track fish caught."
lore:
- "&8Combine with a fishing rod in an anvil to track fish caught."
levels: 1
sheep-sheared:
title: "&7ToolStats: &8Sheep Sheared Token"
lore: "&8Combine with shears in an anvil to track sheep sheared."
lore:
- "&8Combine with shears in an anvil to track sheep sheared."
levels: 1
damage-taken:
title: "&7ToolStats: &8Damage Taken Token"
lore: "&8Combine with an armor piece in an anvil to track damage taken."
lore:
- "&8Combine with an armor piece in an anvil to track damage taken."
levels: 1
arrows-shot:
title: "&7ToolStats: &8Arrows Shot Token"
lore: "&8Combine with a bow or crossbow in an anvil to track arrows shot."
lore:
- "&8Combine with a bow or crossbow in an anvil to track arrows shot."
levels: 1
flight-time:
title: "&7ToolStats: &8Flight Time Token"
lore: "&8Combine with an elytra in an anvil to track flight time."
lore:
- "&8Combine with an elytra in an anvil to track flight time."
levels: 1
reset:
title: "&7ToolStats: &8Reset Token"
lore: "&8Combine in an anvil with to reset ALL stats for this item. Tokens on this item stay."
lore:
- "&8Combine in an anvil with to reset ALL stats for this item. Tokens on this item stay."
levels: 1
enabled: