mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-23 02:25:19 +01:00
Merge pull request #1069 from creeper123123321/master
color rewriting changes
This commit is contained in:
commit
d84c4365c9
@ -47,79 +47,79 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
}
|
||||
};
|
||||
|
||||
public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS = new PacketHandler() { // *insert here a good name*
|
||||
@Override
|
||||
public void handle(PacketWrapper w) throws Exception {
|
||||
// Send fake declare commands
|
||||
w.create(0x11, new ValueCreator() {
|
||||
public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS =
|
||||
new PacketHandler() { // *insert here a good name*
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) {
|
||||
wrapper.write(Type.VAR_INT, 2); // Size
|
||||
// Write root node
|
||||
wrapper.write(Type.VAR_INT, 0); // Mark as command
|
||||
wrapper.write(Type.VAR_INT, 1); // 1 child
|
||||
wrapper.write(Type.VAR_INT, 1); // Child is at 1
|
||||
public void handle(PacketWrapper w) throws Exception {
|
||||
// Send fake declare commands
|
||||
w.create(0x11, new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) {
|
||||
wrapper.write(Type.VAR_INT, 2); // Size
|
||||
// Write root node
|
||||
wrapper.write(Type.VAR_INT, 0); // Mark as command
|
||||
wrapper.write(Type.VAR_INT, 1); // 1 child
|
||||
wrapper.write(Type.VAR_INT, 1); // Child is at 1
|
||||
|
||||
// Write arg node
|
||||
wrapper.write(Type.VAR_INT, 0x02 | 0x04 | 0x10); // Mark as command
|
||||
wrapper.write(Type.VAR_INT, 0); // No children
|
||||
// Extra data
|
||||
wrapper.write(Type.STRING, "args"); // Arg name
|
||||
wrapper.write(Type.STRING, "brigadier:string");
|
||||
wrapper.write(Type.VAR_INT, 2); // Greedy
|
||||
wrapper.write(Type.STRING, "minecraft:ask_server"); // Ask server
|
||||
// Write arg node
|
||||
wrapper.write(Type.VAR_INT, 0x02 | 0x04 | 0x10); // Mark as command
|
||||
wrapper.write(Type.VAR_INT, 0); // No children
|
||||
// Extra data
|
||||
wrapper.write(Type.STRING, "args"); // Arg name
|
||||
wrapper.write(Type.STRING, "brigadier:string");
|
||||
wrapper.write(Type.VAR_INT, 2); // Greedy
|
||||
wrapper.write(Type.STRING, "minecraft:ask_server"); // Ask server
|
||||
|
||||
wrapper.write(Type.VAR_INT, 0); // Root node index
|
||||
wrapper.write(Type.VAR_INT, 0); // Root node index
|
||||
}
|
||||
}).send(Protocol1_13To1_12_2.class);
|
||||
|
||||
// Send tags packet
|
||||
w.create(0x55, new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.VAR_INT, MappingData.blockTags.size()); // block tags
|
||||
for (Map.Entry<String, Integer[]> tag : MappingData.blockTags.entrySet()) {
|
||||
wrapper.write(Type.STRING, tag.getKey());
|
||||
wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone());
|
||||
}
|
||||
wrapper.write(Type.VAR_INT, MappingData.itemTags.size()); // item tags
|
||||
for (Map.Entry<String, Integer[]> tag : MappingData.itemTags.entrySet()) {
|
||||
wrapper.write(Type.STRING, tag.getKey());
|
||||
wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone());
|
||||
}
|
||||
wrapper.write(Type.VAR_INT, MappingData.fluidTags.size()); // fluid tags
|
||||
for (Map.Entry<String, Integer[]> tag : MappingData.fluidTags.entrySet()) {
|
||||
wrapper.write(Type.STRING, tag.getKey());
|
||||
wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone());
|
||||
}
|
||||
}
|
||||
}).send(Protocol1_13To1_12_2.class);
|
||||
}
|
||||
}).send(Protocol1_13To1_12_2.class);
|
||||
|
||||
// Send tags packet
|
||||
w.create(0x55, new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.write(Type.VAR_INT, MappingData.blockTags.size()); // block tags
|
||||
for (Map.Entry<String, Integer[]> tag : MappingData.blockTags.entrySet()) {
|
||||
wrapper.write(Type.STRING, tag.getKey());
|
||||
wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone());
|
||||
}
|
||||
wrapper.write(Type.VAR_INT, MappingData.itemTags.size()); // item tags
|
||||
for (Map.Entry<String, Integer[]> tag : MappingData.itemTags.entrySet()) {
|
||||
wrapper.write(Type.STRING, tag.getKey());
|
||||
wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone());
|
||||
}
|
||||
wrapper.write(Type.VAR_INT, MappingData.fluidTags.size()); // fluid tags
|
||||
for (Map.Entry<String, Integer[]> tag : MappingData.fluidTags.entrySet()) {
|
||||
wrapper.write(Type.STRING, tag.getKey());
|
||||
wrapper.write(Type.VAR_INT_ARRAY, tag.getValue().clone());
|
||||
}
|
||||
}
|
||||
}).send(Protocol1_13To1_12_2.class);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// @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 + "?");
|
||||
}};
|
||||
protected static EnumMap<ChatColor, Character> SCOREBOARD_TEAM_NAME_REWRITE = new EnumMap<>(ChatColor.class);
|
||||
// @formatter:on
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -933,14 +933,13 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
// will just send colour as 'invisible' character
|
||||
if (ChatColor.stripColor(name).length() == 0) {
|
||||
StringBuilder newName = new StringBuilder();
|
||||
for (int i = 0; i < name.length() / 2; i++) {
|
||||
ChatColor color = ChatColor.getByChar(name.charAt(i * 2 + 1));
|
||||
String rewrite = SCOREBOARD_TEAM_NAME_REWRITE.get(color);
|
||||
if (rewrite != null) { // just in case, should never happen
|
||||
newName.append(rewrite);
|
||||
} else {
|
||||
newName.append(name);
|
||||
for (int i = 1; i < name.length(); i += 2) {
|
||||
char colorChar = name.charAt(i);
|
||||
Character rewrite = SCOREBOARD_TEAM_NAME_REWRITE.get(ChatColor.getByChar(colorChar));
|
||||
if (rewrite == null) {
|
||||
rewrite = colorChar;
|
||||
}
|
||||
newName.append(ChatColor.COLOR_CHAR).append(rewrite);
|
||||
}
|
||||
name = newName.toString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user