From 5437fa90cca5c2600e4ee6ec3a2fd4048aee0644 Mon Sep 17 00:00:00 2001 From: Draycia Date: Sun, 3 May 2020 05:05:43 -0700 Subject: [PATCH] Remove old Chat methods Note: I'm 100% certain things will break because of theee changes. I'll fix things as I find them broken. 10/10 strategy. --- .../java/net/minestom/server/chat/Chat.java | 19 +++---------------- .../net/minestom/server/entity/Player.java | 10 +++++----- .../server/listener/ChatMessageListener.java | 3 ++- .../server/play/AdvancementsPacket.java | 5 ++--- .../packet/server/play/BossBarPacket.java | 5 ++--- .../packet/server/play/DisconnectPacket.java | 3 +-- .../play/ScoreboardObjectivePacket.java | 3 +-- .../packet/server/play/TeamsPacket.java | 6 +++--- .../packet/server/play/TitlePacket.java | 6 +++--- .../java/net/minestom/server/utils/Utils.java | 4 ++-- 10 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/main/java/net/minestom/server/chat/Chat.java b/src/main/java/net/minestom/server/chat/Chat.java index fc96687f0..cbf738ce5 100644 --- a/src/main/java/net/minestom/server/chat/Chat.java +++ b/src/main/java/net/minestom/server/chat/Chat.java @@ -4,7 +4,6 @@ import net.kyori.text.Component; import net.kyori.text.TextComponent; import net.kyori.text.serializer.gson.GsonComponentSerializer; import net.kyori.text.serializer.legacy.LegacyComponentSerializer; -import net.kyori.text.serializer.plain.PlainComponentSerializer; /** * Thank for the minecraft-text library made by rbrick: @@ -26,23 +25,11 @@ public class Chat { return LegacyComponentSerializer.legacyLinking().serialize(component); } - public static TextComponent legacyText(String text, char colorChar) { + public static TextComponent toLegacyText(String text, char colorChar) { return LegacyComponentSerializer.legacyLinking().deserialize(text, colorChar); } - public static TextComponent legacyText(String text) { - return legacyText(text, COLOR_CHAR); + public static TextComponent toLegacyText(String text) { + return toLegacyText(text, COLOR_CHAR); } - - public static String legacyTextString(String text) { - // TODO: Find out where this is used and ensure this is correct - return GsonComponentSerializer.INSTANCE.serialize(legacyText(text, COLOR_CHAR)); - } - - public static String uncoloredLegacyText(String text) { - // TODO: Find out where this is used and ensure this is correct - // TODO: Improve this, I'm not sure the old method is correct - return PlainComponentSerializer.INSTANCE.serialize(legacyText(text)); - } - } diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 28c02a95e..6e15329f9 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -398,11 +398,11 @@ public class Player extends LivingEntity { // Use legacy color formatting public void sendMessage(String message) { - sendMessage(Chat.legacyText(message)); + sendMessage(Chat.toLegacyText(message)); } public void sendMessage(String message, char colorChar) { - sendMessage(Chat.legacyText(message, colorChar)); + sendMessage(Chat.toLegacyText(message, colorChar)); } public void sendMessage(JsonObject jsonObject) { @@ -456,8 +456,8 @@ public class Player extends LivingEntity { playerListHeaderAndFooterPacket.emptyHeader = header == null; playerListHeaderAndFooterPacket.emptyFooter = footer == null; - playerListHeaderAndFooterPacket.header = Chat.toJsonString(Chat.legacyText(header, colorChar)); - playerListHeaderAndFooterPacket.footer = Chat.toJsonString(Chat.legacyText(footer, colorChar)); + playerListHeaderAndFooterPacket.header = Chat.toJsonString(Chat.toLegacyText(header, colorChar)); + playerListHeaderAndFooterPacket.footer = Chat.toJsonString(Chat.toLegacyText(footer, colorChar)); playerConnection.sendPacket(playerListHeaderAndFooterPacket); } @@ -465,7 +465,7 @@ public class Player extends LivingEntity { public void sendActionBarMessage(String message, char colorChar) { TitlePacket titlePacket = new TitlePacket(); titlePacket.action = TitlePacket.Action.SET_ACTION_BAR; - titlePacket.actionBarText = Chat.toJsonString(Chat.legacyText(message, colorChar)); + titlePacket.actionBarText = Chat.toJsonString(Chat.toLegacyText(message, colorChar)); playerConnection.sendPacket(titlePacket); } diff --git a/src/main/java/net/minestom/server/listener/ChatMessageListener.java b/src/main/java/net/minestom/server/listener/ChatMessageListener.java index 261f16ecf..abd97322b 100644 --- a/src/main/java/net/minestom/server/listener/ChatMessageListener.java +++ b/src/main/java/net/minestom/server/listener/ChatMessageListener.java @@ -4,6 +4,7 @@ import net.kyori.text.TextComponent; import net.kyori.text.event.ClickEvent; import net.kyori.text.event.HoverEvent; import net.kyori.text.format.TextColor; +import net.kyori.text.serializer.plain.PlainComponentSerializer; import net.minestom.server.MinecraftServer; import net.minestom.server.chat.Chat; import net.minestom.server.command.CommandManager; @@ -17,7 +18,7 @@ import java.util.function.Function; public class ChatMessageListener { public static void listener(ClientChatMessagePacket packet, Player player) { - String message = Chat.uncoloredLegacyText(packet.message); + String message = PlainComponentSerializer.INSTANCE.serialize(Chat.toLegacyText(packet.message)); CommandManager commandManager = MinecraftServer.getCommandManager(); String cmdPrefix = commandManager.getCommandPrefix(); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java index 6081869f3..0eee0aa48 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/AdvancementsPacket.java @@ -1,6 +1,5 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.chat.Chat; import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; @@ -92,8 +91,8 @@ public class AdvancementsPacket implements ServerPacket { public float y; private void write(PacketWriter writer) { - writer.writeSizedString(Chat.legacyTextString(title)); - writer.writeSizedString(Chat.legacyTextString(description)); + writer.writeSizedString(title); + writer.writeSizedString(description); writer.writeItemStack(icon); writer.writeVarInt(frameType.ordinal()); writer.writeInt(flags); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/BossBarPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/BossBarPacket.java index 78cdb1840..173f4c508 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/BossBarPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/BossBarPacket.java @@ -2,7 +2,6 @@ package net.minestom.server.network.packet.server.play; import net.minestom.server.bossbar.BarColor; import net.minestom.server.bossbar.BarDivision; -import net.minestom.server.chat.Chat; import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; @@ -28,7 +27,7 @@ public class BossBarPacket implements ServerPacket { switch (action) { case ADD: - writer.writeSizedString(Chat.legacyTextString(title)); + writer.writeSizedString(title); writer.writeFloat(health); writer.writeVarInt(color.ordinal()); writer.writeVarInt(division.ordinal()); @@ -41,7 +40,7 @@ public class BossBarPacket implements ServerPacket { writer.writeFloat(health); break; case UPDATE_TITLE: - writer.writeSizedString(Chat.legacyTextString(title)); + writer.writeSizedString(title); break; case UPDATE_STYLE: writer.writeVarInt(color.ordinal()); diff --git a/src/main/java/net/minestom/server/network/packet/server/play/DisconnectPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/DisconnectPacket.java index 1ab8f6866..4eaffd5f8 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/DisconnectPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/DisconnectPacket.java @@ -1,6 +1,5 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.chat.Chat; import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; @@ -11,7 +10,7 @@ public class DisconnectPacket implements ServerPacket { @Override public void write(PacketWriter writer) { - writer.writeSizedString(Chat.legacyTextString(message)); + writer.writeSizedString(message); } @Override diff --git a/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java index 6ce6b0c56..ba23eb20d 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/ScoreboardObjectivePacket.java @@ -1,6 +1,5 @@ package net.minestom.server.network.packet.server.play; -import net.minestom.server.chat.Chat; import net.minestom.server.network.packet.PacketWriter; import net.minestom.server.network.packet.server.ServerPacket; import net.minestom.server.network.packet.server.ServerPacketIdentifier; @@ -18,7 +17,7 @@ public class ScoreboardObjectivePacket implements ServerPacket { writer.writeByte(mode); if (mode == 0 || mode == 2) { - writer.writeSizedString(Chat.legacyTextString(objectiveValue)); + writer.writeSizedString(objectiveValue); writer.writeVarInt(type); } } diff --git a/src/main/java/net/minestom/server/network/packet/server/play/TeamsPacket.java b/src/main/java/net/minestom/server/network/packet/server/play/TeamsPacket.java index a2eb77eaf..b48e91de4 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/TeamsPacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/TeamsPacket.java @@ -27,13 +27,13 @@ public class TeamsPacket implements ServerPacket { switch (action) { case CREATE_TEAM: case UPDATE_TEAM_INFO: - writer.writeSizedString(Chat.legacyTextString(teamDisplayName)); + writer.writeSizedString(teamDisplayName); writer.writeByte(friendlyFlags); writer.writeSizedString(nameTagVisibility.getIdentifier()); writer.writeSizedString(collisionRule.getIdentifier()); writer.writeVarInt(teamColor); - writer.writeSizedString(Chat.legacyTextString(teamPrefix)); - writer.writeSizedString(Chat.legacyTextString(teamSuffix)); + writer.writeSizedString(teamPrefix); + writer.writeSizedString(teamSuffix); break; case REMOVE_TEAM: diff --git a/src/main/java/net/minestom/server/network/packet/server/play/TitlePacket.java b/src/main/java/net/minestom/server/network/packet/server/play/TitlePacket.java index 028e86a4e..77aef0c10 100644 --- a/src/main/java/net/minestom/server/network/packet/server/play/TitlePacket.java +++ b/src/main/java/net/minestom/server/network/packet/server/play/TitlePacket.java @@ -25,13 +25,13 @@ public class TitlePacket implements ServerPacket { switch (action) { case SET_TITLE: - writer.writeSizedString(Chat.legacyTextString(titleText)); + writer.writeSizedString(titleText); break; case SET_SUBTITLE: - writer.writeSizedString(Chat.legacyTextString(subtitleText)); + writer.writeSizedString(subtitleText); break; case SET_ACTION_BAR: - writer.writeSizedString(Chat.legacyTextString(actionBarText)); + writer.writeSizedString(actionBarText); break; case SET_TIMES_AND_DISPLAY: writer.writeInt(fadeIn); diff --git a/src/main/java/net/minestom/server/utils/Utils.java b/src/main/java/net/minestom/server/utils/Utils.java index 7ab3faed5..8268b5cb3 100644 --- a/src/main/java/net/minestom/server/utils/Utils.java +++ b/src/main/java/net/minestom/server/utils/Utils.java @@ -117,7 +117,7 @@ public class Utils { if (hasDisplayName) { packet.writeByte((byte) 0x08); packet.writeShortSizedString("Name"); - packet.writeShortSizedString(Chat.legacyTextString(itemStack.getDisplayName())); + packet.writeShortSizedString(itemStack.getDisplayName()); } if (hasLore) { @@ -128,7 +128,7 @@ public class Utils { packet.writeByte((byte) 0x08); packet.writeInt(lore.size()); for (String line : lore) { - packet.writeShortSizedString(Chat.legacyTextString(line)); + packet.writeShortSizedString(line); } }