From b1c4d563b476de00f2badb18ffe8661692fd3c58 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Thu, 2 Jan 2020 19:34:31 +0100 Subject: [PATCH] Add option to (not) add the 1.13 scoreboard team color --- .../java/nl/matsv/viabackwards/ViaBackwardsConfig.java | 7 +++++++ .../java/nl/matsv/viabackwards/api/ViaBackwardsConfig.java | 7 +++++++ .../protocol1_12_2to1_13/packets/PlayerPacket1_13.java | 6 ++++-- core/src/main/resources/assets/viabackwards/config.yml | 5 ++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/ViaBackwardsConfig.java b/core/src/main/java/nl/matsv/viabackwards/ViaBackwardsConfig.java index e52f785a..0c66484b 100644 --- a/core/src/main/java/nl/matsv/viabackwards/ViaBackwardsConfig.java +++ b/core/src/main/java/nl/matsv/viabackwards/ViaBackwardsConfig.java @@ -11,6 +11,7 @@ import java.util.Map; public class ViaBackwardsConfig extends Config implements nl.matsv.viabackwards.api.ViaBackwardsConfig { private boolean addCustomEnchantsToLore; + private boolean addTeamColorToPrefix; public ViaBackwardsConfig(File configFile) { super(configFile); @@ -24,6 +25,7 @@ public class ViaBackwardsConfig extends Config implements nl.matsv.viabackwards. private void loadFields() { addCustomEnchantsToLore = getBoolean("add-custom-enchants-into-lore", true); + addTeamColorToPrefix = getBoolean("add-teamcolor-to-prefix", true); } @Override @@ -31,6 +33,11 @@ public class ViaBackwardsConfig extends Config implements nl.matsv.viabackwards. return addCustomEnchantsToLore; } + @Override + public boolean addTeamColorTo1_13Prefix() { + return addTeamColorToPrefix; + } + @Override public URL getDefaultConfigURL() { return getClass().getClassLoader().getResource("assets/viabackwards/config.yml"); diff --git a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsConfig.java b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsConfig.java index 6065969f..01ccafbb 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsConfig.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsConfig.java @@ -8,4 +8,11 @@ public interface ViaBackwardsConfig { * @return true if enabled */ boolean addCustomEnchantsToLore(); + + /** + * Writes the color of the scoreboard team after the prefix. + * + * @return true if enabled + */ + boolean addTeamColorTo1_13Prefix(); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java index 29ba8cc1..9526cf65 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -239,11 +239,13 @@ public class PlayerPacket1_13 extends Rewriter { colour = -1; } - //TODO team color/prefix handling changed from 1.12.2 to 1.13 and to 1.13.1 again afaik String prefix = wrapper.read(Type.STRING); String suffix = wrapper.read(Type.STRING); prefix = prefix == null || prefix.equals("null") ? "" : ChatRewriter.jsonTextToLegacy(prefix); - prefix += "§" + (colour > -1 && colour <= 15 ? Integer.toHexString(colour) : "r"); + if (ViaBackwards.getConfig().addTeamColorTo1_13Prefix()) { + prefix += "§" + (colour > -1 && colour <= 15 ? Integer.toHexString(colour) : "r"); + } + prefix = ChatUtil.removeUnusedColor(prefix, 'f', true); if (prefix.length() > 16) prefix = prefix.substring(0, 16); if (prefix.endsWith("§")) prefix = prefix.substring(0, prefix.length() - 1); diff --git a/core/src/main/resources/assets/viabackwards/config.yml b/core/src/main/resources/assets/viabackwards/config.yml index 528657eb..f27096c3 100644 --- a/core/src/main/resources/assets/viabackwards/config.yml +++ b/core/src/main/resources/assets/viabackwards/config.yml @@ -2,4 +2,7 @@ # # Writes name and level of custom enchantments into the item's lore. # Set this to false if you see the entries doubled/if the custom-enchant plugin already writes these into the lore manually. -add-custom-enchants-into-lore: true \ No newline at end of file +add-custom-enchants-into-lore: true +# +# Adds the color of a scoreboard team after its prefix for 1.12 clients on 1.13+ servers. +add-teamcolor-to-prefix: true \ No newline at end of file