From 55c82cfddb75e01bf76da377ffba5cf7e7b3adb6 Mon Sep 17 00:00:00 2001 From: EternalHuman Date: Tue, 31 Oct 2023 11:49:10 +0300 Subject: [PATCH 1/8] NamedTextColor -> GlowColor --- .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 1 + .../conversion/znpcs/ZNpcImporter.java | 1 + .../entity/EntityPropertyRegistryImpl.java | 2 +- .../entity/properties/GlowProperty.java | 8 +- .../GlowColorPropertySerializer.java | 22 ++ .../NamedTextColorPropertySerializer.java | 1 + .../pyr/znpcsplus/hologram/HologramImpl.java | 2 +- .../pyr/znpcsplus/packets/PacketFactory.java | 3 +- .../znpcsplus/packets/V1_17PacketFactory.java | 3 +- .../packets/V1_20_2PacketFactory.java | 3 +- .../znpcsplus/packets/V1_8PacketFactory.java | 9 +- .../znpcsplus/parsers/GlowColorParser.java | 21 ++ .../parsers/NamedTextColorParser.java | 1 + .../lol/pyr/znpcsplus/util/GlowColor.java | 252 ++++++++++++++++++ 14 files changed, 316 insertions(+), 13 deletions(-) create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/parsers/GlowColorParser.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index 5aaa60a..b71004c 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -247,6 +247,7 @@ public class ZNpcsPlus { manager.registerParser(Float.class, new FloatParser(incorrectUsageMessage)); manager.registerParser(Boolean.class, new BooleanParser(incorrectUsageMessage)); manager.registerParser(NamedTextColor.class, new NamedTextColorParser(incorrectUsageMessage)); + manager.registerParser(GlowColor.class, new GlowColorParser(incorrectUsageMessage)); manager.registerParser(InteractionType.class, new InteractionTypeParser(incorrectUsageMessage)); manager.registerParser(Color.class, new ColorParser(incorrectUsageMessage)); manager.registerParser(Vector3f.class, new Vector3fParser(incorrectUsageMessage)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java index 09233b6..3ecdad1 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/conversion/znpcs/ZNpcImporter.java @@ -36,6 +36,7 @@ import lol.pyr.znpcsplus.util.LookType; import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.DyeColor; import org.bukkit.inventory.ItemStack; diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java index 86662d7..ee1a5be 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -49,7 +49,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { public EntityPropertyRegistryImpl(MojangSkinCache skinCache, ConfigManager configManager) { registerSerializer(new ComponentPropertySerializer()); - registerSerializer(new NamedTextColorPropertySerializer()); + registerSerializer(new GlowColorPropertySerializer()); registerSerializer(new SkinDescriptorSerializer(skinCache)); registerSerializer(new ItemStackPropertySerializer()); registerSerializer(new ColorPropertySerializer()); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java index 13931d8..6c45325 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java @@ -5,22 +5,22 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.packets.PacketFactory; -import net.kyori.adventure.text.format.NamedTextColor; +import lol.pyr.znpcsplus.util.GlowColor; import org.bukkit.entity.Player; import java.util.Map; -public class GlowProperty extends EntityPropertyImpl { +public class GlowProperty extends EntityPropertyImpl { private final PacketFactory packetFactory; public GlowProperty(PacketFactory packetFactory) { - super("glow", null, NamedTextColor.class); + super("glow", null, GlowColor.class); this.packetFactory = packetFactory; } @Override public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { - NamedTextColor value = entity.getProperty(this); + GlowColor value = entity.getProperty(this); EntityData oldData = properties.get(0); byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (value == null ? 0 : 0x40)))); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java new file mode 100644 index 0000000..c7f2d4f --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java @@ -0,0 +1,22 @@ +package lol.pyr.znpcsplus.entity.serializers; + +import lol.pyr.znpcsplus.entity.PropertySerializer; +import lol.pyr.znpcsplus.util.GlowColor; +import net.kyori.adventure.text.format.NamedTextColor; + +public class GlowColorPropertySerializer implements PropertySerializer { + @Override + public String serialize(GlowColor property) { + return String.valueOf(property.value()); + } + + @Override + public GlowColor deserialize(String property) { + return GlowColor.namedColor(Integer.parseInt(property)); + } + + @Override + public Class getTypeClass() { + return GlowColor.class; + } +} \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedTextColorPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedTextColorPropertySerializer.java index 49eea80..8916ae4 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedTextColorPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedTextColorPropertySerializer.java @@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.entity.serializers; import lol.pyr.znpcsplus.entity.PropertySerializer; import net.kyori.adventure.text.format.NamedTextColor; +@Deprecated public class NamedTextColorPropertySerializer implements PropertySerializer { @Override public String serialize(NamedTextColor property) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java index e1816e0..2380fdd 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java @@ -45,7 +45,7 @@ public class HologramImpl extends Viewable implements Hologram { } public void addTextLine(String line) { - addTextLineComponent(textSerializer.deserialize(textSerializer.serialize(MiniMessage.miniMessage().deserialize(line)))); + addTextLineComponent(Component.text(line)); } public void addItemLineStack(org.bukkit.inventory.ItemStack item) { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java index 462a99d..32dd8a5 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java @@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.player.Equipment; import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.entity.PacketEntity; +import lol.pyr.znpcsplus.util.GlowColor; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.entity.Player; @@ -17,7 +18,7 @@ public interface PacketFactory { void teleportEntity(Player player, PacketEntity entity); CompletableFuture addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties); void removeTabPlayer(Player player, PacketEntity entity); - void createTeam(Player player, PacketEntity entity, NamedTextColor glowColor); + void createTeam(Player player, PacketEntity entity, GlowColor glowColor); void removeTeam(Player player, PacketEntity entity); void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties); void sendEquipment(Player player, PacketEntity entity, Equipment equipment); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java index dcb4c27..5a26b85 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java @@ -8,6 +8,7 @@ import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.scheduling.TaskScheduler; +import lol.pyr.znpcsplus.util.GlowColor; import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -27,6 +28,6 @@ public class V1_17PacketFactory extends V1_8PacketFactory { sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d()))); sendAllMetadata(player, entity, properties); - createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class))); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class))); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_20_2PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_20_2PacketFactory.java index 6b44216..bfdf5bd 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_20_2PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_20_2PacketFactory.java @@ -9,6 +9,7 @@ import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.scheduling.TaskScheduler; +import lol.pyr.znpcsplus.util.GlowColor; import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; @@ -28,7 +29,7 @@ public class V1_20_2PacketFactory extends V1_19_2PacketFactory { @Override public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) { addTabPlayer(player, entity, properties).thenAccept(ignored -> { - createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class))); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class))); NpcLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d()))); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index 1bee6a7..8aa3a08 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -20,6 +20,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.skin.BaseSkinDescriptor; +import lol.pyr.znpcsplus.util.GlowColor; import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -48,7 +49,7 @@ public class V1_8PacketFactory implements PacketFactory { @Override public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) { addTabPlayer(player, entity, properties).thenAccept(ignored -> { - createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class))); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class))); NpcLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(), entity.getUuid(), npcLocationToVector(location), location.getYaw(), location.getPitch(), Collections.emptyList())); @@ -69,7 +70,7 @@ public class V1_8PacketFactory implements PacketFactory { new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); sendAllMetadata(player, entity, properties); - createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class))); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class))); } protected Vector3d npcLocationToVector(NpcLocation location) { @@ -111,12 +112,12 @@ public class V1_8PacketFactory implements PacketFactory { } @Override - public void createTeam(Player player, PacketEntity entity, NamedTextColor glowColor) { + public void createTeam(Player player, PacketEntity entity, GlowColor glowColor) { sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.CREATE, new WrapperPlayServerTeams.ScoreBoardTeamInfo( Component.empty(), Component.empty(), Component.empty(), WrapperPlayServerTeams.NameTagVisibility.NEVER, WrapperPlayServerTeams.CollisionRule.NEVER, - glowColor == null ? NamedTextColor.WHITE : glowColor, + glowColor == null ? NamedTextColor.WHITE : glowColor.toNamedTextColor(), WrapperPlayServerTeams.OptionData.NONE ))); sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.ADD_ENTITIES, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null, diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/parsers/GlowColorParser.java b/plugin/src/main/java/lol/pyr/znpcsplus/parsers/GlowColorParser.java new file mode 100644 index 0000000..1210bb5 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/parsers/GlowColorParser.java @@ -0,0 +1,21 @@ +package lol.pyr.znpcsplus.parsers; + +import lol.pyr.director.adventure.command.CommandContext; +import lol.pyr.director.adventure.parse.ParserType; +import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.director.common.message.Message; +import lol.pyr.znpcsplus.util.GlowColor; +import java.util.Deque; + +public class GlowColorParser extends ParserType { + public GlowColorParser(Message message) { + super(message); + } + + @Override + public GlowColor parse(Deque deque) throws CommandExecutionException { + GlowColor color = GlowColor.NAMES.value(deque.pop()); + if (color == null) throw new CommandExecutionException(); + return color; + } +} \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedTextColorParser.java b/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedTextColorParser.java index f399d47..604f74d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedTextColorParser.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedTextColorParser.java @@ -8,6 +8,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.util.Deque; +@Deprecated public class NamedTextColorParser extends ParserType { public NamedTextColorParser(Message message) { super(message); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java b/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java new file mode 100644 index 0000000..fd0fb68 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java @@ -0,0 +1,252 @@ +package lol.pyr.znpcsplus.util; + +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.util.HSVLike; +import net.kyori.adventure.util.Index; +import net.kyori.examination.ExaminableProperty; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Stream; + +public class GlowColor implements TextColor { + private static final int BLACK_VALUE = 0x000000; + private static final int DARK_BLUE_VALUE = 0x0000aa; + private static final int DARK_GREEN_VALUE = 0x00aa00; + private static final int DARK_AQUA_VALUE = 0x00aaaa; + private static final int DARK_RED_VALUE = 0xaa0000; + private static final int DARK_PURPLE_VALUE = 0xaa00aa; + private static final int GOLD_VALUE = 0xffaa00; + private static final int GRAY_VALUE = 0xaaaaaa; + private static final int DARK_GRAY_VALUE = 0x555555; + private static final int BLUE_VALUE = 0x5555ff; + private static final int GREEN_VALUE = 0x55ff55; + private static final int AQUA_VALUE = 0x55ffff; + private static final int RED_VALUE = 0xff5555; + private static final int LIGHT_PURPLE_VALUE = 0xff55ff; + private static final int YELLOW_VALUE = 0xffff55; + private static final int WHITE_VALUE = 0xffffff; + + /** + * The standard {@code black} colour. + * + * @since 4.0.0 + */ + public static final GlowColor BLACK = new GlowColor("black", BLACK_VALUE); + /** + * The standard {@code dark_blue} colour. + * + * @since 4.0.0 + */ + public static final GlowColor DARK_BLUE = new GlowColor("dark_blue", DARK_BLUE_VALUE); + /** + * The standard {@code dark_green} colour. + * + * @since 4.0.0 + */ + public static final GlowColor DARK_GREEN = new GlowColor("dark_green", DARK_GREEN_VALUE); + /** + * The standard {@code dark_aqua} colour. + * + * @since 4.0.0 + */ + public static final GlowColor DARK_AQUA = new GlowColor("dark_aqua", DARK_AQUA_VALUE); + /** + * The standard {@code dark_red} colour. + * + * @since 4.0.0 + */ + public static final GlowColor DARK_RED = new GlowColor("dark_red", DARK_RED_VALUE); + /** + * The standard {@code dark_purple} colour. + * + * @since 4.0.0 + */ + public static final GlowColor DARK_PURPLE = new GlowColor("dark_purple", DARK_PURPLE_VALUE); + /** + * The standard {@code gold} colour. + * + * @since 4.0.0 + */ + public static final GlowColor GOLD = new GlowColor("gold", GOLD_VALUE); + /** + * The standard {@code gray} colour. + * + * @since 4.0.0 + */ + public static final GlowColor GRAY = new GlowColor("gray", GRAY_VALUE); + /** + * The standard {@code dark_gray} colour. + * + * @since 4.0.0 + */ + public static final GlowColor DARK_GRAY = new GlowColor("dark_gray", DARK_GRAY_VALUE); + /** + * The standard {@code blue} colour. + * + * @since 4.0.0 + */ + public static final GlowColor BLUE = new GlowColor("blue", BLUE_VALUE); + /** + * The standard {@code green} colour. + * + * @since 4.0.0 + */ + public static final GlowColor GREEN = new GlowColor("green", GREEN_VALUE); + /** + * The standard {@code aqua} colour. + * + * @since 4.0.0 + */ + public static final GlowColor AQUA = new GlowColor("aqua", AQUA_VALUE); + /** + * The standard {@code red} colour. + * + * @since 4.0.0 + */ + public static final GlowColor RED = new GlowColor("red", RED_VALUE); + /** + * The standard {@code light_purple} colour. + * + * @since 4.0.0 + */ + public static final GlowColor LIGHT_PURPLE = new GlowColor("light_purple", LIGHT_PURPLE_VALUE); + /** + * The standard {@code yellow} colour. + * + * @since 4.0.0 + */ + public static final GlowColor YELLOW = new GlowColor("yellow", YELLOW_VALUE); + /** + * The standard {@code white} colour. + * + * @since 4.0.0 + */ + public static final GlowColor WHITE = new GlowColor("white", WHITE_VALUE); + + private static final List VALUES = Collections.unmodifiableList(Arrays.asList(BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE)); + /** + * An index of name to color. + * + * @since 4.0.0 + */ + public static final Index NAMES = Index.create(constant -> constant.name, VALUES); + + /** + * Gets the named color exactly matching the provided color. + * + * @param value the color to match + * @return the matched color, or null + * @since 4.10.0 + */ + public static @Nullable GlowColor namedColor(final int value) { + switch (value) { + case BLACK_VALUE: return BLACK; + case DARK_BLUE_VALUE: return DARK_BLUE; + case DARK_GREEN_VALUE: return DARK_GREEN; + case DARK_AQUA_VALUE: return DARK_AQUA; + case DARK_RED_VALUE: return DARK_RED; + case DARK_PURPLE_VALUE: return DARK_PURPLE; + case GOLD_VALUE: return GOLD; + case GRAY_VALUE: return GRAY; + case DARK_GRAY_VALUE: return DARK_GRAY; + case BLUE_VALUE: return BLUE; + case GREEN_VALUE: return GREEN; + case AQUA_VALUE: return AQUA; + case RED_VALUE: return RED; + case LIGHT_PURPLE_VALUE: return LIGHT_PURPLE; + case YELLOW_VALUE: return YELLOW; + case WHITE_VALUE: return WHITE; + default: return null; + } + } + + /** + * Gets the named color exactly matching the provided color. + * + * @param value the color to match + * @return the matched color, or null + * @since 4.0.0 + * @deprecated for removal since 4.10.0, use {@link #namedColor(int)} instead + */ + @Deprecated + @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") + public static @Nullable GlowColor ofExact(final int value) { + switch (value) { + case BLACK_VALUE: return BLACK; + case DARK_BLUE_VALUE: return DARK_BLUE; + case DARK_GREEN_VALUE: return DARK_GREEN; + case DARK_AQUA_VALUE: return DARK_AQUA; + case DARK_RED_VALUE: return DARK_RED; + case DARK_PURPLE_VALUE: return DARK_PURPLE; + case GOLD_VALUE: return GOLD; + case GRAY_VALUE: return GRAY; + case DARK_GRAY_VALUE: return DARK_GRAY; + case BLUE_VALUE: return BLUE; + case GREEN_VALUE: return GREEN; + case AQUA_VALUE: return AQUA; + case RED_VALUE: return RED; + case LIGHT_PURPLE_VALUE: return LIGHT_PURPLE; + case YELLOW_VALUE: return YELLOW; + case WHITE_VALUE: return WHITE; + default: return null; + } + } + + /** + * Find the named colour nearest to the provided colour. + * + * @param any colour to match + * @return nearest named colour. will always return a value + * @since 4.0.0 + */ + public static @NotNull GlowColor nearestTo(final @NotNull TextColor any) { + if (any instanceof NamedTextColor) { + return (GlowColor) any; + } + + return TextColor.nearestColorTo(VALUES, any); + } + + private final String name; + private final int value; + private final HSVLike hsv; + + private GlowColor(final String name, final int value) { + this.name = name; + this.value = value; + this.hsv = HSVLike.fromRGB(this.red(), this.green(), this.blue()); + } + + @Override + public int value() { + return this.value; + } + + public NamedTextColor toNamedTextColor() { + return NamedTextColor.namedColor(this.value); + } + + @Override + public @NotNull HSVLike asHSV() { + return this.hsv; + } + + @Override + public @NotNull String toString() { + return this.name; + } + + @Override + public @NotNull Stream examinableProperties() { + return Stream.concat( + Stream.of(ExaminableProperty.of("name", this.name)), + TextColor.super.examinableProperties() + ); + } +} From 95a9a6b140d75ba2e450ab3d6ff454c88a8d05df Mon Sep 17 00:00:00 2001 From: EternalHuman Date: Tue, 31 Oct 2023 11:50:15 +0300 Subject: [PATCH 2/8] NamedTextColor -> GlowColor --- .../pyr/znpcsplus/commands/property/PropertySetCommand.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index d5ff9dd..caa6bda 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -61,6 +61,10 @@ public class PropertySetCommand implements CommandHandler { value = null; valueName = "NONE"; } + else if (type == GlowColor.class && context.argSize() < 1 && npc.getProperty(property) != null) { + value = null; + valueName = "NONE"; + } else if (type == Color.class && context.argSize() < 1 && npc.getProperty(property) != null) { value = Color.BLACK; valueName = "NONE"; @@ -152,6 +156,7 @@ public class PropertySetCommand implements CommandHandler { if (context.argSize() == 3) { if (type == Boolean.class) return context.suggestLiteral("true", "false"); if (type == NamedTextColor.class) return context.suggestCollection(NamedTextColor.NAMES.keys()); + if (type == GlowColor.class) return context.suggestCollection(GlowColor.NAMES.keys()); if (type == Color.class) return context.suggestLiteral("0x0F00FF", "#FFFFFF"); if (type == BlockState.class) return context.suggestLiteral("hand", "looking_at", "block"); if (type == SpellType.class) return PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_13) ? From cbf8f9a4f19f2e51e44c7c48baff8229c8231690 Mon Sep 17 00:00:00 2001 From: EternalHuman Date: Tue, 31 Oct 2023 12:04:19 +0300 Subject: [PATCH 3/8] NamedTextColor -> GlowColor + fix --- .../GlowColorPropertySerializer.java | 1 - .../lol/pyr/znpcsplus/util/GlowColor.java | 155 +++--------------- 2 files changed, 20 insertions(+), 136 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java index c7f2d4f..b1baeaa 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java @@ -2,7 +2,6 @@ package lol.pyr.znpcsplus.entity.serializers; import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.util.GlowColor; -import net.kyori.adventure.text.format.NamedTextColor; public class GlowColorPropertySerializer implements PropertySerializer { @Override diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java b/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java index fd0fb68..fa40cc8 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java @@ -1,20 +1,33 @@ package lol.pyr.znpcsplus.util; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.util.HSVLike; import net.kyori.adventure.util.Index; -import net.kyori.examination.ExaminableProperty; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; - import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.stream.Stream; -public class GlowColor implements TextColor { +public enum GlowColor { + BLACK("black", 0x000000), + DARK_BLUE("dark_blue", 0x0000aa), + DARK_GREEN("dark_green",0x00aa00), + DARK_AQUA("dark_aqua", 0x00aaaa), + DARK_RED("dark_red", 0xaa0000), + DARK_PURPLE("dark_purple", 0xaa00aa), + GOLD("gold", 0xffaa00), + GRAY("gray", 0xaaaaaa), + DARK_GRAY("dark_gray", 0x555555), + BLUE("blue", 0x5555ff), + GREEN("green", 0x55ff55), + AQUA("aqua", 0x55ffff), + RED("red", 0xff5555), + LIGHT_PURPLE("light_purple", 0xff55ff), + YELLOW("yellow", 0xffff55), + WHITE("white", 0xffffff); + private static final int BLACK_VALUE = 0x000000; private static final int DARK_BLUE_VALUE = 0x0000aa; private static final int DARK_GREEN_VALUE = 0x00aa00; @@ -32,103 +45,6 @@ public class GlowColor implements TextColor { private static final int YELLOW_VALUE = 0xffff55; private static final int WHITE_VALUE = 0xffffff; - /** - * The standard {@code black} colour. - * - * @since 4.0.0 - */ - public static final GlowColor BLACK = new GlowColor("black", BLACK_VALUE); - /** - * The standard {@code dark_blue} colour. - * - * @since 4.0.0 - */ - public static final GlowColor DARK_BLUE = new GlowColor("dark_blue", DARK_BLUE_VALUE); - /** - * The standard {@code dark_green} colour. - * - * @since 4.0.0 - */ - public static final GlowColor DARK_GREEN = new GlowColor("dark_green", DARK_GREEN_VALUE); - /** - * The standard {@code dark_aqua} colour. - * - * @since 4.0.0 - */ - public static final GlowColor DARK_AQUA = new GlowColor("dark_aqua", DARK_AQUA_VALUE); - /** - * The standard {@code dark_red} colour. - * - * @since 4.0.0 - */ - public static final GlowColor DARK_RED = new GlowColor("dark_red", DARK_RED_VALUE); - /** - * The standard {@code dark_purple} colour. - * - * @since 4.0.0 - */ - public static final GlowColor DARK_PURPLE = new GlowColor("dark_purple", DARK_PURPLE_VALUE); - /** - * The standard {@code gold} colour. - * - * @since 4.0.0 - */ - public static final GlowColor GOLD = new GlowColor("gold", GOLD_VALUE); - /** - * The standard {@code gray} colour. - * - * @since 4.0.0 - */ - public static final GlowColor GRAY = new GlowColor("gray", GRAY_VALUE); - /** - * The standard {@code dark_gray} colour. - * - * @since 4.0.0 - */ - public static final GlowColor DARK_GRAY = new GlowColor("dark_gray", DARK_GRAY_VALUE); - /** - * The standard {@code blue} colour. - * - * @since 4.0.0 - */ - public static final GlowColor BLUE = new GlowColor("blue", BLUE_VALUE); - /** - * The standard {@code green} colour. - * - * @since 4.0.0 - */ - public static final GlowColor GREEN = new GlowColor("green", GREEN_VALUE); - /** - * The standard {@code aqua} colour. - * - * @since 4.0.0 - */ - public static final GlowColor AQUA = new GlowColor("aqua", AQUA_VALUE); - /** - * The standard {@code red} colour. - * - * @since 4.0.0 - */ - public static final GlowColor RED = new GlowColor("red", RED_VALUE); - /** - * The standard {@code light_purple} colour. - * - * @since 4.0.0 - */ - public static final GlowColor LIGHT_PURPLE = new GlowColor("light_purple", LIGHT_PURPLE_VALUE); - /** - * The standard {@code yellow} colour. - * - * @since 4.0.0 - */ - public static final GlowColor YELLOW = new GlowColor("yellow", YELLOW_VALUE); - /** - * The standard {@code white} colour. - * - * @since 4.0.0 - */ - public static final GlowColor WHITE = new GlowColor("white", WHITE_VALUE); - private static final List VALUES = Collections.unmodifiableList(Arrays.asList(BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE)); /** * An index of name to color. @@ -198,55 +114,24 @@ public class GlowColor implements TextColor { } } - /** - * Find the named colour nearest to the provided colour. - * - * @param any colour to match - * @return nearest named colour. will always return a value - * @since 4.0.0 - */ - public static @NotNull GlowColor nearestTo(final @NotNull TextColor any) { - if (any instanceof NamedTextColor) { - return (GlowColor) any; - } - - return TextColor.nearestColorTo(VALUES, any); - } - private final String name; private final int value; - private final HSVLike hsv; private GlowColor(final String name, final int value) { this.name = name; this.value = value; - this.hsv = HSVLike.fromRGB(this.red(), this.green(), this.blue()); - } - - @Override - public int value() { - return this.value; } public NamedTextColor toNamedTextColor() { return NamedTextColor.namedColor(this.value); } - @Override - public @NotNull HSVLike asHSV() { - return this.hsv; + public int value() { + return this.value; } @Override public @NotNull String toString() { return this.name; } - - @Override - public @NotNull Stream examinableProperties() { - return Stream.concat( - Stream.of(ExaminableProperty.of("name", this.name)), - TextColor.super.examinableProperties() - ); - } } From 4994578ad15a66ea54c662d7176be8c71087700d Mon Sep 17 00:00:00 2001 From: EternalHuman Date: Tue, 31 Oct 2023 12:11:28 +0300 Subject: [PATCH 4/8] final changes --- .../lol/pyr/znpcsplus/util/GlowColor.java | 113 +++--------------- 1 file changed, 16 insertions(+), 97 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java b/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java index fa40cc8..4ecd276 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java @@ -1,49 +1,29 @@ package lol.pyr.znpcsplus.util; import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.util.HSVLike; import net.kyori.adventure.util.Index; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Collections; import java.util.List; public enum GlowColor { - BLACK("black", 0x000000), - DARK_BLUE("dark_blue", 0x0000aa), - DARK_GREEN("dark_green",0x00aa00), - DARK_AQUA("dark_aqua", 0x00aaaa), - DARK_RED("dark_red", 0xaa0000), - DARK_PURPLE("dark_purple", 0xaa00aa), - GOLD("gold", 0xffaa00), - GRAY("gray", 0xaaaaaa), - DARK_GRAY("dark_gray", 0x555555), - BLUE("blue", 0x5555ff), - GREEN("green", 0x55ff55), - AQUA("aqua", 0x55ffff), - RED("red", 0xff5555), - LIGHT_PURPLE("light_purple", 0xff55ff), - YELLOW("yellow", 0xffff55), - WHITE("white", 0xffffff); - - private static final int BLACK_VALUE = 0x000000; - private static final int DARK_BLUE_VALUE = 0x0000aa; - private static final int DARK_GREEN_VALUE = 0x00aa00; - private static final int DARK_AQUA_VALUE = 0x00aaaa; - private static final int DARK_RED_VALUE = 0xaa0000; - private static final int DARK_PURPLE_VALUE = 0xaa00aa; - private static final int GOLD_VALUE = 0xffaa00; - private static final int GRAY_VALUE = 0xaaaaaa; - private static final int DARK_GRAY_VALUE = 0x555555; - private static final int BLUE_VALUE = 0x5555ff; - private static final int GREEN_VALUE = 0x55ff55; - private static final int AQUA_VALUE = 0x55ffff; - private static final int RED_VALUE = 0xff5555; - private static final int LIGHT_PURPLE_VALUE = 0xff55ff; - private static final int YELLOW_VALUE = 0xffff55; - private static final int WHITE_VALUE = 0xffffff; + BLACK("black", NamedTextColor.BLACK.value()), + DARK_BLUE("dark_blue", NamedTextColor.DARK_BLUE.value()), + DARK_GREEN("dark_green",NamedTextColor.DARK_GREEN.value()), + DARK_AQUA("dark_aqua", NamedTextColor.AQUA.value()), + DARK_RED("dark_red", NamedTextColor.RED.value()), + DARK_PURPLE("dark_purple", NamedTextColor.DARK_PURPLE.value()), + GOLD("gold", NamedTextColor.GOLD.value()), + GRAY("gray", NamedTextColor.GRAY.value()), + DARK_GRAY("dark_gray", NamedTextColor.DARK_GRAY.value()), + BLUE("blue", NamedTextColor.BLUE.value()), + GREEN("green", NamedTextColor.GREEN.value()), + AQUA("aqua", NamedTextColor.AQUA.value()), + RED("red", NamedTextColor.RED.value()), + LIGHT_PURPLE("light_purple", NamedTextColor.LIGHT_PURPLE.value()), + YELLOW("yellow", NamedTextColor.YELLOW.value()), + WHITE("white", NamedTextColor.WHITE.value()); private static final List VALUES = Collections.unmodifiableList(Arrays.asList(BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE)); /** @@ -53,67 +33,6 @@ public enum GlowColor { */ public static final Index NAMES = Index.create(constant -> constant.name, VALUES); - /** - * Gets the named color exactly matching the provided color. - * - * @param value the color to match - * @return the matched color, or null - * @since 4.10.0 - */ - public static @Nullable GlowColor namedColor(final int value) { - switch (value) { - case BLACK_VALUE: return BLACK; - case DARK_BLUE_VALUE: return DARK_BLUE; - case DARK_GREEN_VALUE: return DARK_GREEN; - case DARK_AQUA_VALUE: return DARK_AQUA; - case DARK_RED_VALUE: return DARK_RED; - case DARK_PURPLE_VALUE: return DARK_PURPLE; - case GOLD_VALUE: return GOLD; - case GRAY_VALUE: return GRAY; - case DARK_GRAY_VALUE: return DARK_GRAY; - case BLUE_VALUE: return BLUE; - case GREEN_VALUE: return GREEN; - case AQUA_VALUE: return AQUA; - case RED_VALUE: return RED; - case LIGHT_PURPLE_VALUE: return LIGHT_PURPLE; - case YELLOW_VALUE: return YELLOW; - case WHITE_VALUE: return WHITE; - default: return null; - } - } - - /** - * Gets the named color exactly matching the provided color. - * - * @param value the color to match - * @return the matched color, or null - * @since 4.0.0 - * @deprecated for removal since 4.10.0, use {@link #namedColor(int)} instead - */ - @Deprecated - @ApiStatus.ScheduledForRemoval(inVersion = "5.0.0") - public static @Nullable GlowColor ofExact(final int value) { - switch (value) { - case BLACK_VALUE: return BLACK; - case DARK_BLUE_VALUE: return DARK_BLUE; - case DARK_GREEN_VALUE: return DARK_GREEN; - case DARK_AQUA_VALUE: return DARK_AQUA; - case DARK_RED_VALUE: return DARK_RED; - case DARK_PURPLE_VALUE: return DARK_PURPLE; - case GOLD_VALUE: return GOLD; - case GRAY_VALUE: return GRAY; - case DARK_GRAY_VALUE: return DARK_GRAY; - case BLUE_VALUE: return BLUE; - case GREEN_VALUE: return GREEN; - case AQUA_VALUE: return AQUA; - case RED_VALUE: return RED; - case LIGHT_PURPLE_VALUE: return LIGHT_PURPLE; - case YELLOW_VALUE: return YELLOW; - case WHITE_VALUE: return WHITE; - default: return null; - } - } - private final String name; private final int value; From e7c912fb7705ef6b2559b9e5f494c73070d928f2 Mon Sep 17 00:00:00 2001 From: EternalHuman Date: Tue, 31 Oct 2023 12:15:52 +0300 Subject: [PATCH 5/8] final changes --- .../entity/serializers/GlowColorPropertySerializer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java index b1baeaa..d227950 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java @@ -2,6 +2,9 @@ package lol.pyr.znpcsplus.entity.serializers; import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.util.GlowColor; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.Objects; public class GlowColorPropertySerializer implements PropertySerializer { @Override @@ -11,7 +14,9 @@ public class GlowColorPropertySerializer implements PropertySerializer Date: Tue, 31 Oct 2023 12:16:22 +0300 Subject: [PATCH 6/8] . --- .../entity/serializers/GlowColorPropertySerializer.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java index d227950..d547e8d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java @@ -4,8 +4,6 @@ import lol.pyr.znpcsplus.entity.PropertySerializer; import lol.pyr.znpcsplus.util.GlowColor; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.Objects; - public class GlowColorPropertySerializer implements PropertySerializer { @Override public String serialize(GlowColor property) { From ca1416e761b953126073c846055bacc9eba2d120 Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Tue, 31 Oct 2023 18:58:42 +0100 Subject: [PATCH 7/8] revert this (why??) --- .../src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java index 2380fdd..e1816e0 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/hologram/HologramImpl.java @@ -45,7 +45,7 @@ public class HologramImpl extends Viewable implements Hologram { } public void addTextLine(String line) { - addTextLineComponent(Component.text(line)); + addTextLineComponent(textSerializer.deserialize(textSerializer.serialize(MiniMessage.miniMessage().deserialize(line)))); } public void addItemLineStack(org.bukkit.inventory.ItemStack item) { From 2264ff3d710536f99f1bbab747f055cea2c2165b Mon Sep 17 00:00:00 2001 From: Pyrbu Date: Tue, 31 Oct 2023 19:00:29 +0100 Subject: [PATCH 8/8] convert the color class to an enum & move it to the api package --- .../lol/pyr/znpcsplus/util/NamedColor.java | 20 +++++++ .../java/lol/pyr/znpcsplus/ZNpcsPlus.java | 3 +- .../commands/property/PropertySetCommand.java | 9 +-- .../entity/EntityPropertyRegistryImpl.java | 4 +- .../entity/properties/GlowProperty.java | 8 +-- .../GlowColorPropertySerializer.java | 24 -------- .../NamedColorPropertySerializer.java | 25 +++++++++ .../NamedTextColorPropertySerializer.java | 22 -------- .../pyr/znpcsplus/packets/PacketFactory.java | 5 +- .../znpcsplus/packets/V1_17PacketFactory.java | 5 +- .../packets/V1_20_2PacketFactory.java | 5 +- .../znpcsplus/packets/V1_8PacketFactory.java | 10 ++-- .../znpcsplus/parsers/GlowColorParser.java | 21 ------- .../znpcsplus/parsers/NamedColorParser.java | 23 ++++++++ .../parsers/NamedTextColorParser.java | 23 -------- .../lol/pyr/znpcsplus/util/GlowColor.java | 56 ------------------- 16 files changed, 88 insertions(+), 175 deletions(-) create mode 100644 api/src/main/java/lol/pyr/znpcsplus/util/NamedColor.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedColorPropertySerializer.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedTextColorPropertySerializer.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/parsers/GlowColorParser.java create mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedColorParser.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedTextColorParser.java delete mode 100644 plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java diff --git a/api/src/main/java/lol/pyr/znpcsplus/util/NamedColor.java b/api/src/main/java/lol/pyr/znpcsplus/util/NamedColor.java new file mode 100644 index 0000000..42147d6 --- /dev/null +++ b/api/src/main/java/lol/pyr/znpcsplus/util/NamedColor.java @@ -0,0 +1,20 @@ +package lol.pyr.znpcsplus.util; + +public enum NamedColor { + BLACK, + DARK_BLUE, + DARK_GREEN, + DARK_AQUA, + DARK_RED, + DARK_PURPLE, + GOLD, + GRAY, + DARK_GRAY, + BLUE, + GREEN, + AQUA, + RED, + LIGHT_PURPLE, + YELLOW, + WHITE +} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java index b71004c..46addce 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/ZNpcsPlus.java @@ -246,8 +246,7 @@ public class ZNpcsPlus { manager.registerParser(Double.class, new DoubleParser(incorrectUsageMessage)); manager.registerParser(Float.class, new FloatParser(incorrectUsageMessage)); manager.registerParser(Boolean.class, new BooleanParser(incorrectUsageMessage)); - manager.registerParser(NamedTextColor.class, new NamedTextColorParser(incorrectUsageMessage)); - manager.registerParser(GlowColor.class, new GlowColorParser(incorrectUsageMessage)); + manager.registerParser(NamedColor.class, new NamedColorParser(incorrectUsageMessage)); manager.registerParser(InteractionType.class, new InteractionTypeParser(incorrectUsageMessage)); manager.registerParser(Color.class, new ColorParser(incorrectUsageMessage)); manager.registerParser(Vector3f.class, new Vector3fParser(incorrectUsageMessage)); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java index caa6bda..334d7f6 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/commands/property/PropertySetCommand.java @@ -57,11 +57,7 @@ public class PropertySetCommand implements CommandHandler { valueName = bukkitStack.toString(); } } - else if (type == NamedTextColor.class && context.argSize() < 1 && npc.getProperty(property) != null) { - value = null; - valueName = "NONE"; - } - else if (type == GlowColor.class && context.argSize() < 1 && npc.getProperty(property) != null) { + else if (type == NamedColor.class && context.argSize() < 1 && npc.getProperty(property) != null) { value = null; valueName = "NONE"; } @@ -155,8 +151,7 @@ public class PropertySetCommand implements CommandHandler { if (type == Vector3f.class && context.argSize() <= 5) return context.suggestLiteral("0", "0.0"); if (context.argSize() == 3) { if (type == Boolean.class) return context.suggestLiteral("true", "false"); - if (type == NamedTextColor.class) return context.suggestCollection(NamedTextColor.NAMES.keys()); - if (type == GlowColor.class) return context.suggestCollection(GlowColor.NAMES.keys()); + if (type == NamedColor.class) return context.suggestEnum(NamedColor.values()); if (type == Color.class) return context.suggestLiteral("0x0F00FF", "#FFFFFF"); if (type == BlockState.class) return context.suggestLiteral("hand", "looking_at", "block"); if (type == SpellType.class) return PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_13) ? diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java index ee1a5be..b011137 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -49,7 +49,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { public EntityPropertyRegistryImpl(MojangSkinCache skinCache, ConfigManager configManager) { registerSerializer(new ComponentPropertySerializer()); - registerSerializer(new GlowColorPropertySerializer()); + registerSerializer(new NamedColorPropertySerializer()); registerSerializer(new SkinDescriptorSerializer(skinCache)); registerSerializer(new ItemStackPropertySerializer()); registerSerializer(new ColorPropertySerializer()); @@ -273,7 +273,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { else if (ver.isNewerThanOrEquals(ServerVersion.V_1_9)) guardianIndex = 11; else guardianIndex = 16; register(new BitsetProperty("is_elder", guardianIndex, 0x04, false, legacyBooleans)); - register(new BitsetProperty("is_retracting_spikes", guardianIndex++, 0x02, false, legacyBooleans)); + register(new BitsetProperty("is_retracting_spikes", guardianIndex, 0x02, false, legacyBooleans)); linkProperties("is_elder", "is_retracting_spikes"); // TODO: add guardian beam target } else { diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java index 6c45325..e32f61d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/GlowProperty.java @@ -5,22 +5,22 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes; import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.packets.PacketFactory; -import lol.pyr.znpcsplus.util.GlowColor; +import lol.pyr.znpcsplus.util.NamedColor; import org.bukkit.entity.Player; import java.util.Map; -public class GlowProperty extends EntityPropertyImpl { +public class GlowProperty extends EntityPropertyImpl { private final PacketFactory packetFactory; public GlowProperty(PacketFactory packetFactory) { - super("glow", null, GlowColor.class); + super("glow", null, NamedColor.class); this.packetFactory = packetFactory; } @Override public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { - GlowColor value = entity.getProperty(this); + NamedColor value = entity.getProperty(this); EntityData oldData = properties.get(0); byte oldValue = oldData == null ? 0 : (byte) oldData.getValue(); properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (value == null ? 0 : 0x40)))); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java deleted file mode 100644 index d547e8d..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/GlowColorPropertySerializer.java +++ /dev/null @@ -1,24 +0,0 @@ -package lol.pyr.znpcsplus.entity.serializers; - -import lol.pyr.znpcsplus.entity.PropertySerializer; -import lol.pyr.znpcsplus.util.GlowColor; -import net.kyori.adventure.text.format.NamedTextColor; - -public class GlowColorPropertySerializer implements PropertySerializer { - @Override - public String serialize(GlowColor property) { - return String.valueOf(property.value()); - } - - @Override - public GlowColor deserialize(String property) { - NamedTextColor namedTextColor = NamedTextColor.namedColor(Integer.parseInt(property)); - if (namedTextColor == null) return null; - return GlowColor.valueOf(namedTextColor.toString().toUpperCase()); - } - - @Override - public Class getTypeClass() { - return GlowColor.class; - } -} \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedColorPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedColorPropertySerializer.java new file mode 100644 index 0000000..a227ae7 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedColorPropertySerializer.java @@ -0,0 +1,25 @@ +package lol.pyr.znpcsplus.entity.serializers; + +import lol.pyr.znpcsplus.entity.PropertySerializer; +import lol.pyr.znpcsplus.util.NamedColor; + +public class NamedColorPropertySerializer implements PropertySerializer { + @Override + public String serialize(NamedColor property) { + return property.name(); + } + + @Override + public NamedColor deserialize(String property) { + try { + return NamedColor.valueOf(property.toUpperCase()); + } catch (IllegalArgumentException exception) { + return NamedColor.WHITE; + } + } + + @Override + public Class getTypeClass() { + return NamedColor.class; + } +} \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedTextColorPropertySerializer.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedTextColorPropertySerializer.java deleted file mode 100644 index 8916ae4..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/serializers/NamedTextColorPropertySerializer.java +++ /dev/null @@ -1,22 +0,0 @@ -package lol.pyr.znpcsplus.entity.serializers; - -import lol.pyr.znpcsplus.entity.PropertySerializer; -import net.kyori.adventure.text.format.NamedTextColor; - -@Deprecated -public class NamedTextColorPropertySerializer implements PropertySerializer { - @Override - public String serialize(NamedTextColor property) { - return String.valueOf(property.value()); - } - - @Override - public NamedTextColor deserialize(String property) { - return NamedTextColor.namedColor(Integer.parseInt(property)); - } - - @Override - public Class getTypeClass() { - return NamedTextColor.class; - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java index 32dd8a5..6fe3fde 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/PacketFactory.java @@ -4,8 +4,7 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityData; import com.github.retrooper.packetevents.protocol.player.Equipment; import lol.pyr.znpcsplus.api.entity.PropertyHolder; import lol.pyr.znpcsplus.entity.PacketEntity; -import lol.pyr.znpcsplus.util.GlowColor; -import net.kyori.adventure.text.format.NamedTextColor; +import lol.pyr.znpcsplus.util.NamedColor; import org.bukkit.entity.Player; import java.util.List; @@ -18,7 +17,7 @@ public interface PacketFactory { void teleportEntity(Player player, PacketEntity entity); CompletableFuture addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties); void removeTabPlayer(Player player, PacketEntity entity); - void createTeam(Player player, PacketEntity entity, GlowColor glowColor); + void createTeam(Player player, PacketEntity entity, NamedColor namedColor); void removeTeam(Player player, PacketEntity entity); void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties); void sendEquipment(Player player, PacketEntity entity, Equipment equipment); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java index 5a26b85..45b6e41 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_17PacketFactory.java @@ -8,9 +8,8 @@ import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.scheduling.TaskScheduler; -import lol.pyr.znpcsplus.util.GlowColor; +import lol.pyr.znpcsplus.util.NamedColor; import lol.pyr.znpcsplus.util.NpcLocation; -import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -28,6 +27,6 @@ public class V1_17PacketFactory extends V1_8PacketFactory { sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d()))); sendAllMetadata(player, entity, properties); - createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class))); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedColor.class))); } } diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_20_2PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_20_2PacketFactory.java index bfdf5bd..761476f 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_20_2PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_20_2PacketFactory.java @@ -9,9 +9,8 @@ import lol.pyr.znpcsplus.config.ConfigManager; import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.scheduling.TaskScheduler; -import lol.pyr.znpcsplus.util.GlowColor; +import lol.pyr.znpcsplus.util.NamedColor; import lol.pyr.znpcsplus.util.NpcLocation; -import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -29,7 +28,7 @@ public class V1_20_2PacketFactory extends V1_19_2PacketFactory { @Override public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) { addTabPlayer(player, entity, properties).thenAccept(ignored -> { - createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class))); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedColor.class))); NpcLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d()))); diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java index 8aa3a08..4eb4df2 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/packets/V1_8PacketFactory.java @@ -20,7 +20,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl; import lol.pyr.znpcsplus.entity.PacketEntity; import lol.pyr.znpcsplus.scheduling.TaskScheduler; import lol.pyr.znpcsplus.skin.BaseSkinDescriptor; -import lol.pyr.znpcsplus.util.GlowColor; +import lol.pyr.znpcsplus.util.NamedColor; import lol.pyr.znpcsplus.util.NpcLocation; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; @@ -49,7 +49,7 @@ public class V1_8PacketFactory implements PacketFactory { @Override public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) { addTabPlayer(player, entity, properties).thenAccept(ignored -> { - createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class))); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedColor.class))); NpcLocation location = entity.getLocation(); sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(), entity.getUuid(), npcLocationToVector(location), location.getYaw(), location.getPitch(), Collections.emptyList())); @@ -70,7 +70,7 @@ public class V1_8PacketFactory implements PacketFactory { new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty())); sendAllMetadata(player, entity, properties); - createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class))); + createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedColor.class))); } protected Vector3d npcLocationToVector(NpcLocation location) { @@ -112,12 +112,12 @@ public class V1_8PacketFactory implements PacketFactory { } @Override - public void createTeam(Player player, PacketEntity entity, GlowColor glowColor) { + public void createTeam(Player player, PacketEntity entity, NamedColor namedColor) { sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.CREATE, new WrapperPlayServerTeams.ScoreBoardTeamInfo( Component.empty(), Component.empty(), Component.empty(), WrapperPlayServerTeams.NameTagVisibility.NEVER, WrapperPlayServerTeams.CollisionRule.NEVER, - glowColor == null ? NamedTextColor.WHITE : glowColor.toNamedTextColor(), + namedColor == null ? NamedTextColor.WHITE : NamedTextColor.NAMES.value(namedColor.name().toLowerCase()), WrapperPlayServerTeams.OptionData.NONE ))); sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.ADD_ENTITIES, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null, diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/parsers/GlowColorParser.java b/plugin/src/main/java/lol/pyr/znpcsplus/parsers/GlowColorParser.java deleted file mode 100644 index 1210bb5..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/parsers/GlowColorParser.java +++ /dev/null @@ -1,21 +0,0 @@ -package lol.pyr.znpcsplus.parsers; - -import lol.pyr.director.adventure.command.CommandContext; -import lol.pyr.director.adventure.parse.ParserType; -import lol.pyr.director.common.command.CommandExecutionException; -import lol.pyr.director.common.message.Message; -import lol.pyr.znpcsplus.util.GlowColor; -import java.util.Deque; - -public class GlowColorParser extends ParserType { - public GlowColorParser(Message message) { - super(message); - } - - @Override - public GlowColor parse(Deque deque) throws CommandExecutionException { - GlowColor color = GlowColor.NAMES.value(deque.pop()); - if (color == null) throw new CommandExecutionException(); - return color; - } -} \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedColorParser.java b/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedColorParser.java new file mode 100644 index 0000000..33451a0 --- /dev/null +++ b/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedColorParser.java @@ -0,0 +1,23 @@ +package lol.pyr.znpcsplus.parsers; + +import lol.pyr.director.adventure.command.CommandContext; +import lol.pyr.director.adventure.parse.ParserType; +import lol.pyr.director.common.command.CommandExecutionException; +import lol.pyr.director.common.message.Message; +import lol.pyr.znpcsplus.util.NamedColor; +import java.util.Deque; + +public class NamedColorParser extends ParserType { + public NamedColorParser(Message message) { + super(message); + } + + @Override + public NamedColor parse(Deque deque) throws CommandExecutionException { + try { + return NamedColor.valueOf(deque.pop()); + } catch (IllegalArgumentException exception) { + throw new CommandExecutionException(); + } + } +} \ No newline at end of file diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedTextColorParser.java b/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedTextColorParser.java deleted file mode 100644 index 604f74d..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/parsers/NamedTextColorParser.java +++ /dev/null @@ -1,23 +0,0 @@ -package lol.pyr.znpcsplus.parsers; - -import lol.pyr.director.adventure.command.CommandContext; -import lol.pyr.director.adventure.parse.ParserType; -import lol.pyr.director.common.command.CommandExecutionException; -import lol.pyr.director.common.message.Message; -import net.kyori.adventure.text.format.NamedTextColor; - -import java.util.Deque; - -@Deprecated -public class NamedTextColorParser extends ParserType { - public NamedTextColorParser(Message message) { - super(message); - } - - @Override - public NamedTextColor parse(Deque deque) throws CommandExecutionException { - NamedTextColor color = NamedTextColor.NAMES.value(deque.pop()); - if (color == null) throw new CommandExecutionException(); - return color; - } -} diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java b/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java deleted file mode 100644 index 4ecd276..0000000 --- a/plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java +++ /dev/null @@ -1,56 +0,0 @@ -package lol.pyr.znpcsplus.util; - -import net.kyori.adventure.text.format.NamedTextColor; -import net.kyori.adventure.util.Index; -import org.jetbrains.annotations.NotNull; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -public enum GlowColor { - BLACK("black", NamedTextColor.BLACK.value()), - DARK_BLUE("dark_blue", NamedTextColor.DARK_BLUE.value()), - DARK_GREEN("dark_green",NamedTextColor.DARK_GREEN.value()), - DARK_AQUA("dark_aqua", NamedTextColor.AQUA.value()), - DARK_RED("dark_red", NamedTextColor.RED.value()), - DARK_PURPLE("dark_purple", NamedTextColor.DARK_PURPLE.value()), - GOLD("gold", NamedTextColor.GOLD.value()), - GRAY("gray", NamedTextColor.GRAY.value()), - DARK_GRAY("dark_gray", NamedTextColor.DARK_GRAY.value()), - BLUE("blue", NamedTextColor.BLUE.value()), - GREEN("green", NamedTextColor.GREEN.value()), - AQUA("aqua", NamedTextColor.AQUA.value()), - RED("red", NamedTextColor.RED.value()), - LIGHT_PURPLE("light_purple", NamedTextColor.LIGHT_PURPLE.value()), - YELLOW("yellow", NamedTextColor.YELLOW.value()), - WHITE("white", NamedTextColor.WHITE.value()); - - private static final List VALUES = Collections.unmodifiableList(Arrays.asList(BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE)); - /** - * An index of name to color. - * - * @since 4.0.0 - */ - public static final Index NAMES = Index.create(constant -> constant.name, VALUES); - - private final String name; - private final int value; - - private GlowColor(final String name, final int value) { - this.name = name; - this.value = value; - } - - public NamedTextColor toNamedTextColor() { - return NamedTextColor.namedColor(this.value); - } - - public int value() { - return this.value; - } - - @Override - public @NotNull String toString() { - return this.name; - } -}