mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-28 12:07:42 +01:00
Merge pull request #5 from Draycia/master
Replace minecraft-text with kyori-text
This commit is contained in:
commit
ca7e220543
@ -11,7 +11,6 @@ sourceCompatibility = 1.11
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://jitpack.io' }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -33,7 +32,6 @@ dependencies {
|
||||
api group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|
||||
|
||||
api 'com.github.TheMode:CommandBuilder:f893cfbfe4'
|
||||
api 'com.github.Minestom:minecraft-text:69fd808e92'
|
||||
|
||||
// https://jitpack.io/#Articdive/Jnoise/1.0-SNAPSHOT
|
||||
api 'com.github.Articdive:Jnoise:1.0-SNAPSHOT'
|
||||
@ -41,4 +39,8 @@ dependencies {
|
||||
// https://mvnrepository.com/artifact/org.rocksdb/rocksdbjni
|
||||
api group: 'org.rocksdb', name: 'rocksdbjni', version: '6.8.1'
|
||||
|
||||
api 'net.kyori:text-api:3.0.3'
|
||||
api 'net.kyori:text-serializer-legacy:3.0.3'
|
||||
api 'net.kyori:text-serializer-gson:3.0.3'
|
||||
api 'net.kyori:text-serializer-plain:3.0.3'
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import club.thectm.minecraft.text.LegacyText;
|
||||
import club.thectm.minecraft.text.TextObject;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
/**
|
||||
* Thank for the minecraft-text library made by rbrick:
|
||||
@ -11,23 +13,23 @@ public class Chat {
|
||||
|
||||
public static final char COLOR_CHAR = (char) 0xA7; // Represent the character '§'
|
||||
|
||||
public static TextObject legacyText(String text, char colorChar) {
|
||||
return LegacyText.fromLegacy(text, colorChar);
|
||||
public static String toJsonString(Component component) {
|
||||
return GsonComponentSerializer.INSTANCE.serialize(component);
|
||||
}
|
||||
|
||||
public static TextObject legacyText(String text) {
|
||||
return legacyText(text, COLOR_CHAR);
|
||||
public static Component fromJsonString(String json) {
|
||||
return GsonComponentSerializer.INSTANCE.deserialize(json);
|
||||
}
|
||||
|
||||
public static String legacyTextString(String text, char colorChar) {
|
||||
return legacyText(text, colorChar).toJson().toString();
|
||||
public static String toLegacyText(Component component) {
|
||||
return LegacyComponentSerializer.legacyLinking().serialize(component);
|
||||
}
|
||||
|
||||
public static String legacyTextString(String text) {
|
||||
return legacyText(text).toJson().toString();
|
||||
public static TextComponent fromLegacyText(String text, char colorChar) {
|
||||
return LegacyComponentSerializer.legacyLinking().deserialize(text, colorChar);
|
||||
}
|
||||
|
||||
public static String uncoloredLegacyText(String text) {
|
||||
return text.replace(String.valueOf(COLOR_CHAR), "");
|
||||
public static TextComponent fromLegacyText(String text) {
|
||||
return fromLegacyText(text, COLOR_CHAR);
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import net.minestom.server.utils.HexUtils;
|
||||
|
||||
public enum ChatColor {
|
||||
|
||||
BLACK((byte) 0),
|
||||
DARK_BLUE((byte) 1),
|
||||
DARK_GREEN((byte) 2),
|
||||
DARK_AQUA((byte) 3),
|
||||
DARK_RED((byte) 4),
|
||||
DARK_PURPLE((byte) 5),
|
||||
GOLD((byte) 6),
|
||||
GRAY((byte) 7),
|
||||
DARK_GRAY((byte) 8),
|
||||
BLUE((byte) 9),
|
||||
GREEN((byte) 0xa),
|
||||
AQUA((byte) 0xb),
|
||||
RED((byte) 0xc),
|
||||
LIGHT_PURPLE((byte) 0xd),
|
||||
YELLOW((byte) 0xe),
|
||||
WHITE((byte) 0xf);
|
||||
|
||||
|
||||
private byte id;
|
||||
|
||||
ChatColor(byte id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public byte getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Chat.COLOR_CHAR + String.valueOf(HexUtils.byteToHex(id));
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
package net.minestom.server.entity;
|
||||
|
||||
import club.thectm.minecraft.text.TextBuilder;
|
||||
import club.thectm.minecraft.text.TextObject;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.bossbar.BossBar;
|
||||
import net.minestom.server.chat.Chat;
|
||||
@ -249,21 +248,21 @@ public class Player extends LivingEntity {
|
||||
public void kill() {
|
||||
if (!isDead()) {
|
||||
// send death message to player
|
||||
TextObject deathMessage;
|
||||
Component deathMessage;
|
||||
if (lastDamageSource != null) {
|
||||
deathMessage = lastDamageSource.buildDeathScreenMessage(this);
|
||||
} else { // may happen if killed by the server without applying damage
|
||||
deathMessage = TextBuilder.of("Killed by poor programming.").build();
|
||||
deathMessage = TextComponent.of("Killed by poor programming.");
|
||||
}
|
||||
CombatEventPacket deathPacket = CombatEventPacket.death(this, Optional.empty(), deathMessage);
|
||||
playerConnection.sendPacket(deathPacket);
|
||||
|
||||
// send death message to chat
|
||||
TextObject chatMessage;
|
||||
Component chatMessage;
|
||||
if (lastDamageSource != null) {
|
||||
chatMessage = lastDamageSource.buildChatMessage(this);
|
||||
} else { // may happen if killed by the server without applying damage
|
||||
chatMessage = TextBuilder.of(getUsername() + " was killed by poor programming.").build();
|
||||
chatMessage = TextComponent.of(getUsername() + " was killed by poor programming.");
|
||||
}
|
||||
MinecraftServer.getConnectionManager().getOnlinePlayers().forEach(player -> {
|
||||
player.sendMessage(chatMessage);
|
||||
@ -399,20 +398,16 @@ public class Player extends LivingEntity {
|
||||
|
||||
// Use legacy color formatting
|
||||
public void sendMessage(String message) {
|
||||
sendMessage(Chat.legacyText(message));
|
||||
sendMessage(Chat.fromLegacyText(message));
|
||||
}
|
||||
|
||||
public void sendMessage(String message, char colorChar) {
|
||||
sendMessage(Chat.legacyText(message, colorChar));
|
||||
sendMessage(Chat.fromLegacyText(message, colorChar));
|
||||
}
|
||||
|
||||
public void sendMessage(JsonObject jsonObject) {
|
||||
ChatMessagePacket chatMessagePacket = new ChatMessagePacket(jsonObject.toString(), ChatMessagePacket.Position.CHAT);
|
||||
playerConnection.sendPacket(chatMessagePacket);
|
||||
}
|
||||
|
||||
public void sendMessage(TextObject textObject) {
|
||||
sendMessage(textObject.toJson());
|
||||
public void sendMessage(Component textObject) {
|
||||
String json = Chat.toJsonString(textObject);
|
||||
playerConnection.sendPacket(new ChatMessagePacket(json, ChatMessagePacket.Position.CHAT));
|
||||
}
|
||||
|
||||
public void playSound(Sound sound, SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) {
|
||||
@ -452,24 +447,77 @@ public class Player extends LivingEntity {
|
||||
playerConnection.sendPacket(stopSoundPacket);
|
||||
}
|
||||
|
||||
public void sendHeaderFooter(String header, String footer, char colorChar) {
|
||||
public void sendHeaderFooter(Component header, Component footer) {
|
||||
PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket();
|
||||
playerListHeaderAndFooterPacket.emptyHeader = header == null;
|
||||
playerListHeaderAndFooterPacket.emptyFooter = footer == null;
|
||||
|
||||
playerListHeaderAndFooterPacket.header = Chat.legacyText(header, colorChar).toJson().toString();
|
||||
playerListHeaderAndFooterPacket.footer = Chat.legacyText(footer, colorChar).toJson().toString();
|
||||
playerListHeaderAndFooterPacket.header = Chat.toJsonString(header);
|
||||
playerListHeaderAndFooterPacket.footer = Chat.toJsonString(footer);
|
||||
|
||||
playerConnection.sendPacket(playerListHeaderAndFooterPacket);
|
||||
}
|
||||
|
||||
public void sendActionBarMessage(String message, char colorChar) {
|
||||
public void sendHeaderFooter(String header, String footer, char colorChar) {
|
||||
sendHeaderFooter(Chat.fromLegacyText(header, colorChar), Chat.fromLegacyText(footer, colorChar));
|
||||
}
|
||||
|
||||
private void sendTitle(Component title, TitlePacket.Action action) {
|
||||
TitlePacket titlePacket = new TitlePacket();
|
||||
titlePacket.action = TitlePacket.Action.SET_ACTION_BAR;
|
||||
titlePacket.actionBarText = Chat.legacyText(message, colorChar).toJson().toString();
|
||||
titlePacket.action = action;
|
||||
|
||||
switch (action) {
|
||||
case SET_TITLE:
|
||||
titlePacket.titleText = Chat.toJsonString(title);
|
||||
break;
|
||||
case SET_SUBTITLE:
|
||||
titlePacket.subtitleText = Chat.toJsonString(title);
|
||||
break;
|
||||
case SET_ACTION_BAR:
|
||||
titlePacket.actionBarText = Chat.toJsonString(title);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Invalid TitlePacket.Action type!");
|
||||
}
|
||||
|
||||
playerConnection.sendPacket(titlePacket);
|
||||
}
|
||||
|
||||
public void sendTitleSubtitleMessage(Component title, Component subtitle) {
|
||||
sendTitle(title, TitlePacket.Action.SET_TITLE);
|
||||
sendTitle(subtitle, TitlePacket.Action.SET_SUBTITLE);
|
||||
}
|
||||
|
||||
public void sendTitleMessage(Component title) {
|
||||
sendTitle(title, TitlePacket.Action.SET_TITLE);
|
||||
}
|
||||
|
||||
public void sendTitleMessage(String title, char colorChar) {
|
||||
sendTitleMessage(Chat.fromLegacyText(title, colorChar));
|
||||
}
|
||||
|
||||
public void sendTitleMessage(String title) {
|
||||
sendTitleMessage(title, Chat.COLOR_CHAR);
|
||||
}
|
||||
|
||||
public void sendSubtitleMessage(Component subtitle) {
|
||||
sendTitle(subtitle, TitlePacket.Action.SET_SUBTITLE);
|
||||
}
|
||||
|
||||
public void sendSubtitleMessage(String subtitle, char colorChar) {
|
||||
sendSubtitleMessage(Chat.fromLegacyText(subtitle, colorChar));
|
||||
}
|
||||
|
||||
public void sendSubtitleMessage(String subtitle) {
|
||||
sendSubtitleMessage(subtitle, Chat.COLOR_CHAR);
|
||||
}
|
||||
|
||||
public void sendActionBarMessage(Component actionBar) {
|
||||
sendTitle(actionBar, TitlePacket.Action.SET_ACTION_BAR);
|
||||
}
|
||||
|
||||
public void sendActionBarMessage(String message, char colorChar) {
|
||||
sendActionBarMessage(Chat.fromLegacyText(message, colorChar));
|
||||
}
|
||||
|
||||
public void sendActionBarMessage(String message) {
|
||||
sendActionBarMessage(message, Chat.COLOR_CHAR);
|
||||
}
|
||||
@ -703,13 +751,17 @@ public class Player extends LivingEntity {
|
||||
playerConnection.sendPacket(respawnPacket);
|
||||
}
|
||||
|
||||
public void kick(String message) {
|
||||
public void kick(Component message) {
|
||||
DisconnectPacket disconnectPacket = new DisconnectPacket();
|
||||
disconnectPacket.message = message;
|
||||
disconnectPacket.message = Chat.toJsonString(message);
|
||||
playerConnection.sendPacket(disconnectPacket);
|
||||
playerConnection.getChannel().close();
|
||||
}
|
||||
|
||||
public void kick(String message) {
|
||||
kick(Chat.fromLegacyText(message));
|
||||
}
|
||||
|
||||
public LevelType getLevelType() {
|
||||
return levelType;
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
package net.minestom.server.entity.damage;
|
||||
|
||||
import club.thectm.minecraft.text.TextBuilder;
|
||||
import club.thectm.minecraft.text.TextObject;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.TranslatableComponent;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.LivingEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
@ -34,15 +35,15 @@ public class DamageType {
|
||||
return new EntityProjectileDamage(shooter, projectile);
|
||||
}
|
||||
|
||||
public TextObject buildChatMessage(Player killed) {
|
||||
return TextBuilder.ofTranslation("death."+identifier, TextBuilder.of(killed.getUsername()).build()).build();
|
||||
public Component buildChatMessage(Player killed) {
|
||||
return TranslatableComponent.of("death."+identifier, TextComponent.of(killed.getUsername()));
|
||||
}
|
||||
|
||||
public static DamageType fromPlayer(Player player) {
|
||||
return new EntityDamage(player);
|
||||
}
|
||||
|
||||
public TextObject buildDeathScreenMessage(Player killed) {
|
||||
public Component buildDeathScreenMessage(Player killed) {
|
||||
return buildChatMessage(killed);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.minestom.server.event;
|
||||
|
||||
import club.thectm.minecraft.text.TextObject;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -12,7 +12,7 @@ public class PlayerChatEvent extends CancellableEvent {
|
||||
private Player sender;
|
||||
private Collection<Player> recipients;
|
||||
private String message;
|
||||
private Function<PlayerChatEvent, TextObject> chatFormat;
|
||||
private Function<PlayerChatEvent, TextComponent> chatFormat;
|
||||
|
||||
public PlayerChatEvent(Player sender, Collection<Player> recipients, String message) {
|
||||
this.sender = sender;
|
||||
@ -20,7 +20,7 @@ public class PlayerChatEvent extends CancellableEvent {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public void setChatFormat(Function<PlayerChatEvent, TextObject> chatFormat) {
|
||||
public void setChatFormat(Function<PlayerChatEvent, TextComponent> chatFormat) {
|
||||
this.chatFormat = chatFormat;
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ public class PlayerChatEvent extends CancellableEvent {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Function<PlayerChatEvent, TextObject> getChatFormatFunction() {
|
||||
public Function<PlayerChatEvent, TextComponent> getChatFormatFunction() {
|
||||
return chatFormat;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
package net.minestom.server.listener;
|
||||
|
||||
import club.thectm.minecraft.text.*;
|
||||
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;
|
||||
@ -14,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.fromLegacyText(packet.message));
|
||||
|
||||
CommandManager commandManager = MinecraftServer.getCommandManager();
|
||||
String cmdPrefix = commandManager.getCommandPrefix();
|
||||
@ -38,12 +42,11 @@ public class ChatMessageListener {
|
||||
playerChatEvent.setChatFormat((event) -> {
|
||||
String username = player.getUsername();
|
||||
|
||||
TextObject usernameText = TextBuilder.of(String.format("<%s>", username))
|
||||
.color(ChatColor.WHITE)
|
||||
.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatColor.GRAY + "Its " + username))
|
||||
.clickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + username + " "))
|
||||
.append(" " + event.getMessage())
|
||||
.build();
|
||||
TextComponent usernameText = TextComponent.of(String.format("<%s>", username))
|
||||
.color(TextColor.WHITE)
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Its " + username).color(TextColor.GRAY)))
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/msg " + username + " "))
|
||||
.append(TextComponent.of(" " + event.getMessage()));
|
||||
|
||||
return usernameText;
|
||||
});
|
||||
@ -51,11 +54,11 @@ public class ChatMessageListener {
|
||||
// Call the event
|
||||
player.callCancellableEvent(PlayerChatEvent.class, playerChatEvent, () -> {
|
||||
|
||||
Function<PlayerChatEvent, TextObject> formatFunction = playerChatEvent.getChatFormatFunction();
|
||||
Function<PlayerChatEvent, TextComponent> formatFunction = playerChatEvent.getChatFormatFunction();
|
||||
if (formatFunction == null)
|
||||
throw new NullPointerException("PlayerChatEvent#chatFormat cannot be null!");
|
||||
|
||||
TextObject textObject = formatFunction.apply(playerChatEvent);
|
||||
TextComponent textObject = formatFunction.apply(playerChatEvent);
|
||||
|
||||
for (Player recipient : playerChatEvent.getRecipients()) {
|
||||
recipient.sendMessage(textObject);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.minestom.server.listener;
|
||||
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.client.play.ClientKeepAlivePacket;
|
||||
|
||||
@ -8,7 +8,7 @@ public class KeepAliveListener {
|
||||
|
||||
public static void listener(ClientKeepAlivePacket packet, Player player) {
|
||||
if (packet.id != player.getLastKeepAlive()) {
|
||||
player.kick(ChatColor.RED + "Bad Keep Alive packet");
|
||||
player.kick(TextColor.RED + "Bad Keep Alive packet");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,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(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||
writer.writeItemStack(icon);
|
||||
writer.writeVarInt(frameType.ordinal());
|
||||
writer.writeInt(flags);
|
||||
|
@ -28,7 +28,7 @@ public class BossBarPacket implements ServerPacket {
|
||||
|
||||
switch (action) {
|
||||
case ADD:
|
||||
writer.writeSizedString(Chat.legacyTextString(title));
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||
writer.writeFloat(health);
|
||||
writer.writeVarInt(color.ordinal());
|
||||
writer.writeVarInt(division.ordinal());
|
||||
@ -41,7 +41,7 @@ public class BossBarPacket implements ServerPacket {
|
||||
writer.writeFloat(health);
|
||||
break;
|
||||
case UPDATE_TITLE:
|
||||
writer.writeSizedString(Chat.legacyTextString(title));
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(title)));
|
||||
break;
|
||||
case UPDATE_STYLE:
|
||||
writer.writeVarInt(color.ordinal());
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import club.thectm.minecraft.text.TextObject;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Player;
|
||||
@ -20,7 +21,7 @@ public class CombatEventPacket implements ServerPacket {
|
||||
private int duration;
|
||||
private int opponent;
|
||||
private int playerID;
|
||||
private TextObject deathMessage;
|
||||
private Component deathMessage;
|
||||
|
||||
private CombatEventPacket() {}
|
||||
|
||||
@ -38,7 +39,7 @@ public class CombatEventPacket implements ServerPacket {
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static CombatEventPacket death(Player player, Optional<Entity> killer, TextObject message) {
|
||||
public static CombatEventPacket death(Player player, Optional<Entity> killer, Component message) {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
packet.type = EventType.DEATH;
|
||||
packet.playerID = player.getEntityId();
|
||||
@ -63,7 +64,7 @@ public class CombatEventPacket implements ServerPacket {
|
||||
case DEATH:
|
||||
writer.writeVarInt(playerID);
|
||||
writer.writeInt(opponent);
|
||||
writer.writeSizedString(deathMessage.toJson().toString());
|
||||
writer.writeSizedString(Chat.toJsonString(deathMessage));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -18,7 +18,7 @@ public class ScoreboardObjectivePacket implements ServerPacket {
|
||||
writer.writeByte(mode);
|
||||
|
||||
if (mode == 0 || mode == 2) {
|
||||
writer.writeSizedString(Chat.legacyTextString(objectiveValue));
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(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(Chat.toJsonString(Chat.fromLegacyText(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(Chat.toJsonString(Chat.fromLegacyText(teamPrefix)));
|
||||
writer.writeSizedString(Chat.toJsonString(Chat.fromLegacyText(teamSuffix)));
|
||||
break;
|
||||
case REMOVE_TEAM:
|
||||
|
||||
|
@ -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;
|
||||
@ -25,13 +24,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);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.minestom.server.scoreboard;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
@ -17,7 +17,7 @@ public class Team {
|
||||
private byte friendlyFlags = 0x00;
|
||||
private TeamsPacket.NameTagVisibility nameTagVisibility = TeamsPacket.NameTagVisibility.ALWAYS;
|
||||
private TeamsPacket.CollisionRule collisionRule = TeamsPacket.CollisionRule.NEVER;
|
||||
private ChatColor teamColor = ChatColor.WHITE;
|
||||
private TextColor teamColor = TextColor.WHITE;
|
||||
private String prefix = "", suffix = "";
|
||||
private String[] entities = new String[0];
|
||||
private Set<Player> players = new CopyOnWriteArraySet<>();
|
||||
@ -36,7 +36,7 @@ public class Team {
|
||||
teamsCreationPacket.friendlyFlags = friendlyFlags;
|
||||
teamsCreationPacket.nameTagVisibility = nameTagVisibility;
|
||||
teamsCreationPacket.collisionRule = collisionRule;
|
||||
teamsCreationPacket.teamColor = teamColor.getId();
|
||||
teamsCreationPacket.teamColor = teamColor.ordinal();
|
||||
teamsCreationPacket.teamPrefix = prefix;
|
||||
teamsCreationPacket.teamSuffix = suffix;
|
||||
teamsCreationPacket.entities = entities;
|
||||
@ -107,9 +107,9 @@ public class Team {
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
public void setTeamColor(ChatColor teamColor) {
|
||||
public void setTeamColor(TextColor teamColor) {
|
||||
this.teamColor = teamColor;
|
||||
this.teamsCreationPacket.teamColor = teamColor.getId();
|
||||
this.teamsCreationPacket.teamColor = teamColor.ordinal();
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ public class Team {
|
||||
updatePacket.friendlyFlags = friendlyFlags;
|
||||
updatePacket.nameTagVisibility = nameTagVisibility;
|
||||
updatePacket.collisionRule = collisionRule;
|
||||
updatePacket.teamColor = teamColor.getId();
|
||||
updatePacket.teamColor = teamColor.ordinal();
|
||||
updatePacket.teamPrefix = prefix;
|
||||
updatePacket.teamSuffix = suffix;
|
||||
ByteBuf buffer = PacketUtils.writePacket(updatePacket);
|
||||
|
@ -1,8 +1,7 @@
|
||||
package net.minestom.server.utils;
|
||||
|
||||
import club.thectm.minecraft.text.LegacyText;
|
||||
import club.thectm.minecraft.text.TextObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.kyori.text.Component;
|
||||
import net.minestom.server.chat.Chat;
|
||||
import net.minestom.server.item.Enchantment;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.PacketReader;
|
||||
@ -122,8 +121,9 @@ public class NbtReaderUtils {
|
||||
|
||||
if (stringName.equals("Name")) {
|
||||
String jsonDisplayName = reader.readShortSizedString();
|
||||
TextObject textObject = TextObject.fromJson(new JsonParser().parse(jsonDisplayName).getAsJsonObject());
|
||||
String displayName = LegacyText.toLegacy(textObject);
|
||||
Component textObject = Chat.fromJsonString(jsonDisplayName);
|
||||
String displayName = Chat.toLegacyText(textObject);
|
||||
|
||||
item.setDisplayName(displayName);
|
||||
readItemStackDisplayNBT(reader, item);
|
||||
}
|
||||
@ -139,9 +139,9 @@ public class NbtReaderUtils {
|
||||
ArrayList<String> lore = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
String string = reader.readShortSizedString();
|
||||
Component textObject = Chat.fromJsonString(string);
|
||||
String line = Chat.toLegacyText(textObject);
|
||||
|
||||
TextObject textObject = TextObject.fromJson(new JsonParser().parse(string).getAsJsonObject());
|
||||
String line = LegacyText.toLegacy(textObject);
|
||||
lore.add(line);
|
||||
if (lore.size() == size) {
|
||||
item.setLore(lore);
|
||||
|
@ -117,7 +117,7 @@ public class Utils {
|
||||
if (hasDisplayName) {
|
||||
packet.writeByte((byte) 0x08);
|
||||
packet.writeShortSizedString("Name");
|
||||
packet.writeShortSizedString(Chat.legacyTextString(itemStack.getDisplayName()));
|
||||
packet.writeShortSizedString(Chat.toJsonString(Chat.fromLegacyText(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(Chat.toJsonString(Chat.fromLegacyText(line)));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user