diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java index d432bf830..c55a407ee 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/platform/BukkitConfigAPI.java @@ -199,4 +199,9 @@ public class BukkitConfigAPI extends Config implements ViaVersionConfig { public List getUnsupportedOptions() { return UNSUPPORTED; } + + @Override + public boolean is1_13TeamColourFix() { + return getBoolean("team-colour-fix", true); + } } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java index e4f8d7a1f..79ae44916 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeConfigAPI.java @@ -252,4 +252,9 @@ public class BungeeConfigAPI extends Config implements ViaVersionConfig { public Map getBungeeServerProtocols() { return get("bungee-servers", Map.class, new HashMap<>()); } + + @Override + public boolean is1_13TeamColourFix() { + return getBoolean("team-colour-fix", true); + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java index 98578e5d0..106ad9d40 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaVersionConfig.java @@ -209,6 +209,13 @@ public interface ViaVersionConfig { * @return True if enabled */ boolean is1_12NBTArrayFix(); + + /** + * Should we make team colours based on the last colour in team prefix + * + * @return True if enabled + */ + boolean is1_13TeamColourFix(); /** * Should we fix shift quick move action for 1.12 clients diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 25baaaba7..00554e957 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -1,8 +1,10 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2; +import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.chat.ComponentSerializer; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.entities.Entity1_13Types; import us.myles.ViaVersion.api.minecraft.Position; @@ -370,12 +372,16 @@ public class Protocol1_13To1_12_2 extends Protocol { wrapper.passthrough(Type.STRING); // Collision rule // Handle new colors - byte color = wrapper.read(Type.BYTE); + int colour = wrapper.read(Type.BYTE).intValue(); + if (colour == -1) { + colour = 21; // -1 changed to 21 + } - if (color == -1) // -1 changed to 21 - wrapper.write(Type.VAR_INT, 21); // RESET - else - wrapper.write(Type.VAR_INT, (int) color); + if (Via.getConfig().is1_13TeamColourFix()) { + colour = getLastColor(prefix); + } + + wrapper.write(Type.VAR_INT, colour); wrapper.write(Type.STRING, legacyTextToJson(prefix)); // Prefix wrapper.write(Type.STRING, legacyTextToJson(suffix)); // Suffix @@ -769,4 +775,33 @@ public class Protocol1_13To1_12_2 extends Protocol { private int getNewSoundID(final int oldID) { return MappingData.oldToNewSounds.get(oldID); } + + // Based on method from https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/ChatColor.java + public int getLastColor(String input) { + int length = input.length(); + + for (int index = length - 1; index > -1; index--) { + char section = input.charAt(index); + if (section == ChatColor.COLOR_CHAR && index < length - 1) { + char c = input.charAt(index + 1); + ChatColor color = ChatColor.getByChar(c); + + if (color != null) { + switch (color) { + case MAGIC: + case BOLD: + case STRIKETHROUGH: + case UNDERLINE: + case ITALIC: + case RESET: + break; + default: + return color.ordinal(); + } + } + } + } + + return ChatColor.RESET.ordinal(); + } } diff --git a/common/src/main/resources/assets/viaversion/config.yml b/common/src/main/resources/assets/viaversion/config.yml index 5d59fd1f6..c72913019 100644 --- a/common/src/main/resources/assets/viaversion/config.yml +++ b/common/src/main/resources/assets/viaversion/config.yml @@ -86,6 +86,8 @@ piston-animation-patch: false chat-nbt-fix: true # Experimental - Should we fix shift quick move action for 1.12 clients (causes shift + double click not to work when moving items) (only works on 1.8-1.11.2 bukkit based servers) quick-move-action-fix: false +# Should we use prefix for team colour on 1.13 and above clients +team-colour-fix: true # #----------------------------------------------------------# # 1.9 & 1.10 CLIENTS ON 1.8 SERVERS OPTIONS # diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java index da5cd7dcc..a6088b53f 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/platform/SpongeConfigAPI.java @@ -205,4 +205,9 @@ public class SpongeConfigAPI extends Config implements ViaVersionConfig { public String getReloadDisconnectMsg() { return getString("reload-disconnect-msg", "Server reload, please rejoin!"); } + + @Override + public boolean is1_13TeamColourFix() { + return getBoolean("team-colour-fix", true); + } }