mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 21:17:53 +01:00
Remove longly deprecated chat package
This commit is contained in:
parent
2cc92e5e3e
commit
5285665939
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.advancements;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
@ -43,26 +42,6 @@ public class Advancement {
|
||||
// Packet
|
||||
private AdvancementsPacket.Criteria criteria;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #Advancement(Component, Component, ItemStack, FrameType, float, float)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Advancement(@NotNull JsonMessage title, JsonMessage description,
|
||||
@NotNull ItemStack icon, @NotNull FrameType frameType,
|
||||
float x, float y) {
|
||||
this(title.asComponent(), description.asComponent(), icon, frameType, x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #Advancement(Component, Component, Material, FrameType, float, float)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Advancement(@NotNull JsonMessage title, @NotNull JsonMessage description,
|
||||
@NotNull Material icon, @NotNull FrameType frameType,
|
||||
float x, float y) {
|
||||
this(title, description, ItemStack.of(icon), frameType, x, y);
|
||||
}
|
||||
|
||||
public Advancement(@NotNull Component title, Component description,
|
||||
@NotNull ItemStack icon, @NotNull FrameType frameType,
|
||||
float x, float y) {
|
||||
@ -106,8 +85,7 @@ public class Advancement {
|
||||
*
|
||||
* @return the {@link AdvancementTab} linked to this advancement, null if not linked to anything yet
|
||||
*/
|
||||
@Nullable
|
||||
public AdvancementTab getTab() {
|
||||
public @Nullable AdvancementTab getTab() {
|
||||
return tab;
|
||||
}
|
||||
|
||||
@ -124,18 +102,6 @@ public class Advancement {
|
||||
return title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title of the advancement.
|
||||
*
|
||||
* @return the advancement title
|
||||
* @deprecated Use {@link #getTitle()}
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public JsonMessage getTitleJson() {
|
||||
return JsonMessage.fromComponent(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the advancement title.
|
||||
*
|
||||
@ -146,40 +112,15 @@ public class Advancement {
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the advancement title.
|
||||
*
|
||||
* @param title the new title
|
||||
* @deprecated Use {@link #setTitle(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setTitle(@NotNull JsonMessage title) {
|
||||
this.title = title.asComponent();
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the description of the advancement.
|
||||
*
|
||||
* @return the description title
|
||||
*/
|
||||
@NotNull
|
||||
public Component getDescription() {
|
||||
public @NotNull Component getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the description of the advancement.
|
||||
*
|
||||
* @return the description title
|
||||
* @deprecated Use {@link #getDescription()}
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public JsonMessage getDescriptionJson() {
|
||||
return JsonMessage.fromComponent(description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the description title.
|
||||
*
|
||||
@ -190,25 +131,12 @@ public class Advancement {
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the description title.
|
||||
*
|
||||
* @param description the new description
|
||||
* @deprecated Use {@link #setDescription(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDescription(@NotNull JsonMessage description) {
|
||||
this.description = description.asComponent();
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the advancement icon.
|
||||
*
|
||||
* @return the advancement icon
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getIcon() {
|
||||
public @NotNull ItemStack getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.advancements;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -14,31 +13,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
* The difference between this and an {@link Advancement} is that the root is responsible for the tab background.
|
||||
*/
|
||||
public class AdvancementRoot extends Advancement {
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #AdvancementRoot(Component, Component, ItemStack, FrameType, float, float, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public AdvancementRoot(@NotNull JsonMessage title, @NotNull JsonMessage description,
|
||||
@NotNull ItemStack icon, @NotNull FrameType frameType,
|
||||
float x, float y,
|
||||
@Nullable String background) {
|
||||
super(title, description, icon, frameType, x, y);
|
||||
setBackground(background);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #AdvancementRoot(Component, Component, Material, FrameType, float, float, String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public AdvancementRoot(@NotNull JsonMessage title, @NotNull JsonMessage description,
|
||||
@NotNull Material icon, FrameType frameType,
|
||||
float x, float y,
|
||||
@Nullable String background) {
|
||||
super(title, description, icon, frameType, x, y);
|
||||
setBackground(background);
|
||||
}
|
||||
|
||||
public AdvancementRoot(@NotNull Component title, @NotNull Component description,
|
||||
@NotNull ItemStack icon, @NotNull FrameType frameType,
|
||||
float x, float y,
|
||||
@ -54,5 +28,4 @@ public class AdvancementRoot extends Advancement {
|
||||
super(title, description, icon, frameType, x, y);
|
||||
setBackground(background);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package net.minestom.server.advancements.notifications;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.advancements.FrameType;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -16,42 +15,14 @@ public class Notification {
|
||||
private final FrameType frameType;
|
||||
private final ItemStack icon;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #Notification(Component, FrameType, ItemStack)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Notification(@NotNull JsonMessage title, @NotNull FrameType frameType, @NotNull ItemStack icon) {
|
||||
this(title.asComponent(), frameType, icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #Notification(Component, FrameType, Material)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Notification(@NotNull JsonMessage title, @NotNull FrameType frameType, @NotNull Material icon) {
|
||||
this(title.asComponent(), frameType, icon);
|
||||
}
|
||||
|
||||
public Notification(@NotNull Component title, @NotNull FrameType frameType, @NotNull Material icon) {
|
||||
this(title, frameType, ItemStack.of(icon));
|
||||
}
|
||||
|
||||
public Notification(@NotNull Component title, @NotNull FrameType frameType, @NotNull ItemStack icon) {
|
||||
this.title = title;
|
||||
this.frameType = frameType;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the title of the notification.
|
||||
*
|
||||
* @return the notification title
|
||||
* @deprecated Use {@link #getTitle()}
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public JsonMessage getTitleJson() {
|
||||
return JsonMessage.fromComponent(title);
|
||||
public Notification(@NotNull Component title, @NotNull FrameType frameType, @NotNull Material icon) {
|
||||
this(title, frameType, ItemStack.of(icon));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,8 +39,7 @@ public class Notification {
|
||||
*
|
||||
* @return the notification frame type
|
||||
*/
|
||||
@NotNull
|
||||
public FrameType getFrameType() {
|
||||
public @NotNull FrameType getFrameType() {
|
||||
return frameType;
|
||||
}
|
||||
|
||||
@ -78,8 +48,7 @@ public class Notification {
|
||||
*
|
||||
* @return the notification icon
|
||||
*/
|
||||
@NotNull
|
||||
protected ItemStack getIcon() {
|
||||
protected @NotNull ItemStack getIcon() {
|
||||
return icon;
|
||||
}
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a click event for a specific portion of the message.
|
||||
* @deprecated Use {@link ClickEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ChatClickEvent {
|
||||
|
||||
private final String action;
|
||||
private final String value;
|
||||
|
||||
private ChatClickEvent(@NotNull String action, @NotNull String value) {
|
||||
this.action = action;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an URL when clicked.
|
||||
*
|
||||
* @param url the URL to open
|
||||
* @return the chat click event
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatClickEvent openUrl(@NotNull String url) {
|
||||
return new ChatClickEvent("open_url", url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a command when clicked.
|
||||
*
|
||||
* @param command the command to run
|
||||
* @return the chat click event
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatClickEvent runCommand(@NotNull String command) {
|
||||
return new ChatClickEvent("run_command", command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a string in the player's chat when clicked.
|
||||
*
|
||||
* @param command the command to suggest
|
||||
* @return the chat click event
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatClickEvent suggestCommand(@NotNull String command) {
|
||||
return new ChatClickEvent("suggest_command", command);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ChatClickEvent copyToClipboard(@NotNull String text) {
|
||||
return new ChatClickEvent("copy_to_clipboard", text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
@ -1,340 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import it.unimi.dsi.fastutil.chars.Char2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.kyori.adventure.text.format.*;
|
||||
import net.minestom.server.color.Color;
|
||||
import net.minestom.server.color.DyeColor;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a color in a text. You can either use one of the pre-made colors
|
||||
* or make your own using RGB. {@link ChatColor#fromRGB(byte, byte, byte)}.
|
||||
* <p>
|
||||
* Immutable class.
|
||||
* @deprecated For chat colors, use {@link TextColor} or {@link NamedTextColor}. For styles, use {@link TextDecoration}.
|
||||
* For colors in other contexts, see {@link Color} or {@link DyeColor}.
|
||||
*/
|
||||
@Deprecated
|
||||
public final class ChatColor implements StyleBuilderApplicable {
|
||||
|
||||
// Special
|
||||
public static final ChatColor NO_COLOR = new ChatColor();
|
||||
public static final ChatColor RESET = new ChatColor("reset");
|
||||
public static final ChatColor BOLD = new ChatColor("bold");
|
||||
public static final ChatColor ITALIC = new ChatColor("italic");
|
||||
public static final ChatColor UNDERLINED = new ChatColor("underlined");
|
||||
public static final ChatColor STRIKETHROUGH = new ChatColor("strikethrough");
|
||||
public static final ChatColor OBFUSCATED = new ChatColor("obfuscated");
|
||||
|
||||
// Color
|
||||
public static final ChatColor BLACK = fromRGB((byte) 0, (byte) 0, (byte) 0, 0, "black");
|
||||
public static final ChatColor DARK_BLUE = fromRGB((byte) 0, (byte) 0, (byte) 170, 1, "dark_blue");
|
||||
public static final ChatColor DARK_GREEN = fromRGB((byte) 0, (byte) 170, (byte) 0, 2, "dark_green");
|
||||
public static final ChatColor DARK_CYAN = fromRGB((byte) 0, (byte) 170, (byte) 170, 3, "dark_aqua");
|
||||
public static final ChatColor DARK_RED = fromRGB((byte) 170, (byte) 0, (byte) 0, 4, "dark_red");
|
||||
public static final ChatColor PURPLE = fromRGB((byte) 170, (byte) 0, (byte) 170, 5, "dark_purple");
|
||||
public static final ChatColor GOLD = fromRGB((byte) 255, (byte) 170, (byte) 0, 6, "gold");
|
||||
public static final ChatColor GRAY = fromRGB((byte) 170, (byte) 170, (byte) 170, 7, "gray");
|
||||
public static final ChatColor DARK_GRAY = fromRGB((byte) 85, (byte) 85, (byte) 85, 8, "dark_gray");
|
||||
public static final ChatColor BLUE = fromRGB((byte) 85, (byte) 85, (byte) 255, 9, "blue");
|
||||
public static final ChatColor BRIGHT_GREEN = fromRGB((byte) 85, (byte) 255, (byte) 85, 10, "green");
|
||||
public static final ChatColor CYAN = fromRGB((byte) 85, (byte) 255, (byte) 255, 11, "aqua");
|
||||
public static final ChatColor RED = fromRGB((byte) 255, (byte) 85, (byte) 85, 12, "red");
|
||||
public static final ChatColor PINK = fromRGB((byte) 255, (byte) 85, (byte) 255, 13, "light_purple");
|
||||
public static final ChatColor YELLOW = fromRGB((byte) 255, (byte) 255, (byte) 85, 14, "yellow");
|
||||
public static final ChatColor WHITE = fromRGB((byte) 255, (byte) 255, (byte) 255, 15, "white");
|
||||
|
||||
private static final Int2ObjectMap<ChatColor> idColorMap = new Int2ObjectOpenHashMap<>();
|
||||
private static final Map<String, ChatColor> colorCode = new HashMap<>();
|
||||
private static final Char2ObjectMap<ChatColor> legacyColorCodesMap = new Char2ObjectOpenHashMap<>();
|
||||
|
||||
static {
|
||||
idColorMap.put(0, BLACK);
|
||||
idColorMap.put(1, DARK_BLUE);
|
||||
idColorMap.put(2, DARK_GREEN);
|
||||
idColorMap.put(3, DARK_CYAN);
|
||||
idColorMap.put(4, DARK_RED);
|
||||
idColorMap.put(5, PURPLE);
|
||||
idColorMap.put(6, GOLD);
|
||||
idColorMap.put(7, GRAY);
|
||||
idColorMap.put(8, DARK_GRAY);
|
||||
idColorMap.put(9, BLUE);
|
||||
idColorMap.put(10, BRIGHT_GREEN);
|
||||
idColorMap.put(11, CYAN);
|
||||
idColorMap.put(12, RED);
|
||||
idColorMap.put(13, PINK);
|
||||
idColorMap.put(14, YELLOW);
|
||||
idColorMap.put(15, WHITE);
|
||||
|
||||
colorCode.put("reset", RESET);
|
||||
colorCode.put("bold", BOLD);
|
||||
colorCode.put("italic", ITALIC);
|
||||
colorCode.put("underlined", UNDERLINED);
|
||||
colorCode.put("strikethrough", STRIKETHROUGH);
|
||||
colorCode.put("obfuscated", OBFUSCATED);
|
||||
|
||||
colorCode.put("black", BLACK);
|
||||
colorCode.put("dark_blue", DARK_BLUE);
|
||||
colorCode.put("dark_green", DARK_GREEN);
|
||||
colorCode.put("dark_aqua", DARK_CYAN);
|
||||
colorCode.put("dark_red", DARK_RED);
|
||||
colorCode.put("dark_purple", PURPLE);
|
||||
colorCode.put("gold", GOLD);
|
||||
colorCode.put("gray", GRAY);
|
||||
colorCode.put("dark_gray", DARK_GRAY);
|
||||
colorCode.put("blue", BLUE);
|
||||
colorCode.put("green", BRIGHT_GREEN);
|
||||
colorCode.put("aqua", CYAN);
|
||||
colorCode.put("red", RED);
|
||||
colorCode.put("light_purple", PINK);
|
||||
colorCode.put("yellow", YELLOW);
|
||||
colorCode.put("white", WHITE);
|
||||
|
||||
legacyColorCodesMap.put('k', OBFUSCATED);
|
||||
legacyColorCodesMap.put('l', BOLD);
|
||||
legacyColorCodesMap.put('m', STRIKETHROUGH);
|
||||
legacyColorCodesMap.put('n', UNDERLINED);
|
||||
legacyColorCodesMap.put('o', ITALIC);
|
||||
legacyColorCodesMap.put('r', RESET);
|
||||
|
||||
legacyColorCodesMap.put('0', BLACK);
|
||||
legacyColorCodesMap.put('1', DARK_BLUE);
|
||||
legacyColorCodesMap.put('2', DARK_GREEN);
|
||||
legacyColorCodesMap.put('3', DARK_CYAN);
|
||||
legacyColorCodesMap.put('4', DARK_RED);
|
||||
legacyColorCodesMap.put('5', PURPLE);
|
||||
legacyColorCodesMap.put('6', GOLD);
|
||||
legacyColorCodesMap.put('7', GRAY);
|
||||
legacyColorCodesMap.put('8', DARK_GRAY);
|
||||
legacyColorCodesMap.put('9', BLUE);
|
||||
legacyColorCodesMap.put('a', BRIGHT_GREEN);
|
||||
legacyColorCodesMap.put('b', CYAN);
|
||||
legacyColorCodesMap.put('c', RED);
|
||||
legacyColorCodesMap.put('d', PINK);
|
||||
legacyColorCodesMap.put('e', YELLOW);
|
||||
legacyColorCodesMap.put('f', WHITE);
|
||||
}
|
||||
|
||||
private boolean empty;
|
||||
private final byte red, green, blue;
|
||||
private final int id;
|
||||
|
||||
private final String codeName;
|
||||
|
||||
private final boolean special;
|
||||
|
||||
private ChatColor(byte r, byte g, byte b, int id, @Nullable String codeName, boolean special) {
|
||||
this.empty = false;
|
||||
this.red = r;
|
||||
this.green = g;
|
||||
this.blue = b;
|
||||
this.id = id;
|
||||
this.codeName = codeName;
|
||||
this.special = special;
|
||||
}
|
||||
|
||||
private ChatColor(byte r, byte g, byte b, int id, @Nullable String codeName) {
|
||||
this(r, g, b, id, codeName, false);
|
||||
}
|
||||
|
||||
private ChatColor(String codeName) {
|
||||
this((byte) 0, (byte) 0, (byte) 0, 0, codeName, true);
|
||||
}
|
||||
|
||||
private ChatColor() {
|
||||
this((byte) 0, (byte) 0, (byte) 0, 0, null, true);
|
||||
this.empty = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an RGB color.
|
||||
*
|
||||
* @param r the red component
|
||||
* @param g the green component
|
||||
* @param b the blue component
|
||||
* @return a chat color with the specified RGB color
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatColor fromRGB(byte r, byte g, byte b) {
|
||||
return fromRGB(r, g, b, -1, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ChatColor fromRGB(byte r, byte g, byte b, int id, String codeName) {
|
||||
return new ChatColor(r, g, b, id, codeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a color based on its name (eg: white, black, aqua, etc...).
|
||||
*
|
||||
* @param name the color name
|
||||
* @return the color associated with the name, {@link #NO_COLOR} if not found
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatColor fromName(@NotNull String name) {
|
||||
return colorCode.getOrDefault(name.toLowerCase(), NO_COLOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a color based on its numerical id (0;15).
|
||||
*
|
||||
* @param id the id of the color
|
||||
* @return the color associated with the id, {@link #NO_COLOR} if not found
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatColor fromId(int id) {
|
||||
return idColorMap.getOrDefault(id, NO_COLOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a color based on its legacy color code (eg: 1, 2, 3,... f).
|
||||
*
|
||||
* @param colorCode the color legacy code
|
||||
* @return the color associated with the code, {@link #NO_COLOR} if not found
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatColor fromLegacyColorCodes(char colorCode) {
|
||||
return legacyColorCodesMap.getOrDefault(colorCode, NO_COLOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a collection of all chat colors
|
||||
* @return a collection of all chat colors
|
||||
*/
|
||||
@NotNull
|
||||
public static Collection<ChatColor> values() {
|
||||
return colorCode.values();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return empty;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the red component of the color.
|
||||
*
|
||||
* @return the red component of the color
|
||||
*/
|
||||
public byte getRed() {
|
||||
return red;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the green component of the color.
|
||||
*
|
||||
* @return the green component of the color
|
||||
*/
|
||||
public byte getGreen() {
|
||||
return green;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the blue component of the color.
|
||||
*
|
||||
* @return the blue component of the color
|
||||
*/
|
||||
public byte getBlue() {
|
||||
return blue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the color is special (eg: no color, bold, reset, etc...).
|
||||
*
|
||||
* @return true if the color is special, false otherwise
|
||||
*/
|
||||
public boolean isSpecial() {
|
||||
return special;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the code name.
|
||||
*
|
||||
* @return the color code name, null if not any
|
||||
*/
|
||||
@Nullable
|
||||
public String getCodeName() {
|
||||
return codeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color id, only present if this color has been retrieved from {@link ChatColor} constants.
|
||||
* <p>
|
||||
* Should only be used for some special packets which require it.
|
||||
*
|
||||
* @return the color id
|
||||
* @throws IllegalStateException if the color is not from the class constants
|
||||
*/
|
||||
public int getId() {
|
||||
Check.stateCondition(id == -1, "Please use one of the ChatColor constant instead");
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Adventure text color from this chat color.
|
||||
* @return the text color
|
||||
*/
|
||||
public @NotNull TextColor asTextColor() {
|
||||
return TextColor.color(red, blue, green);
|
||||
}
|
||||
|
||||
public @NotNull Color asColor() {
|
||||
return new Color(red, green, blue);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
if (empty)
|
||||
return "";
|
||||
|
||||
final String header = "{#";
|
||||
final String footer = "}";
|
||||
|
||||
String code;
|
||||
|
||||
if (codeName != null) {
|
||||
// color or special code (white/red/reset/bold/etc...)
|
||||
code = codeName;
|
||||
} else {
|
||||
// RGB color (special code not set)
|
||||
final int color = (red & 0xFF) << 16 | (green & 0xFF) << 8 | blue & 0xFF;
|
||||
|
||||
code = Integer.toHexString(color);
|
||||
}
|
||||
|
||||
return header + code + footer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Contract(mutates = "param")
|
||||
public void styleApply(Style.@NotNull Builder style) {
|
||||
if (this.isEmpty()) {
|
||||
style.color(NamedTextColor.WHITE);
|
||||
} else if (Objects.equals(this.codeName, "reset")) {
|
||||
style.color(NamedTextColor.WHITE);
|
||||
|
||||
for (TextDecoration value : TextDecoration.NAMES.values()) {
|
||||
style.decoration(value, TextDecoration.State.FALSE);
|
||||
}
|
||||
} else if (this.isSpecial() && this.codeName != null) {
|
||||
TextDecoration decoration = TextDecoration.NAMES.value(this.codeName);
|
||||
|
||||
if (decoration != null) {
|
||||
style.decorate(decoration);
|
||||
}
|
||||
} else {
|
||||
style.color(TextColor.color(this.red, this.green, this.blue));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Represents a hover event for a specific portion of the message.
|
||||
*
|
||||
* @deprecated Use {@link HoverEvent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ChatHoverEvent {
|
||||
|
||||
private final String action;
|
||||
private final String value;
|
||||
private final JsonObject valueObject;
|
||||
private final boolean isJson;
|
||||
|
||||
private ChatHoverEvent(@NotNull String action, @NotNull String value) {
|
||||
this.action = action;
|
||||
this.value = value;
|
||||
this.valueObject = null;
|
||||
this.isJson = false;
|
||||
}
|
||||
|
||||
private ChatHoverEvent(@NotNull String action, @NotNull JsonObject valueObject) {
|
||||
this.action = action;
|
||||
this.value = null;
|
||||
this.valueObject = valueObject;
|
||||
this.isJson = true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JsonObject getValueObject() {
|
||||
return valueObject;
|
||||
}
|
||||
|
||||
protected boolean isJson() {
|
||||
return isJson;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a {@link JsonMessage} when hovered.
|
||||
*
|
||||
* @param text the text to show
|
||||
* @return the chat hover event
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatHoverEvent showText(@NotNull JsonMessage text) {
|
||||
return new ChatHoverEvent("show_text", text.getJsonObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a raw text when hovered.
|
||||
*
|
||||
* @param text the text to show
|
||||
* @return the chat hover event
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatHoverEvent showText(@NotNull String text) {
|
||||
return new ChatHoverEvent("show_text", text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows an item when hovered.
|
||||
*
|
||||
* @param itemStack the item to show
|
||||
* @return the chat hover event
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatHoverEvent showItem(@NotNull ItemStack itemStack) {
|
||||
HoverEvent<HoverEvent.ShowItem> event = HoverEvent.showItem(itemStack.getMaterial().key(), itemStack.getAmount());
|
||||
JsonObject obj = GsonComponentSerializer.gson().serializer().toJsonTree(Component.empty().hoverEvent(event)).getAsJsonObject();
|
||||
obj = obj.get("hoverEvent").getAsJsonObject().get("contents").getAsJsonObject();
|
||||
|
||||
final String snbt = itemStack.getMeta().toSNBT();
|
||||
obj.add("tag", new JsonPrimitive(snbt));
|
||||
|
||||
return new ChatHoverEvent("show_item", obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows an entity when hovered.
|
||||
*
|
||||
* @param entity the entity to show
|
||||
* @return the chat hover event
|
||||
*/
|
||||
@NotNull
|
||||
public static ChatHoverEvent showEntity(@NotNull Entity entity) {
|
||||
HoverEvent<HoverEvent.ShowEntity> event = HoverEvent.showEntity(entity.getEntityType().key(), entity.getUuid());
|
||||
JsonObject obj = GsonComponentSerializer.gson().serializer().toJsonTree(Component.empty().hoverEvent(event)).getAsJsonObject();
|
||||
return new ChatHoverEvent("show_entity", obj.get("hoverEvent").getAsJsonObject().get("contents").getAsJsonObject());
|
||||
}
|
||||
|
||||
public static ChatHoverEvent showEntity(UUID uuid, EntityType entityType) {
|
||||
HoverEvent<HoverEvent.ShowEntity> event = HoverEvent.showEntity(entityType.key(), uuid);
|
||||
JsonObject obj = GsonComponentSerializer.gson().serializer().toJsonTree(Component.empty().hoverEvent(event)).getAsJsonObject();
|
||||
return new ChatHoverEvent("show_entity", obj.get("hoverEvent").getAsJsonObject().get("contents").getAsJsonObject());
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Class used to convert JSON string to proper chat message representation.
|
||||
* @deprecated Use {@link GsonComponentSerializer}
|
||||
*/
|
||||
@Deprecated
|
||||
public final class ChatParser {
|
||||
|
||||
public static final char COLOR_CHAR = (char) 0xA7; // Represent the character '§'
|
||||
|
||||
/**
|
||||
* Converts a simple colored message json (text/color) to a {@link ColoredText}.
|
||||
*
|
||||
* @param json the json containing the text and color
|
||||
* @return a {@link ColoredText} representing the text
|
||||
*/
|
||||
@NotNull
|
||||
public static ColoredText toColoredText(@NotNull String json) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
try {
|
||||
final JsonElement element = JsonParser.parseString(json);
|
||||
|
||||
if (element instanceof JsonObject) {
|
||||
final JsonObject object = element.getAsJsonObject();
|
||||
appendBuilder(builder, object);
|
||||
} else if (element instanceof JsonArray) {
|
||||
final JsonArray array = element.getAsJsonArray();
|
||||
for (JsonElement e : array) {
|
||||
final JsonObject object = e.getAsJsonObject();
|
||||
appendBuilder(builder, object);
|
||||
}
|
||||
}
|
||||
|
||||
return ColoredText.of(builder.toString());
|
||||
} catch (JsonSyntaxException e) {
|
||||
// Not a json text
|
||||
return ColoredText.of(json);
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendBuilder(@NotNull StringBuilder builder, @NotNull JsonObject object) {
|
||||
builder.append(parseText(object));
|
||||
|
||||
final boolean hasExtra = object.has("extra");
|
||||
if (hasExtra) {
|
||||
final JsonArray extraArray = object.get("extra").getAsJsonArray();
|
||||
for (JsonElement extraElement : extraArray) {
|
||||
final JsonObject extraObject = extraElement.getAsJsonObject();
|
||||
builder.append(parseText(extraObject));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the format representing of a single text component (text + color key).
|
||||
*
|
||||
* @param textObject the text component to parse
|
||||
* @return the colored text format of the text component
|
||||
*/
|
||||
@NotNull
|
||||
private static String parseText(@NotNull JsonObject textObject) {
|
||||
final boolean hasText = textObject.has("text");
|
||||
if (!hasText)
|
||||
return "";
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
appendColor(textObject, builder);
|
||||
appendExtra(textObject, builder, "bold");
|
||||
appendExtra(textObject, builder, "italic");
|
||||
appendExtra(textObject, builder, "underlined");
|
||||
appendExtra(textObject, builder, "strikethrough");
|
||||
appendExtra(textObject, builder, "obfuscated");
|
||||
|
||||
// Add text
|
||||
final String text = textObject.get("text").getAsString();
|
||||
builder.append(text);
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static void appendColor(@NotNull JsonObject textObject, @NotNull StringBuilder builder) {
|
||||
if (textObject.has("color")) {
|
||||
final String colorString = textObject.get("color").getAsString();
|
||||
if (colorString.startsWith("#")) {
|
||||
// RGB format
|
||||
builder.append("{").append(colorString).append("}");
|
||||
} else {
|
||||
// Color simple name
|
||||
final ChatColor color = ChatColor.fromName(colorString);
|
||||
builder.append(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void appendExtra(@NotNull JsonObject textObject, @NotNull StringBuilder builder,
|
||||
@NotNull String name) {
|
||||
if (textObject.has(name)) {
|
||||
final boolean value = textObject.get(name).getAsBoolean();
|
||||
if (value) {
|
||||
builder.append("{#").append(name).append("}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,403 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Represents a text with one or multiple colors.
|
||||
* <p>
|
||||
* Used when the message can contain colors but not events like in {@link RichMessage}.
|
||||
* <p>
|
||||
* To create one, you simply call one of the static methods like {@link #of(ChatColor, String)},
|
||||
* you can then continue to append text with {@link #append(ChatColor, String)}.
|
||||
* @deprecated Use {@link Component#text(String, TextColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ColoredText extends JsonMessage {
|
||||
|
||||
private static final char SEPARATOR_START = '{';
|
||||
private static final char SEPARATOR_END = '}';
|
||||
private static final String COLOR_PREFIX = "#";
|
||||
private static final String TRANSLATABLE_PREFIX = "@";
|
||||
private static final String KEYBIND_PREFIX = "&";
|
||||
|
||||
/**
|
||||
* The raw text StringBuilder.
|
||||
* Its a single StringBuilder instance for easier and faster concatenation.
|
||||
*/
|
||||
private final StringBuilder message = new StringBuilder();
|
||||
|
||||
/**
|
||||
* Creates a colored text.
|
||||
* <p>
|
||||
* You need to use one of the static methods instead of the constructor.
|
||||
*
|
||||
* @param message the content of the text
|
||||
* @see #of(String) to create a colored text
|
||||
*/
|
||||
private ColoredText(@NotNull String message) {
|
||||
this.message.append(message);
|
||||
refreshUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ColoredText}.
|
||||
*
|
||||
* @param color the text color
|
||||
* @param message the text message
|
||||
* @return the created {@link ColoredText}
|
||||
*/
|
||||
public static ColoredText of(@NotNull ChatColor color, @NotNull String message) {
|
||||
return new ColoredText(color + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ColoredText}.
|
||||
*
|
||||
* @param message the text message
|
||||
* @return the created {@link ColoredText}
|
||||
*/
|
||||
@NotNull
|
||||
public static ColoredText of(@NotNull String message) {
|
||||
return of(ChatColor.WHITE, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ColoredText} with a legacy text.
|
||||
*
|
||||
* @param message the text message
|
||||
* @param colorChar the char used before the color code
|
||||
* @return the created {@link ColoredText}
|
||||
*/
|
||||
@NotNull
|
||||
public static ColoredText ofLegacy(@NotNull String message, char colorChar) {
|
||||
final String legacy = legacyToFormat(message, colorChar);
|
||||
return of(legacy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the text.
|
||||
*
|
||||
* @param color the text color
|
||||
* @param message the text message
|
||||
* @return this {@link ColoredText}
|
||||
*/
|
||||
@NotNull
|
||||
public ColoredText append(@NotNull ChatColor color, @NotNull String message) {
|
||||
this.message.append(color).append(message);
|
||||
refreshUpdate();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the text.
|
||||
*
|
||||
* @param message the text message
|
||||
* @return this {@link ColoredText}
|
||||
*/
|
||||
@NotNull
|
||||
public ColoredText append(@NotNull String message) {
|
||||
return append(ChatColor.NO_COLOR, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds legacy text.
|
||||
*
|
||||
* @param message the legacy text
|
||||
* @param colorChar the char used before the color code
|
||||
* @return this {@link ColoredText}
|
||||
*/
|
||||
@NotNull
|
||||
public ColoredText appendLegacy(@NotNull String message, char colorChar) {
|
||||
final String legacy = legacyToFormat(message, colorChar);
|
||||
return of(legacy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw text.
|
||||
*
|
||||
* @return the raw text
|
||||
* @see #toString() for the Json representation
|
||||
*/
|
||||
@NotNull
|
||||
public String getMessage() {
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Json representation of this colored text.
|
||||
* <p>
|
||||
* Used to "compile" the message, retrieved with {@link #toString()}.
|
||||
*
|
||||
* @return the Json representation of the text
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public JsonObject getJsonObject() {
|
||||
final List<JsonObject> components = getComponents();
|
||||
|
||||
// No message, return empty object
|
||||
if (components.isEmpty()) {
|
||||
return new JsonObject();
|
||||
}
|
||||
|
||||
// Get the first element and remove it
|
||||
JsonObject mainObject = components.remove(0);
|
||||
|
||||
// Append all the components
|
||||
if (!components.isEmpty()) {
|
||||
JsonArray extraArray = new JsonArray();
|
||||
for (JsonObject component : components) {
|
||||
extraArray.add(component);
|
||||
}
|
||||
mainObject.add("extra", extraArray);
|
||||
}
|
||||
|
||||
return mainObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of objects composing the message.
|
||||
*
|
||||
* @return the list of objects composing the message
|
||||
*/
|
||||
@NotNull
|
||||
protected List<JsonObject> getComponents() {
|
||||
final List<JsonObject> objects = new ArrayList<>();
|
||||
// No message, return empty list
|
||||
if (getMessage().isEmpty())
|
||||
return objects;
|
||||
|
||||
boolean inFormat = false;
|
||||
int formatStart = 0;
|
||||
int formatEnd = 0;
|
||||
|
||||
String currentColor = "";
|
||||
SpecialComponentContainer specialComponentContainer = new SpecialComponentContainer();
|
||||
for (int i = 0; i < message.length(); i++) {
|
||||
// Last char or null
|
||||
final Character p = i == 0 ? null : message.charAt(i - 1);
|
||||
// Current char
|
||||
final char c = message.charAt(i);
|
||||
if (c == SEPARATOR_START && !inFormat) {
|
||||
|
||||
formatEnd = formatEnd > 0 ? formatEnd + 1 : formatEnd;
|
||||
final String rawMessage = message.substring(formatEnd, i);
|
||||
if (!rawMessage.isEmpty()) {
|
||||
objects.add(getMessagePart(MessageType.RAW, rawMessage, currentColor, specialComponentContainer));
|
||||
}
|
||||
|
||||
inFormat = true;
|
||||
formatStart = i;
|
||||
continue;
|
||||
} else if (c == SEPARATOR_END && inFormat) {
|
||||
// Represent the custom format between the brackets
|
||||
final String formatString = message.substring(formatStart + 1, i);
|
||||
if (formatString.isEmpty())
|
||||
continue;
|
||||
|
||||
inFormat = false;
|
||||
//formatStart = 0;
|
||||
formatEnd = i;
|
||||
|
||||
// Color component
|
||||
if (formatString.startsWith(COLOR_PREFIX)) {
|
||||
// Remove the first # character to get code
|
||||
final String colorCode = formatString.substring(1);
|
||||
final ChatColor color = ChatColor.fromName(colorCode);
|
||||
if (color == ChatColor.NO_COLOR) {
|
||||
// Use rgb formatting (#ffffff)
|
||||
currentColor = COLOR_PREFIX + colorCode;
|
||||
} else if (color.isSpecial()) {
|
||||
// Check for special color (reset/bold/etc...)
|
||||
if (color == ChatColor.RESET) {
|
||||
// Remove all additional component
|
||||
currentColor = "";
|
||||
specialComponentContainer.reset();
|
||||
} else if (color == ChatColor.BOLD) {
|
||||
specialComponentContainer.bold = true;
|
||||
} else if (color == ChatColor.ITALIC) {
|
||||
specialComponentContainer.italic = true;
|
||||
} else if (color == ChatColor.UNDERLINED) {
|
||||
specialComponentContainer.underlined = true;
|
||||
} else if (color == ChatColor.STRIKETHROUGH) {
|
||||
specialComponentContainer.strikethrough = true;
|
||||
} else if (color == ChatColor.OBFUSCATED) {
|
||||
specialComponentContainer.obfuscated = true;
|
||||
}
|
||||
} else {
|
||||
// Use color name formatting (white)
|
||||
currentColor = colorCode;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Translatable component
|
||||
if (formatString.startsWith(TRANSLATABLE_PREFIX)) {
|
||||
final String translatableCode = formatString.substring(1);
|
||||
final boolean hasArgs = translatableCode.contains(",");
|
||||
if (!hasArgs) {
|
||||
// Without argument
|
||||
// ex: {@translatable.key}
|
||||
objects.add(getMessagePart(MessageType.TRANSLATABLE, translatableCode, currentColor, specialComponentContainer));
|
||||
} else {
|
||||
// Arguments parsing
|
||||
// ex: {@translatable.key,arg1,arg2,etc}
|
||||
final String[] split = translatableCode.split(Pattern.quote(","));
|
||||
final String finalTranslatableCode = split[0];
|
||||
final String[] arguments = Arrays.copyOfRange(split, 1, split.length);
|
||||
|
||||
JsonObject translatableObject = getMessagePart(MessageType.TRANSLATABLE, finalTranslatableCode, currentColor, specialComponentContainer);
|
||||
if (arguments.length > 0) {
|
||||
JsonArray argArray = new JsonArray();
|
||||
for (String arg : arguments) {
|
||||
argArray.add(getMessagePart(MessageType.RAW, arg, currentColor, specialComponentContainer));
|
||||
}
|
||||
translatableObject.add("with", argArray);
|
||||
objects.add(translatableObject);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Keybind component
|
||||
if (formatString.startsWith(KEYBIND_PREFIX)) {
|
||||
// ex: {&key.drop}
|
||||
final String keybindCode = formatString.substring(1);
|
||||
objects.add(getMessagePart(MessageType.KEYBIND, keybindCode, currentColor, specialComponentContainer));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Was not a component, add the encapsulated string
|
||||
final String current = message.substring(formatStart, i + 1);
|
||||
objects.add(getMessagePart(MessageType.RAW, current, currentColor, specialComponentContainer));
|
||||
}
|
||||
}
|
||||
|
||||
// Add the remaining of the message as a raw message when any
|
||||
if (formatEnd < message.length()) {
|
||||
final String lastRawMessage = message.substring(formatEnd + 1);
|
||||
// if 'objects' is empty, an empty message is required for the client to understand the final JSON
|
||||
if (!lastRawMessage.isEmpty() || objects.isEmpty()) {
|
||||
objects.add(getMessagePart(MessageType.RAW, lastRawMessage, currentColor, specialComponentContainer));
|
||||
}
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object representing a message (raw/keybind/translatable).
|
||||
*
|
||||
* @param messageType the message type
|
||||
* @param message the message
|
||||
* @param color the last color
|
||||
* @return a json object representing a message
|
||||
*/
|
||||
private JsonObject getMessagePart(@NotNull MessageType messageType, @NotNull String message, @NotNull String color,
|
||||
@NotNull SpecialComponentContainer specialComponentContainer) {
|
||||
JsonObject object = new JsonObject();
|
||||
switch (messageType) {
|
||||
case RAW:
|
||||
object.addProperty("text", message);
|
||||
break;
|
||||
case KEYBIND:
|
||||
object.addProperty("keybind", message);
|
||||
break;
|
||||
case TRANSLATABLE:
|
||||
object.addProperty("translate", message);
|
||||
break;
|
||||
}
|
||||
if (!color.isEmpty()) {
|
||||
object.addProperty("color", color);
|
||||
}
|
||||
|
||||
|
||||
object.addProperty("bold", getBoolean(specialComponentContainer.bold));
|
||||
object.addProperty("italic", getBoolean(specialComponentContainer.italic));
|
||||
object.addProperty("underlined", getBoolean(specialComponentContainer.underlined));
|
||||
object.addProperty("strikethrough", getBoolean(specialComponentContainer.strikethrough));
|
||||
object.addProperty("obfuscated", getBoolean(specialComponentContainer.obfuscated));
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getBoolean(boolean value) {
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a legacy text to our format which can be used by {@link #of(String)} etc...
|
||||
* <p>
|
||||
* eg: "&fHey" -> "{#white}Hey"
|
||||
*
|
||||
* @param message the legacy text
|
||||
* @param colorChar the char used before the color code
|
||||
* @return the converted legacy text
|
||||
*/
|
||||
@NotNull
|
||||
private static String legacyToFormat(@NotNull String message, char colorChar) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < message.length(); i++) {
|
||||
final char c = message.charAt(i);
|
||||
if (c == colorChar) {
|
||||
final char nextChar = message.charAt(i + 1);
|
||||
final ChatColor color = ChatColor.fromLegacyColorCodes(nextChar);
|
||||
if (color != ChatColor.NO_COLOR) {
|
||||
final String replacement = color.toString();
|
||||
result.append(replacement);
|
||||
i++; // Increment to ignore the color code
|
||||
} else {
|
||||
result.append(c);
|
||||
}
|
||||
} else {
|
||||
result.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an element which can change based on the client which receive the text.
|
||||
*/
|
||||
private enum MessageType {
|
||||
RAW, KEYBIND, TRANSLATABLE
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to keep a "color" state in the text.
|
||||
*/
|
||||
private static class SpecialComponentContainer {
|
||||
boolean bold = false;
|
||||
|
||||
boolean italic = false;
|
||||
|
||||
boolean underlined = false;
|
||||
|
||||
boolean strikethrough = false;
|
||||
|
||||
boolean obfuscated = false;
|
||||
|
||||
private void reset() {
|
||||
this.bold = false;
|
||||
|
||||
this.italic = false;
|
||||
|
||||
this.underlined = false;
|
||||
|
||||
this.strikethrough = false;
|
||||
|
||||
this.obfuscated = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a json message which can be send to a player.
|
||||
* <p>
|
||||
* Examples are {@link ColoredText} and {@link RichMessage}.
|
||||
*
|
||||
* @see <a href="https://wiki.vg/Chat">Chat Format</a>
|
||||
* @deprecated Use {@link Component}
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class JsonMessage implements ComponentLike {
|
||||
|
||||
// true if the compiled string is up-to-date, false otherwise
|
||||
private boolean updated;
|
||||
// the compiled json string of the message (can be outdated)
|
||||
private String compiledJson;
|
||||
|
||||
/**
|
||||
* Gets the json representation of this message.
|
||||
* <p>
|
||||
* Sent directly to the client.
|
||||
*
|
||||
* @return the json representation of the message
|
||||
* @see #toString()
|
||||
*/
|
||||
@NotNull
|
||||
public abstract JsonObject getJsonObject();
|
||||
|
||||
/**
|
||||
* Signals that the final json string changed and that it will need to be updated.
|
||||
*/
|
||||
protected void refreshUpdate() {
|
||||
this.updated = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of the message without any formatting or effects.
|
||||
*
|
||||
* @return The message without formatting or effects
|
||||
*/
|
||||
@NotNull
|
||||
public String getRawMessage() {
|
||||
return getTextMessage(getJsonObject()).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component asComponent() {
|
||||
return GsonComponentSerializer.gson().deserializeFromTree(this.getJsonObject());
|
||||
}
|
||||
|
||||
public static @NotNull JsonMessage fromComponent(@NotNull Component component) {
|
||||
return new RawJsonMessage(GsonComponentSerializer.gson().serializer().toJsonTree(component).getAsJsonObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Json representation.
|
||||
* <p>
|
||||
* Will check of the current cached compiled json is up-to-date in order to prevent
|
||||
* re-parsing the message every time.
|
||||
*
|
||||
* @return the string json representation
|
||||
* @see #getJsonObject()
|
||||
* @see #refreshUpdate()
|
||||
*/
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
if (!updated) {
|
||||
this.compiledJson = getJsonObject().toString();
|
||||
this.updated = true;
|
||||
}
|
||||
|
||||
return compiledJson;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
JsonMessage message = (JsonMessage) o;
|
||||
return Objects.equals(toString(), message.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return toString().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively collects the 'text' field from the provided object and it's 'extra's.
|
||||
*
|
||||
* @param obj The object to parse
|
||||
* @return The text content of the object and its 'extra's
|
||||
*/
|
||||
@NotNull
|
||||
private static StringBuilder getTextMessage(@NotNull JsonObject obj) {
|
||||
StringBuilder message = new StringBuilder(obj.get("text").getAsString());
|
||||
JsonElement extra = obj.get("extra");
|
||||
if (extra != null && extra.isJsonArray()) {
|
||||
for (JsonElement child : extra.getAsJsonArray()) {
|
||||
if (!child.isJsonObject()) continue;
|
||||
message.append(getTextMessage(child.getAsJsonObject()));
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static class RawJsonMessage extends JsonMessage {
|
||||
|
||||
private final JsonObject jsonObject;
|
||||
|
||||
public RawJsonMessage(@NotNull JsonObject jsonObject) {
|
||||
this.jsonObject = jsonObject;
|
||||
}
|
||||
|
||||
public RawJsonMessage(@NotNull String jsonObject) {
|
||||
this.jsonObject = JsonParser.parseString(jsonObject).getAsJsonObject();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JsonObject getJsonObject() {
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,236 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents multiple {@link ColoredText} batched together with the possibility to add
|
||||
* click and hover events.
|
||||
* <p>
|
||||
* Used when the message can contain both colored text and event (otherwise, use {@link ColoredText}).
|
||||
* <p>
|
||||
* You will need to call the static method to initialize the message {@link #of(ColoredText)},
|
||||
* events can be assigned with {@link #setClickEvent(ChatClickEvent)} and {@link #setHoverEvent(ChatHoverEvent)}
|
||||
* and new text element can also be appended {@link #append(ColoredText)}.
|
||||
* @deprecated Use {@link Component}
|
||||
*/
|
||||
@Deprecated
|
||||
public class RichMessage extends JsonMessage {
|
||||
|
||||
private final List<RichComponent> components = new ArrayList<>();
|
||||
private RichComponent currentComponent;
|
||||
|
||||
/**
|
||||
* @see #of(ColoredText) to create a rich message
|
||||
*/
|
||||
private RichMessage() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link RichMessage} by adding the first rich component.
|
||||
*
|
||||
* @param coloredText the text composing the first rich component
|
||||
* @return the created rich message object
|
||||
*/
|
||||
public static RichMessage of(@NotNull ColoredText coloredText) {
|
||||
|
||||
RichMessage richMessage = new RichMessage();
|
||||
appendText(richMessage, coloredText);
|
||||
|
||||
return richMessage;
|
||||
}
|
||||
|
||||
private static void appendText(@NotNull RichMessage richMessage, @NotNull ColoredText coloredText) {
|
||||
RichComponent component = new RichComponent(coloredText);
|
||||
richMessage.components.add(component);
|
||||
richMessage.currentComponent = component;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new rich component to the message.
|
||||
*
|
||||
* @param coloredText the text composing the rich component
|
||||
* @return the rich message
|
||||
*/
|
||||
public RichMessage append(@NotNull ColoredText coloredText) {
|
||||
|
||||
appendText(this, coloredText);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the click event of the current rich component.
|
||||
*
|
||||
* @param clickEvent the click event to set
|
||||
* @return the rich message
|
||||
*/
|
||||
public RichMessage setClickEvent(@Nullable ChatClickEvent clickEvent) {
|
||||
currentComponent.setClickEvent(clickEvent);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hover event of the current rich component.
|
||||
*
|
||||
* @param hoverEvent the hover event to set
|
||||
* @return the rich message
|
||||
*/
|
||||
public RichMessage setHoverEvent(@Nullable ChatHoverEvent hoverEvent) {
|
||||
currentComponent.setHoverEvent(hoverEvent);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the insertion string of the current rich component.
|
||||
*
|
||||
* @param insertion the string to insert in the chat box
|
||||
* @return the rich message
|
||||
*/
|
||||
public RichMessage setInsertion(@Nullable String insertion) {
|
||||
currentComponent.setInsertion(insertion);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JsonObject getJsonObject() {
|
||||
List<RichComponent> cacheComponents = new ArrayList<>(components);
|
||||
|
||||
// No component, return empty json object
|
||||
if (cacheComponents.isEmpty())
|
||||
return new JsonObject();
|
||||
|
||||
// The main object contains the extra array, with an empty text to do not share its state with the others
|
||||
JsonObject mainObject = new JsonObject();
|
||||
mainObject.addProperty("text", "");
|
||||
|
||||
// The extra array contains all the components
|
||||
JsonArray extraArray = new JsonArray();
|
||||
|
||||
// Add all the components
|
||||
for (RichComponent component : cacheComponents) {
|
||||
List<JsonObject> componentObjects = getComponentObject(component);
|
||||
for (JsonObject componentObject : componentObjects) {
|
||||
extraArray.add(componentObject);
|
||||
}
|
||||
}
|
||||
|
||||
mainObject.add("extra", extraArray);
|
||||
|
||||
|
||||
return mainObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the components to add click/hover events.
|
||||
*
|
||||
* @param component the rich component to process
|
||||
* @return a list of processed components
|
||||
*/
|
||||
private List<JsonObject> getComponentObject(@NotNull RichComponent component) {
|
||||
final ColoredText coloredText = component.getText();
|
||||
final List<JsonObject> componentObjects = coloredText.getComponents();
|
||||
|
||||
final ChatClickEvent clickEvent = component.getClickEvent();
|
||||
final ChatHoverEvent hoverEvent = component.getHoverEvent();
|
||||
final String insertion = component.getInsertion();
|
||||
|
||||
// Nothing to process
|
||||
if (clickEvent == null && hoverEvent == null && insertion == null) {
|
||||
return componentObjects;
|
||||
}
|
||||
|
||||
// Add hover/click event to all components
|
||||
for (JsonObject componentObject : componentObjects) {
|
||||
// Add click event if any
|
||||
if (clickEvent != null) {
|
||||
final JsonObject clickObject =
|
||||
getEventObject(clickEvent.getAction(), clickEvent.getValue());
|
||||
componentObject.add("clickEvent", clickObject);
|
||||
}
|
||||
// Add hover event if any
|
||||
if (hoverEvent != null) {
|
||||
final JsonObject hoverObject;
|
||||
if (hoverEvent.isJson()) {
|
||||
// The value is a JsonObject
|
||||
hoverObject = new JsonObject();
|
||||
hoverObject.addProperty("action", hoverEvent.getAction());
|
||||
hoverObject.add("contents", hoverEvent.getValueObject());
|
||||
} else {
|
||||
// The value is a raw string
|
||||
final String hoverValue = hoverEvent.getValue();
|
||||
Check.notNull(hoverValue, "The hover value cannot be null");
|
||||
hoverObject = getEventObject(hoverEvent.getAction(), hoverValue);
|
||||
}
|
||||
componentObject.add("hoverEvent", hoverObject);
|
||||
}
|
||||
// Add insertion if any
|
||||
if (insertion != null) {
|
||||
componentObject.addProperty("insertion", insertion);
|
||||
}
|
||||
}
|
||||
|
||||
return componentObjects;
|
||||
}
|
||||
|
||||
private JsonObject getEventObject(@NotNull String action, @NotNull String value) {
|
||||
JsonObject eventObject = new JsonObject();
|
||||
eventObject.addProperty("action", action);
|
||||
eventObject.addProperty("value", value);
|
||||
return eventObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a {@link ColoredText} with a click and hover event (can be null).
|
||||
*/
|
||||
private static class RichComponent {
|
||||
|
||||
private final ColoredText text;
|
||||
private ChatClickEvent clickEvent;
|
||||
private ChatHoverEvent hoverEvent;
|
||||
private String insertion;
|
||||
|
||||
private RichComponent(@NotNull ColoredText text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ColoredText getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ChatClickEvent getClickEvent() {
|
||||
return clickEvent;
|
||||
}
|
||||
|
||||
public void setClickEvent(@Nullable ChatClickEvent clickEvent) {
|
||||
this.clickEvent = clickEvent;
|
||||
}
|
||||
|
||||
public ChatHoverEvent getHoverEvent() {
|
||||
return hoverEvent;
|
||||
}
|
||||
|
||||
public void setHoverEvent(@Nullable ChatHoverEvent hoverEvent) {
|
||||
this.hoverEvent = hoverEvent;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getInsertion() {
|
||||
return insertion;
|
||||
}
|
||||
|
||||
public void setInsertion(@Nullable String insertion) {
|
||||
this.insertion = insertion;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package net.minestom.server.chat;
|
||||
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a translatable component which can be used in {@link ColoredText}.
|
||||
* @deprecated Use {@link TranslatableComponent}
|
||||
*/
|
||||
@Deprecated
|
||||
public class TranslatableText {
|
||||
|
||||
private final String code;
|
||||
private final String[] arguments;
|
||||
|
||||
private TranslatableText(@NotNull String code, @Nullable String[] arguments) {
|
||||
this.code = code;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the translatable component of the specific code.
|
||||
*
|
||||
* @param code the translatable code
|
||||
* @return the translatable component linked to the code
|
||||
*/
|
||||
@NotNull
|
||||
public static TranslatableText of(@NotNull String code) {
|
||||
return new TranslatableText(code, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the translatable component and the specific code with arguments.
|
||||
*
|
||||
* @param code the translatable code
|
||||
* @param arguments the translatable component arguments in order
|
||||
* @return the translatable component linked to the code and arguments
|
||||
*/
|
||||
@NotNull
|
||||
public static TranslatableText of(@NotNull String code, @NotNull String... arguments) {
|
||||
return new TranslatableText(code, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final String prefix = "{@";
|
||||
final String suffix = "}";
|
||||
|
||||
StringBuilder content = new StringBuilder(code);
|
||||
|
||||
if (arguments != null && arguments.length > 0) {
|
||||
for (String arg : arguments) {
|
||||
content.append(",").append(arg);
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + content + suffix;
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.color;
|
||||
|
||||
import net.kyori.adventure.util.RGBLike;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -159,17 +158,6 @@ public class Color implements RGBLike {
|
||||
this.green = Math.round(averageGreen * gainFactor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ChatColor representation of this color.
|
||||
*
|
||||
* @return the chat color
|
||||
* @deprecated ChatColor is deprecated and should not be used
|
||||
*/
|
||||
@Deprecated
|
||||
public ChatColor asLegacyChatColor() {
|
||||
return ChatColor.fromRGB((byte) red, (byte) blue, (byte) green);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -2,7 +2,6 @@ package net.minestom.server.command;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.permission.PermissionHandler;
|
||||
import net.minestom.server.tag.TagHandler;
|
||||
@ -35,18 +34,6 @@ public interface CommandSender extends PermissionHandler, Audience, TagHandler {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a {@link JsonMessage} message.
|
||||
* If this is not a {@link Player}, only the content of the message will be sent as a string.
|
||||
*
|
||||
* @param text The {@link JsonMessage} to send.
|
||||
* @deprecated Use {@link #sendMessage(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
default void sendMessage(@NotNull JsonMessage text) {
|
||||
this.sendMessage(text.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the sender is a {@link Player}.
|
||||
*
|
||||
|
@ -1,50 +1,27 @@
|
||||
package net.minestom.server.command.builder.suggestion;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SuggestionEntry {
|
||||
|
||||
private final String entry;
|
||||
private final Component tooltip;
|
||||
|
||||
/**
|
||||
* @deprecated Use {{@link #SuggestionEntry(String, JsonMessage)}}
|
||||
*/
|
||||
@Deprecated
|
||||
public SuggestionEntry(@NotNull String entry, @Nullable JsonMessage tooltip) {
|
||||
this.entry = entry;
|
||||
this.tooltip = tooltip.asComponent();
|
||||
}
|
||||
|
||||
public SuggestionEntry(@NotNull String entry, @Nullable Component tooltip) {
|
||||
this.entry = entry;
|
||||
this.tooltip = tooltip.asComponent();
|
||||
this.tooltip = tooltip;
|
||||
}
|
||||
|
||||
public SuggestionEntry(@NotNull String entry) {
|
||||
this.entry = entry;
|
||||
this.tooltip = null;
|
||||
this(entry, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getEntry() {
|
||||
public @NotNull String getEntry() {
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Component getTooltip() {
|
||||
public @Nullable Component getTooltip() {
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getTooltip()}
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public JsonMessage getTooltipJson() {
|
||||
return JsonMessage.fromComponent(tooltip);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.Tickable;
|
||||
import net.minestom.server.Viewable;
|
||||
import net.minestom.server.acquirable.Acquirable;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.collision.BoundingBox;
|
||||
import net.minestom.server.collision.CollisionUtils;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
@ -1053,7 +1052,6 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
*
|
||||
* @param pose the new entity pose
|
||||
*/
|
||||
@NotNull
|
||||
public void setPose(@NotNull Pose pose) {
|
||||
this.entityMeta.setPose(pose);
|
||||
}
|
||||
@ -1062,35 +1060,11 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
* Gets the entity custom name.
|
||||
*
|
||||
* @return the custom name of the entity, null if there is not
|
||||
* @deprecated Use {@link #getCustomName()}
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public JsonMessage getCustomNameJson() {
|
||||
return this.entityMeta.getCustomNameJson();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the entity custom name.
|
||||
*
|
||||
* @return the custom name of the entity, null if there is not
|
||||
*/
|
||||
@Nullable
|
||||
public Component getCustomName() {
|
||||
public @Nullable Component getCustomName() {
|
||||
return this.entityMeta.getCustomName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the entity custom name.
|
||||
*
|
||||
* @param customName the custom name of the entity, null to remove it
|
||||
* @deprecated Use {@link #setCustomName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setCustomName(@Nullable JsonMessage customName) {
|
||||
this.entityMeta.setCustomName(customName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the entity custom name.
|
||||
*
|
||||
|
@ -2,7 +2,6 @@ package net.minestom.server.entity;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.coordinate.Vec;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
@ -44,30 +43,6 @@ public class Metadata {
|
||||
return new Value<>(TYPE_STRING, value, writer -> writer.writeSizedString(value), BinaryReader::readSizedString);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Value<JsonMessage> Chat(@NotNull JsonMessage value) {
|
||||
return new Value<>(TYPE_CHAT, value, writer -> writer.writeSizedString(value.toString()), reader -> reader.readJsonMessage(Integer.MAX_VALUE));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Value<JsonMessage> OptChat(@Nullable JsonMessage value) {
|
||||
return new Value<>(TYPE_OPTCHAT, value, writer -> {
|
||||
final boolean present = value != null;
|
||||
writer.writeBoolean(present);
|
||||
if (present) {
|
||||
writer.writeSizedString(value.toString());
|
||||
}
|
||||
},
|
||||
reader -> {
|
||||
boolean present = reader.readBoolean();
|
||||
if (present) {
|
||||
return reader.readJsonMessage(Integer.MAX_VALUE);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Value<Component> Chat(@NotNull Component value) {
|
||||
return new Value<>(TYPE_CHAT, value, writer -> writer.writeComponent(value), BinaryReader::readComponent);
|
||||
}
|
||||
|
@ -20,9 +20,6 @@ import net.minestom.server.adventure.AdventurePacketConvertor;
|
||||
import net.minestom.server.adventure.Localizable;
|
||||
import net.minestom.server.adventure.audience.Audiences;
|
||||
import net.minestom.server.attribute.Attribute;
|
||||
import net.minestom.server.chat.ChatParser;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.collision.BoundingBox;
|
||||
import net.minestom.server.command.CommandManager;
|
||||
import net.minestom.server.command.CommandSender;
|
||||
@ -65,8 +62,6 @@ import net.minestom.server.recipe.RecipeManager;
|
||||
import net.minestom.server.resourcepack.ResourcePack;
|
||||
import net.minestom.server.scoreboard.BelowNameTag;
|
||||
import net.minestom.server.scoreboard.Team;
|
||||
import net.minestom.server.sound.SoundCategory;
|
||||
import net.minestom.server.sound.SoundEvent;
|
||||
import net.minestom.server.stat.PlayerStatistic;
|
||||
import net.minestom.server.utils.ArrayUtils;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
@ -618,31 +613,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
sendPluginMessage(channel, message.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a legacy message with the specified color char.
|
||||
*
|
||||
* @param text the text with the legacy color formatting
|
||||
* @param colorChar the color character
|
||||
* @deprecated Use {@link #sendMessage(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void sendLegacyMessage(@NotNull String text, char colorChar) {
|
||||
ColoredText coloredText = ColoredText.ofLegacy(text, colorChar);
|
||||
sendJsonMessage(coloredText.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a legacy message with the default color char {@link ChatParser#COLOR_CHAR}.
|
||||
*
|
||||
* @param text the text with the legacy color formatting
|
||||
* @deprecated Use {@link #sendMessage(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void sendLegacyMessage(@NotNull String text) {
|
||||
ColoredText coloredText = ColoredText.ofLegacy(text, ChatParser.COLOR_CHAR);
|
||||
sendJsonMessage(coloredText.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #sendMessage(Component)}
|
||||
*/
|
||||
@ -667,76 +637,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
addPacketToQueue(chatMessagePacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a sound from the {@link SoundEvent} enum.
|
||||
*
|
||||
* @param sound the sound to play
|
||||
* @param soundCategory the sound category
|
||||
* @param x the effect X
|
||||
* @param y the effect Y
|
||||
* @param z the effect Z
|
||||
* @param volume the volume of the sound (1 is 100%)
|
||||
* @param pitch the pitch of the sound, between 0.5 and 2.0
|
||||
* @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound, double, double, double)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void playSound(@NotNull SoundEvent sound, @NotNull SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) {
|
||||
SoundEffectPacket soundEffectPacket = new SoundEffectPacket();
|
||||
soundEffectPacket.soundId = sound.getId();
|
||||
soundEffectPacket.soundSource = soundCategory.asSource();
|
||||
soundEffectPacket.x = x;
|
||||
soundEffectPacket.y = y;
|
||||
soundEffectPacket.z = z;
|
||||
soundEffectPacket.volume = volume;
|
||||
soundEffectPacket.pitch = pitch;
|
||||
playerConnection.sendPacket(soundEffectPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a sound from an identifier (represents a custom sound in a resource pack).
|
||||
*
|
||||
* @param identifier the identifier of the sound to play
|
||||
* @param soundCategory the sound category
|
||||
* @param x the effect X
|
||||
* @param y the effect Y
|
||||
* @param z the effect Z
|
||||
* @param volume the volume of the sound (1 is 100%)
|
||||
* @param pitch the pitch of the sound, between 0.5 and 2.0
|
||||
* @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound, double, double, double)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void playSound(@NotNull String identifier, @NotNull SoundCategory soundCategory, int x, int y, int z, float volume, float pitch) {
|
||||
NamedSoundEffectPacket namedSoundEffectPacket = new NamedSoundEffectPacket();
|
||||
namedSoundEffectPacket.soundName = identifier;
|
||||
namedSoundEffectPacket.soundSource = soundCategory.asSource();
|
||||
namedSoundEffectPacket.x = x;
|
||||
namedSoundEffectPacket.y = y;
|
||||
namedSoundEffectPacket.z = z;
|
||||
namedSoundEffectPacket.volume = volume;
|
||||
namedSoundEffectPacket.pitch = pitch;
|
||||
playerConnection.sendPacket(namedSoundEffectPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a sound directly to the player (constant volume).
|
||||
*
|
||||
* @param sound the sound to play
|
||||
* @param soundCategory the sound category
|
||||
* @param volume the volume of the sound (1 is 100%)
|
||||
* @param pitch the pitch of the sound, between 0.5 and 2.0
|
||||
* @deprecated Use {@link #playSound(net.kyori.adventure.sound.Sound)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void playSound(@NotNull SoundEvent sound, @NotNull SoundCategory soundCategory, float volume, float pitch) {
|
||||
EntitySoundEffectPacket entitySoundEffectPacket = new EntitySoundEffectPacket();
|
||||
entitySoundEffectPacket.entityId = getEntityId();
|
||||
entitySoundEffectPacket.soundId = sound.getId();
|
||||
entitySoundEffectPacket.soundSource = soundCategory.asSource();
|
||||
entitySoundEffectPacket.volume = volume;
|
||||
entitySoundEffectPacket.pitch = pitch;
|
||||
playerConnection.sendPacket(entitySoundEffectPacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound(@NotNull Sound sound) {
|
||||
this.playSound(sound, this.position.x(), this.position.y(), this.position.z());
|
||||
@ -784,84 +684,9 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
playerConnection.sendPacket(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a {@link StopSoundPacket} packet.
|
||||
*
|
||||
* @deprecated Use {@link #stopSound(SoundStop)} with {@link SoundStop#all()}
|
||||
*/
|
||||
@Deprecated
|
||||
public void stopSound() {
|
||||
StopSoundPacket stopSoundPacket = new StopSoundPacket();
|
||||
stopSoundPacket.flags = 0x00;
|
||||
playerConnection.sendPacket(stopSoundPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the header and footer of a player which will be displayed in his tab window.
|
||||
*
|
||||
* @param header the header text, null to set empty
|
||||
* @param footer the footer text, null to set empty
|
||||
* @deprecated Use {@link #sendPlayerListHeaderAndFooter(Component, Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void sendHeaderFooter(@Nullable JsonMessage header, @Nullable JsonMessage footer) {
|
||||
this.sendPlayerListHeaderAndFooter(header == null ? Component.empty() : header.asComponent(),
|
||||
footer == null ? Component.empty() : footer.asComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerListHeaderAndFooter(@NotNull Component header, @NotNull Component footer) {
|
||||
PlayerListHeaderAndFooterPacket packet = new PlayerListHeaderAndFooterPacket(header, footer);
|
||||
playerConnection.sendPacket(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a title and subtitle message.
|
||||
*
|
||||
* @param title the title message
|
||||
* @param subtitle the subtitle message
|
||||
* @see #sendTitleTime(int, int, int) to specify the display time
|
||||
* @deprecated Use {@link #showTitle(Title)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void sendTitleSubtitleMessage(@NotNull JsonMessage title, @NotNull JsonMessage subtitle) {
|
||||
this.showTitle(Title.title(title.asComponent(), subtitle.asComponent()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a title message.
|
||||
*
|
||||
* @param title the title message
|
||||
* @see #sendTitleTime(int, int, int) to specify the display time
|
||||
* @deprecated Use {@link #showTitle(Title)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void sendTitleMessage(@NotNull JsonMessage title) {
|
||||
this.showTitle(Title.title(title.asComponent(), Component.empty()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a subtitle message.
|
||||
*
|
||||
* @param subtitle the subtitle message
|
||||
* @see #sendTitleTime(int, int, int) to specify the display time
|
||||
* @deprecated Use {@link #showTitle(Title)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void sendSubtitleMessage(@NotNull JsonMessage subtitle) {
|
||||
this.showTitle(Title.title(Component.empty(), subtitle.asComponent()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an action bar message.
|
||||
*
|
||||
* @param actionBar the action bar message
|
||||
* @see #sendTitleTime(int, int, int) to specify the display time
|
||||
* @deprecated Use {@link #sendActionBar(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void sendActionBarMessage(@NotNull JsonMessage actionBar) {
|
||||
this.sendActionBar(actionBar.asComponent());
|
||||
playerConnection.sendPacket(new PlayerListHeaderAndFooterPacket(header, footer));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1045,37 +870,11 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
* Gets the player display name in the tab-list.
|
||||
*
|
||||
* @return the player display name, null means that {@link #getUsername()} is displayed
|
||||
* @deprecated Use {@link #getDisplayName()}
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public JsonMessage getDisplayNameJson() {
|
||||
return JsonMessage.fromComponent(displayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player display name in the tab-list.
|
||||
*
|
||||
* @return the player display name, null means that {@link #getUsername()} is displayed
|
||||
*/
|
||||
@Nullable
|
||||
public Component getDisplayName() {
|
||||
public @Nullable Component getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the player display name in the tab-list.
|
||||
* <p>
|
||||
* Sets to null to show the player username.
|
||||
*
|
||||
* @param displayName the display name, null to display the username
|
||||
* @deprecated Use {@link #setDisplayName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDisplayName(@Nullable JsonMessage displayName) {
|
||||
this.setDisplayName(displayName == null ? null : displayName.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the player display name in the tab-list.
|
||||
* <p>
|
||||
@ -1097,8 +896,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
* @return the player skin object,
|
||||
* null means that the player has his {@link #getUuid()} default skin
|
||||
*/
|
||||
@Nullable
|
||||
public PlayerSkin getSkin() {
|
||||
public @Nullable PlayerSkin getSkin() {
|
||||
return skin;
|
||||
}
|
||||
|
||||
@ -1573,28 +1371,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
playerConnection.sendPacket(respawnPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks the player with a reason.
|
||||
*
|
||||
* @param text the kick reason
|
||||
* @deprecated Use {@link #kick(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void kick(@NotNull JsonMessage text) {
|
||||
this.kick(text.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks the player with a reason.
|
||||
*
|
||||
* @param message the kick reason
|
||||
* @deprecated Use {@link #kick(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void kick(@NotNull String message) {
|
||||
this.kick(Component.text(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks the player with a reason.
|
||||
*
|
||||
@ -1602,7 +1378,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
*/
|
||||
public void kick(@NotNull Component component) {
|
||||
final ConnectionState connectionState = playerConnection.getConnectionState();
|
||||
|
||||
// Packet type depends on the current player connection state
|
||||
final ServerPacket disconnectPacket;
|
||||
if (connectionState == ConnectionState.LOGIN) {
|
||||
@ -1610,7 +1385,6 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
} else {
|
||||
disconnectPacket = new DisconnectPacket(component);
|
||||
}
|
||||
|
||||
if (playerConnection instanceof NettyPlayerConnection) {
|
||||
((NettyPlayerConnection) playerConnection).writeAndFlush(disconnectPacket);
|
||||
playerConnection.disconnect();
|
||||
@ -1620,6 +1394,15 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks the player with a reason.
|
||||
*
|
||||
* @param message the kick reason
|
||||
*/
|
||||
public void kick(@NotNull String message) {
|
||||
this.kick(Component.text(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the current held slot for the player.
|
||||
*
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.entity.damage;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.LivingEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
@ -49,19 +48,10 @@ public class DamageType implements TagHandler {
|
||||
*
|
||||
* @return the damage type identifier
|
||||
*/
|
||||
@NotNull
|
||||
public String getIdentifier() {
|
||||
public @NotNull String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #buildDeathMessage(Player)}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage buildDeathMessageJson(@NotNull Player killed) {
|
||||
return JsonMessage.fromComponent(this.buildDeathMessage(killed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the death message linked to this damage type.
|
||||
* <p>
|
||||
@ -70,8 +60,7 @@ public class DamageType implements TagHandler {
|
||||
* @param killed the player who has been killed
|
||||
* @return the death message, null to do not send anything
|
||||
*/
|
||||
@Nullable
|
||||
public Component buildDeathMessage(@NotNull Player killed) {
|
||||
public @Nullable Component buildDeathMessage(@NotNull Player killed) {
|
||||
return Component.translatable("death." + identifier, Component.text(killed.getUsername()));
|
||||
}
|
||||
|
||||
@ -82,8 +71,7 @@ public class DamageType implements TagHandler {
|
||||
* @param projectile the actual projectile
|
||||
* @return a new {@link EntityProjectileDamage}
|
||||
*/
|
||||
@NotNull
|
||||
public static DamageType fromProjectile(@Nullable Entity shooter, @NotNull Entity projectile) {
|
||||
public static @NotNull DamageType fromProjectile(@Nullable Entity shooter, @NotNull Entity projectile) {
|
||||
return new EntityProjectileDamage(shooter, projectile);
|
||||
}
|
||||
|
||||
@ -93,8 +81,7 @@ public class DamageType implements TagHandler {
|
||||
* @param player the player damager
|
||||
* @return a new {@link EntityDamage}
|
||||
*/
|
||||
@NotNull
|
||||
public static EntityDamage fromPlayer(@NotNull Player player) {
|
||||
public static @NotNull EntityDamage fromPlayer(@NotNull Player player) {
|
||||
return new EntityDamage(player);
|
||||
}
|
||||
|
||||
@ -104,27 +91,17 @@ public class DamageType implements TagHandler {
|
||||
* @param entity the entity damager
|
||||
* @return a new {@link EntityDamage}
|
||||
*/
|
||||
@NotNull
|
||||
public static EntityDamage fromEntity(@NotNull Entity entity) {
|
||||
public static @NotNull EntityDamage fromEntity(@NotNull Entity entity) {
|
||||
return new EntityDamage(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #buildDeathScreenText(Player)}
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public JsonMessage buildDeathScreenTextJson(@NotNull Player killed) {
|
||||
return JsonMessage.fromComponent(this.buildDeathScreenText(killed));
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the text sent to a player in his death screen.
|
||||
*
|
||||
* @param killed the player who has been killed
|
||||
* @return the death screen text, null to do not send anything
|
||||
*/
|
||||
public Component buildDeathScreenText(@NotNull Player killed) {
|
||||
public @Nullable Component buildDeathScreenText(@NotNull Player killed) {
|
||||
return Component.translatable("death." + identifier);
|
||||
}
|
||||
|
||||
@ -134,8 +111,7 @@ public class DamageType implements TagHandler {
|
||||
* @param entity the entity hit by this damage
|
||||
* @return the sound to play when the given entity is hurt by this damage type. Can be null if no sound should play
|
||||
*/
|
||||
@Nullable
|
||||
public SoundEvent getSound(@NotNull LivingEntity entity) {
|
||||
public @Nullable SoundEvent getSound(@NotNull LivingEntity entity) {
|
||||
if (entity instanceof Player) {
|
||||
return getPlayerSound((Player) entity);
|
||||
}
|
||||
|
@ -2,13 +2,12 @@ package net.minestom.server.entity.hologram;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.Viewable;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.metadata.other.ArmorStandMeta;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -68,7 +67,7 @@ public class Hologram implements Viewable {
|
||||
|
||||
armorStandMeta.setNotifyAboutChanges(false);
|
||||
|
||||
if(marker) {
|
||||
if (marker) {
|
||||
this.yOffset = MARKER_OFFSET_Y;
|
||||
armorStandMeta.setMarker(true);
|
||||
} else {
|
||||
@ -109,17 +108,6 @@ public class Hologram implements Viewable {
|
||||
this.entity.teleport(this.position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hologram text.
|
||||
*
|
||||
* @return the hologram text
|
||||
* @deprecated Use {@link #getText()}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage getTextJson() {
|
||||
return JsonMessage.fromComponent(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the hologram text.
|
||||
*
|
||||
@ -129,17 +117,6 @@ public class Hologram implements Viewable {
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the hologram text.
|
||||
*
|
||||
* @param text the new hologram text
|
||||
* @deprecated Use {@link #setText(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setText(JsonMessage text) {
|
||||
this.setText(text.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the hologram text.
|
||||
*
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.entity.metadata;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -107,24 +106,6 @@ public class EntityMeta {
|
||||
this.metadata.setIndex(OFFSET + 1, Metadata.VarInt(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getCustomName()}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage getCustomNameJson() {
|
||||
return JsonMessage.fromComponent(this.getCustomName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setCustomName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setCustomName(JsonMessage value) {
|
||||
if (value != null) {
|
||||
this.setCustomName(value.asComponent());
|
||||
}
|
||||
}
|
||||
|
||||
public Component getCustomName() {
|
||||
return this.metadata.getIndex(OFFSET + 2, null);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.entity.metadata.minecart;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Metadata;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -14,8 +13,7 @@ public class CommandBlockMinecartMeta extends AbstractMinecartMeta {
|
||||
super(entity, metadata);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getCommand() {
|
||||
public @NotNull String getCommand() {
|
||||
return super.metadata.getIndex(OFFSET, "");
|
||||
}
|
||||
|
||||
@ -23,28 +21,10 @@ public class CommandBlockMinecartMeta extends AbstractMinecartMeta {
|
||||
super.metadata.setIndex(OFFSET, Metadata.String(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getLastOutput()}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public JsonMessage getLastOutputJson() {
|
||||
return JsonMessage.fromComponent(getLastOutput());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Component getLastOutput() {
|
||||
public @NotNull Component getLastOutput() {
|
||||
return super.metadata.getIndex(OFFSET + 1, Component.empty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #setLastOutput(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setLastOutput(@NotNull JsonMessage value) {
|
||||
this.setLastOutput(value.asComponent());
|
||||
}
|
||||
|
||||
public void setLastOutput(@NotNull Component value) {
|
||||
super.metadata.setIndex(OFFSET + 1, Metadata.Chat(value));
|
||||
}
|
||||
@ -53,5 +33,4 @@ public class CommandBlockMinecartMeta extends AbstractMinecartMeta {
|
||||
public int getObjectData() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.event.player;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.trait.CancellableEvent;
|
||||
import net.minestom.server.event.trait.PlayerEvent;
|
||||
@ -36,17 +35,6 @@ public class PlayerChatEvent implements PlayerEvent, CancellableEvent {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the chat format.
|
||||
*
|
||||
* @param chatFormat the custom chat format, null to use the default one
|
||||
* @deprecated Use {@link #setChatFormat(Function)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setChatFormatJson(@Nullable Function<PlayerChatEvent, JsonMessage> chatFormat) {
|
||||
this.chatFormat = chatFormat == null ? null : chatFormat.andThen(JsonMessage::asComponent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the chat format.
|
||||
*
|
||||
|
@ -1,9 +1,7 @@
|
||||
package net.minestom.server.event.player;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.event.Event;
|
||||
import net.minestom.server.event.trait.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -17,14 +15,6 @@ public class PlayerDeathEvent implements PlayerEvent {
|
||||
private Component deathText;
|
||||
private Component chatMessage;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #PlayerDeathEvent(Player, Component, Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public PlayerDeathEvent(@NotNull Player player, JsonMessage deathText, JsonMessage chatMessage) {
|
||||
this(player, deathText.asComponent(), chatMessage.asComponent());
|
||||
}
|
||||
|
||||
public PlayerDeathEvent(@NotNull Player player, Component deathText, Component chatMessage) {
|
||||
this.player = player;
|
||||
this.deathText = deathText;
|
||||
@ -35,35 +25,11 @@ public class PlayerDeathEvent implements PlayerEvent {
|
||||
* Gets the text displayed in the death screen.
|
||||
*
|
||||
* @return the death text, can be null
|
||||
* @deprecated Use {@link #getDeathText()}
|
||||
*/
|
||||
@Nullable
|
||||
@Deprecated
|
||||
public JsonMessage getDeathTextJson() {
|
||||
return JsonMessage.fromComponent(deathText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text displayed in the death screen.
|
||||
*
|
||||
* @return the death text, can be null
|
||||
*/
|
||||
@Nullable
|
||||
public Component getDeathText() {
|
||||
public @Nullable Component getDeathText() {
|
||||
return deathText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text displayed in the death screen.
|
||||
*
|
||||
* @param deathText the death text to display, null to remove
|
||||
* @deprecated Use {@link #setDeathText(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setDeathText(@Nullable JsonMessage deathText) {
|
||||
this.deathText = deathText == null ? null : deathText.asComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text displayed in the death screen.
|
||||
*
|
||||
@ -77,35 +43,11 @@ public class PlayerDeathEvent implements PlayerEvent {
|
||||
* Gets the message sent to chat.
|
||||
*
|
||||
* @return the death chat message
|
||||
* @deprecated Use {@link #getChatMessage()}
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public JsonMessage getChatMessageJson() {
|
||||
return JsonMessage.fromComponent(chatMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message sent to chat.
|
||||
*
|
||||
* @return the death chat message
|
||||
*/
|
||||
@Nullable
|
||||
public Component getChatMessage() {
|
||||
public @Nullable Component getChatMessage() {
|
||||
return chatMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text sent in chat
|
||||
*
|
||||
* @param chatMessage the death message to send, null to remove
|
||||
* @deprecated Use {@link #setChatMessage(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setChatMessage(@Nullable JsonMessage chatMessage) {
|
||||
this.chatMessage = chatMessage == null ? null : chatMessage.asComponent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the text sent in chat
|
||||
*
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.item.metadata;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.color.Color;
|
||||
import net.minestom.server.item.ItemMeta;
|
||||
import net.minestom.server.item.ItemMetaBuilder;
|
||||
@ -62,17 +61,6 @@ public class MapMeta extends ItemMeta implements ItemMetaBuilder.Provider<MapMet
|
||||
return decorations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map color.
|
||||
*
|
||||
* @return the map color
|
||||
* @deprecated Use {@link #getMapColor()}
|
||||
*/
|
||||
@Deprecated
|
||||
public ChatColor getLegacyMapColor() {
|
||||
return this.mapColor.asLegacyChatColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map color.
|
||||
*
|
||||
|
@ -1,12 +1,9 @@
|
||||
package net.minestom.server.network;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.adventure.audience.Audiences;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.fakeplayer.FakePlayer;
|
||||
import net.minestom.server.event.EventDispatcher;
|
||||
@ -23,7 +20,6 @@ import net.minestom.server.network.player.NettyPlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.StringUtils;
|
||||
import net.minestom.server.utils.async.AsyncUtils;
|
||||
import net.minestom.server.utils.callback.validator.PlayerValidator;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -35,7 +31,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Manages the connected clients.
|
||||
@ -134,33 +129,6 @@ public final class ConnectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a {@link JsonMessage} to all online players who validate the condition {@code condition}.
|
||||
*
|
||||
* @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 Audiences#players(Predicate)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void broadcastMessage(@NotNull JsonMessage jsonMessage, @Nullable PlayerValidator condition) {
|
||||
if (condition == null) {
|
||||
Audiences.players().sendMessage(jsonMessage);
|
||||
} else {
|
||||
Audiences.players(condition).sendMessage(jsonMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 Audience#sendMessage(Component)} on {@link Audiences#players()}
|
||||
*/
|
||||
@Deprecated
|
||||
public void broadcastMessage(@NotNull JsonMessage jsonMessage) {
|
||||
this.broadcastMessage(jsonMessage, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the listeners which are called for each packet received.
|
||||
*
|
||||
@ -260,18 +228,6 @@ public final class ConnectionManager {
|
||||
return playerProvider == null ? playerProvider = Player::new : playerProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()}.
|
||||
*
|
||||
@ -281,18 +237,6 @@ public final class ConnectionManager {
|
||||
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.
|
||||
*
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.minestom.server.network.packet.server.login;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
@ -23,14 +22,6 @@ public class LoginDisconnectPacket implements ComponentHoldingServerPacket {
|
||||
this.kickMessage = kickMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #LoginDisconnectPacket(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public LoginDisconnectPacket(@NotNull JsonMessage jsonKickMessage) {
|
||||
this(jsonKickMessage.asComponent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeComponent(kickMessage);
|
||||
|
@ -3,7 +3,6 @@ package net.minestom.server.scoreboard;
|
||||
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.DisplayScoreboardPacket;
|
||||
import net.minestom.server.network.packet.server.play.ScoreboardObjectivePacket;
|
||||
@ -139,18 +138,6 @@ public class Sidebar implements Scoreboard {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a {@link ScoreboardLine} content through the given identifier.
|
||||
*
|
||||
* @param id The identifier of the {@link ScoreboardLine}
|
||||
* @param content The new content for the {@link ScoreboardLine}
|
||||
* @deprecated Use {@link #updateLineContent(String, Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateLineContent(@NotNull String id, @NotNull JsonMessage content) {
|
||||
this.updateLineContent(id, content.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a {@link ScoreboardLine} content through the given identifier.
|
||||
*
|
||||
@ -295,14 +282,6 @@ public class Sidebar implements Scoreboard {
|
||||
*/
|
||||
private SidebarTeam sidebarTeam;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #ScoreboardLine(String, Component, int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public ScoreboardLine(@NotNull String id, @NotNull JsonMessage content, int line) {
|
||||
this(id, content.asComponent(), line);
|
||||
}
|
||||
|
||||
public ScoreboardLine(@NotNull String id, @NotNull Component content, int line) {
|
||||
this.id = id;
|
||||
this.content = content;
|
||||
@ -316,8 +295,7 @@ public class Sidebar implements Scoreboard {
|
||||
*
|
||||
* @return the line identifier
|
||||
*/
|
||||
@NotNull
|
||||
public String getId() {
|
||||
public @NotNull String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -325,21 +303,8 @@ public class Sidebar implements Scoreboard {
|
||||
* Gets the content of the line
|
||||
*
|
||||
* @return The line content
|
||||
* @deprecated Use {@link #getContent()}
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public JsonMessage getContentJson() {
|
||||
return JsonMessage.fromComponent(getContent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of the line
|
||||
*
|
||||
* @return The line content
|
||||
*/
|
||||
@NotNull
|
||||
public Component getContent() {
|
||||
public @NotNull Component getContent() {
|
||||
return sidebarTeam == null ? content : sidebarTeam.getPrefix();
|
||||
}
|
||||
|
||||
@ -536,6 +501,4 @@ public class Sidebar implements Scoreboard {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,10 +5,7 @@ import net.kyori.adventure.pointer.Pointers;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.adventure.AdventurePacketConvertor;
|
||||
import net.minestom.server.adventure.audience.PacketGroupingAudience;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.entity.LivingEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
@ -149,19 +146,6 @@ public class Team implements PacketGroupingAudience {
|
||||
this.isPlayerMembersUpToDate = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the display name of the team.
|
||||
* <br><br>
|
||||
* <b>Warning:</b> This is only changed <b>server side</b>.
|
||||
*
|
||||
* @param teamDisplayName The new display name
|
||||
* @deprecated Use {@link #setTeamDisplayName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setTeamDisplayName(JsonMessage teamDisplayName) {
|
||||
this.setTeamDisplayName(teamDisplayName.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the display name of the team.
|
||||
* <br><br>
|
||||
@ -173,17 +157,6 @@ public class Team implements PacketGroupingAudience {
|
||||
this.teamDisplayName = teamDisplayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the display name of the team and sends an update packet.
|
||||
*
|
||||
* @param teamDisplayName The new display name
|
||||
* @deprecated Use {@link #updateTeamDisplayName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateTeamDisplayName(JsonMessage teamDisplayName) {
|
||||
this.updateTeamDisplayName(teamDisplayName.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the display name of the team and sends an update packet.
|
||||
*
|
||||
@ -238,20 +211,6 @@ public class Team implements PacketGroupingAudience {
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the color of the team.
|
||||
* <br><br>
|
||||
* <b>Warning:</b> This is only changed on the <b>server side</b>.
|
||||
*
|
||||
* @param color The new team color
|
||||
* @see #updateTeamColor(ChatColor)
|
||||
* @deprecated Use {@link #setTeamColor(NamedTextColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setTeamColor(@NotNull ChatColor color) {
|
||||
this.setTeamColor(NamedTextColor.nearestTo(color.asTextColor()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the color of the team.
|
||||
* <br><br>
|
||||
@ -264,17 +223,6 @@ public class Team implements PacketGroupingAudience {
|
||||
this.teamColor = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the color of the team and sends an update packet.
|
||||
*
|
||||
* @param chatColor The new team color
|
||||
* @deprecated Use {@link #updateTeamColor(NamedTextColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateTeamColor(@NotNull ChatColor chatColor) {
|
||||
this.updateTeamColor(NamedTextColor.nearestTo(chatColor.asTextColor()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the color of the team and sends an update packet.
|
||||
*
|
||||
@ -285,19 +233,6 @@ public class Team implements PacketGroupingAudience {
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the prefix of the team.
|
||||
* <br><br>
|
||||
* <b>Warning:</b> This is only changed on the <b>server side</b>.
|
||||
*
|
||||
* @param prefix The new prefix
|
||||
* @deprecated Use {@link #setPrefix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPrefix(JsonMessage prefix) {
|
||||
this.setPrefix(prefix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the prefix of the team.
|
||||
* <br><br>
|
||||
@ -309,17 +244,6 @@ public class Team implements PacketGroupingAudience {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the prefix of the team and sends an update packet.
|
||||
*
|
||||
* @param prefix The new prefix
|
||||
* @deprecated Use {@link #updatePrefix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void updatePrefix(JsonMessage prefix) {
|
||||
this.updatePrefix(prefix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the prefix of the team and sends an update packet.
|
||||
*
|
||||
@ -330,19 +254,6 @@ public class Team implements PacketGroupingAudience {
|
||||
sendUpdatePacket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the suffix of the team.
|
||||
* <br><br>
|
||||
* <b>Warning:</b> This is only changed on the <b>server side</b>.
|
||||
*
|
||||
* @param suffix The new suffix
|
||||
* @deprecated Use {@link #setSuffix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setSuffix(JsonMessage suffix) {
|
||||
this.setSuffix(suffix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the suffix of the team.
|
||||
* <br><br>
|
||||
@ -354,17 +265,6 @@ public class Team implements PacketGroupingAudience {
|
||||
this.suffix = suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the suffix of the team and sends an update packet.
|
||||
*
|
||||
* @param suffix The new suffix
|
||||
* @deprecated Use {@link #updateSuffix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void updateSuffix(JsonMessage suffix) {
|
||||
this.updateSuffix(suffix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the suffix of the team and sends an update packet.
|
||||
*
|
||||
@ -445,22 +345,10 @@ public class Team implements PacketGroupingAudience {
|
||||
*
|
||||
* @return an unmodifiable {@link Set} of registered players
|
||||
*/
|
||||
@NotNull
|
||||
public Set<String> getMembers() {
|
||||
public @NotNull Set<String> getMembers() {
|
||||
return Collections.unmodifiableSet(members);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name of the team.
|
||||
*
|
||||
* @return the display name
|
||||
* @deprecated Use {@link #getTeamDisplayName()}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage getTeamDisplayNameJson() {
|
||||
return JsonMessage.fromComponent(this.teamDisplayName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name of the team.
|
||||
*
|
||||
@ -484,8 +372,7 @@ public class Team implements PacketGroupingAudience {
|
||||
*
|
||||
* @return the tag visibility
|
||||
*/
|
||||
@NotNull
|
||||
public NameTagVisibility getNameTagVisibility() {
|
||||
public @NotNull NameTagVisibility getNameTagVisibility() {
|
||||
return nameTagVisibility;
|
||||
}
|
||||
|
||||
@ -494,8 +381,7 @@ public class Team implements PacketGroupingAudience {
|
||||
*
|
||||
* @return the collision rule
|
||||
*/
|
||||
@NotNull
|
||||
public CollisionRule getCollisionRule() {
|
||||
public @NotNull CollisionRule getCollisionRule() {
|
||||
return collisionRule;
|
||||
}
|
||||
|
||||
@ -503,35 +389,11 @@ public class Team implements PacketGroupingAudience {
|
||||
* Gets the color of the team.
|
||||
*
|
||||
* @return the team color
|
||||
* @deprecated Use {@link #getTeamColor()}
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public ChatColor getTeamColorOld() {
|
||||
return ChatColor.fromId(AdventurePacketConvertor.getNamedTextColorValue(teamColor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color of the team.
|
||||
*
|
||||
* @return the team color
|
||||
*/
|
||||
@NotNull
|
||||
public NamedTextColor getTeamColor() {
|
||||
public @NotNull NamedTextColor getTeamColor() {
|
||||
return teamColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the prefix of the team.
|
||||
*
|
||||
* @return the team prefix
|
||||
* @deprecated Use {@link #getPrefix()}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage getPrefixJson() {
|
||||
return JsonMessage.fromComponent(prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the prefix of the team.
|
||||
*
|
||||
@ -541,17 +403,6 @@ public class Team implements PacketGroupingAudience {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the suffix of the team.
|
||||
*
|
||||
* @return the suffix team
|
||||
* @deprecated Use {@link #getSuffix()}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage getSuffixJson() {
|
||||
return JsonMessage.fromComponent(suffix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the suffix of the team.
|
||||
*
|
||||
|
@ -2,8 +2,6 @@ package net.minestom.server.scoreboard;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket.CollisionRule;
|
||||
import net.minestom.server.network.packet.server.play.TeamsPacket.NameTagVisibility;
|
||||
|
||||
@ -47,30 +45,6 @@ public class TeamBuilder {
|
||||
this.updateTeam = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the prefix of the {@link Team}.
|
||||
*
|
||||
* @param prefix The new prefix
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #updatePrefix(Component)}}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder updatePrefix(String prefix) {
|
||||
return this.updatePrefix(Component.text(prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the prefix of the {@link Team}.
|
||||
*
|
||||
* @param prefix The new prefix
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #updatePrefix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder updatePrefix(JsonMessage prefix) {
|
||||
return this.updatePrefix(prefix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the prefix of the {@link Team}.
|
||||
*
|
||||
@ -82,18 +56,6 @@ public class TeamBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the color of the {@link Team}.
|
||||
*
|
||||
* @param color The new color
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #updateTeamColor(NamedTextColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder updateTeamColor(ChatColor color) {
|
||||
return this.updateTeamColor(NamedTextColor.nearestTo(color.asTextColor()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the color of the {@link Team}.
|
||||
*
|
||||
@ -105,30 +67,6 @@ public class TeamBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the suffix of the {@link Team}.
|
||||
*
|
||||
* @param suffix The new suffix
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #updateSuffix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder updateSuffix(String suffix) {
|
||||
return this.updateSuffix(Component.text(suffix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the suffix of the {@link Team}.
|
||||
*
|
||||
* @param suffix The new suffix
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #updateSuffix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder updateSuffix(JsonMessage suffix) {
|
||||
return this.updateSuffix(suffix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the suffix of the {@link Team}.
|
||||
*
|
||||
@ -140,30 +78,6 @@ public class TeamBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the display name of the {@link Team}.
|
||||
*
|
||||
* @param displayName The new display name
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #updateTeamDisplayName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder updateTeamDisplayName(String displayName) {
|
||||
return this.updateTeamDisplayName(Component.text(displayName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the display name of the {@link Team}.
|
||||
*
|
||||
* @param displayName The new display name
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #updateTeamDisplayName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder updateTeamDisplayName(JsonMessage displayName) {
|
||||
return this.updateTeamDisplayName(displayName.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the display name of the {@link Team}.
|
||||
*
|
||||
@ -226,34 +140,6 @@ public class TeamBuilder {
|
||||
return this.updateFriendlyFlags((byte) 0x01);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the prefix of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
* <b>Warning: </b> If you do not call {@link #updateTeamPacket()}, this is only changed of the <b>server side</b>.
|
||||
*
|
||||
* @param prefix The new prefix
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #prefix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder prefix(String prefix) {
|
||||
return this.prefix(Component.text(prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the prefix of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
* <b>Warning: </b> If you do not call {@link #updateTeamPacket()}, this is only changed of the <b>server side</b>.
|
||||
*
|
||||
* @param prefix The new prefix
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #prefix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder prefix(JsonMessage prefix) {
|
||||
return this.prefix(prefix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the prefix of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
@ -267,34 +153,6 @@ public class TeamBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the suffix of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
* <b>Warning: </b> If you do not call {@link #updateTeamPacket()}, this is only changed of the <b>server side</b>.
|
||||
*
|
||||
* @param suffix The new suffix
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #suffix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder suffix(String suffix) {
|
||||
return this.suffix(Component.text(suffix));
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the suffix of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
* <b>Warning: </b> If you do not call {@link #updateTeamPacket()}, this is only changed of the <b>server side</b>.
|
||||
*
|
||||
* @param suffix The new suffix
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #suffix(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder suffix(JsonMessage suffix) {
|
||||
return this.suffix(suffix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the suffix of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
@ -308,20 +166,6 @@ public class TeamBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the color of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
* <b>Warning: </b> If you do not call {@link #updateTeamPacket()}, this is only changed of the <b>server side</b>.
|
||||
*
|
||||
* @param color The new team color
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #teamColor(NamedTextColor)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder teamColor(ChatColor color) {
|
||||
return this.teamColor(NamedTextColor.nearestTo(color.asTextColor()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the color of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
@ -335,34 +179,6 @@ public class TeamBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the display name of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
* <b>Warning: </b> If you do not call {@link #updateTeamPacket()}, this is only changed of the <b>server side</b>.
|
||||
*
|
||||
* @param displayName The new display name
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #teamDisplayName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder teamDisplayName(String displayName) {
|
||||
return this.teamDisplayName(Component.text(displayName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the display name of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
* <b>Warning: </b> If you do not call {@link #updateTeamPacket()}, this is only changed of the <b>server side</b>.
|
||||
*
|
||||
* @param displayName The new display name
|
||||
* @return this builder, for chaining
|
||||
* @deprecated Use {@link #teamDisplayName(Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public TeamBuilder teamDisplayName(JsonMessage displayName) {
|
||||
return this.teamDisplayName(displayName.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the display name of the {@link Team} without an update packet.
|
||||
* <br><br>
|
||||
|
@ -3,8 +3,6 @@ package net.minestom.server.scoreboard;
|
||||
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.JsonMessage;
|
||||
import net.minestom.server.entity.LivingEntity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
@ -92,27 +90,12 @@ public final class TeamManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Team} with the registry name, prefix, suffix and the team color
|
||||
* Creates a {@link Team} with the registry name, prefix, suffix and the team format
|
||||
*
|
||||
* @param name The registry name
|
||||
* @param prefix The team prefix
|
||||
* @param teamColor The team color
|
||||
* @param suffix The team suffix
|
||||
* @return the created {@link Team} with a prefix, teamColor and suffix
|
||||
* @deprecated Use {@link #createTeam(String, Component, NamedTextColor, Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Team createTeam(String name, JsonMessage prefix, ChatColor teamColor, JsonMessage suffix) {
|
||||
return this.createTeam(name, prefix.asComponent(), NamedTextColor.nearestTo(teamColor.asTextColor()), suffix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Team} with the registry name, prefix, suffix and the team format
|
||||
*
|
||||
* @param name The registry name
|
||||
* @param prefix The team prefix
|
||||
* @param teamColor The team format
|
||||
* @param suffix The team suffix
|
||||
* @param suffix The team suffix
|
||||
* @return the created {@link Team} with a prefix, teamColor and suffix
|
||||
*/
|
||||
public Team createTeam(String name, Component prefix, NamedTextColor teamColor, Component suffix) {
|
||||
@ -128,22 +111,6 @@ public final class TeamManager {
|
||||
* @param teamColor The team color
|
||||
* @param suffix The team suffix
|
||||
* @return the created {@link Team} with a prefix, teamColor, suffix and the display name
|
||||
* @deprecated Use {@link #createTeam(String, Component, Component, NamedTextColor, Component)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Team createTeam(String name, JsonMessage displayName, JsonMessage prefix, ChatColor teamColor, JsonMessage suffix) {
|
||||
return this.createTeam(name, displayName.asComponent(), prefix.asComponent(), NamedTextColor.nearestTo(teamColor.asTextColor()), suffix.asComponent());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Team} with the registry name, display name, prefix, suffix and the team colro
|
||||
*
|
||||
* @param name The registry name
|
||||
* @param displayName The display name
|
||||
* @param prefix The team prefix
|
||||
* @param teamColor The team color
|
||||
* @param suffix The team suffix
|
||||
* @return the created {@link Team} with a prefix, teamColor, suffix and the display name
|
||||
*/
|
||||
public Team createTeam(String name, Component displayName, Component prefix, NamedTextColor teamColor, Component suffix) {
|
||||
return this.createBuilder(name).teamDisplayName(displayName).prefix(prefix).teamColor(teamColor).suffix(suffix).updateTeamPacket().build();
|
||||
|
@ -4,12 +4,11 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.NBTUtils;
|
||||
import net.minestom.server.utils.SerializerUtils;
|
||||
import net.minestom.server.utils.Utils;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBT;
|
||||
@ -187,23 +186,6 @@ public class BinaryReader extends InputStream {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as readItemStack
|
||||
*/
|
||||
@Deprecated
|
||||
public ItemStack readSlot() {
|
||||
return readItemStack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Use {@link #readComponent(int)}
|
||||
*/
|
||||
@Deprecated
|
||||
public JsonMessage readJsonMessage(int maxLength) {
|
||||
final String jsonObject = readSizedString(maxLength);
|
||||
return new JsonMessage.RawJsonMessage(jsonObject);
|
||||
}
|
||||
|
||||
public Component readComponent(int maxLength) {
|
||||
final String jsonObject = readSizedString(maxLength);
|
||||
return GsonComponentSerializer.gson().deserialize(jsonObject);
|
||||
|
@ -6,7 +6,6 @@ import io.netty.buffer.Unpooled;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
import net.minestom.server.coordinate.Point;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.SerializerUtils;
|
||||
@ -188,16 +187,6 @@ public class BinaryWriter extends OutputStream {
|
||||
buffer.writeCharSequence(string + '\0', charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a JsonMessage to the buffer.
|
||||
* Simply a writeSizedString with message.toString()
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public void writeJsonMessage(JsonMessage message) {
|
||||
writeSizedString(message.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a var-int array to the buffer.
|
||||
* <p>
|
||||
|
Loading…
Reference in New Issue
Block a user