From cd98ed353969c36081956af53ab18d8db550ddf0 Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 19 Nov 2024 03:34:55 +0800 Subject: [PATCH] Split speech bubble text into newlines --- main/src/main/java/net/citizensnpcs/trait/text/Text.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main/src/main/java/net/citizensnpcs/trait/text/Text.java b/main/src/main/java/net/citizensnpcs/trait/text/Text.java index 6e15e2c3b..51a846d48 100644 --- a/main/src/main/java/net/citizensnpcs/trait/text/Text.java +++ b/main/src/main/java/net/citizensnpcs/trait/text/Text.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.UUID; +import java.util.regex.Pattern; import org.bukkit.command.CommandSender; import org.bukkit.conversations.Conversation; @@ -211,7 +212,10 @@ public class Text extends Trait implements Runnable, Listener { } if (speechBubbles) { HologramTrait trait = npc.getOrAddTrait(HologramTrait.class); - trait.addTemporaryLine(Placeholders.replace(text.get(index), player, npc), speechBubbleDuration); + String replaced = Placeholders.replace(text.get(index), player, npc); + for (String line : NEWLINE_PATTERN.split(replaced)) { + trait.addTemporaryLine(line, speechBubbleDuration); + } } if (sendTextToChat) { npc.getDefaultSpeechController().speak(new SpeechContext(text.get(index), player)); @@ -325,5 +329,6 @@ public class Text extends Trait implements Runnable, Listener { return speechBubbles; } + private static final Pattern NEWLINE_PATTERN = Pattern.compile("
|\\n"); private static final Random RANDOM = Util.getFastRandom(); } \ No newline at end of file