mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-14 20:21:53 +01:00
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.
This commit is contained in:
parent
83bb14d5a0
commit
5437fa90cc
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user