NamedTextColor -> GlowColor
This commit is contained in:
parent
781d81cf7f
commit
55c82cfddb
14 changed files with 316 additions and 13 deletions
|
@ -247,6 +247,7 @@ public class ZNpcsPlus {
|
||||||
manager.registerParser(Float.class, new FloatParser(incorrectUsageMessage));
|
manager.registerParser(Float.class, new FloatParser(incorrectUsageMessage));
|
||||||
manager.registerParser(Boolean.class, new BooleanParser(incorrectUsageMessage));
|
manager.registerParser(Boolean.class, new BooleanParser(incorrectUsageMessage));
|
||||||
manager.registerParser(NamedTextColor.class, new NamedTextColorParser(incorrectUsageMessage));
|
manager.registerParser(NamedTextColor.class, new NamedTextColorParser(incorrectUsageMessage));
|
||||||
|
manager.registerParser(GlowColor.class, new GlowColorParser(incorrectUsageMessage));
|
||||||
manager.registerParser(InteractionType.class, new InteractionTypeParser(incorrectUsageMessage));
|
manager.registerParser(InteractionType.class, new InteractionTypeParser(incorrectUsageMessage));
|
||||||
manager.registerParser(Color.class, new ColorParser(incorrectUsageMessage));
|
manager.registerParser(Color.class, new ColorParser(incorrectUsageMessage));
|
||||||
manager.registerParser(Vector3f.class, new Vector3fParser(incorrectUsageMessage));
|
manager.registerParser(Vector3f.class, new Vector3fParser(incorrectUsageMessage));
|
||||||
|
|
|
@ -36,6 +36,7 @@ import lol.pyr.znpcsplus.util.LookType;
|
||||||
import lol.pyr.znpcsplus.util.NpcLocation;
|
import lol.pyr.znpcsplus.util.NpcLocation;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
||||||
|
|
||||||
public EntityPropertyRegistryImpl(MojangSkinCache skinCache, ConfigManager configManager) {
|
public EntityPropertyRegistryImpl(MojangSkinCache skinCache, ConfigManager configManager) {
|
||||||
registerSerializer(new ComponentPropertySerializer());
|
registerSerializer(new ComponentPropertySerializer());
|
||||||
registerSerializer(new NamedTextColorPropertySerializer());
|
registerSerializer(new GlowColorPropertySerializer());
|
||||||
registerSerializer(new SkinDescriptorSerializer(skinCache));
|
registerSerializer(new SkinDescriptorSerializer(skinCache));
|
||||||
registerSerializer(new ItemStackPropertySerializer());
|
registerSerializer(new ItemStackPropertySerializer());
|
||||||
registerSerializer(new ColorPropertySerializer());
|
registerSerializer(new ColorPropertySerializer());
|
||||||
|
|
|
@ -5,22 +5,22 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
|
||||||
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||||
import lol.pyr.znpcsplus.packets.PacketFactory;
|
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 org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class GlowProperty extends EntityPropertyImpl<NamedTextColor> {
|
public class GlowProperty extends EntityPropertyImpl<GlowColor> {
|
||||||
private final PacketFactory packetFactory;
|
private final PacketFactory packetFactory;
|
||||||
|
|
||||||
public GlowProperty(PacketFactory packetFactory) {
|
public GlowProperty(PacketFactory packetFactory) {
|
||||||
super("glow", null, NamedTextColor.class);
|
super("glow", null, GlowColor.class);
|
||||||
this.packetFactory = packetFactory;
|
this.packetFactory = packetFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
||||||
NamedTextColor value = entity.getProperty(this);
|
GlowColor value = entity.getProperty(this);
|
||||||
EntityData oldData = properties.get(0);
|
EntityData oldData = properties.get(0);
|
||||||
byte oldValue = oldData == null ? 0 : (byte) oldData.getValue();
|
byte oldValue = oldData == null ? 0 : (byte) oldData.getValue();
|
||||||
properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (value == null ? 0 : 0x40))));
|
properties.put(0, newEntityData(0, EntityDataTypes.BYTE, (byte) (oldValue | (value == null ? 0 : 0x40))));
|
||||||
|
|
|
@ -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<GlowColor> {
|
||||||
|
@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<GlowColor> getTypeClass() {
|
||||||
|
return GlowColor.class;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package lol.pyr.znpcsplus.entity.serializers;
|
||||||
import lol.pyr.znpcsplus.entity.PropertySerializer;
|
import lol.pyr.znpcsplus.entity.PropertySerializer;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class NamedTextColorPropertySerializer implements PropertySerializer<NamedTextColor> {
|
public class NamedTextColorPropertySerializer implements PropertySerializer<NamedTextColor> {
|
||||||
@Override
|
@Override
|
||||||
public String serialize(NamedTextColor property) {
|
public String serialize(NamedTextColor property) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class HologramImpl extends Viewable implements Hologram {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTextLine(String line) {
|
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) {
|
public void addItemLineStack(org.bukkit.inventory.ItemStack item) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||||
import com.github.retrooper.packetevents.protocol.player.Equipment;
|
import com.github.retrooper.packetevents.protocol.player.Equipment;
|
||||||
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
import lol.pyr.znpcsplus.api.entity.PropertyHolder;
|
||||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||||
|
import lol.pyr.znpcsplus.util.GlowColor;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ public interface PacketFactory {
|
||||||
void teleportEntity(Player player, PacketEntity entity);
|
void teleportEntity(Player player, PacketEntity entity);
|
||||||
CompletableFuture<Void> addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties);
|
CompletableFuture<Void> addTabPlayer(Player player, PacketEntity entity, PropertyHolder properties);
|
||||||
void removeTabPlayer(Player player, PacketEntity entity);
|
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 removeTeam(Player player, PacketEntity entity);
|
||||||
void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties);
|
void sendAllMetadata(Player player, PacketEntity entity, PropertyHolder properties);
|
||||||
void sendEquipment(Player player, PacketEntity entity, Equipment equipment);
|
void sendEquipment(Player player, PacketEntity entity, Equipment equipment);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import lol.pyr.znpcsplus.config.ConfigManager;
|
||||||
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
||||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||||
|
import lol.pyr.znpcsplus.util.GlowColor;
|
||||||
import lol.pyr.znpcsplus.util.NpcLocation;
|
import lol.pyr.znpcsplus.util.NpcLocation;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
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(),
|
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())));
|
npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d())));
|
||||||
sendAllMetadata(player, entity, properties);
|
sendAllMetadata(player, entity, properties);
|
||||||
createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", NamedTextColor.class)));
|
createTeam(player, entity, properties.getProperty(propertyRegistry.getByName("glow", GlowColor.class)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import lol.pyr.znpcsplus.config.ConfigManager;
|
||||||
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
||||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||||
|
import lol.pyr.znpcsplus.util.GlowColor;
|
||||||
import lol.pyr.znpcsplus.util.NpcLocation;
|
import lol.pyr.znpcsplus.util.NpcLocation;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
@ -28,7 +29,7 @@ public class V1_20_2PacketFactory extends V1_19_2PacketFactory {
|
||||||
@Override
|
@Override
|
||||||
public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) {
|
public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) {
|
||||||
addTabPlayer(player, entity, properties).thenAccept(ignored -> {
|
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();
|
NpcLocation location = entity.getLocation();
|
||||||
sendPacket(player, new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(),
|
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())));
|
npcLocationToVector(location), location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.of(new Vector3d())));
|
||||||
|
|
|
@ -20,6 +20,7 @@ import lol.pyr.znpcsplus.entity.EntityPropertyRegistryImpl;
|
||||||
import lol.pyr.znpcsplus.entity.PacketEntity;
|
import lol.pyr.znpcsplus.entity.PacketEntity;
|
||||||
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
import lol.pyr.znpcsplus.scheduling.TaskScheduler;
|
||||||
import lol.pyr.znpcsplus.skin.BaseSkinDescriptor;
|
import lol.pyr.znpcsplus.skin.BaseSkinDescriptor;
|
||||||
|
import lol.pyr.znpcsplus.util.GlowColor;
|
||||||
import lol.pyr.znpcsplus.util.NpcLocation;
|
import lol.pyr.znpcsplus.util.NpcLocation;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
@ -48,7 +49,7 @@ public class V1_8PacketFactory implements PacketFactory {
|
||||||
@Override
|
@Override
|
||||||
public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) {
|
public void spawnPlayer(Player player, PacketEntity entity, PropertyHolder properties) {
|
||||||
addTabPlayer(player, entity, properties).thenAccept(ignored -> {
|
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();
|
NpcLocation location = entity.getLocation();
|
||||||
sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(),
|
sendPacket(player, new WrapperPlayServerSpawnPlayer(entity.getEntityId(),
|
||||||
entity.getUuid(), npcLocationToVector(location), location.getYaw(), location.getPitch(), Collections.emptyList()));
|
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),
|
new WrapperPlayServerSpawnEntity(entity.getEntityId(), Optional.of(entity.getUuid()), entity.getType(), npcLocationToVector(location),
|
||||||
location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty()));
|
location.getPitch(), location.getYaw(), location.getYaw(), 0, Optional.empty()));
|
||||||
sendAllMetadata(player, entity, properties);
|
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) {
|
protected Vector3d npcLocationToVector(NpcLocation location) {
|
||||||
|
@ -111,12 +112,12 @@ public class V1_8PacketFactory implements PacketFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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(
|
sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.CREATE, new WrapperPlayServerTeams.ScoreBoardTeamInfo(
|
||||||
Component.empty(), Component.empty(), Component.empty(),
|
Component.empty(), Component.empty(), Component.empty(),
|
||||||
WrapperPlayServerTeams.NameTagVisibility.NEVER,
|
WrapperPlayServerTeams.NameTagVisibility.NEVER,
|
||||||
WrapperPlayServerTeams.CollisionRule.NEVER,
|
WrapperPlayServerTeams.CollisionRule.NEVER,
|
||||||
glowColor == null ? NamedTextColor.WHITE : glowColor,
|
glowColor == null ? NamedTextColor.WHITE : glowColor.toNamedTextColor(),
|
||||||
WrapperPlayServerTeams.OptionData.NONE
|
WrapperPlayServerTeams.OptionData.NONE
|
||||||
)));
|
)));
|
||||||
sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.ADD_ENTITIES, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null,
|
sendPacket(player, new WrapperPlayServerTeams("npc_team_" + entity.getEntityId(), WrapperPlayServerTeams.TeamMode.ADD_ENTITIES, (WrapperPlayServerTeams.ScoreBoardTeamInfo) null,
|
||||||
|
|
|
@ -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<GlowColor> {
|
||||||
|
public GlowColorParser(Message<CommandContext> message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GlowColor parse(Deque<String> deque) throws CommandExecutionException {
|
||||||
|
GlowColor color = GlowColor.NAMES.value(deque.pop());
|
||||||
|
if (color == null) throw new CommandExecutionException();
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class NamedTextColorParser extends ParserType<NamedTextColor> {
|
public class NamedTextColorParser extends ParserType<NamedTextColor> {
|
||||||
public NamedTextColorParser(Message<CommandContext> message) {
|
public NamedTextColorParser(Message<CommandContext> message) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
252
plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java
Normal file
252
plugin/src/main/java/lol/pyr/znpcsplus/util/GlowColor.java
Normal file
|
@ -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<GlowColor> 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<String, GlowColor> 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<? extends ExaminableProperty> examinableProperties() {
|
||||||
|
return Stream.concat(
|
||||||
|
Stream.of(ExaminableProperty.of("name", this.name)),
|
||||||
|
TextColor.super.examinableProperties()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue