9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-19 15:09:19 +00:00

refactor: swap to commons color api

This commit is contained in:
Boy0000
2025-05-09 15:53:51 +02:00
parent 41ac857a11
commit 172ffc0333
3 changed files with 14 additions and 47 deletions

View File

@@ -69,6 +69,8 @@ allprojects {
// Hibiscus Commons // Hibiscus Commons
maven("https://repo.hibiscusmc.com/releases") maven("https://repo.hibiscusmc.com/releases")
mavenLocal()
} }
dependencies { dependencies {
@@ -86,7 +88,7 @@ allprojects {
compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library
//compileOnly("it.unimi.dsi:fastutil:8.5.14") //compileOnly("it.unimi.dsi:fastutil:8.5.14")
compileOnly("org.projectlombok:lombok:1.18.34") compileOnly("org.projectlombok:lombok:1.18.34")
compileOnly("me.lojosho:HibiscusCommons:0.6.3-d97e5686") compileOnly("me.lojosho:HibiscusCommons:0.6.3-7ef40c1")
// Handled by Spigot Library Loader // Handled by Spigot Library Loader
compileOnly("net.kyori:adventure-api:4.19.0") compileOnly("net.kyori:adventure-api:4.19.0")

View File

@@ -9,14 +9,14 @@ import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticHolder;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import me.lojosho.hibiscuscommons.hooks.Hooks; import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
import me.lojosho.hibiscuscommons.nms.NMSHandlers; import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.AdventureUtils; import me.lojosho.hibiscuscommons.util.AdventureUtils;
import me.lojosho.hibiscuscommons.util.StringUtils; import me.lojosho.hibiscuscommons.util.StringUtils;
import org.bukkit.*; import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -37,30 +37,7 @@ public class DyeMenu {
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot()); ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
if (item == null) return; if (item == null) return;
Color color = null; Color color = NMSHandlers.getHandler().getUtilHandler().getColor(item);
try {
// Uses Idofront Colorable logic as 1.21.4+ lets any item be dyed
// Requires NMS or Paper's DataComponent API
// If it fails it will fall back to getting it from ItemMeta
// with an extra fallback here in-case HMCColor is old
color = HMCColorApi.getItemColor(item);
} catch (Exception e) {
ItemMeta meta = item.getItemMeta();
switch (meta) {
case null -> { return; }
case LeatherArmorMeta leatherMeta -> color = leatherMeta.getColor();
case PotionMeta potionMeta -> color = potionMeta.getColor();
case MapMeta mapMeta -> color = mapMeta.getColor();
case FireworkEffectMeta fireworkEffectMeta -> {
FireworkEffect effect = fireworkEffectMeta.getEffect();
if (effect != null) {
color = effect.getColors().stream().findFirst().isPresent() ? effect.getColors().stream().findFirst().get() : null;
}
}
default -> {}
}
}
if (color == null) return; if (color == null) return;
addCosmetic(viewer, cosmeticHolder, cosmetic, color); addCosmetic(viewer, cosmeticHolder, cosmetic, color);

View File

@@ -22,8 +22,10 @@ import com.hibiscusmc.hmccosmetics.user.manager.UserWardrobeManager;
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils; import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager; import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
import com.ticxo.modelengine.api.nms.NMSHandler;
import lombok.Getter; import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks; import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.InventoryUtils; import me.lojosho.hibiscuscommons.util.InventoryUtils;
import me.lojosho.hibiscuscommons.util.packets.PacketManager; import me.lojosho.hibiscuscommons.util.packets.PacketManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -405,29 +407,15 @@ public class CosmeticUser implements CosmeticHolder {
} }
if (colors.containsKey(cosmetic.getSlot())) {
Color color = colors.get(cosmetic.getSlot());
if (itemMeta instanceof LeatherArmorMeta leatherMeta) {
leatherMeta.setColor(color);
} else if (itemMeta instanceof PotionMeta potionMeta) {
potionMeta.setColor(color);
} else if (itemMeta instanceof MapMeta mapMeta) {
mapMeta.setColor(color);
} else if (itemMeta instanceof FireworkEffectMeta fireworkMeta) {
fireworkMeta.setEffect(
FireworkEffect.builder()
.with(FireworkEffect.Type.BALL)
.withColor(color)
.trail(false)
.flicker(false)
.build()
);
}
}
itemMeta.getPersistentDataContainer().set(HMCCInventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId()); itemMeta.getPersistentDataContainer().set(HMCCInventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId());
itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getEntity().getUniqueId().toString()); itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getEntity().getUniqueId().toString());
item.setItemMeta(itemMeta); item.setItemMeta(itemMeta);
if (colors.containsKey(cosmetic.getSlot())) {
Color color = colors.get(cosmetic.getSlot());
NMSHandlers.getHandler().getUtilHandler().setColor(item, color);
}
} }
return item; return item;
} }