From 5ab346a02b620430dcf91384a9e5806b4896db60 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Sat, 29 Sep 2018 01:34:45 -0400 Subject: [PATCH] Don't tediously hardcode the names of channels if we can help it --- .../protocol/util/PluginMessageUtil.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java index 45a682fd1..04988d7f9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/util/PluginMessageUtil.java @@ -12,22 +12,31 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.List; -public enum PluginMessageUtil { - ; +public class PluginMessageUtil { + public static final String BRAND_CHANNEL = "MC|Brand"; + public static final String BRAND_CHANNEL_1_13 = "minecraft:brand"; + public static final String REGISTER_CHANNEL = "REGISTER"; + public static final String REGISTER_CHANNEL_1_13 = "minecraft:register"; + public static final String UNREGISTER_CHANNEL = "UNREGISTER"; + public static final String UNREGISTER_CHANNEL_1_13 = "minecraft:unregister"; + + private PluginMessageUtil() { + throw new AssertionError(); + } public static boolean isMCBrand(PluginMessage message) { Preconditions.checkNotNull(message, "message"); - return message.getChannel().equals("MC|Brand") || message.getChannel().equals("minecraft:brand"); + return message.getChannel().equals(BRAND_CHANNEL) || message.getChannel().equals(BRAND_CHANNEL_1_13); } public static boolean isMCRegister(PluginMessage message) { Preconditions.checkNotNull(message, "message"); - return message.getChannel().equals("REGISTER") || message.getChannel().equals("minecraft:register"); + return message.getChannel().equals(REGISTER_CHANNEL) || message.getChannel().equals(REGISTER_CHANNEL_1_13); } public static boolean isMCUnregister(PluginMessage message) { Preconditions.checkNotNull(message, "message"); - return message.getChannel().equals("UNREGISTER") || message.getChannel().equals("minecraft:unregister"); + return message.getChannel().equals(UNREGISTER_CHANNEL) || message.getChannel().equals(UNREGISTER_CHANNEL_1_13); } public static List getChannels(PluginMessage message) { @@ -40,7 +49,7 @@ public enum PluginMessageUtil { public static PluginMessage constructChannelsPacket(int protocolVersion, Collection channels) { Preconditions.checkNotNull(channels, "channels"); - String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:register" : "REGISTER"; + String channelName = protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ? REGISTER_CHANNEL_1_13 : REGISTER_CHANNEL; PluginMessage message = new PluginMessage(); message.setChannel(channelName); message.setData(String.join("\0", channels).getBytes(StandardCharsets.UTF_8));