From 150d3eb443a75fb8872b346c4116ac7d77277f18 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Sun, 5 Feb 2023 09:28:58 -0800 Subject: [PATCH] patch newlines in 'chat' --- .../denizen/paper/properties/PaperElementExtensions.java | 2 +- .../denizen/paper/utilities/PaperAPIToolsImpl.java | 8 ++++++-- .../com/denizenscript/denizen/npc/speech/DenizenChat.java | 6 +++--- .../scripts/commands/world/CreateWorldCommand.java | 2 +- .../denizenscript/denizen/utilities/PaperAPITools.java | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperElementExtensions.java b/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperElementExtensions.java index 83ca40c5e6..1b5e9822ea 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperElementExtensions.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/properties/PaperElementExtensions.java @@ -34,7 +34,7 @@ public static void register() { // This may be useful for sending data to external plugins, but should not be used in normal scripts. // --> ElementTag.tagProcessor.registerTag(ElementTag.class, "to_minimessage", (attribute, object) -> { - return new ElementTag(PaperAPITools.instance.convertTextToMiniMessage(object.asString())); + return new ElementTag(PaperAPITools.instance.convertTextToMiniMessage(object.asString(), false)); }); } } diff --git a/paper/src/main/java/com/denizenscript/denizen/paper/utilities/PaperAPIToolsImpl.java b/paper/src/main/java/com/denizenscript/denizen/paper/utilities/PaperAPIToolsImpl.java index 3c0343f456..fc6d790041 100644 --- a/paper/src/main/java/com/denizenscript/denizen/paper/utilities/PaperAPIToolsImpl.java +++ b/paper/src/main/java/com/denizenscript/denizen/paper/utilities/PaperAPIToolsImpl.java @@ -7,7 +7,6 @@ import com.denizenscript.denizen.utilities.FormattedTextHelper; import com.denizenscript.denizen.utilities.PaperAPITools; import com.denizenscript.denizencore.DenizenCore; -import com.denizenscript.denizencore.objects.core.ElementTag; import com.denizenscript.denizencore.utilities.CoreUtilities; import com.destroystokyo.paper.profile.PlayerProfile; import com.destroystokyo.paper.profile.ProfileProperty; @@ -31,6 +30,7 @@ import org.bukkit.util.Consumer; import java.util.*; +import java.util.stream.Collectors; public class PaperAPIToolsImpl extends PaperAPITools { @@ -294,7 +294,11 @@ public String getTeamSuffix(Team team) { } @Override - public String convertTextToMiniMessage(String text) { + public String convertTextToMiniMessage(String text, boolean splitNewlines) { + if (splitNewlines) { + List lines = CoreUtilities.split(text, '\n'); + return lines.stream().map(l -> convertTextToMiniMessage(l, false)).collect(Collectors.joining("\n")); + } Component parsed = PaperModule.jsonToComponent(FormattedTextHelper.componentToJson(FormattedTextHelper.parse(text, ChatColor.WHITE, false))); return MiniMessage.miniMessage().serialize(parsed); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/npc/speech/DenizenChat.java b/plugin/src/main/java/com/denizenscript/denizen/npc/speech/DenizenChat.java index 21fd31d3fb..19de1cbbc5 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/npc/speech/DenizenChat.java +++ b/plugin/src/main/java/com/denizenscript/denizen/npc/speech/DenizenChat.java @@ -67,7 +67,7 @@ else if (context.size() <= 1) { // Send chat to target String text = TagManager.tag(Settings.chatToTargetFormat(), new BukkitTagContext(entry)); for (Talkable entity : context) { - entity.talkTo(context, PaperAPITools.instance.convertTextToMiniMessage(text), this); + entity.talkTo(context, PaperAPITools.instance.convertTextToMiniMessage(text, true), this); } // Check if bystanders hear targeted chat if (context.isBystandersEnabled()) { @@ -89,7 +89,7 @@ else if (context.size() <= 1) { // Send chat to targets String text = TagManager.tag(Settings.chatToTargetFormat(), new BukkitTagContext(entry)); for (Talkable entity : context) { - entity.talkTo(context, PaperAPITools.instance.convertTextToMiniMessage(text), this); + entity.talkTo(context, PaperAPITools.instance.convertTextToMiniMessage(text, true), this); } if (context.isBystandersEnabled()) { String[] format = Settings.chatMultipleTargetsFormat().split("%target%"); @@ -155,7 +155,7 @@ private void talkToBystanders(Talkable talkable, String text, DenizenSpeechConte // Found a nearby LivingEntity, make it Talkable and // talkNear it if 'should_talk' if (shouldTalk) { - new TalkableEntity(bystander).talkNear(context, PaperAPITools.instance.convertTextToMiniMessage(text), this); + new TalkableEntity(bystander).talkNear(context, PaperAPITools.instance.convertTextToMiniMessage(text, true), this); } } } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/CreateWorldCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/CreateWorldCommand.java index d6fe5468c9..ae729a1542 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/CreateWorldCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/CreateWorldCommand.java @@ -52,7 +52,7 @@ public CreateWorldCommand() { // Optionally specify a world type which can be specified with 'worldtype:' (defaults to NORMAL). // For all world types, see: <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/WorldType.html> // - // Optionally specify an environment (defaults to NORMAL, can also be NETHER, THE_END, or CUSTOM). + // Optionally specify an environment (defaults to NORMAL, can also be NETHER, THE_END). // // Optionally choose whether to generate structures in this world. // diff --git a/plugin/src/main/java/com/denizenscript/denizen/utilities/PaperAPITools.java b/plugin/src/main/java/com/denizenscript/denizen/utilities/PaperAPITools.java index 952fe9934d..b15f5db69a 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/utilities/PaperAPITools.java +++ b/plugin/src/main/java/com/denizenscript/denizen/utilities/PaperAPITools.java @@ -157,7 +157,7 @@ public String getTeamSuffix(Team team) { return team.getSuffix(); } - public String convertTextToMiniMessage(String text) { + public String convertTextToMiniMessage(String text, boolean splitNewlines) { return text; } }