mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-09 22:24:59 +00:00
handle lore better for tokens
This commit is contained in:
@@ -24,6 +24,9 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
|||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.Material;
|
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.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -162,4 +165,34 @@ public class ConfigTools {
|
|||||||
|
|
||||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,11 +44,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.player-kills.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "player-kills");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "player-kills");
|
||||||
@@ -64,11 +62,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.mob-kills.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "mob-kills");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "mob-kills");
|
||||||
@@ -84,11 +80,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.blocks-mined.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "blocks-mined");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "blocks-mined");
|
||||||
@@ -104,11 +98,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.crops-mined.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "crops-mined");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "crops-mined");
|
||||||
@@ -124,11 +116,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.fish-caught.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "fish-caught");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "fish-caught");
|
||||||
@@ -144,11 +134,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.sheep-sheared.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "sheep-sheared");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "sheep-sheared");
|
||||||
@@ -164,11 +152,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.damage-taken.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "damage-taken");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "damage-taken");
|
||||||
@@ -184,11 +170,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.arrows-shot.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "arrows-shot");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "arrows-shot");
|
||||||
@@ -204,11 +188,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.flight-time.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "flight-time");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "flight-time");
|
||||||
@@ -224,11 +206,9 @@ public class TokenItems {
|
|||||||
|
|
||||||
// set the title and lore
|
// set the title and lore
|
||||||
Component title = toolStats.configTools.format("tokens.data.reset.title");
|
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);
|
tokenMeta.displayName(title);
|
||||||
List<Component> newLore = new ArrayList<>();
|
tokenMeta.lore(lore);
|
||||||
newLore.add(lore);
|
|
||||||
tokenMeta.lore(newLore);
|
|
||||||
|
|
||||||
// set the PDC
|
// set the PDC
|
||||||
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "reset");
|
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "reset");
|
||||||
|
|||||||
@@ -6,43 +6,53 @@ tokens:
|
|||||||
data:
|
data:
|
||||||
player-kills:
|
player-kills:
|
||||||
title: "&7ToolStats: &8Player Kills Token"
|
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
|
levels: 1
|
||||||
mob-kills:
|
mob-kills:
|
||||||
title: "&7ToolStats: &8Mob Kills Token"
|
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
|
levels: 1
|
||||||
blocks-mined:
|
blocks-mined:
|
||||||
title: "&7ToolStats: &8Blocks Mined Token"
|
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
|
levels: 1
|
||||||
crops-mined:
|
crops-mined:
|
||||||
title: "&7ToolStats: &8Crops Mined Token"
|
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
|
levels: 1
|
||||||
fish-caught:
|
fish-caught:
|
||||||
title: "&7ToolStats: &8Fish Caught Token"
|
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
|
levels: 1
|
||||||
sheep-sheared:
|
sheep-sheared:
|
||||||
title: "&7ToolStats: &8Sheep Sheared Token"
|
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
|
levels: 1
|
||||||
damage-taken:
|
damage-taken:
|
||||||
title: "&7ToolStats: &8Damage Taken Token"
|
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
|
levels: 1
|
||||||
arrows-shot:
|
arrows-shot:
|
||||||
title: "&7ToolStats: &8Arrows Shot Token"
|
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
|
levels: 1
|
||||||
flight-time:
|
flight-time:
|
||||||
title: "&7ToolStats: &8Flight Time Token"
|
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
|
levels: 1
|
||||||
reset:
|
reset:
|
||||||
title: "&7ToolStats: &8Reset Token"
|
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
|
levels: 1
|
||||||
|
|
||||||
enabled:
|
enabled:
|
||||||
|
|||||||
Reference in New Issue
Block a user