9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-22 08:29:27 +00:00

Merge pull request #176 from HibiscusMC/le-epic-minor-tweaks-again-we-love-it

feat: dyeable click-type & color changes
This commit is contained in:
Logan
2025-05-09 10:56:31 -05:00
committed by GitHub
10 changed files with 44 additions and 58 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

@@ -53,6 +53,7 @@ public class Settings {
private static final String COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type"; private static final String COSMETIC_TYPE_SETTINGS_PATH = "cosmetic-type";
private static final String EQUIP_CLICK_TYPE = "equip-click"; private static final String EQUIP_CLICK_TYPE = "equip-click";
private static final String UNEQUIP_CLICK_TYPE = "unequip-click"; private static final String UNEQUIP_CLICK_TYPE = "unequip-click";
private static final String DYE_CLICK_TYPE = "dye-click";
private static final String SHADING_PATH = "shading"; private static final String SHADING_PATH = "shading";
private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift"; private static final String FIRST_ROW_SHIFT_PATH = "first-row-shift";
private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift"; private static final String SEQUENT_ROW_SHIFT_PATH = "sequent-row-shift";
@@ -130,6 +131,8 @@ public class Settings {
@Getter @Getter
private static String cosmeticUnEquipClickType; private static String cosmeticUnEquipClickType;
@Getter @Getter
private static String cosmeticDyeClickType;
@Getter
private static boolean defaultShading; private static boolean defaultShading;
@Getter @Getter
private static String firstRowShift; private static String firstRowShift;
@@ -227,6 +230,7 @@ public class Settings {
ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH); ConfigurationNode cosmeticTypeSettings = menuSettings.node(COSMETIC_TYPE_SETTINGS_PATH);
cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ALL"); cosmeticEquipClickType = cosmeticTypeSettings.node(EQUIP_CLICK_TYPE).getString("ALL");
cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ALL"); cosmeticUnEquipClickType = cosmeticTypeSettings.node(UNEQUIP_CLICK_TYPE).getString("ALL");
cosmeticDyeClickType = cosmeticTypeSettings.node(DYE_CLICK_TYPE).getString("ALL");
final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET); final var balloonSection = cosmeticSettings.node(BALLOON_OFFSET);
balloonOffset = loadVector(balloonSection); balloonOffset = loadVector(balloonSection);

View File

@@ -26,7 +26,7 @@ public abstract class Cosmetic {
@Getter @Setter @Getter @Setter
private CosmeticSlot slot; private CosmeticSlot slot;
@Getter @Setter @Getter @Setter
private boolean dyable; private boolean dyeable;
protected Cosmetic(String id, @NotNull ConfigurationNode config) { protected Cosmetic(String id, @NotNull ConfigurationNode config) {
this.id = id; this.id = id;
@@ -45,9 +45,9 @@ public abstract class Cosmetic {
MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString()); MessagesUtil.sendDebugMessages("Slot: " + config.node("slot").getString());
setSlot(CosmeticSlot.valueOf(config.node("slot").getString())); setSlot(CosmeticSlot.valueOf(config.node("slot").getString()));
setDyable(config.node("dyeable").getBoolean(false)); setDyeable(config.node("dyeable").getBoolean(false));
MessagesUtil.sendDebugMessages("Dyeable " + dyable); MessagesUtil.sendDebugMessages("Dyeable " + dyeable);
Cosmetics.addCosmetic(this); Cosmetics.addCosmetic(this);
} }

View File

@@ -23,7 +23,7 @@ public class CosmeticBalloonType extends Cosmetic {
@Getter @Getter
private final String modelName; private final String modelName;
@Getter @Getter
private List<String> dyableParts; private List<String> dyeableParts;
@Getter @Getter
private final boolean showLead; private final boolean showLead;
@Getter @Getter
@@ -42,8 +42,8 @@ public class CosmeticBalloonType extends Cosmetic {
balloonOffset = Settings.loadVector(balloonOffsetNode); balloonOffset = Settings.loadVector(balloonOffsetNode);
try { try {
if (!config.node("dyable-parts").virtual()) { if (!config.node("dyeable-parts").virtual()) {
dyableParts = config.node("dyable-parts").getList(String.class); dyeableParts = config.node("dyeable-parts").getList(String.class);
} }
} catch (SerializationException e) { } catch (SerializationException e) {
// Seriously? // Seriously?
@@ -101,10 +101,10 @@ public class CosmeticBalloonType extends Cosmetic {
} }
} }
public boolean isDyablePart(String name) { public boolean isDyeablePart(String name) {
// If player does not define parts, dye whole model // If player does not define parts, dye whole model
if (dyableParts == null) return true; if (dyeableParts == null) return true;
if (dyableParts.isEmpty()) return true; if (dyeableParts.isEmpty()) return true;
return dyableParts.contains(name); return dyeableParts.contains(name);
} }
} }

View File

@@ -9,12 +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.util.ColorBuilder; import me.lojosho.hibiscuscommons.nms.NMSHandlers;
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;
@@ -25,31 +27,17 @@ public class DyeMenu {
return; return;
} }
ItemStack originalItem = cosmetic.getItem(); ItemStack originalItem = cosmetic.getItem();
if (originalItem == null || !cosmetic.isDyable()) return; if (originalItem == null || !cosmetic.isDyeable()) return;
Gui gui = HMCColorApi.createColorMenu(viewer); Gui gui = HMCColorApi.createColorMenu(viewer);
gui.updateTitle(Hooks.processPlaceholders(viewer, StringUtils.parseStringToString(Settings.getDyeMenuName()))); gui.updateTitle(AdventureUtils.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(viewer, StringUtils.parseStringToString(Settings.getDyeMenuName()))));
gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem)); gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem));
gui.setDefaultTopClickAction(event -> { gui.setDefaultTopClickAction(event -> {
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 = NMSHandlers.getHandler().getUtilHandler().getColor(item);
if (meta instanceof LeatherArmorMeta leatherMeta) {
color = leatherMeta.getColor();
} else if (meta instanceof PotionMeta potionMeta) {
color = potionMeta.getColor();
} else if (meta instanceof MapMeta mapMeta) {
color = mapMeta.getColor();
} else if (meta instanceof FireworkEffectMeta fireworkEffectMeta) {
FireworkEffect effect = fireworkEffectMeta.getEffect();
if (effect != null) {
color = effect.getColors().stream().findFirst().isPresent() ? effect.getColors().stream().findFirst().get() : null;
}
}
if (color == null) return; if (color == null) return;
addCosmetic(viewer, cosmeticHolder, cosmetic, color); addCosmetic(viewer, cosmeticHolder, cosmetic, color);

View File

@@ -59,17 +59,22 @@ public class TypeCosmetic extends Type {
boolean isUnEquippingCosmetic = false; boolean isUnEquippingCosmetic = false;
if (cosmeticHolder.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true; if (cosmeticHolder.getCosmetic(cosmetic.getSlot()) == cosmetic) isUnEquippingCosmetic = true;
String dyeClick = Settings.getCosmeticDyeClickType();
String requiredClick; String requiredClick;
if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType(); if (isUnEquippingCosmetic) requiredClick = Settings.getCosmeticUnEquipClickType();
else requiredClick = Settings.getCosmeticEquipClickType(); else requiredClick = Settings.getCosmeticEquipClickType();
MessagesUtil.sendDebugMessages("Required click type: " + requiredClick); MessagesUtil.sendDebugMessages("Required click type: " + requiredClick);
MessagesUtil.sendDebugMessages("Click type: " + clickType.name()); MessagesUtil.sendDebugMessages("Click type: " + clickType.name());
if (!requiredClick.equalsIgnoreCase("ANY") && !requiredClick.equalsIgnoreCase(clickType.name())) { boolean isRequiredClick = requiredClick.equalsIgnoreCase("ANY") || requiredClick.equalsIgnoreCase(clickType.name());
boolean isDyeClick = dyeClick.equalsIgnoreCase("ANY") || dyeClick.equalsIgnoreCase(clickType.name());
if (!isRequiredClick && !isDyeClick) {
MessagesUtil.sendMessage(viewer.getPlayer(), "invalid-click-type"); MessagesUtil.sendMessage(viewer.getPlayer(), "invalid-click-type");
return; return;
} }
if (!isRequiredClick && isDyeClick) isUnEquippingCosmetic = false;
List<String> actionStrings = new ArrayList<>(); List<String> actionStrings = new ArrayList<>();
ConfigurationNode actionConfig = config.node("actions"); ConfigurationNode actionConfig = config.node("actions");
@@ -101,9 +106,9 @@ public class TypeCosmetic extends Type {
if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class)); if (!actionConfig.node("on-equip").virtual()) actionStrings.addAll(actionConfig.node("on-equip").getList(String.class));
MessagesUtil.sendDebugMessages("on-equip"); MessagesUtil.sendDebugMessages("on-equip");
// TODO: Redo this // TODO: Redo this
if (cosmetic.isDyable() && Hooks.isActiveHook("HMCColor")) { if (cosmetic.isDyeable() && isDyeClick && Hooks.isActiveHook("HMCColor")) {
DyeMenu.openMenu(viewer, cosmeticHolder, cosmetic); DyeMenu.openMenu(viewer, cosmeticHolder, cosmetic);
} else { } else if (isRequiredClick) {
cosmeticHolder.addCosmetic(cosmetic); cosmeticHolder.addCosmetic(cosmetic);
} }
} }

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;
} }
@@ -623,13 +611,13 @@ public class CosmeticUser implements CosmeticHolder {
} }
public List<CosmeticSlot> getDyeableSlots() { public List<CosmeticSlot> getDyeableSlots() {
ArrayList<CosmeticSlot> dyableSlots = new ArrayList<>(); ArrayList<CosmeticSlot> dyeableSlots = new ArrayList<>();
for (Cosmetic cosmetic : playerCosmetics.values()) { for (Cosmetic cosmetic : playerCosmetics.values()) {
if (cosmetic.isDyable()) dyableSlots.add(cosmetic.getSlot()); if (cosmetic.isDyeable()) dyeableSlots.add(cosmetic.getSlot());
} }
return dyableSlots; return dyeableSlots;
} }
@Override @Override

View File

@@ -11,7 +11,6 @@ import com.ticxo.modelengine.api.ModelEngineAPI;
import com.ticxo.modelengine.api.entity.data.BukkitEntityData; import com.ticxo.modelengine.api.entity.data.BukkitEntityData;
import com.ticxo.modelengine.api.model.ActiveModel; import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity; import com.ticxo.modelengine.api.model.ModeledEntity;
import com.ticxo.modelengine.api.nms.RenderParsers;
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.nms.NMSHandlers;
@@ -82,7 +81,7 @@ public class UserBalloonManager {
if (color != null) { if (color != null) {
modeledEntity.getModels().forEach((d, singleModel) -> { modeledEntity.getModels().forEach((d, singleModel) -> {
if (cosmeticBalloonType.isDyablePart(d)) { if (cosmeticBalloonType.isDyeablePart(d)) {
singleModel.setDefaultTint(color); singleModel.setDefaultTint(color);
singleModel.getModelRenderer().sendToClient(ModelEngineAPI.getNMSHandler().createParsers()); singleModel.getModelRenderer().sendToClient(ModelEngineAPI.getNMSHandler().createParsers());
} }

Binary file not shown.

BIN
lib/HMCColor-2.4-all.jar Normal file

Binary file not shown.