Skip to content

Commit

Permalink
patch newlines in 'chat'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 5, 2023
1 parent 6de5e25 commit 150d3eb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Expand Up @@ -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));
});
}
}
Expand Down
Expand Up @@ -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;
Expand All @@ -31,6 +30,7 @@
import org.bukkit.util.Consumer;

import java.util.*;
import java.util.stream.Collectors;

public class PaperAPIToolsImpl extends PaperAPITools {

Expand Down Expand Up @@ -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<String> 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);
}
Expand Down
Expand Up @@ -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()) {
Expand All @@ -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%");
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Expand Up @@ -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.
//
Expand Down
Expand Up @@ -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;
}
}

0 comments on commit 150d3eb

Please sign in to comment.