From 95cfa7db521d8537747540e86b05815cc932e8ad Mon Sep 17 00:00:00 2001 From: Draycia Date: Fri, 26 Jun 2020 03:47:56 -0700 Subject: [PATCH] More options --- .../channels/impls/AllianceChatChannel.java | 7 +++++-- .../channels/impls/NationChatChannel.java | 7 +++++-- .../channels/impls/PartyChatChannel.java | 7 +++++-- .../channels/impls/SimpleChatChannel.java | 7 +++++-- .../simplechat/channels/impls/TownChatChannel.java | 7 +++++-- src/main/resources/config.yml | 14 ++++++++++---- 6 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/draycia/simplechat/channels/impls/AllianceChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/AllianceChatChannel.java index 03f415cc..f07c4023 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/AllianceChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/AllianceChatChannel.java @@ -51,8 +51,11 @@ public class AllianceChatChannel extends SimpleChatChannel { Component component = LegacyComponentSerializer.legacy('&').deserialize(messageFormat); messageFormat = MiniMessageSerializer.serialize(component); - // Continue parsing the format - messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + getColor().toString() + ">"); + // First pass for placeholders, to support placeholders in placeholders + messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + getColor().toString() + ">", + "phase", Long.toString(System.currentTimeMillis() % 25), "server", getSimpleChat().getConfig().getString("server-name", "Server")); + + // Finally, parse remaining placeholders and parse format messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "message", event.getMessage()); Component formattedMessage = MiniMessageParser.parseFormat(messageFormat); diff --git a/src/main/java/net/draycia/simplechat/channels/impls/NationChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/NationChatChannel.java index 544d304c..19621fe0 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/NationChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/NationChatChannel.java @@ -52,8 +52,11 @@ public class NationChatChannel extends SimpleChatChannel { Component component = LegacyComponentSerializer.legacy('&').deserialize(messageFormat); messageFormat = MiniMessageSerializer.serialize(component); - // Continue parsing the format - messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + getColor().toString() + ">"); + // First pass for placeholders, to support placeholders in placeholders + messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + getColor().toString() + ">", + "phase", Long.toString(System.currentTimeMillis() % 25), "server", getSimpleChat().getConfig().getString("server-name", "Server")); + + // Finally, parse remaining placeholders and parse format messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "message", event.getMessage()); Component formattedMessage = MiniMessageParser.parseFormat(messageFormat); diff --git a/src/main/java/net/draycia/simplechat/channels/impls/PartyChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/PartyChatChannel.java index 2e45f50b..7442144c 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/PartyChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/PartyChatChannel.java @@ -49,8 +49,11 @@ public class PartyChatChannel extends SimpleChatChannel { Component component = LegacyComponentSerializer.legacy('&').deserialize(messageFormat); messageFormat = MiniMessageSerializer.serialize(component); - // Continue parsing the format - messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + getColor().toString() + ">"); + // First pass for placeholders, to support placeholders in placeholders + messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + getColor().toString() + ">", + "phase", Long.toString(System.currentTimeMillis() % 25), "server", getSimpleChat().getConfig().getString("server-name", "Server")); + + // Finally, parse remaining placeholders and parse format messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "message", event.getMessage()); Component formattedMessage = MiniMessageParser.parseFormat(messageFormat); diff --git a/src/main/java/net/draycia/simplechat/channels/impls/SimpleChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/SimpleChatChannel.java index 7aaff493..a2afc45f 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/SimpleChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/SimpleChatChannel.java @@ -144,8 +144,11 @@ public class SimpleChatChannel extends ChatChannel { Component component = LegacyComponentSerializer.legacy('&').deserialize(messageFormat); messageFormat = MiniMessageSerializer.serialize(component); - // Continue parsing the format - messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + color.toString() + ">", "phase", Long.toString(System.currentTimeMillis() % 25)); + // First pass for placeholders, to support placeholders in placeholders + messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + color.toString() + ">", + "phase", Long.toString(System.currentTimeMillis() % 25), "server", simpleChat.getConfig().getString("server-name", "Server")); + + // Finally, parse remaining placeholders and parse format messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "message", event.getMessage()); Component formattedMessage = MiniMessageParser.parseFormat(messageFormat); diff --git a/src/main/java/net/draycia/simplechat/channels/impls/TownChatChannel.java b/src/main/java/net/draycia/simplechat/channels/impls/TownChatChannel.java index 0a93de16..cc11b57c 100644 --- a/src/main/java/net/draycia/simplechat/channels/impls/TownChatChannel.java +++ b/src/main/java/net/draycia/simplechat/channels/impls/TownChatChannel.java @@ -52,8 +52,11 @@ public class TownChatChannel extends SimpleChatChannel { Component component = LegacyComponentSerializer.legacy('&').deserialize(messageFormat); messageFormat = MiniMessageSerializer.serialize(component); - // Continue parsing the format - messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + getColor().toString() + ">"); + // First pass for placeholders, to support placeholders in placeholders + messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "color", "<" + getColor().toString() + ">", + "phase", Long.toString(System.currentTimeMillis() % 25), "server", getSimpleChat().getConfig().getString("server-name", "Server")); + + // Finally, parse remaining placeholders and parse format messageFormat = MiniMessageParser.handlePlaceholders(messageFormat, "message", event.getMessage()); Component formattedMessage = MiniMessageParser.parseFormat(messageFormat); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e76defd6..a76d32d6 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,4 +1,7 @@ # https://github.com/MiniDigger/MiniMessage/blob/feature/adventure/DOCS.md +# IMPORTANT: Use the
 tag around ALL user inputs.
+# All  placeholders should be prefixed with 
 and suffixed with 
+# Failure to do so may and likely will result in users being able to inject formatting in messages. channels: global: @@ -7,17 +10,20 @@ channels: toggle-on-message: 'You can now see chat!' toggle-off-message: 'You can no longer see chat!' formats: - discord-to-mc: '[Discord] : ' # Placeholders: username, displayname, channel, server, message, primaryrole - staff: '{[%deluxetags_tag%]} %player_displayname% » ' - default: '[%deluxetags_tag%] %player_displayname%: ' + discord-to-mc: '[Discord] :
' # Placeholders: username, displayname, channel, server, message, primaryrole
+      staff: '{[%deluxetags_tag%]} %player_displayname% » 
'
+      default: '[%deluxetags_tag%] %player_displayname%: 
'
     webhook: 'URL_HERE' # Comment out / remove to disable webhook
     color: WHITE # Removing this option defaults to 'WHITE'
     default: true # Removing this option defaults to 'false'
     ignorable: true # Removing this option defaults to 'true'
     distance: -1 # Set to -1, comment out, or remove to disable distance checking
+    forward-format: true # Removing this option defaults to 'true'. Forces all other servers to use this server's formatting for this channel.
 
 bot-token: -1
 
 language:
   ignoring-user: 'You are now ignoring !'
-  not-ignoring-user: 'You are no longer ignoring !'
\ No newline at end of file
+  not-ignoring-user: 'You are no longer ignoring !'
+
+server-name: 'Server'
\ No newline at end of file