mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
feat: add itemmodel & itemname placeholders, bump api to 1.21.4 with attribute wrapper
This commit is contained in:
@@ -7,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.behavior.CosmeticUpdateBehavior;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEntity;
|
||||
import com.hibiscusmc.hmccosmetics.util.AttributeWrapper;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
@@ -63,7 +64,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(AttributeWrapper.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;
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.AttributeWrapper;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
@@ -60,7 +61,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(AttributeWrapper.SCALE);
|
||||
if (scaleAttribute != null) {
|
||||
HMCCPacketManager.sendEntityScalePacket(getFirstArmorStandId(), scaleAttribute.getValue(), outsideViewers);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.AttributeWrapper;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCInventoryUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
@@ -143,7 +144,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(AttributeWrapper.SCALE);
|
||||
if (scaleAttribute != null) {
|
||||
HMCCPacketManager.sendEntityScalePacket(NPC_ID, scaleAttribute.getValue(), viewer);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.hibiscusmc.hmccosmetics.util;
|
||||
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public class AttributeWrapper {
|
||||
@Deprecated
|
||||
@ApiStatus.ScheduledForRemoval
|
||||
public static Attribute SCALE;
|
||||
|
||||
static {
|
||||
try {
|
||||
SCALE = Attribute.SCALE;
|
||||
} catch (Exception e) {
|
||||
SCALE = Attribute.valueOf("GENERIC_SCALE");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user