From c41e0d91f5b19a4e42c512e8f3bc924b59b913d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZX=E5=A4=8F=E5=A4=9C=E4=B9=8B=E9=A3=8E?= Date: Tue, 12 Nov 2024 22:11:40 +0800 Subject: [PATCH] feat: introduce Paper's change on TextDisplay --- .../v1_20_R1/entity/CraftTextDisplay.java | 12 +++++++++++ .../java/org/bukkit/entity/TextDisplay.java | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/v1_20_R1/entity/CraftTextDisplay.java b/src/main/java/org/bukkit/craftbukkit/v1_20_R1/entity/CraftTextDisplay.java index ef75567845..f2f1849f86 100644 --- a/src/main/java/org/bukkit/craftbukkit/v1_20_R1/entity/CraftTextDisplay.java +++ b/src/main/java/org/bukkit/craftbukkit/v1_20_R1/entity/CraftTextDisplay.java @@ -34,6 +34,18 @@ public void setText(String text) { getHandle().setText(CraftChatMessage.fromString(text, true)[0]); } + // Paper start + @Override + public net.kyori.adventure.text.Component text() { + return com.mohistmc.paper.adventure.PaperAdventure.asAdventure(this.getHandle().getText()); // Mohist - Use Mohist's PaperAdventure + } + + @Override + public void text(net.kyori.adventure.text.Component text) { + this.getHandle().setText(text == null ? net.minecraft.network.chat.Component.empty() : com.mohistmc.paper.adventure.PaperAdventure.asVanilla(text)); // Mohist - Use Mohist's PaperAdventure + } + // Paper end + @Override public int getLineWidth() { return getHandle().getLineWidth(); diff --git a/src/main/java/org/bukkit/entity/TextDisplay.java b/src/main/java/org/bukkit/entity/TextDisplay.java index d6d7ada3d3..f101ffde9e 100644 --- a/src/main/java/org/bukkit/entity/TextDisplay.java +++ b/src/main/java/org/bukkit/entity/TextDisplay.java @@ -13,17 +13,37 @@ public interface TextDisplay extends Display { * Gets the displayed text. * * @return the displayed text. + * @deprecated in favour of {@link #text()} */ @Nullable + @Deprecated // Paper String getText(); /** * Sets the displayed text. * * @param text the new text + * @deprecated in favour of {@link #text(net.kyori.adventure.text.Component)} */ + @Deprecated // Paper void setText(@Nullable String text); + // Paper start + /** + * Gets the displayed text. + * + * @return the displayed text + */ + net.kyori.adventure.text.@NotNull Component text(); + + /** + * Sets the displayed text. + * + * @param text the new text + */ + void text(net.kyori.adventure.text.@Nullable Component text); + // Paper end + /** * Gets the maximum line width before wrapping. *