mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 09:27:58 +01:00
Deprecate old chat in packets
This commit is contained in:
parent
316ecbbf5a
commit
6095523d8a
@ -3,6 +3,10 @@ package net.minestom.server.network;
|
||||
import io.netty.channel.Channel;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
@ -43,7 +47,7 @@ public final class ConnectionManager implements ForwardingAudience {
|
||||
|
||||
private static final long KEEP_ALIVE_DELAY = 10_000;
|
||||
private static final long KEEP_ALIVE_KICK = 30_000;
|
||||
private static final ColoredText TIMEOUT_TEXT = ColoredText.of(ChatColor.RED + "Timeout");
|
||||
private static final Component TIMEOUT_TEXT = Component.text("Timeout", NamedTextColor.RED);
|
||||
|
||||
private final Queue<Player> waitingPlayers = new ConcurrentLinkedQueue<>();
|
||||
private final Set<Player> players = new CopyOnWriteArraySet<>();
|
||||
@ -60,7 +64,7 @@ public final class ConnectionManager implements ForwardingAudience {
|
||||
// The consumers to call once a player connect, mostly used to init events
|
||||
private final List<Consumer<Player>> playerInitializations = new CopyOnWriteArrayList<>();
|
||||
|
||||
private JsonMessage shutdownText = ColoredText.of(ChatColor.RED, "The server is shutting down.");
|
||||
private Component shutdownText = Component.text("The server is shutting down.", NamedTextColor.RED);
|
||||
|
||||
/**
|
||||
* Gets the {@link Player} linked to a {@link PlayerConnection}.
|
||||
@ -146,7 +150,10 @@ public final class ConnectionManager implements ForwardingAudience {
|
||||
*
|
||||
* @param jsonMessage the message to send, probably a {@link net.minestom.server.chat.ColoredText} or {@link net.minestom.server.chat.RichMessage}
|
||||
* @param condition the condition to receive the message
|
||||
*
|
||||
* @deprecated Use {@link Audience#sendMessage(Component)} on {@link #audiences(PlayerValidator)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void broadcastMessage(@NotNull JsonMessage jsonMessage, @Nullable PlayerValidator condition) {
|
||||
final Collection<Player> recipients = getRecipients(condition);
|
||||
|
||||
@ -160,7 +167,9 @@ public final class ConnectionManager implements ForwardingAudience {
|
||||
* Sends a {@link JsonMessage} to all online players.
|
||||
*
|
||||
* @param jsonMessage the message to send, probably a {@link net.minestom.server.chat.ColoredText} or {@link net.minestom.server.chat.RichMessage}
|
||||
* @deprecated Use {@link #sendMessage(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void broadcastMessage(@NotNull JsonMessage jsonMessage) {
|
||||
broadcastMessage(jsonMessage, null);
|
||||
}
|
||||
@ -315,23 +324,48 @@ public final class ConnectionManager implements ForwardingAudience {
|
||||
this.playerInitializations.remove(playerInitialization);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the kick reason when the server is shutdown using {@link MinecraftServer#stopCleanly()}.
|
||||
*
|
||||
* @return the kick reason in case on a shutdown
|
||||
*
|
||||
* @deprecated Use {@link #getShutdownText()}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public JsonMessage getShutdownTextJson() {
|
||||
return JsonMessage.fromComponent(shutdownText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the kick reason when the server is shutdown using {@link MinecraftServer#stopCleanly()}.
|
||||
*
|
||||
* @return the kick reason in case on a shutdown
|
||||
*/
|
||||
@NotNull
|
||||
public JsonMessage getShutdownText() {
|
||||
public Component getShutdownText() {
|
||||
return shutdownText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the kick reason in case of a shutdown.
|
||||
*
|
||||
* @param shutdownText the new shutdown kick reason
|
||||
* @see #getShutdownTextJson()
|
||||
* @deprecated Use {@link #setShutdownText(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setShutdownText(@NotNull JsonMessage shutdownText) {
|
||||
this.shutdownText = shutdownText.asComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the kick reason in case of a shutdown.
|
||||
*
|
||||
* @param shutdownText the new shutdown kick reason
|
||||
* @see #getShutdownText()
|
||||
*/
|
||||
public void setShutdownText(@NotNull JsonMessage shutdownText) {
|
||||
public void setShutdownText(@NotNull Component shutdownText) {
|
||||
this.shutdownText = shutdownText;
|
||||
}
|
||||
|
||||
@ -461,7 +495,7 @@ public final class ConnectionManager implements ForwardingAudience {
|
||||
* Shutdowns the connection manager by kicking all the currently connected players.
|
||||
*/
|
||||
public void shutdown() {
|
||||
DisconnectPacket disconnectPacket = new DisconnectPacket(getShutdownText());
|
||||
DisconnectPacket disconnectPacket = new DisconnectPacket(MinecraftServer.getSerializationManager().serialize(shutdownText));
|
||||
for (Player player : getOnlinePlayers()) {
|
||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
if (playerConnection instanceof NettyPlayerConnection) {
|
||||
@ -535,4 +569,27 @@ public final class ConnectionManager implements ForwardingAudience {
|
||||
public @NotNull Iterable<? extends Audience> audiences() {
|
||||
return this.getOnlinePlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the audiences of players who match a given validator.
|
||||
*
|
||||
* @param validator the validator
|
||||
*
|
||||
* @return the audience
|
||||
*/
|
||||
public @NotNull Iterable<? extends Audience> audiences(@Nullable PlayerValidator validator) {
|
||||
if (validator == null) {
|
||||
return this.audiences();
|
||||
}
|
||||
|
||||
List<Player> validatedPlayers = new ArrayList<>();
|
||||
|
||||
for (Player onlinePlayer : this.getOnlinePlayers()) {
|
||||
if (validator.isValid(onlinePlayer)) {
|
||||
validatedPlayers.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
|
||||
return validatedPlayers;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.minestom.server.network.packet.client.handshake;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.entity.PlayerSkin;
|
||||
import net.minestom.server.extras.bungee.BungeeCordProxy;
|
||||
import net.minestom.server.network.ConnectionState;
|
||||
@ -21,9 +21,8 @@ public class HandshakePacket implements ClientPreplayPacket {
|
||||
/**
|
||||
* Text sent if a player tries to connect with an invalid version of the client
|
||||
*/
|
||||
private static final ColoredText INVALID_VERSION_TEXT = ColoredText.of(ChatColor.RED, "Invalid Version, please use " + MinecraftServer.VERSION_NAME);
|
||||
|
||||
private static final ColoredText INVALID_BUNGEE_FORWARDING = ColoredText.of(ChatColor.RED, "If you wish to use IP forwarding, please enable it in your BungeeCord config as well!");
|
||||
private static final Component INVALID_VERSION_TEXT = Component.text("Invalid Version, please use " + MinecraftServer.VERSION_NAME, NamedTextColor.RED);
|
||||
private static final Component INVALID_BUNGEE_FORWARDING = Component.text("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!", NamedTextColor.RED);
|
||||
|
||||
private int protocolVersion;
|
||||
private String serverAddress;
|
||||
@ -71,7 +70,7 @@ public class HandshakePacket implements ClientPreplayPacket {
|
||||
nettyPlayerConnection.UNSAFE_setBungeeSkin(playerSkin);
|
||||
|
||||
} else {
|
||||
nettyPlayerConnection.sendPacket(new LoginDisconnectPacket(INVALID_BUNGEE_FORWARDING));
|
||||
nettyPlayerConnection.sendPacket(new LoginDisconnectPacket(MinecraftServer.getSerializationManager().serialize(INVALID_BUNGEE_FORWARDING)));
|
||||
nettyPlayerConnection.disconnect();
|
||||
return;
|
||||
}
|
||||
@ -95,7 +94,7 @@ public class HandshakePacket implements ClientPreplayPacket {
|
||||
}
|
||||
} else {
|
||||
// Incorrect client version
|
||||
connection.sendPacket(new LoginDisconnectPacket(INVALID_VERSION_TEXT.toString()));
|
||||
connection.sendPacket(new LoginDisconnectPacket(MinecraftServer.getSerializationManager().serialize(INVALID_VERSION_TEXT)));
|
||||
connection.disconnect();
|
||||
}
|
||||
break;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.minestom.server.network.packet.client.login;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.PlayerSkin;
|
||||
import net.minestom.server.extras.velocity.VelocityProxy;
|
||||
@ -23,7 +23,7 @@ public class LoginPluginResponsePacket implements ClientPreplayPacket {
|
||||
|
||||
private final static ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager();
|
||||
|
||||
public static final ColoredText INVALID_PROXY_RESPONSE = ColoredText.of(ChatColor.RED, "Invalid proxy response!");
|
||||
public static final Component INVALID_PROXY_RESPONSE = Component.text("Invalid proxy response!", NamedTextColor.RED);
|
||||
|
||||
public int messageId;
|
||||
public boolean successful;
|
||||
@ -80,7 +80,7 @@ public class LoginPluginResponsePacket implements ClientPreplayPacket {
|
||||
Player player = CONNECTION_MANAGER.startPlayState(connection, uuid, username, true);
|
||||
player.setSkin(playerSkin);
|
||||
} else {
|
||||
LoginDisconnectPacket disconnectPacket = new LoginDisconnectPacket(INVALID_PROXY_RESPONSE);
|
||||
LoginDisconnectPacket disconnectPacket = new LoginDisconnectPacket(MinecraftServer.getSerializationManager().serialize(INVALID_PROXY_RESPONSE));
|
||||
nettyPlayerConnection.sendPacket(disconnectPacket);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.minestom.server.network.packet.client.login;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
@ -22,7 +24,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class LoginStartPacket implements ClientPreplayPacket {
|
||||
|
||||
private static final ColoredText ALREADY_CONNECTED_JSON = ColoredText.of(ChatColor.RED, "You are already on this server");
|
||||
private static final Component ALREADY_CONNECTED = Component.text("You are already on this server", NamedTextColor.RED);
|
||||
|
||||
public String username;
|
||||
|
||||
@ -72,7 +74,7 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
if (MojangAuth.isEnabled() && isNettyClient) {
|
||||
// Mojang auth
|
||||
if (CONNECTION_MANAGER.getPlayer(username) != null) {
|
||||
connection.sendPacket(new LoginDisconnectPacket(ALREADY_CONNECTED_JSON));
|
||||
connection.sendPacket(new LoginDisconnectPacket(MinecraftServer.getSerializationManager().serialize(ALREADY_CONNECTED)));
|
||||
connection.disconnect();
|
||||
return;
|
||||
}
|
||||
|
@ -14,6 +14,10 @@ public class LoginDisconnectPacket implements ServerPacket {
|
||||
this.kickMessage = kickMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #LoginDisconnectPacket(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public LoginDisconnectPacket(@NotNull JsonMessage jsonKickMessage) {
|
||||
this(jsonKickMessage.toString());
|
||||
}
|
||||
|
@ -84,8 +84,8 @@ public class AdvancementsPacket implements ServerPacket {
|
||||
}
|
||||
|
||||
public static class DisplayData implements Writeable {
|
||||
public JsonMessage title; // Only text
|
||||
public JsonMessage description; // Only text
|
||||
public String title; // Only text
|
||||
public String description; // Only text
|
||||
public ItemStack icon;
|
||||
public FrameType frameType;
|
||||
public int flags;
|
||||
@ -93,10 +93,19 @@ public class AdvancementsPacket implements ServerPacket {
|
||||
public float x;
|
||||
public float y;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #title}
|
||||
*/
|
||||
public @Deprecated JsonMessage titleJson; // Only text
|
||||
/**
|
||||
* @deprecated Use {@link #description}
|
||||
*/
|
||||
public @Deprecated JsonMessage descriptionJson; // Only text
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(title.toString());
|
||||
writer.writeSizedString(description.toString());
|
||||
writer.writeSizedString(titleJson != null ? titleJson.toString() : title);
|
||||
writer.writeSizedString(descriptionJson != null ? descriptionJson.toString() : description);
|
||||
writer.writeItemStack(icon);
|
||||
writer.writeVarInt(frameType.ordinal());
|
||||
writer.writeInt(flags);
|
||||
|
@ -15,12 +15,24 @@ public class BossBarPacket implements ServerPacket {
|
||||
public UUID uuid;
|
||||
public Action action;
|
||||
|
||||
public String title;
|
||||
public String title; // Only text
|
||||
public float health;
|
||||
public int color;
|
||||
public int division;
|
||||
public byte flags;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #title}
|
||||
*/
|
||||
public @Deprecated JsonMessage titleJson;
|
||||
/**
|
||||
* @deprecated Use {@link #color}
|
||||
*/
|
||||
public @Deprecated BarColor colorOld;
|
||||
/**
|
||||
* @deprecated Use {@link #division}
|
||||
*/
|
||||
public @Deprecated BarDivision divisionOld;
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
@ -29,10 +41,10 @@ public class BossBarPacket implements ServerPacket {
|
||||
|
||||
switch (action) {
|
||||
case ADD:
|
||||
writer.writeSizedString(title);
|
||||
writer.writeSizedString(titleJson != null ? titleJson.toString() : title);
|
||||
writer.writeFloat(health);
|
||||
writer.writeVarInt(color);
|
||||
writer.writeVarInt(division);
|
||||
writer.writeVarInt(colorOld != null ? colorOld.ordinal() : color);
|
||||
writer.writeVarInt(divisionOld != null ? divisionOld.ordinal() : division);
|
||||
writer.writeByte(flags);
|
||||
break;
|
||||
case REMOVE:
|
||||
@ -42,11 +54,11 @@ public class BossBarPacket implements ServerPacket {
|
||||
writer.writeFloat(health);
|
||||
break;
|
||||
case UPDATE_TITLE:
|
||||
writer.writeSizedString(title);
|
||||
writer.writeSizedString(titleJson != null ? titleJson.toString() : title);
|
||||
break;
|
||||
case UPDATE_STYLE:
|
||||
writer.writeVarInt(color);
|
||||
writer.writeVarInt(division);
|
||||
writer.writeVarInt(colorOld != null ? colorOld.ordinal() : color);
|
||||
writer.writeVarInt(divisionOld != null ? divisionOld.ordinal() : division);
|
||||
break;
|
||||
case UPDATE_FLAGS:
|
||||
writer.writeByte(flags);
|
||||
|
@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.MessageType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
@ -19,10 +20,19 @@ import java.util.UUID;
|
||||
public class ChatMessagePacket implements ServerPacket {
|
||||
private static final UUID NULL_UUID = new UUID(0, 0);
|
||||
|
||||
public String jsonMessage;
|
||||
public String message;
|
||||
public MessageType messageType;
|
||||
public UUID uuid;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #message}
|
||||
*/
|
||||
public @Deprecated JsonMessage jsonMessage;
|
||||
/**
|
||||
* @deprecated Use {@link #messageType}
|
||||
*/
|
||||
public @Deprecated Position position;
|
||||
|
||||
@Deprecated
|
||||
public ChatMessagePacket(String jsonMessage, Position position, UUID uuid) {
|
||||
this(jsonMessage, position.asMessageType(), uuid);
|
||||
@ -49,20 +59,20 @@ public class ChatMessagePacket implements ServerPacket {
|
||||
* Constructs a new chat message packet. To send formatted messages please use the
|
||||
* respective {@link Audience#sendMessage(Component)} functions.
|
||||
*
|
||||
* @param jsonMessage the raw message payload
|
||||
* @param message the raw message payload
|
||||
* @param messageType the message type
|
||||
* @param uuid the sender of the chat message
|
||||
*/
|
||||
public ChatMessagePacket(String jsonMessage, MessageType messageType, UUID uuid) {
|
||||
this.jsonMessage = jsonMessage;
|
||||
public ChatMessagePacket(String message, MessageType messageType, UUID uuid) {
|
||||
this.message = message;
|
||||
this.messageType = messageType;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(jsonMessage);
|
||||
writer.writeByte((byte) (messageType == null ? 3 : messageType.ordinal()));
|
||||
writer.writeSizedString(jsonMessage != null ? jsonMessage.toString() : message);
|
||||
writer.writeByte((byte) (position != null ? position.ordinal() : messageType == null ? 3 : messageType.ordinal()));
|
||||
writer.writeUuid(uuid);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class CombatEventPacket implements ServerPacket {
|
||||
private int duration;
|
||||
private int opponent;
|
||||
private int playerID;
|
||||
private JsonMessage deathMessage; // Only text
|
||||
private String deathMessage;
|
||||
|
||||
private CombatEventPacket() {
|
||||
}
|
||||
@ -39,7 +39,15 @@ public class CombatEventPacket implements ServerPacket {
|
||||
return packet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #death(Player, Entity, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static CombatEventPacket death(Player player, Entity killer, JsonMessage message) {
|
||||
return death(player, killer, message.toString());
|
||||
}
|
||||
|
||||
public static CombatEventPacket death(Player player, Entity killer, String message) {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
packet.type = EventType.DEATH;
|
||||
packet.playerID = player.getEntityId();
|
||||
@ -64,7 +72,7 @@ public class CombatEventPacket implements ServerPacket {
|
||||
case DEATH:
|
||||
writer.writeVarInt(playerID);
|
||||
writer.writeInt(opponent);
|
||||
writer.writeSizedString(deathMessage.toString());
|
||||
writer.writeSizedString(deathMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class DisconnectPacket implements ServerPacket {
|
||||
public String message;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #message}
|
||||
*/
|
||||
@Deprecated public JsonMessage messageJson;
|
||||
|
||||
/**
|
||||
* Creates a new disconnect packet with a given string.
|
||||
* @param message the message
|
||||
@ -27,7 +32,7 @@ public class DisconnectPacket implements ServerPacket {
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(message);
|
||||
writer.writeSizedString(messageJson != null ? messageJson.toString() : message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.sound.SoundCategory;
|
||||
@ -9,15 +10,20 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class EntitySoundEffectPacket implements ServerPacket {
|
||||
|
||||
public int soundId;
|
||||
public SoundCategory soundCategory;
|
||||
public Sound.Source soundSource;
|
||||
public int entityId;
|
||||
public float volume;
|
||||
public float pitch;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #soundSource}
|
||||
*/
|
||||
@Deprecated public SoundCategory soundCategory;
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(soundId);
|
||||
writer.writeVarInt(soundCategory.ordinal());
|
||||
writer.writeVarInt(soundCategory != null ? soundCategory.ordinal() : soundSource.ordinal());
|
||||
writer.writeVarInt(entityId);
|
||||
writer.writeFloat(volume);
|
||||
writer.writeFloat(pitch);
|
||||
|
@ -63,7 +63,13 @@ public class MapDataPacket implements ServerPacket {
|
||||
public int type;
|
||||
public byte x, z;
|
||||
public byte direction;
|
||||
public JsonMessage displayName; // Only text
|
||||
public String displayName;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #displayName}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage displayNameJson; // Only text
|
||||
|
||||
private void write(BinaryWriter writer) {
|
||||
writer.writeVarInt(type);
|
||||
@ -71,10 +77,10 @@ public class MapDataPacket implements ServerPacket {
|
||||
writer.writeByte(z);
|
||||
writer.writeByte(direction);
|
||||
|
||||
final boolean hasDisplayName = displayName != null;
|
||||
final boolean hasDisplayName = displayName != null || displayNameJson != null;
|
||||
writer.writeBoolean(hasDisplayName);
|
||||
if (hasDisplayName) {
|
||||
writer.writeSizedString(displayName.toString());
|
||||
writer.writeSizedString(displayNameJson != null ? displayNameJson.toString() : displayName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,15 @@ public class NamedSoundEffectPacket implements ServerPacket {
|
||||
public float volume;
|
||||
public float pitch;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #soundCategory}
|
||||
*/
|
||||
@Deprecated public SoundCategory soundCategoryOld;
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(soundName);
|
||||
writer.writeVarInt(soundCategory);
|
||||
writer.writeVarInt(soundCategoryOld != null ? soundCategoryOld.ordinal() : soundCategory);
|
||||
writer.writeInt(x * 8);
|
||||
writer.writeInt(y * 8);
|
||||
writer.writeInt(z * 8);
|
||||
|
@ -75,7 +75,12 @@ public class PlayerInfoPacket implements ServerPacket {
|
||||
public List<Property> properties;
|
||||
public GameMode gameMode;
|
||||
public int ping;
|
||||
public JsonMessage displayName; // Only text
|
||||
public String displayName;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #displayName}
|
||||
*/
|
||||
@Deprecated public JsonMessage displayNameJson; // Only text
|
||||
|
||||
public AddPlayer(UUID uuid, String name, GameMode gameMode, int ping) {
|
||||
super(uuid);
|
||||
@ -95,10 +100,10 @@ public class PlayerInfoPacket implements ServerPacket {
|
||||
writer.writeVarInt(gameMode.getId());
|
||||
writer.writeVarInt(ping);
|
||||
|
||||
final boolean hasDisplayName = displayName != null;
|
||||
final boolean hasDisplayName = displayName != null || displayNameJson != null;
|
||||
writer.writeBoolean(hasDisplayName);
|
||||
if (hasDisplayName)
|
||||
writer.writeSizedString(displayName.toString());
|
||||
writer.writeSizedString(displayNameJson != null ? displayNameJson.toString() : displayName);
|
||||
}
|
||||
|
||||
public static class Property {
|
||||
@ -161,9 +166,22 @@ public class PlayerInfoPacket implements ServerPacket {
|
||||
|
||||
public static class UpdateDisplayName extends PlayerInfo {
|
||||
|
||||
public JsonMessage displayName; // Only text
|
||||
public String displayName;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #displayName}
|
||||
*/
|
||||
@Deprecated public JsonMessage displayNameJson; // Only text
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #UpdateDisplayName(UUID, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public UpdateDisplayName(UUID uuid, JsonMessage displayName) {
|
||||
this(uuid, displayName.toString());
|
||||
}
|
||||
|
||||
public UpdateDisplayName(UUID uuid, String displayName) {
|
||||
super(uuid);
|
||||
this.displayName = displayName;
|
||||
}
|
||||
@ -173,7 +191,7 @@ public class PlayerInfoPacket implements ServerPacket {
|
||||
final boolean hasDisplayName = displayName != null;
|
||||
writer.writeBoolean(hasDisplayName);
|
||||
if (hasDisplayName)
|
||||
writer.writeSizedString(displayName.toString());
|
||||
writer.writeSizedString(displayNameJson != null ? displayNameJson.toString() : displayName);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package net.minestom.server.network.packet.server.play;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
@ -16,10 +17,20 @@ public class PlayerListHeaderAndFooterPacket implements ServerPacket {
|
||||
public String header;
|
||||
public String footer;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #header}
|
||||
*/
|
||||
@Deprecated public JsonMessage headerJson;
|
||||
|
||||
/**
|
||||
@deprecated Use {@link #footer}
|
||||
*/
|
||||
@Deprecated public JsonMessage footerJson;
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(Objects.requireNonNullElse(header, EMPTY_COMPONENT));
|
||||
writer.writeSizedString(Objects.requireNonNullElse(footer, EMPTY_COMPONENT));
|
||||
writer.writeSizedString(headerJson != null ? headerJson.toString() : Objects.requireNonNullElse(header, EMPTY_COMPONENT));
|
||||
writer.writeSizedString(footerJson != null ? footerJson.toString() : Objects.requireNonNullElse(footer, EMPTY_COMPONENT));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,19 +21,25 @@ public class ScoreboardObjectivePacket implements ServerPacket {
|
||||
/**
|
||||
* The text to be displayed for the score
|
||||
*/
|
||||
public JsonMessage objectiveValue; // Only text
|
||||
public String objectiveValue; // Only text
|
||||
/**
|
||||
* The type how the score is displayed
|
||||
*/
|
||||
public Type type;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #objectiveValue}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage objectiveValueJson;
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(objectiveName);
|
||||
writer.writeByte(mode);
|
||||
|
||||
if (mode == 0 || mode == 2) {
|
||||
writer.writeSizedString(objectiveValue.toString());
|
||||
writer.writeSizedString(objectiveValueJson != null ? objectiveValueJson.toString() : objectiveValue);
|
||||
writer.writeVarInt(type.ordinal());
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,11 @@ public class SoundEffectPacket implements ServerPacket {
|
||||
public float volume;
|
||||
public float pitch;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #soundCategory}
|
||||
*/
|
||||
@Deprecated public SoundCategory soundCategoryOld;
|
||||
|
||||
/**
|
||||
* @deprecated Use variables
|
||||
*/
|
||||
@ -37,7 +42,7 @@ public class SoundEffectPacket implements ServerPacket {
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(soundId);
|
||||
writer.writeVarInt(soundCategory);
|
||||
writer.writeVarInt(soundCategoryOld != null ? soundCategoryOld.ordinal() : soundCategory);
|
||||
writer.writeInt(x * 8);
|
||||
writer.writeInt(y * 8);
|
||||
writer.writeInt(z * 8);
|
||||
|
@ -24,7 +24,7 @@ public class TabCompletePacket implements ServerPacket {
|
||||
writer.writeSizedString(match.match);
|
||||
writer.writeBoolean(match.hasTooltip);
|
||||
if (match.hasTooltip)
|
||||
writer.writeSizedString(match.tooltip.toString());
|
||||
writer.writeSizedString(match.tooltipJson != null ? match.tooltipJson.toString() : match.tooltip);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,7 +36,12 @@ public class TabCompletePacket implements ServerPacket {
|
||||
public static class Match {
|
||||
public String match;
|
||||
public boolean hasTooltip;
|
||||
public JsonMessage tooltip; // Only text
|
||||
public String tooltip;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #tooltip}
|
||||
*/
|
||||
@Deprecated public String tooltipJson;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class TeamsPacket implements ServerPacket {
|
||||
/**
|
||||
* The display name for the team
|
||||
*/
|
||||
public JsonMessage teamDisplayName;
|
||||
public String teamDisplayName;
|
||||
/**
|
||||
* The friendly flags to
|
||||
*/
|
||||
@ -43,16 +43,29 @@ public class TeamsPacket implements ServerPacket {
|
||||
/**
|
||||
* The prefix of the team
|
||||
*/
|
||||
public JsonMessage teamPrefix;
|
||||
public String teamPrefix;
|
||||
/**
|
||||
* The suffix of the team
|
||||
*/
|
||||
public JsonMessage teamSuffix;
|
||||
public String teamSuffix;
|
||||
/**
|
||||
* An array with all entities in the team
|
||||
*/
|
||||
public String[] entities;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #teamDisplayName}
|
||||
*/
|
||||
@Deprecated public JsonMessage teamDisplayNameJson;
|
||||
/**
|
||||
@deprecated Use {@link #teamPrefix}
|
||||
*/
|
||||
@Deprecated public JsonMessage teamPrefixJson;
|
||||
/**
|
||||
@deprecated Use {@link #teamSuffix}
|
||||
*/
|
||||
@Deprecated public JsonMessage teamSuffixJson;
|
||||
|
||||
/**
|
||||
* Writes data into the {@link BinaryWriter}
|
||||
*
|
||||
@ -66,13 +79,13 @@ public class TeamsPacket implements ServerPacket {
|
||||
switch (action) {
|
||||
case CREATE_TEAM:
|
||||
case UPDATE_TEAM_INFO:
|
||||
writer.writeSizedString(this.teamDisplayName.toString());
|
||||
writer.writeSizedString(this.teamDisplayNameJson != null ? this.teamDisplayNameJson.toString() : this.teamDisplayName);
|
||||
writer.writeByte(this.friendlyFlags);
|
||||
writer.writeSizedString(this.nameTagVisibility.getIdentifier());
|
||||
writer.writeSizedString(this.collisionRule.getIdentifier());
|
||||
writer.writeVarInt(this.teamColor);
|
||||
writer.writeSizedString(this.teamPrefix.toString());
|
||||
writer.writeSizedString(this.teamSuffix.toString());
|
||||
writer.writeSizedString(this.teamPrefixJson != null ? this.teamPrefixJson.toString() : this.teamPrefix);
|
||||
writer.writeSizedString(this.teamSuffixJson != null ? this.teamSuffixJson.toString() : this.teamSuffix);
|
||||
break;
|
||||
case REMOVE_TEAM:
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.minestom.server.network.player;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.listener.manager.PacketListenerManager;
|
||||
import net.minestom.server.listener.manager.ServerPacketConsumer;
|
||||
@ -29,7 +29,7 @@ public abstract class PlayerConnection {
|
||||
private boolean online;
|
||||
|
||||
// Text used to kick client sending too many packets
|
||||
private static final ColoredText rateLimitKickMessage = ColoredText.of(ChatColor.RED + "Too Many Packets");
|
||||
private static final Component rateLimitKickMessage = Component.text("Too Many Packets", NamedTextColor.RED);
|
||||
|
||||
//Connection Stats
|
||||
private final AtomicInteger packetCounter = new AtomicInteger(0);
|
||||
|
Loading…
Reference in New Issue
Block a user