Improve deprecation messages, allow ChatColor to be used in Adventure component styling

This commit is contained in:
Kieran Wallbanks 2021-04-04 14:40:29 +01:00
parent 785a0bb66c
commit 9182ab7e84
11 changed files with 47 additions and 5 deletions

View File

@ -2,7 +2,7 @@ package net.minestom.server.bossbar;
/**
* Represents the displayed color of a {@link BossBar}.
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar}
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar.Color}
*/
@Deprecated
public enum BarColor {

View File

@ -3,7 +3,7 @@ package net.minestom.server.bossbar;
/**
* Used to define the number of segments on a {@link BossBar}.
*
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar}
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar.Overlay}
*/
@Deprecated
public enum BarDivision {

View File

@ -20,7 +20,7 @@ import java.util.concurrent.CopyOnWriteArraySet;
* <p>
* You can retrieve all the boss bars of a {@link Player} with {@link #getBossBars(Player)}.
*
* @deprecated Use {@link net.kyori.adventure.audience.Audience#showBossBar(net.kyori.adventure.bossbar.BossBar)}
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar}
*/
@Deprecated
public class BossBar implements Viewable {

View File

@ -1,9 +1,11 @@
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 {

View File

@ -4,24 +4,31 @@ 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.TextColor;
import net.kyori.adventure.text.ComponentBuilder;
import net.kyori.adventure.text.format.*;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
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 {
public final class ChatColor implements StyleBuilderApplicable {
// Special
public static final ChatColor NO_COLOR = new ChatColor();
@ -310,4 +317,26 @@ public final class ChatColor {
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));
}
}
}

View File

@ -17,6 +17,7 @@ import java.util.UUID;
/**
* Represents a hover event for a specific portion of the message.
* @deprecated Use {@link HoverEvent}
*/
@Deprecated
public class ChatHoverEvent {

View File

@ -2,10 +2,12 @@ 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 {

View File

@ -2,6 +2,8 @@ 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;
@ -16,6 +18,7 @@ import java.util.regex.Pattern;
* <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 {

View File

@ -16,6 +16,7 @@ import java.util.Objects;
* 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 {

View File

@ -2,6 +2,7 @@ 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;
@ -18,6 +19,7 @@ import java.util.List;
* 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 {

View File

@ -1,10 +1,12 @@
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 {