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

Merge pull request #204 from HibiscusMC/itemmodel-placeholder

feat: add itemmodel & itemname placeholders, bump api to 1.21.4 with …
This commit is contained in:
Logan
2025-12-17 11:09:09 -06:00
committed by GitHub
5 changed files with 57 additions and 25 deletions

View File

@@ -75,7 +75,7 @@ allprojects {
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") }) compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
compileOnly("com.mojang:authlib:1.5.25") compileOnly("com.mojang:authlib:1.5.25")
//compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT") //compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:24.1.0") compileOnly("org.jetbrains:annotations:24.1.0")
compileOnly("me.clip:placeholderapi:2.11.6") compileOnly("me.clip:placeholderapi:2.11.6")
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6") compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6")

View File

@@ -18,7 +18,6 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -66,7 +65,7 @@ public class CosmeticBackpackType extends Cosmetic implements CosmeticUpdateBeha
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), newViewers); PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), newViewers);
if (user.getPlayer() != null) { if (user.getPlayer() != null) {
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE); AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
if (scaleAttribute != null) { if (scaleAttribute != null) {
HMCCPacketManager.sendEntityScalePacket(user.getUserBackpackManager().getFirstArmorStandId(), scaleAttribute.getValue(), newViewers); HMCCPacketManager.sendEntityScalePacket(user.getUserBackpackManager().getFirstArmorStandId(), scaleAttribute.getValue(), newViewers);
} }

View File

@@ -73,29 +73,20 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
if (placeholderArgs.size() >= 2) { if (placeholderArgs.size() >= 2) {
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase()); CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
if (slot == null) return null; if (slot == null) return null;
if (user.getCosmetic(slot) == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic"); Cosmetic cosmetic = user.getCosmetic(slot);
if (cosmetic == null) return TranslationUtil.getTranslation("current-cosmetic", "no-cosmetic");
if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId(); if (placeholderArgs.size() == 2) return user.getCosmetic(slot).getId();
String output; String output;
switch (placeholderArgs.get(2).toLowerCase()) { switch (placeholderArgs.get(2).toLowerCase()) {
case "material" -> { case "material" -> output = getMaterialName(cosmetic);
output = getMaterialName(user.getCosmetic(slot)); case "custommodeldata" -> output = getModelData(cosmetic);
} case "itemmodel" -> output = getItemModel(cosmetic);
case "custommodeldata" -> { case "itemname" -> output = getItemName(cosmetic);
output = getModelData(user.getCosmetic(slot)); case "name" -> output = getDisplayName(cosmetic);
} case "lore" -> output = getItemLore(cosmetic);
case "name" -> { case "permission" -> output = user.getCosmetic(slot).getPermission();
output = getItemName(user.getCosmetic(slot)); default -> output = user.getCosmetic(slot).getId();
}
case "lore" -> {
output = getItemLore(user.getCosmetic(slot));
}
case "permission" -> {
output = user.getCosmetic(slot).getPermission();
}
default -> {
output = user.getCosmetic(slot).getId();
}
} }
if (output == null) output = "none"; if (output == null) output = "none";
return TranslationUtil.getTranslation("current-cosmetic", output); return TranslationUtil.getTranslation("current-cosmetic", output);
@@ -217,13 +208,55 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
return String.valueOf(itemMeta.getCustomModelData()); return String.valueOf(itemMeta.getCustomModelData());
} }
/**
* Gets the cosmetic items item model
* @param cosmetic The cosmetic to get its item model
* @return The cosmetic items item model
*/
@Nullable
public String getItemModel(@NotNull Cosmetic cosmetic) {
try {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
if (!item.hasItemMeta()) return null;
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null && itemMeta.hasItemModel() ) return null;
return itemMeta.getItemModel().asString();
} catch (Exception e) {
return null;
}
}
/**
* Gets the cosmetic items item name
* @param cosmetic The cosmetic to get its items item name
* @return The cosmetic items item name
*/
@Nullable
public String getItemName(@NotNull Cosmetic cosmetic) {
try {
ItemStack item = cosmetic.getItem();
if (item == null) return null;
if (!item.hasItemMeta()) return null;
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta == null || !itemMeta.hasItemName()) return null;
return itemMeta.getDisplayName();
} catch (Exception e) {
return null;
}
}
/** /**
* Gets the cosmetic items display name * Gets the cosmetic items display name
* @param cosmetic The cosmetic to get its items display name * @param cosmetic The cosmetic to get its items display name
* @return The cosmetic items display name * @return The cosmetic items display name
*/ */
@Nullable @Nullable
public String getItemName(@NotNull Cosmetic cosmetic) { public String getDisplayName(@NotNull Cosmetic cosmetic) {
ItemStack item = cosmetic.getItem(); ItemStack item = cosmetic.getItem();
if (item == null) return null; if (item == null) return null;
if (!item.hasItemMeta()) return null; if (!item.hasItemMeta()) return null;

View File

@@ -59,7 +59,7 @@ public class UserBackpackManager {
HMCCPacketManager.spawnInvisibleArmorstand(getFirstArmorStandId(), user.getEntity().getLocation(), UUID.randomUUID(), outsideViewers); HMCCPacketManager.spawnInvisibleArmorstand(getFirstArmorStandId(), user.getEntity().getLocation(), UUID.randomUUID(), outsideViewers);
if (user.getPlayer() != null) { if (user.getPlayer() != null) {
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE); AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
if (scaleAttribute != null) { if (scaleAttribute != null) {
HMCCPacketManager.sendEntityScalePacket(getFirstArmorStandId(), scaleAttribute.getValue(), outsideViewers); HMCCPacketManager.sendEntityScalePacket(getFirstArmorStandId(), scaleAttribute.getValue(), outsideViewers);
} }

View File

@@ -142,7 +142,7 @@ public class UserWardrobeManager {
HMCCPacketManager.sendPlayerOverlayPacket(NPC_ID, viewer); HMCCPacketManager.sendPlayerOverlayPacket(NPC_ID, viewer);
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation); MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
NMSHandlers.getHandler().getPacketHandler().sendScoreboardHideNamePacket(player, npcName); NMSHandlers.getHandler().getPacketHandler().sendScoreboardHideNamePacket(player, npcName);
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE); AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
if (scaleAttribute != null) { if (scaleAttribute != null) {
HMCCPacketManager.sendEntityScalePacket(NPC_ID, scaleAttribute.getValue(), viewer); HMCCPacketManager.sendEntityScalePacket(NPC_ID, scaleAttribute.getValue(), viewer);
} }