Skip to content

Commit 71c9cde

Browse files
Fix legacy formatting code support (#8613)
1 parent 89617aa commit 71c9cde

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/main/java/ch/njol/skript/command/Commands.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,25 @@ static boolean handleEffectCommand(CommandSender sender, String command) {
181181
Effect effect = Effect.parse(command, null);
182182
parserInstance.deleteCurrentEvent();
183183

184+
TextComponentParser textParser = TextComponentParser.instance();
184185
if (effect != null) {
185186
log.clear(); // ignore warnings and stuff
186187
log.printLog();
187188
if (!effectCommand.isCancelled()) {
188-
sender.sendRichMessage("<gray>Executing '" + TextComponentParser.instance().escape(command) + "'");
189+
sender.sendMessage(textParser.parse("<gray>Executing '" + textParser.escape(command) + "'"));
189190
if (SkriptConfig.logEffectCommands.value() && !(sender instanceof ConsoleCommandSender))
190-
Skript.info(sender.getName() + " issued effect command: " + TextComponentParser.instance().escape(command));
191+
Skript.info(sender.getName() + " issued effect command: " + textParser.escape(command));
191192
TriggerItem.walk(effect, effectCommand);
192193
Variables.removeLocals(effectCommand);
193194
} else {
194-
sender.sendRichMessage("<red>Your effect command '" + TextComponentParser.instance().escape(command) + "' was cancelled.");
195+
sender.sendMessage(textParser.parse("<red>Your effect command '" + textParser.escape(command) + "' was cancelled."));
195196
}
196197
} else {
197198
if (sender == Bukkit.getConsoleSender()) // log as SEVERE instead of INFO like printErrors below
198-
SkriptLogger.LOGGER.severe("Error in: " + TextComponentParser.instance().escape(command));
199+
// No need to escape command here, logger will do it
200+
SkriptLogger.LOGGER.severe("Error in: " + command);
199201
else
200-
sender.sendRichMessage("<red>Error in: <gray>" + TextComponentParser.instance().escape(command));
202+
sender.sendMessage(textParser.parse("<red>Error in: <gray>" + textParser.escape(command)));
201203
// TODO errors likely need to be escaped too
202204
log.printErrors(sender, "(No specific information is available)");
203205
}

src/main/java/org/skriptlang/skript/bukkit/text/TextComponentParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public TextReplacementConfig textReplacementConfig() {
127127
* A pattern for matching legacy hex codes ({@code &x&1&2&3&4&5&6}).
128128
* It also matches all preceding backslashes to determine whether the supposed tag is escaped.
129129
*/
130-
static final Pattern LEGACY_CODE_PATTERN = Pattern.compile("(\\\\*)([&§][a-f0-9])");
130+
static final Pattern LEGACY_CODE_PATTERN = Pattern.compile("(\\\\*)([&§][a-f0-9klomnr])");
131131

132132
static {
133133
INSTANCE = new TextComponentParser();

src/test/java/org/skriptlang/skript/bukkit/text/TextComponentParserTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import net.kyori.adventure.text.format.NamedTextColor;
55
import net.kyori.adventure.text.format.Style;
66
import net.kyori.adventure.text.format.TextDecoration;
7+
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
8+
import org.bukkit.ChatColor;
79
import org.junit.Test;
810

911
import java.util.Set;
@@ -58,6 +60,12 @@ public void testLegacy() {
5860
assertEquals(parser.parse("<#123456>hello"), parser.parse("&x&1&2&3&4&5&6hello"));
5961
assertEquals(Component.text("&chello"), parser.parse("\\&chello"));
6062
assertEquals(Component.text("&x&1&2&3&4&5&6hello"), parser.parse("&x\\&1\\&2\\&3\\&4\\&5\\&6hello"));
63+
64+
//noinspection deprecation - yes i know
65+
for (ChatColor color : ChatColor.values()) {
66+
String message = "&" + color.getChar() + "hello";
67+
assertEquals(LegacyComponentSerializer.legacyAmpersand().deserialize(message), parser.parse(message));
68+
}
6169
}
6270

6371
@Test

0 commit comments

Comments
 (0)