mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
feat: determine color based on new HMCColor API to allow any Material to be dyable
This commit is contained in:
@@ -9,6 +9,8 @@ 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.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.*;
|
||||||
@@ -34,21 +36,30 @@ public class DyeMenu {
|
|||||||
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
|
if (event.getSlot() == Settings.getDyeMenuOutputSlot()) {
|
||||||
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
|
ItemStack item = event.getInventory().getItem(Settings.getDyeMenuOutputSlot());
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
if (meta == null) return;
|
|
||||||
|
|
||||||
Color color = null;
|
Color color = null;
|
||||||
if (meta instanceof LeatherArmorMeta leatherMeta) {
|
try {
|
||||||
color = leatherMeta.getColor();
|
// Uses Idofront Colorable logic as 1.21.4+ lets any item be dyed
|
||||||
} else if (meta instanceof PotionMeta potionMeta) {
|
// Requires NMS or Paper's DataComponent API
|
||||||
color = potionMeta.getColor();
|
// If it fails it will fall back to getting it from ItemMeta
|
||||||
} else if (meta instanceof MapMeta mapMeta) {
|
// with an extra fallback here in-case HMCColor is old
|
||||||
color = mapMeta.getColor();
|
color = HMCColorApi.getItemColor(item);
|
||||||
} else if (meta instanceof FireworkEffectMeta fireworkEffectMeta) {
|
} catch (Exception e) {
|
||||||
FireworkEffect effect = fireworkEffectMeta.getEffect();
|
ItemMeta meta = item.getItemMeta();
|
||||||
if (effect != null) {
|
switch (meta) {
|
||||||
color = effect.getColors().stream().findFirst().isPresent() ? effect.getColors().stream().findFirst().get() : null;
|
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;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user