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

Let's go on an <insert title card>

Dieser Commit ist enthalten in:
KennyTV 2020-11-23 17:28:07 +01:00 committet von Nassim
Ursprung 7f8052c3cd
Commit cf8d11d530
15 geänderte Dateien mit 181 neuen und 199 gelöschten Zeilen

Datei anzeigen

@ -4,7 +4,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import net.md_5.bungee.api.ChatColor;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -14,6 +13,7 @@ import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.exception.InformativeException; import us.myles.ViaVersion.exception.InformativeException;
import us.myles.ViaVersion.packets.Direction; import us.myles.ViaVersion.packets.Direction;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.util.ChatColorUtil;
import us.myles.ViaVersion.util.PipelineUtil; import us.myles.ViaVersion.util.PipelineUtil;
import java.util.Map; import java.util.Map;
@ -53,7 +53,6 @@ public class UserConnection {
} }
/** /**
* @param channel
* @see #UserConnection(Channel, boolean) * @see #UserConnection(Channel, boolean)
*/ */
public UserConnection(@Nullable Channel channel) { public UserConnection(@Nullable Channel channel) {
@ -236,7 +235,7 @@ public class UserConnection {
pendingDisconnect = true; pendingDisconnect = true;
Via.getPlatform().runSync(() -> { Via.getPlatform().runSync(() -> {
if (!Via.getPlatform().disconnect(this, ChatColor.translateAlternateColorCodes('&', reason))) { if (!Via.getPlatform().disconnect(this, ChatColorUtil.translateAlternateColorCodes(reason))) {
channel.close(); // =) channel.close(); // =)
} }
}); });

Datei anzeigen

@ -1,14 +1,30 @@
package us.myles.ViaVersion.commands; package us.myles.ViaVersion.commands;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.command.ViaSubCommand; import us.myles.ViaVersion.api.command.ViaSubCommand;
import us.myles.ViaVersion.api.command.ViaVersionCommand; import us.myles.ViaVersion.api.command.ViaVersionCommand;
import us.myles.ViaVersion.commands.defaultsubs.*; import us.myles.ViaVersion.commands.defaultsubs.AutoTeamSubCmd;
import us.myles.ViaVersion.commands.defaultsubs.DebugSubCmd;
import us.myles.ViaVersion.commands.defaultsubs.DisplayLeaksSubCmd;
import us.myles.ViaVersion.commands.defaultsubs.DontBugMeSubCmd;
import us.myles.ViaVersion.commands.defaultsubs.DumpSubCmd;
import us.myles.ViaVersion.commands.defaultsubs.HelpSubCmd;
import us.myles.ViaVersion.commands.defaultsubs.ListSubCmd;
import us.myles.ViaVersion.commands.defaultsubs.PPSSubCmd;
import us.myles.ViaVersion.commands.defaultsubs.ReloadSubCmd;
import us.myles.ViaVersion.util.ChatColorUtil;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public abstract class ViaCommandHandler implements ViaVersionCommand { public abstract class ViaCommandHandler implements ViaVersionCommand {
private final Map<String, ViaSubCommand> commandMap; private final Map<String, ViaSubCommand> commandMap;
@ -148,11 +164,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
* @return The output String * @return The output String
*/ */
public static String color(String string) { public static String color(String string) {
try { return ChatColorUtil.translateAlternateColorCodes(string);
string = ChatColor.translateAlternateColorCodes('&', string); //Dont replace all & with $ like we did before.
} catch (Exception ignored) {
}
return string;
} }
/** /**

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.commands.defaultsubs;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.ViaManager; import us.myles.ViaVersion.ViaManager;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
@ -60,7 +59,7 @@ public class DumpSubCmd extends ViaSubCommand {
try { try {
con = (HttpURLConnection) new URL("https://dump.viaversion.com/documents").openConnection(); con = (HttpURLConnection) new URL("https://dump.viaversion.com/documents").openConnection();
} catch (IOException e) { } catch (IOException e) {
sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information"); sender.sendMessage("§4Failed to dump, please check the console for more information");
Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to ViaVersion Dump", e); Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to ViaVersion Dump", e);
return; return;
} }
@ -75,7 +74,7 @@ public class DumpSubCmd extends ViaSubCommand {
out.close(); out.close();
if (con.getResponseCode() == 429) { if (con.getResponseCode() == 429) {
sender.sendMessage(ChatColor.RED + "You can only paste ones every minute to protect our systems."); sender.sendMessage("§4You can only paste ones every minute to protect our systems.");
return; return;
} }
@ -87,9 +86,9 @@ public class DumpSubCmd extends ViaSubCommand {
if (!output.has("key")) if (!output.has("key"))
throw new InvalidObjectException("Key is not given in Hastebin output"); throw new InvalidObjectException("Key is not given in Hastebin output");
sender.sendMessage(ChatColor.GREEN + "We've made a dump with useful information, report your issue and provide this url: " + getUrl(output.get("key").getAsString())); sender.sendMessage("§2We've made a dump with useful information, report your issue and provide this url: " + getUrl(output.get("key").getAsString()));
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage(ChatColor.RED + "Failed to dump, please check the console for more information"); sender.sendMessage("§4Failed to dump, please check the console for more information");
Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e); Via.getPlatform().getLogger().log(Level.WARNING, "Could not paste ViaVersion dump to Hastebin", e);
try { try {
if (con.getResponseCode() < 200 || con.getResponseCode() > 400) { if (con.getResponseCode() < 200 || con.getResponseCode() > 400) {

Datei anzeigen

@ -5,7 +5,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -18,6 +17,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import us.myles.ViaVersion.util.ChatColorUtil;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import java.util.List; import java.util.List;
@ -168,7 +168,7 @@ public class BaseProtocol1_7 extends SimpleProtocol {
if (!wrapper.user().shouldApplyBlockProtocol()) return; if (!wrapper.user().shouldApplyBlockProtocol()) return;
PacketWrapper disconnectPacket = new PacketWrapper(0x00, null, wrapper.user()); // Disconnect Packet PacketWrapper disconnectPacket = new PacketWrapper(0x00, null, wrapper.user()); // Disconnect Packet
Protocol1_9To1_8.FIX_JSON.write(disconnectPacket, ChatColor.translateAlternateColorCodes('&', Via.getConfig().getBlockedDisconnectMsg())); Protocol1_9To1_8.FIX_JSON.write(disconnectPacket, ChatColorUtil.translateAlternateColorCodes(Via.getConfig().getBlockedDisconnectMsg()));
wrapper.cancel(); // cancel current wrapper.cancel(); // cancel current
// Send and close // Send and close

Datei anzeigen

@ -1,96 +1,43 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2; package us.myles.ViaVersion.protocols.protocol1_13to1_12_2;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import net.md_5.bungee.api.ChatColor; import com.google.gson.JsonParser;
import net.md_5.bungee.api.chat.TextComponent; import net.kyori.adventure.text.Component;
import net.md_5.bungee.chat.ComponentSerializer; import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.rewriters.ComponentRewriter; import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ComponentRewriter1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ComponentRewriter1_13;
import us.myles.ViaVersion.util.GsonUtil;
public class ChatRewriter { public class ChatRewriter {
private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter1_13(); private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter1_13();
// Based on https://github.com/SpigotMC/BungeeCord/blob/master/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java public static String legacyTextToJsonString(String message, boolean itemData) {
public static String fromLegacyTextAsString(String message, ChatColor defaultColor, boolean itemData) { Component component = Component.text(builder -> {
TextComponent headComponent = new TextComponent(); if (itemData) {
TextComponent component = new TextComponent(); builder.decoration(TextDecoration.ITALIC, false);
StringBuilder builder = new StringBuilder();
if (itemData) {
// Workaround for all italic lore
headComponent.setItalic(false);
//TODO set first child to italics if it doesn't have a color
}
for (int i = 0; i < message.length(); i++) {
char c = message.charAt(i);
if (c == ChatColor.COLOR_CHAR) {
if (++i >= message.length()) {
break;
}
c = message.charAt(i);
if (c >= 'A' && c <= 'Z') {
c += 32;
}
ChatColor format = ChatColor.getByChar(c);
if (format == null) {
continue;
}
if (builder.length() > 0) {
TextComponent old = component;
component = new TextComponent(old);
old.setText(builder.toString());
builder = new StringBuilder();
headComponent.addExtra(old);
}
if (ChatColor.BOLD.equals(format)) {
component.setBold(true);
} else if (ChatColor.ITALIC.equals(format)) {
component.setItalic(true);
} else if (ChatColor.UNDERLINE.equals(format)) {
component.setUnderlined(true);
} else if (ChatColor.STRIKETHROUGH.equals(format)) {
component.setStrikethrough(true);
} else if (ChatColor.MAGIC.equals(format)) {
component.setObfuscated(true);
} else if (ChatColor.RESET.equals(format)) {
format = defaultColor;
component = new TextComponent();
component.setColor(format);
} else {
component = new TextComponent();
component.setColor(format);
}
continue;
} }
builder.append(c); builder.append(LegacyComponentSerializer.legacySection().deserialize(message));
} });
return GsonComponentSerializer.gson().serialize(component);
component.setText(builder.toString());
headComponent.addExtra(component);
return ComponentSerializer.toString(headComponent);
}
public static JsonElement fromLegacyText(String message, ChatColor defaultColor) {
return GsonUtil.getJsonParser().parse(fromLegacyTextAsString(message, defaultColor, false));
}
public static JsonElement legacyTextToJson(String legacyText) {
return fromLegacyText(legacyText, ChatColor.WHITE);
} }
public static String legacyTextToJsonString(String legacyText) { public static String legacyTextToJsonString(String legacyText) {
return fromLegacyTextAsString(legacyText, ChatColor.WHITE, false); return legacyTextToJsonString(legacyText, false);
} }
public static String jsonTextToLegacy(String value) { public static JsonElement legacyTextToJson(String legacyText) {
return JsonParser.parseString(legacyTextToJsonString(legacyText, false));
}
public static String jsonToLegacyText(String value) {
try { try {
return TextComponent.toLegacyText(ComponentSerializer.parse(value)); Component component = GsonComponentSerializer.gson().deserialize(value);
return LegacyComponentSerializer.legacySection().serialize(component);
} catch (Exception e) { } catch (Exception e) {
Via.getPlatform().getLogger().warning("Error converting json text to legacy: " + value); Via.getPlatform().getLogger().warning("Error converting json text to legacy: " + value);
e.printStackTrace();
return ""; return "";
} }
} }

Datei anzeigen

@ -4,7 +4,6 @@ import com.google.common.collect.Sets;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
@ -42,6 +41,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.BlockStorage;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.util.ChatColorUtil;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -53,6 +53,34 @@ import java.util.Set;
public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, ClientboundPackets1_13, ServerboundPackets1_12_1, ServerboundPackets1_13> { public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, ClientboundPackets1_13, ServerboundPackets1_12_1, ServerboundPackets1_13> {
public static final MappingData MAPPINGS = new MappingData(); public static final MappingData MAPPINGS = new MappingData();
// These are arbitrary rewrite values, it just needs an invalid color code character.
private static final Map<Character, Character> SCOREBOARD_TEAM_NAME_REWRITE = new HashMap<>();
private static final Set<Character> FORMATTING_CODES = Sets.newHashSet('k', 'l', 'm', 'n', 'o', 'r');
static {
SCOREBOARD_TEAM_NAME_REWRITE.put('0', 'g');
SCOREBOARD_TEAM_NAME_REWRITE.put('1', 'h');
SCOREBOARD_TEAM_NAME_REWRITE.put('2', 'i');
SCOREBOARD_TEAM_NAME_REWRITE.put('3', 'j');
SCOREBOARD_TEAM_NAME_REWRITE.put('4', 'p');
SCOREBOARD_TEAM_NAME_REWRITE.put('5', 'q');
SCOREBOARD_TEAM_NAME_REWRITE.put('6', 's');
SCOREBOARD_TEAM_NAME_REWRITE.put('7', 't');
SCOREBOARD_TEAM_NAME_REWRITE.put('8', 'u');
SCOREBOARD_TEAM_NAME_REWRITE.put('9', 'v');
SCOREBOARD_TEAM_NAME_REWRITE.put('a', 'w');
SCOREBOARD_TEAM_NAME_REWRITE.put('b', 'x');
SCOREBOARD_TEAM_NAME_REWRITE.put('c', 'y');
SCOREBOARD_TEAM_NAME_REWRITE.put('d', 'z');
SCOREBOARD_TEAM_NAME_REWRITE.put('e', '!');
SCOREBOARD_TEAM_NAME_REWRITE.put('f', '?');
SCOREBOARD_TEAM_NAME_REWRITE.put('k', '#');
SCOREBOARD_TEAM_NAME_REWRITE.put('l', '(');
SCOREBOARD_TEAM_NAME_REWRITE.put('m', ')');
SCOREBOARD_TEAM_NAME_REWRITE.put('n', ':');
SCOREBOARD_TEAM_NAME_REWRITE.put('o', ';');
SCOREBOARD_TEAM_NAME_REWRITE.put('r', '/');
}
public Protocol1_13To1_12_2() { public Protocol1_13To1_12_2() {
super(ClientboundPackets1_12_1.class, ClientboundPackets1_13.class, ServerboundPackets1_12_1.class, ServerboundPackets1_13.class); super(ClientboundPackets1_12_1.class, ClientboundPackets1_13.class, ServerboundPackets1_12_1.class, ServerboundPackets1_13.class);
@ -115,36 +143,6 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
}).send(Protocol1_13To1_12_2.class); }).send(Protocol1_13To1_12_2.class);
}; };
// These are arbitrary rewrite values, it just needs an invalid color code character.
protected static final Map<ChatColor, Character> SCOREBOARD_TEAM_NAME_REWRITE = new HashMap<>();
private static final Set<ChatColor> FORMATTING_CODES = Sets.newHashSet(ChatColor.MAGIC, ChatColor.BOLD, ChatColor.STRIKETHROUGH,
ChatColor.UNDERLINE, ChatColor.ITALIC, ChatColor.RESET);
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, '?');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.MAGIC, '#');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.BOLD, '(');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.STRIKETHROUGH, ')');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.UNDERLINE, ':');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.ITALIC, ';');
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.RESET, '/');
}
@Override @Override
protected void registerPackets() { protected void registerPackets() {
MetadataRewriter metadataRewriter = new MetadataRewriter1_13To1_12_2(this); MetadataRewriter metadataRewriter = new MetadataRewriter1_13To1_12_2(this);
@ -625,9 +623,9 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
} }
if (Via.getConfig().is1_13TeamColourFix()) { if (Via.getConfig().is1_13TeamColourFix()) {
ChatColor lastColor = getLastColor(prefix); char lastColorChar = getLastColorChar(prefix);
colour = lastColor.ordinal(); colour = ChatColorUtil.getColorOrdinal(lastColorChar);
suffix = lastColor.toString() + suffix; suffix = ChatColorUtil.COLOR_CHAR + Character.toString(lastColorChar) + suffix;
} }
wrapper.write(Type.VAR_INT, colour); wrapper.write(Type.VAR_INT, colour);
@ -1049,36 +1047,33 @@ public class Protocol1_13To1_12_2 extends Protocol<ClientboundPackets1_12_1, Cli
} }
// Based on method from https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/ChatColor.java // Based on method from https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/ChatColor.java
public ChatColor getLastColor(String input) { public char getLastColorChar(String input) {
int length = input.length(); int length = input.length();
for (int index = length - 1; index > -1; index--) { for (int index = length - 1; index > -1; index--) {
char section = input.charAt(index); char section = input.charAt(index);
if (section == ChatColor.COLOR_CHAR && index < length - 1) { if (section == ChatColorUtil.COLOR_CHAR && index < length - 1) {
char c = input.charAt(index + 1); char c = input.charAt(index + 1);
ChatColor color = ChatColor.getByChar(c); if (ChatColorUtil.isColorCode(c) && !FORMATTING_CODES.contains(c)) {
if (color != null && !FORMATTING_CODES.contains(color)) { return c;
return color;
} }
} }
} }
return 'r';
return ChatColor.RESET;
} }
protected String rewriteTeamMemberName(String name) { protected String rewriteTeamMemberName(String name) {
// The Display Name is just colours which overwrites the suffix // The Display Name is just colours which overwrites the suffix
// It also overwrites for ANY colour in name but most plugins // It also overwrites for ANY colour in name but most plugins
// will just send colour as 'invisible' character // will just send colour as 'invisible' character
if (ChatColor.stripColor(name).isEmpty()) { if (ChatColorUtil.stripColor(name).isEmpty()) {
StringBuilder newName = new StringBuilder(); StringBuilder newName = new StringBuilder();
for (int i = 1; i < name.length(); i += 2) { for (int i = 1; i < name.length(); i += 2) {
char colorChar = name.charAt(i); char colorChar = name.charAt(i);
Character rewrite = SCOREBOARD_TEAM_NAME_REWRITE.get(ChatColor.getByChar(colorChar)); Character rewrite = SCOREBOARD_TEAM_NAME_REWRITE.get(colorChar);
if (rewrite == null) { if (rewrite == null) {
rewrite = colorChar; rewrite = colorChar;
} }
newName.append(ChatColor.COLOR_CHAR).append(rewrite); newName.append(ChatColorUtil.COLOR_CHAR).append(rewrite);
} }
name = newName.toString(); name = newName.toString();
} }

Datei anzeigen

@ -9,7 +9,6 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -304,7 +303,7 @@ public class InventoryPackets {
if (display.get("Name") instanceof StringTag) { if (display.get("Name") instanceof StringTag) {
StringTag name = display.get("Name"); StringTag name = display.get("Name");
display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue())); display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue()));
name.setValue(ChatRewriter.fromLegacyTextAsString(name.getValue(), ChatColor.WHITE, true)); name.setValue(ChatRewriter.legacyTextToJsonString(name.getValue(), true));
} }
} }
// ench is now Enchantments and now uses identifiers // ench is now Enchantments and now uses identifiers
@ -561,7 +560,7 @@ public class InventoryPackets {
if (display.get("Name") instanceof StringTag) { if (display.get("Name") instanceof StringTag) {
StringTag name = display.get("Name"); StringTag name = display.get("Name");
StringTag via = display.remove(NBT_TAG_NAME + "|Name"); StringTag via = display.remove(NBT_TAG_NAME + "|Name");
name.setValue(via != null ? via.getValue() : ChatRewriter.jsonTextToLegacy(name.getValue())); name.setValue(via != null ? via.getValue() : ChatRewriter.jsonToLegacyText(name.getValue()));
} }
} }

Datei anzeigen

@ -4,7 +4,6 @@ import com.github.steveice10.opennbt.tag.builtin.*;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
@ -248,7 +247,7 @@ public class InventoryPackets {
display.put(new ListTag(NBT_TAG_NAME + "|Lore", lore.clone().getValue())); // Save old lore display.put(new ListTag(NBT_TAG_NAME + "|Lore", lore.clone().getValue())); // Save old lore
for (Tag loreEntry : lore) { for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) { if (loreEntry instanceof StringTag) {
String jsonText = ChatRewriter.fromLegacyTextAsString(((StringTag) loreEntry).getValue(), ChatColor.WHITE, true); String jsonText = ChatRewriter.legacyTextToJsonString(((StringTag) loreEntry).getValue(), true);
((StringTag) loreEntry).setValue(jsonText); ((StringTag) loreEntry).setValue(jsonText);
} }
} }
@ -275,7 +274,7 @@ public class InventoryPackets {
} else { } else {
for (Tag loreEntry : lore) { for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) { if (loreEntry instanceof StringTag) {
((StringTag) loreEntry).setValue(ChatRewriter.jsonTextToLegacy(((StringTag) loreEntry).getValue())); ((StringTag) loreEntry).setValue(ChatRewriter.jsonToLegacyText(((StringTag) loreEntry).getValue()));
} }
} }
} }

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.update;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import net.md_5.bungee.api.ChatColor;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
@ -18,7 +17,7 @@ import java.util.UUID;
public class UpdateUtil { public class UpdateUtil {
public static final String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN; public static final String PREFIX = "§a§l[ViaVersion] §a";
private static final String URL = "https://api.spiget.org/v2/resources/"; private static final String URL = "https://api.spiget.org/v2/resources/";
private static final int PLUGIN = 19254; private static final int PLUGIN = 19254;
private static final String LATEST_VERSION = "/versions/latest"; private static final String LATEST_VERSION = "/versions/latest";

Datei anzeigen

@ -0,0 +1,56 @@
package us.myles.ViaVersion.util;
import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import java.util.regex.Pattern;
// Based on https://github.com/SpigotMC/BungeeCord/blob/master/chat/src/main/java/net/md_5/bungee/api/ChatColor.java
public class ChatColorUtil {
public static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRrXx";
public static final char COLOR_CHAR = '§';
public static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-ORX]");
private static final Int2IntMap COLOR_ORDINALS = new Int2IntOpenHashMap();
private static int ordinalCounter;
static {
addColorOrindal('0', '9');
addColorOrindal('a', 'f');
addColorOrindal('k', 'o');
addColorOrindal('r');
}
public static boolean isColorCode(char c) {
return COLOR_ORDINALS.containsKey(c);
}
public static int getColorOrdinal(char c) {
return COLOR_ORDINALS.getOrDefault(c, -1);
}
public static String translateAlternateColorCodes(String s) {
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length - 1; i++) {
if (chars[i] == '&' && ALL_CODES.indexOf(chars[i + 1]) > -1) {
chars[i] = COLOR_CHAR;
chars[i + 1] = Character.toLowerCase(chars[i + 1]);
}
}
return new String(chars);
}
public static String stripColor(final String input) {
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
}
private static void addColorOrindal(int from, int to) {
for (int c = from; c <= to; c++) {
addColorOrindal(c);
}
}
private static void addColorOrindal(int colorChar) {
COLOR_ORDINALS.put(colorChar, ordinalCounter++);
}
}

Datei anzeigen

@ -2,8 +2,7 @@ package us.myles.ViaVersion;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.inject.Inject; import com.google.inject.Inject;
import net.md_5.bungee.api.chat.TextComponent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.chat.ComponentSerializer;
import org.spongepowered.api.Game; import org.spongepowered.api.Game;
import org.spongepowered.api.config.DefaultConfig; import org.spongepowered.api.config.DefaultConfig;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
@ -25,13 +24,19 @@ import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.sponge.commands.SpongeCommandHandler; import us.myles.ViaVersion.sponge.commands.SpongeCommandHandler;
import us.myles.ViaVersion.sponge.commands.SpongeCommandSender; import us.myles.ViaVersion.sponge.commands.SpongeCommandSender;
import us.myles.ViaVersion.sponge.platform.*; import us.myles.ViaVersion.sponge.platform.SpongeTaskId;
import us.myles.ViaVersion.sponge.platform.SpongeViaAPI;
import us.myles.ViaVersion.sponge.platform.SpongeViaConfig;
import us.myles.ViaVersion.sponge.platform.SpongeViaInjector;
import us.myles.ViaVersion.sponge.platform.SpongeViaLoader;
import us.myles.ViaVersion.sponge.util.LoggerWrapper; import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import us.myles.ViaVersion.util.VersionInfo; import us.myles.ViaVersion.util.VersionInfo;
import java.io.File; import java.io.File;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger; import java.util.logging.Logger;
@Plugin(id = "viaversion", @Plugin(id = "viaversion",
@ -164,16 +169,8 @@ public class SpongePlugin implements ViaPlatform<Player> {
@Override @Override
public void sendMessage(UUID uuid, String message) { public void sendMessage(UUID uuid, String message) {
game.getServer().getPlayer(uuid) String serialized = LegacyComponentSerializer.legacySection().serialize(LegacyComponentSerializer.legacySection().deserialize(message));
.ifPresent(player -> game.getServer().getPlayer(uuid).ifPresent(player -> player.sendMessage(TextSerializers.JSON.deserialize(serialized))); // Hacky way to fix links //TODO ??
player.sendMessage(
TextSerializers.JSON.deserialize(
ComponentSerializer.toString(
TextComponent.fromLegacyText(message) // Hacky way to fix links
)
)
)
);
} }
@Override @Override

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.sponge.commands; package us.myles.ViaVersion.sponge.commands;
import net.md_5.bungee.api.chat.TextComponent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.chat.ComponentSerializer;
import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.text.serializer.TextSerializers; import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.api.util.Identifiable; import org.spongepowered.api.util.Identifiable;
@ -23,13 +22,8 @@ public class SpongeCommandSender implements ViaCommandSender {
@Override @Override
public void sendMessage(String msg) { public void sendMessage(String msg) {
source.sendMessage( String serialized = LegacyComponentSerializer.legacySection().serialize(LegacyComponentSerializer.legacySection().deserialize(msg));
TextSerializers.JSON.deserialize( source.sendMessage(TextSerializers.JSON.deserialize(serialized)); // Hacky way to fix links //TODO ??
ComponentSerializer.toString(
TextComponent.fromLegacyText(msg) // Hacky way to fix links
)
)
);
} }
@Override @Override

Datei anzeigen

@ -10,9 +10,7 @@ import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import net.kyori.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.slf4j.Logger; import org.slf4j.Logger;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
@ -26,7 +24,11 @@ import us.myles.ViaVersion.util.GsonUtil;
import us.myles.ViaVersion.util.VersionInfo; import us.myles.ViaVersion.util.VersionInfo;
import us.myles.ViaVersion.velocity.command.VelocityCommandHandler; import us.myles.ViaVersion.velocity.command.VelocityCommandHandler;
import us.myles.ViaVersion.velocity.command.VelocityCommandSender; import us.myles.ViaVersion.velocity.command.VelocityCommandSender;
import us.myles.ViaVersion.velocity.platform.*; import us.myles.ViaVersion.velocity.platform.VelocityTaskId;
import us.myles.ViaVersion.velocity.platform.VelocityViaAPI;
import us.myles.ViaVersion.velocity.platform.VelocityViaConfig;
import us.myles.ViaVersion.velocity.platform.VelocityViaInjector;
import us.myles.ViaVersion.velocity.platform.VelocityViaLoader;
import us.myles.ViaVersion.velocity.service.ProtocolDetectorService; import us.myles.ViaVersion.velocity.service.ProtocolDetectorService;
import us.myles.ViaVersion.velocity.util.LoggerWrapper; import us.myles.ViaVersion.velocity.util.LoggerWrapper;
@ -65,7 +67,7 @@ public class VelocityPlugin implements ViaPlatform<Player> {
public void onProxyInit(ProxyInitializeEvent e) { public void onProxyInit(ProxyInitializeEvent e) {
PROXY = proxy; PROXY = proxy;
VelocityCommandHandler commandHandler = new VelocityCommandHandler(); VelocityCommandHandler commandHandler = new VelocityCommandHandler();
PROXY.getCommandManager().register(commandHandler, "viaver", "vvvelocity", "viaversion"); PROXY.getCommandManager().register("viaver", commandHandler, "vvvelocity", "viaversion");
api = new VelocityViaAPI(); api = new VelocityViaAPI();
conf = new VelocityViaConfig(configDir.toFile()); conf = new VelocityViaConfig(configDir.toFile());
logger = new LoggerWrapper(loggerslf4j); logger = new LoggerWrapper(loggerslf4j);
@ -152,21 +154,13 @@ public class VelocityPlugin implements ViaPlatform<Player> {
@Override @Override
public void sendMessage(UUID uuid, String message) { public void sendMessage(UUID uuid, String message) {
PROXY.getPlayer(uuid).ifPresent(it -> it.sendMessage( PROXY.getPlayer(uuid).ifPresent(it -> it.sendMessage(LegacyComponentSerializer.legacySection().deserialize(message)));
GsonComponentSerializer.INSTANCE.deserialize(
ComponentSerializer.toString(TextComponent.fromLegacyText(message)) // Fixes links
)
));
} }
@Override @Override
public boolean kickPlayer(UUID uuid, String message) { public boolean kickPlayer(UUID uuid, String message) {
return PROXY.getPlayer(uuid).map(it -> { return PROXY.getPlayer(uuid).map(it -> {
it.disconnect( it.disconnect(LegacyComponentSerializer.legacySection().deserialize(message));
GsonComponentSerializer.INSTANCE.deserialize(
ComponentSerializer.toString(TextComponent.fromLegacyText(message))
)
);
return true; return true;
}).orElse(false); }).orElse(false);
} }

Datei anzeigen

@ -1,14 +1,12 @@
package us.myles.ViaVersion.velocity.command; package us.myles.ViaVersion.velocity.command;
import com.velocitypowered.api.command.Command; import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.command.CommandSource;
import org.checkerframework.checker.nullness.qual.NonNull;
import us.myles.ViaVersion.commands.ViaCommandHandler; import us.myles.ViaVersion.commands.ViaCommandHandler;
import us.myles.ViaVersion.velocity.command.subs.ProbeSubCmd; import us.myles.ViaVersion.velocity.command.subs.ProbeSubCmd;
import java.util.List; import java.util.List;
public class VelocityCommandHandler extends ViaCommandHandler implements Command { public class VelocityCommandHandler extends ViaCommandHandler implements SimpleCommand {
public VelocityCommandHandler() { public VelocityCommandHandler() {
try { try {
registerSubCommand(new ProbeSubCmd()); registerSubCommand(new ProbeSubCmd());
@ -18,12 +16,12 @@ public class VelocityCommandHandler extends ViaCommandHandler implements Command
} }
@Override @Override
public void execute(@NonNull CommandSource source, String[] args) { public void execute(Invocation invocation) {
onCommand(new VelocityCommandSender(source), args); onCommand(new VelocityCommandSender(invocation.source()), invocation.arguments());
} }
@Override @Override
public List<String> suggest(@NonNull CommandSource source, String[] currentArgs) { public List<String> suggest(Invocation invocation) {
return onTabComplete(new VelocityCommandSender(source), currentArgs); return onTabComplete(new VelocityCommandSender(invocation.source()), invocation.arguments());
} }
} }

Datei anzeigen

@ -2,9 +2,7 @@ package us.myles.ViaVersion.velocity.command;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import net.kyori.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import java.util.UUID; import java.util.UUID;
@ -23,11 +21,7 @@ public class VelocityCommandSender implements ViaCommandSender {
@Override @Override
public void sendMessage(String msg) { public void sendMessage(String msg) {
source.sendMessage( source.sendMessage(LegacyComponentSerializer.legacySection().deserialize(msg));
GsonComponentSerializer.INSTANCE.deserialize(
ComponentSerializer.toString(TextComponent.fromLegacyText(msg)) // Fixes links
)
);
} }
@Override @Override