Allow for JsonMessage in packets

This commit is contained in:
themode 2020-10-24 23:28:43 +02:00
parent 26e8dae452
commit df28d25685
13 changed files with 36 additions and 29 deletions

View File

@ -2,6 +2,7 @@ package net.minestom.server.chat;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
@ -120,6 +121,7 @@ public class ColoredText extends JsonMessage {
*
* @return the Json representation of the text
*/
@NotNull
@Override
public JsonObject getJsonObject() {
final List<JsonObject> components = getComponents();

View File

@ -1,6 +1,7 @@
package net.minestom.server.chat;
import com.google.gson.JsonObject;
import org.jetbrains.annotations.NotNull;
/**
* Represents a json message which can be send to a player.
@ -24,6 +25,7 @@ public abstract class JsonMessage {
* @return the json representation of the message
* @see #toString()
*/
@NotNull
public abstract JsonObject getJsonObject();
/**
@ -43,6 +45,7 @@ public abstract class JsonMessage {
* @see #getJsonObject()
* @see #refreshUpdate()
*/
@NotNull
@Override
public String toString() {
if (!updated) {

View File

@ -3,6 +3,7 @@ package net.minestom.server.chat;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minestom.server.utils.validate.Check;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@ -115,6 +116,7 @@ public class RichMessage extends JsonMessage {
return append(coloredText, FormatRetention.ALL);
}
@NotNull
@Override
public JsonObject getJsonObject() {
List<RichComponent> cacheComponents = new ArrayList<>(components);

View File

@ -1,7 +1,7 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.advancements.FrameType;
import net.minestom.server.chat.ColoredText;
import net.minestom.server.chat.JsonMessage;
import net.minestom.server.item.ItemStack;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
@ -80,8 +80,8 @@ public class AdvancementsPacket implements ServerPacket {
}
public static class DisplayData {
public ColoredText title;
public ColoredText description;
public JsonMessage title; // Only text
public JsonMessage description; // Only text
public ItemStack icon;
public FrameType frameType;
public int flags;

View File

@ -2,7 +2,7 @@ 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.ColoredText;
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;
@ -14,7 +14,7 @@ public class BossBarPacket implements ServerPacket {
public UUID uuid;
public Action action;
public ColoredText title;
public JsonMessage title; // Only text
public float health;
public BarColor color;
public BarDivision division;

View File

@ -1,6 +1,6 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.chat.ColoredText;
import net.minestom.server.chat.JsonMessage;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.Player;
import net.minestom.server.network.packet.server.ServerPacket;
@ -19,7 +19,7 @@ public class CombatEventPacket implements ServerPacket {
private int duration;
private int opponent;
private int playerID;
private ColoredText deathMessage;
private JsonMessage deathMessage; // Only text
private CombatEventPacket() {
}
@ -38,7 +38,7 @@ public class CombatEventPacket implements ServerPacket {
return packet;
}
public static CombatEventPacket death(Player player, Optional<Entity> killer, ColoredText message) {
public static CombatEventPacket death(Player player, Optional<Entity> killer, JsonMessage message) {
CombatEventPacket packet = new CombatEventPacket();
packet.type = EventType.DEATH;
packet.playerID = player.getEntityId();

View File

@ -1,13 +1,13 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.chat.ColoredText;
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;
public class DisconnectPacket implements ServerPacket {
public ColoredText message;
public JsonMessage message; // Only text
@Override
public void write(BinaryWriter writer) {

View File

@ -1,6 +1,6 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.chat.ColoredText;
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;
@ -36,12 +36,12 @@ public class MapDataPacket implements ServerPacket {
writer.writeVarInt(0);
}
writer.writeByte((byte)columns);
writer.writeByte((byte) columns);
if (columns <= 0) {
return;
}
writer.writeByte((byte)rows);
writer.writeByte((byte) rows);
writer.writeByte(x);
writer.writeByte(z);
if (data != null && data.length > 0) {
@ -62,7 +62,7 @@ public class MapDataPacket implements ServerPacket {
public int type;
public byte x, z;
public byte direction;
public ColoredText displayName;
public JsonMessage displayName; // Only text
private void write(BinaryWriter writer) {
writer.writeVarInt(type);

View File

@ -1,6 +1,6 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.chat.ColoredText;
import net.minestom.server.chat.JsonMessage;
import net.minestom.server.entity.GameMode;
import net.minestom.server.network.packet.server.ServerPacket;
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
@ -74,7 +74,7 @@ public class PlayerInfoPacket implements ServerPacket {
public ArrayList<Property> properties;
public GameMode gameMode;
public int ping;
public ColoredText displayName;
public JsonMessage displayName; // Only text
public AddPlayer(UUID uuid, String name, GameMode gameMode, int ping) {
super(uuid);
@ -160,9 +160,9 @@ public class PlayerInfoPacket implements ServerPacket {
public static class UpdateDisplayName extends PlayerInfo {
public ColoredText displayName;
public JsonMessage displayName; // Only text
public UpdateDisplayName(UUID uuid, ColoredText displayName) {
public UpdateDisplayName(UUID uuid, JsonMessage displayName) {
super(uuid);
this.displayName = displayName;
}

View File

@ -1,6 +1,6 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.chat.ColoredText;
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;
@ -12,8 +12,8 @@ public class PlayerListHeaderAndFooterPacket implements ServerPacket {
public boolean emptyHeader;
public boolean emptyFooter;
public ColoredText header;
public ColoredText footer;
public JsonMessage header; // Only text
public JsonMessage footer; // Only text
@Override

View File

@ -1,6 +1,6 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.chat.ColoredText;
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;
@ -20,7 +20,7 @@ public class ScoreboardObjectivePacket implements ServerPacket {
/**
* The text to be displayed for the score
*/
public ColoredText objectiveValue;
public JsonMessage objectiveValue; // Only text
/**
* The type how the score is displayed
*/

View File

@ -1,6 +1,6 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.chat.ColoredText;
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;
@ -35,7 +35,7 @@ public class TabCompletePacket implements ServerPacket {
public static class Match {
public String match;
public boolean hasTooltip;
public ColoredText tooltip;
public JsonMessage tooltip; // Only text
}
}

View File

@ -1,6 +1,6 @@
package net.minestom.server.network.packet.server.play;
import net.minestom.server.chat.ColoredText;
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;
@ -9,11 +9,11 @@ public class TitlePacket implements ServerPacket {
public Action action;
public ColoredText titleText;
public JsonMessage titleText; // Only text
public ColoredText subtitleText;
public JsonMessage subtitleText; // Only text
public ColoredText actionBarText;
public JsonMessage actionBarText; // Only text
public int fadeIn;
public int stay;