3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Rewrite scoreboard team member names to fix the color changing

Dieser Commit ist enthalten in:
Plancke 2018-10-21 22:56:11 +02:00
Ursprung 8bfcc550f7
Commit dc6d9367b0

Datei anzeigen

@ -30,6 +30,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Particle1_13Type
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.util.GsonUtil;
import java.util.EnumMap;
import java.util.Map;
// Development of 1.13 support!
@ -96,6 +97,28 @@ public class Protocol1_13To1_12_2 extends Protocol {
}
};
// @formatter:off
// 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) {{
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
static {
MappingData.init();
}
@ -424,12 +447,41 @@ public class Protocol1_13To1_12_2 extends Protocol {
wrapper.write(Type.STRING, ChatRewriter.legacyTextToJson(prefix)); // Prefix
wrapper.write(Type.STRING, ChatRewriter.legacyTextToJson(suffix)); // Suffix
}
if (action == 0 || action == 3 || action == 4) {
wrapper.passthrough(Type.INT); // Entity Count
String[] names = wrapper.read(Type.STRING_ARRAY); // Entities
for (int i = 0; i < names.length; i++) {
names[i] = rewriteTeamMemberName(names[i]);
}
wrapper.write(Type.STRING_ARRAY, names);
}
}
});
}
});
registerOutgoing(State.PLAY, 0x45, 0x48);
registerOutgoing(State.PLAY, 0x45, 0x48, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String displayName = wrapper.read(Type.STRING); // Display Name
displayName = rewriteTeamMemberName(displayName);
wrapper.write(Type.STRING, displayName);
byte action = wrapper.read(Type.BYTE);
wrapper.write(Type.BYTE, action);
wrapper.passthrough(Type.STRING); // Objective Name
if (action != 1) {
wrapper.passthrough(Type.VAR_INT); // Value
}
}
});
}
});
registerOutgoing(State.PLAY, 0x46, 0x49);
registerOutgoing(State.PLAY, 0x47, 0x4A);
registerOutgoing(State.PLAY, 0x48, 0x4B);
@ -876,4 +928,18 @@ public class Protocol1_13To1_12_2 extends Protocol {
return ChatColor.RESET;
}
protected String rewriteTeamMemberName(String name) {
// The Display Name is just colours which overwrites the suffix
// It also overwrites for ANY colour in name but most plugins
// will just send colour as 'invisible' character
if (ChatColor.stripColor(name).length() == 0) {
ChatColor color = ChatColor.getByChar(name.charAt(1));
String newName = SCOREBOARD_TEAM_NAME_REWRITE.get(color);
if (newName != null) { // just in case
name = newName;
}
}
return name;
}
}