3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

color rewriting changes

Dieser Commit ist enthalten in:
creeper123123321 2018-11-04 08:56:22 -02:00
Ursprung e6922eae46
Commit 437b02c961
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1

Datei anzeigen

@ -47,7 +47,8 @@ public class Protocol1_13To1_12_2 extends Protocol {
} }
}; };
public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS = new PacketHandler() { // *insert here a good name* public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS =
new PacketHandler() { // *insert here a good name*
@Override @Override
public void handle(PacketWrapper w) throws Exception { public void handle(PacketWrapper w) throws Exception {
// Send fake declare commands // Send fake declare commands
@ -99,27 +100,26 @@ public class Protocol1_13To1_12_2 extends Protocol {
// @formatter:off // @formatter:off
// These are arbitrary rewrite values, it just needs an invalid color code character. // These are arbitrary rewrite values, it just needs an invalid color code character.
protected static EnumMap<ChatColor, String> SCOREBOARD_TEAM_NAME_REWRITE = new EnumMap<ChatColor, String>(ChatColor.class) {{ protected static EnumMap<ChatColor, Character> SCOREBOARD_TEAM_NAME_REWRITE = new EnumMap<>(ChatColor.class);
put(ChatColor.BLACK, ChatColor.COLOR_CHAR + "g");
put(ChatColor.DARK_BLUE, ChatColor.COLOR_CHAR + "h");
put(ChatColor.DARK_GREEN, ChatColor.COLOR_CHAR + "i");
put(ChatColor.DARK_AQUA, ChatColor.COLOR_CHAR + "j");
put(ChatColor.DARK_RED, ChatColor.COLOR_CHAR + "p");
put(ChatColor.DARK_PURPLE, ChatColor.COLOR_CHAR + "q");
put(ChatColor.GOLD, ChatColor.COLOR_CHAR + "s");
put(ChatColor.GRAY, ChatColor.COLOR_CHAR + "t");
put(ChatColor.DARK_GRAY, ChatColor.COLOR_CHAR + "u");
put(ChatColor.BLUE, ChatColor.COLOR_CHAR + "v");
put(ChatColor.GREEN, ChatColor.COLOR_CHAR + "w");
put(ChatColor.AQUA, ChatColor.COLOR_CHAR + "x");
put(ChatColor.RED, ChatColor.COLOR_CHAR + "y");
put(ChatColor.LIGHT_PURPLE, ChatColor.COLOR_CHAR + "z");
put(ChatColor.YELLOW, ChatColor.COLOR_CHAR + "!");
put(ChatColor.WHITE, ChatColor.COLOR_CHAR + "?");
}};
// @formatter:on // @formatter:on
static { static {
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.BLACK, 'g');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.DARK_BLUE, 'h');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.DARK_GREEN, 'i');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.DARK_AQUA, 'j');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.DARK_RED, 'p');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.DARK_PURPLE, 'q');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.GOLD, 's');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.GRAY, 't');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.DARK_GRAY, 'u');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.BLUE, 'v');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.GREEN, 'w');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.AQUA, 'x');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.RED, 'y');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.LIGHT_PURPLE, 'z');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.YELLOW, '!');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.WHITE, '?');
MappingData.init(); MappingData.init();
} }
@ -933,14 +933,13 @@ public class Protocol1_13To1_12_2 extends Protocol {
// will just send colour as 'invisible' character // will just send colour as 'invisible' character
if (ChatColor.stripColor(name).length() == 0) { if (ChatColor.stripColor(name).length() == 0) {
StringBuilder newName = new StringBuilder(); StringBuilder newName = new StringBuilder();
for (int i = 0; i < name.length() / 2; i++) { for (int i = 1; i < name.length(); i += 2) {
ChatColor color = ChatColor.getByChar(name.charAt(i * 2 + 1)); char colorChar = name.charAt(i);
String rewrite = SCOREBOARD_TEAM_NAME_REWRITE.get(color); Character rewrite = SCOREBOARD_TEAM_NAME_REWRITE.get(ChatColor.getByChar(colorChar));
if (rewrite != null) { // just in case, should never happen if (rewrite == null) {
newName.append(rewrite); rewrite = colorChar;
} else {
newName.append(name);
} }
newName.append('§').append(rewrite);
} }
name = newName.toString(); name = newName.toString();
} }