mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 06:59:24 +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:
@@ -75,7 +75,7 @@ allprojects {
|
||||
compileOnly(fileTree("${project.rootDir}/lib") { include("*.jar") })
|
||||
compileOnly("com.mojang:authlib:1.5.25")
|
||||
//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("me.clip:placeholderapi:2.11.6")
|
||||
compileOnly("com.ticxo.modelengine:ModelEngine:R4.0.6")
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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);
|
||||
|
||||
if (user.getPlayer() != null) {
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
|
||||
if (scaleAttribute != null) {
|
||||
HMCCPacketManager.sendEntityScalePacket(user.getUserBackpackManager().getFirstArmorStandId(), scaleAttribute.getValue(), newViewers);
|
||||
}
|
||||
|
||||
@@ -73,29 +73,20 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
if (placeholderArgs.size() >= 2) {
|
||||
CosmeticSlot slot = CosmeticSlot.valueOf(placeholderArgs.get(1).toUpperCase());
|
||||
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();
|
||||
|
||||
String output;
|
||||
switch (placeholderArgs.get(2).toLowerCase()) {
|
||||
case "material" -> {
|
||||
output = getMaterialName(user.getCosmetic(slot));
|
||||
}
|
||||
case "custommodeldata" -> {
|
||||
output = getModelData(user.getCosmetic(slot));
|
||||
}
|
||||
case "name" -> {
|
||||
output = getItemName(user.getCosmetic(slot));
|
||||
}
|
||||
case "lore" -> {
|
||||
output = getItemLore(user.getCosmetic(slot));
|
||||
}
|
||||
case "permission" -> {
|
||||
output = user.getCosmetic(slot).getPermission();
|
||||
}
|
||||
default -> {
|
||||
output = user.getCosmetic(slot).getId();
|
||||
}
|
||||
case "material" -> output = getMaterialName(cosmetic);
|
||||
case "custommodeldata" -> output = getModelData(cosmetic);
|
||||
case "itemmodel" -> output = getItemModel(cosmetic);
|
||||
case "itemname" -> output = getItemName(cosmetic);
|
||||
case "name" -> output = getDisplayName(cosmetic);
|
||||
case "lore" -> output = getItemLore(cosmetic);
|
||||
case "permission" -> output = user.getCosmetic(slot).getPermission();
|
||||
default -> output = user.getCosmetic(slot).getId();
|
||||
}
|
||||
if (output == null) output = "none";
|
||||
return TranslationUtil.getTranslation("current-cosmetic", output);
|
||||
@@ -217,13 +208,55 @@ public class HMCPlaceholderExpansion extends PlaceholderExpansion {
|
||||
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
|
||||
* @param cosmetic The cosmetic to get its items display name
|
||||
* @return The cosmetic items display name
|
||||
*/
|
||||
@Nullable
|
||||
public String getItemName(@NotNull Cosmetic cosmetic) {
|
||||
public String getDisplayName(@NotNull Cosmetic cosmetic) {
|
||||
ItemStack item = cosmetic.getItem();
|
||||
if (item == null) return null;
|
||||
if (!item.hasItemMeta()) return null;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class UserBackpackManager {
|
||||
HMCCPacketManager.spawnInvisibleArmorstand(getFirstArmorStandId(), user.getEntity().getLocation(), UUID.randomUUID(), outsideViewers);
|
||||
|
||||
if (user.getPlayer() != null) {
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
|
||||
if (scaleAttribute != null) {
|
||||
HMCCPacketManager.sendEntityScalePacket(getFirstArmorStandId(), scaleAttribute.getValue(), outsideViewers);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public class UserWardrobeManager {
|
||||
HMCCPacketManager.sendPlayerOverlayPacket(NPC_ID, viewer);
|
||||
MessagesUtil.sendDebugMessages("Spawned Fake Player on " + npcLocation);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendScoreboardHideNamePacket(player, npcName);
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.GENERIC_SCALE);
|
||||
AttributeInstance scaleAttribute = user.getPlayer().getAttribute(Attribute.SCALE);
|
||||
if (scaleAttribute != null) {
|
||||
HMCCPacketManager.sendEntityScalePacket(NPC_ID, scaleAttribute.getValue(), viewer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user