Use colors in egg names

This commit is contained in:
akastijn 2026-04-05 22:41:28 +02:00
parent f7962b8faa
commit 9f07d983bd
6 changed files with 52 additions and 81 deletions

View File

@ -4,6 +4,7 @@ import com.alttd.easter.commands.SubCommand;
import com.alttd.easter.config.Messages;
import com.alttd.easter.egg.EggType;
import com.alttd.easter.util.ItemUtils;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -34,7 +35,9 @@ public class SpawnEggs extends SubCommand {
EggType specific = parseEggType(args[1]);
if (specific != null) {
giveEgg(player, specific, amount);
player.sendRichMessage("<green>Spawned </green><gold>" + amount + "</gold> <green>of </green><gold>" + ItemUtils.prettify(specific.name()) + "</gold> <green>egg(s).</green>");
player.sendRichMessage("<green>Spawned </green><gold>" + amount + "</gold> <green>of </green><type> <green>egg(s).</green>",
Placeholder.component("type", ItemUtils.typeNameComponent(specific))
);
return true;
}
}
@ -42,7 +45,9 @@ public class SpawnEggs extends SubCommand {
EggType specific = parseEggType(args[2]);
if (specific != null) {
giveEgg(player, specific, amount);
player.sendRichMessage("<green>Spawned </green><gold>" + amount + "</gold> <green>of </green><gold>" + ItemUtils.prettify(specific.name()) + "</gold> <green>egg(s).</green>");
player.sendRichMessage("<green>Spawned </green><gold>" + amount + "</gold> <green>of </green><type> <green>egg(s).</green>",
Placeholder.component("type", ItemUtils.typeNameComponent(specific))
);
return true;
}
}

View File

@ -1,27 +1,28 @@
package com.alttd.easter.egg;
import lombok.Getter;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
public enum EggType {
BROWN_HUSK(Material.BROWN_GLAZED_TERRACOTTA, EntityType.HUSK, Enchantment.FIRE_PROTECTION, 2, Difficulty.NORMAL),
RED_SPIDER(Material.RED_GLAZED_TERRACOTTA, EntityType.SPIDER, Enchantment.BANE_OF_ARTHROPODS, 2, Difficulty.NORMAL),
ORANGE_BLAZE(Material.ORANGE_GLAZED_TERRACOTTA, EntityType.BLAZE, Enchantment.FIRE_ASPECT, 2, Difficulty.NORMAL),
YELLOW_PIGLIN(Material.YELLOW_GLAZED_TERRACOTTA, EntityType.PIGLIN, Enchantment.FORTUNE, 2, Difficulty.NORMAL),
LIME_CREEPER(Material.LIME_GLAZED_TERRACOTTA, EntityType.CREEPER, Enchantment.BLAST_PROTECTION, 2, Difficulty.NORMAL),
GREEN_ZOMBIE(Material.GREEN_GLAZED_TERRACOTTA, EntityType.ZOMBIE, Enchantment.FEATHER_FALLING, 2, Difficulty.NORMAL),
LIGHT_BLUE_STRAY(Material.LIGHT_BLUE_GLAZED_TERRACOTTA, EntityType.STRAY, Enchantment.FROST_WALKER, 2, Difficulty.NORMAL),
CYAN_GUARDIAN(Material.CYAN_GLAZED_TERRACOTTA, EntityType.GUARDIAN, Enchantment.THORNS, 2, Difficulty.EASY),
BLUE_WARDEN(Material.BLUE_GLAZED_TERRACOTTA, EntityType.WARDEN, Enchantment.SWIFT_SNEAK, 2, Difficulty.HARD),
PURPLE_ENDER_DRAGON(Material.PURPLE_GLAZED_TERRACOTTA, EntityType.ENDER_DRAGON, Enchantment.POWER, 2, Difficulty.HARD),
MAGENTA_ENDERMAN(Material.MAGENTA_GLAZED_TERRACOTTA, EntityType.ENDERMAN, Enchantment.INFINITY, 2, Difficulty.EASY),
PINK_HOGLIN(Material.PINK_GLAZED_TERRACOTTA, EntityType.HOGLIN, Enchantment.PIERCING, 2, Difficulty.NORMAL),
WHITE_SKELETON(Material.WHITE_GLAZED_TERRACOTTA, EntityType.SKELETON, Enchantment.MULTISHOT, 2, Difficulty.NORMAL),
LIGHT_GRAY_SILVERFISH(Material.LIGHT_GRAY_GLAZED_TERRACOTTA, EntityType.SILVERFISH, Enchantment.EFFICIENCY, 2, Difficulty.NORMAL),
GRAY_WITHER(Material.GRAY_GLAZED_TERRACOTTA, EntityType.WITHER, Enchantment.SMITE, 2, Difficulty.HARD),
BLACK_WITHER_SKELETON(Material.BLACK_GLAZED_TERRACOTTA, EntityType.WITHER_SKELETON, Enchantment.LOOTING, 2, Difficulty.NORMAL);
BROWN_HUSK(Material.BROWN_GLAZED_TERRACOTTA, EntityType.HUSK, Enchantment.FIRE_PROTECTION, 2, Difficulty.NORMAL, TextColor.color(0x8F4F2A)),
RED_SPIDER(Material.RED_GLAZED_TERRACOTTA, EntityType.SPIDER, Enchantment.BANE_OF_ARTHROPODS, 2, Difficulty.NORMAL, TextColor.color(0xB02E26)),
ORANGE_BLAZE(Material.ORANGE_GLAZED_TERRACOTTA, EntityType.BLAZE, Enchantment.FIRE_ASPECT, 2, Difficulty.NORMAL, TextColor.color(0xF9801D)),
YELLOW_PIGLIN(Material.YELLOW_GLAZED_TERRACOTTA, EntityType.PIGLIN, Enchantment.FORTUNE, 2, Difficulty.NORMAL, TextColor.color(0xFED83D)),
LIME_CREEPER(Material.LIME_GLAZED_TERRACOTTA, EntityType.CREEPER, Enchantment.BLAST_PROTECTION, 2, Difficulty.NORMAL, TextColor.color(0x80C71F)),
GREEN_ZOMBIE(Material.GREEN_GLAZED_TERRACOTTA, EntityType.ZOMBIE, Enchantment.FEATHER_FALLING, 2, Difficulty.NORMAL, TextColor.color(0x5E7C16)),
LIGHT_BLUE_STRAY(Material.LIGHT_BLUE_GLAZED_TERRACOTTA, EntityType.STRAY, Enchantment.FROST_WALKER, 2, Difficulty.NORMAL, TextColor.color(0x3AB3DA)),
CYAN_GUARDIAN(Material.CYAN_GLAZED_TERRACOTTA, EntityType.GUARDIAN, Enchantment.THORNS, 2, Difficulty.EASY, TextColor.color(0x169C9C)),
BLUE_WARDEN(Material.BLUE_GLAZED_TERRACOTTA, EntityType.WARDEN, Enchantment.SWIFT_SNEAK, 2, Difficulty.HARD, TextColor.color(0x3C44AA)),
PURPLE_ENDER_DRAGON(Material.PURPLE_GLAZED_TERRACOTTA, EntityType.ENDER_DRAGON, Enchantment.POWER, 2, Difficulty.HARD, TextColor.color(0x8932B8)),
MAGENTA_ENDERMAN(Material.MAGENTA_GLAZED_TERRACOTTA, EntityType.ENDERMAN, Enchantment.INFINITY, 2, Difficulty.EASY, TextColor.color(0xC74EBD)),
PINK_HOGLIN(Material.PINK_GLAZED_TERRACOTTA, EntityType.HOGLIN, Enchantment.PIERCING, 2, Difficulty.NORMAL, TextColor.color(0xF38BAA)),
WHITE_SKELETON(Material.WHITE_GLAZED_TERRACOTTA, EntityType.SKELETON, Enchantment.MULTISHOT, 2, Difficulty.NORMAL, TextColor.color(0xFFFFFF)),
LIGHT_GRAY_SILVERFISH(Material.LIGHT_GRAY_GLAZED_TERRACOTTA, EntityType.SILVERFISH, Enchantment.EFFICIENCY, 2, Difficulty.NORMAL, TextColor.color(0x9D9D97)),
GRAY_WITHER(Material.GRAY_GLAZED_TERRACOTTA, EntityType.WITHER, Enchantment.SMITE, 2, Difficulty.HARD, TextColor.color(0x474F52)),
BLACK_WITHER_SKELETON(Material.BLACK_GLAZED_TERRACOTTA, EntityType.WITHER_SKELETON, Enchantment.LOOTING, 2, Difficulty.NORMAL, TextColor.color(0x1D1D21));
public enum Difficulty {EASY, NORMAL, HARD}
@ -34,13 +35,16 @@ public enum EggType {
private final int enchantLevel;
@Getter
private final Difficulty difficulty;
@Getter
private final TextColor color;
EggType(Material material, EntityType entityType, Enchantment enchantment, int enchantLevel, Difficulty difficulty) {
EggType(Material material, EntityType entityType, Enchantment enchantment, int enchantLevel, Difficulty difficulty, TextColor color) {
this.material = material;
this.entityType = entityType;
this.enchantment = enchantment;
this.enchantLevel = enchantLevel;
this.difficulty = difficulty;
this.color = color;
}
public static EggType fromEntityType(EntityType entityType) {

View File

@ -1,55 +0,0 @@
package com.alttd.easter.glow;
import com.alttd.easter.egg.EggType;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.plugin.Plugin;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
public class GlowManager {
private final Scoreboard scoreboard;
public GlowManager(Plugin plugin) {
this.scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
}
public void applyGlow(Entity entity, EggType type) {
String teamName = ("easter_" + type.name()).toLowerCase();
Team team = scoreboard.getTeam(teamName);
if (team == null) {
team = scoreboard.registerNewTeam(teamName);
team.setCanSeeFriendlyInvisibles(false);
team.setAllowFriendlyFire(true);
team.color(colorFor(type));
}
String entry = entity.getUniqueId().toString();
if (!team.hasEntry(entry)) {
team.addEntry(entry);
}
}
private NamedTextColor colorFor(EggType type) {
return switch (type) {
case BROWN_HUSK -> NamedTextColor.DARK_RED; // closest
case RED_SPIDER -> NamedTextColor.RED;
case ORANGE_BLAZE -> NamedTextColor.GOLD;
case YELLOW_PIGLIN -> NamedTextColor.YELLOW;
case LIME_CREEPER -> NamedTextColor.GREEN;
case GREEN_ZOMBIE -> NamedTextColor.DARK_GREEN;
case LIGHT_BLUE_STRAY -> NamedTextColor.AQUA;
case CYAN_GUARDIAN -> NamedTextColor.DARK_AQUA;
case BLUE_WARDEN -> NamedTextColor.BLUE;
case PURPLE_ENDER_DRAGON -> NamedTextColor.DARK_PURPLE;
case MAGENTA_ENDERMAN -> NamedTextColor.LIGHT_PURPLE;
case PINK_HOGLIN -> NamedTextColor.LIGHT_PURPLE;
case WHITE_SKELETON -> NamedTextColor.WHITE;
case LIGHT_GRAY_SILVERFISH -> NamedTextColor.GRAY;
case GRAY_WITHER -> NamedTextColor.DARK_GRAY;
case BLACK_WITHER_SKELETON -> NamedTextColor.BLACK;
default -> NamedTextColor.WHITE;
};
}
}

View File

@ -108,7 +108,7 @@ public class TurnInGuiManager implements Listener {
// Dialog formatting for submission summary
List<Component> eggComponents = new ArrayList<>();
for (EggType type : submitted) {
eggComponents.add(Component.text(ItemUtils.colorName(type)));
eggComponents.add(ItemUtils.colorNameComponent(type));
}
if (eggComponents.size() == 1) {
player.sendRichMessage(Messages.RABBIT.ONE_EGG,

View File

@ -101,11 +101,14 @@ public class RabbitNpcManager implements Listener {
List<EggType> sorted = eggs.stream()
.sorted(Comparator.comparingInt(Enum::ordinal))
.toList();
String names = sorted.stream()
.map(e -> ItemUtils.prettify(e.name()))
.collect(Collectors.joining(", "));
var components = sorted.stream()
.map(ItemUtils::colorNameComponent)
.toList();
var joined = net.kyori.adventure.text.Component.join(net.kyori.adventure.text.JoinConfiguration.builder()
.separator(net.kyori.adventure.text.Component.text(", "))
.build(), components);
player.sendRichMessage(Messages.RABBIT.TURNED_IN_LIST,
Placeholder.parsed("eggs", names));
Placeholder.component("eggs", joined));
}
private void openTurnIn(Player player) {

View File

@ -3,6 +3,9 @@ package com.alttd.easter.util;
import com.alttd.easter.egg.EggType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -13,7 +16,7 @@ import java.util.List;
public final class ItemUtils {
public static String colorName(EggType type) {
private static String colorName(EggType type) {
return switch (type) {
case BROWN_HUSK -> "Brown";
case RED_SPIDER -> "Red";
@ -34,12 +37,23 @@ public final class ItemUtils {
};
}
public static Component colorNameComponent(EggType type) {
return Component.text(colorName(type), type.getColor());
}
public static Component typeNameComponent(EggType type) {
return Component.text(prettify(type.name()), type.getColor());
}
public static ItemStack createEggItem(EggType type) {
ItemStack item = new ItemStack(type.getMaterial());
ItemMeta meta = item.getItemMeta();
meta.addEnchant(type.getEnchantment(), type.getEnchantLevel(), true);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.displayName(Component.text("Easter Egg - " + prettify(type.name()), NamedTextColor.GOLD));
Component name = MiniMessage.miniMessage().deserialize("<gold>Easter Egg - </gold><type>",
Placeholder.component("type", typeNameComponent(type))
);
meta.displayName(name);
meta.getPersistentDataContainer().set(Keys.EGG_ITEM, PersistentDataType.STRING, type.name());
item.setItemMeta(meta);
return item;