Fix legacy text

This commit is contained in:
creeper123123321 2020-07-01 17:44:27 -03:00
parent c83411f7be
commit 4bf7c9c303

View File

@ -56,9 +56,10 @@ import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaConnectionManager; import us.myles.ViaVersion.api.platform.ViaConnectionManager;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.sponge.VersionInfo; import us.myles.ViaVersion.sponge.VersionInfo;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import us.myles.viaversion.libs.bungeecordchat.api.chat.TextComponent;
import us.myles.viaversion.libs.bungeecordchat.chat.ComponentSerializer;
import us.myles.viaversion.libs.gson.JsonObject; import us.myles.viaversion.libs.gson.JsonObject;
import java.io.File; import java.io.File;
@ -230,7 +231,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
runServerSync(() -> { runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return; if (player == null) return;
player.sendChatMessage(Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(s)), MessageType.SYSTEM); player.sendChatMessage(Text.Serializer.fromJson(legacyToJson(s)), MessageType.SYSTEM);
}); });
} }
@ -240,7 +241,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
if (handler != null) { if (handler != null) {
try { try {
handler.onChatMessage(new ChatMessageS2CPacket( handler.onChatMessage(new ChatMessageS2CPacket(
Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(s)) Text.Serializer.fromJson(legacyToJson(s))
)); ));
} catch (OffThreadException ignored) { } catch (OffThreadException ignored) {
} }
@ -263,7 +264,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
if (handler != null) { if (handler != null) {
try { try {
handler.onDisconnect(new DisconnectS2CPacket( handler.onDisconnect(new DisconnectS2CPacket(
Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(msg)) Text.Serializer.fromJson(legacyToJson(msg))
)); ));
} catch (OffThreadException ignored) { } catch (OffThreadException ignored) {
} }
@ -278,7 +279,7 @@ public class VRPlatform implements ViaPlatform<UUID> {
Supplier<Boolean> kickTask = () -> { Supplier<Boolean> kickTask = () -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid); ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return false; if (player == null) return false;
player.networkHandler.disconnect(Text.Serializer.fromJson(ChatRewriter.legacyTextToJson(s))); player.networkHandler.disconnect(Text.Serializer.fromJson(legacyToJson(s)));
return true; return true;
}; };
if (server.isOnThread()) { if (server.isOnThread()) {
@ -349,4 +350,8 @@ public class VRPlatform implements ViaPlatform<UUID> {
public ViaConnectionManager getConnectionManager() { public ViaConnectionManager getConnectionManager() {
return connectionManager; return connectionManager;
} }
private String legacyToJson(String legacy) {
return ComponentSerializer.toString(TextComponent.fromLegacyText(legacy));
}
} }