Skip to content

Commit ea1e438

Browse files
Jan Klukaclaude
andcommitted
Add item, escaping and hover support to XPrisonTextAPI
Migrating the addons off Adventure surfaced three gaps the String-only surface could not cover: - applyDisplayName / applyLore: ItemMeta#displayName(Component) and #lore(List) name Adventure types in their descriptors, which is enough on its own to stop the calling class loading on a server without Adventure. Every addon that builds GUI items hit this. - escapeTags: the Discord addon escapes MiniMessage tags in relayed chat so a player cannot inject a working click or hover tag. Dropping it during the migration would have turned a fixed injection into a live one. Item hovers are expressed as a <hover:show_item:...> tag in the message string rather than needing a component-placeholder API, which keeps the surface String-only and degrades correctly where hover cannot be sent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bdb6qa8CXKgSedjZAGuavL
1 parent ea50ab3 commit ea1e438

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

src/main/java/dev/drawethree/xprison/api/text/XPrisonTextAPI.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.bukkit.command.CommandSender;
44
import org.bukkit.entity.Player;
5+
import org.bukkit.inventory.meta.ItemMeta;
56
import org.jetbrains.annotations.NotNull;
67
import org.jetbrains.annotations.Nullable;
78

@@ -64,6 +65,43 @@ public interface XPrisonTextAPI {
6465
void sendTitle(@NotNull Player target, @Nullable String title, @Nullable String subtitle,
6566
int fadeInTicks, int stayTicks, int fadeOutTicks);
6667

68+
/**
69+
* Sets an item's display name from MiniMessage text.
70+
*
71+
* <p>Use this rather than {@code ItemMeta#displayName(Component)}: that overload names an
72+
* Adventure type in its signature, which is enough on its own to stop the calling class from
73+
* loading on a server without Adventure.
74+
*
75+
* <p>Item text renders in italics by default. Prefix the string with {@code <italic:false>} to
76+
* turn that off, as X-Prison's own configs do.
77+
*
78+
* @param meta the meta to modify in place
79+
* @param miniMessage raw display name
80+
*/
81+
void applyDisplayName(@NotNull ItemMeta meta, @Nullable String miniMessage);
82+
83+
/**
84+
* Replaces an item's lore with the given MiniMessage lines.
85+
*
86+
* @param meta the meta to modify in place
87+
* @param miniMessage raw lore lines
88+
*/
89+
void applyLore(@NotNull ItemMeta meta, @NotNull List<String> miniMessage);
90+
91+
/**
92+
* Escapes MiniMessage tags so they render as literal text.
93+
*
94+
* <p>Apply this to anything a player can type before putting it into a message - chat relayed
95+
* from another platform, nicknames, gang names, sign text. Without it a player can type
96+
* {@code <click:run_command:'/op them'>} into your message and have it rendered as a real
97+
* clickable tag.
98+
*
99+
* @param text untrusted text
100+
* @return the text with tag syntax neutralised
101+
*/
102+
@NotNull
103+
String escapeTags(@Nullable String text);
104+
67105
/**
68106
* Renders text to legacy section codes.
69107
*

0 commit comments

Comments
 (0)