Fixes custom model data of skill icons in 1.20.6+

This commit is contained in:
Jules 2024-08-14 13:33:41 -07:00
parent 84e587ba0b
commit d792b84219
3 changed files with 27 additions and 18 deletions

View File

@ -21,6 +21,7 @@ import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import org.jetbrains.annotations.NotNull;
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
import java.io.ByteArrayInputStream;
@ -115,10 +116,18 @@ public class MMOCoreUtils {
return material == Material.PLAYER_HEAD || material == Material.PLAYER_WALL_HEAD;
}
public static ItemStack readIcon(String string) throws IllegalArgumentException {
String[] split = string.split(":");
Material material = Material.valueOf(split[0].toUpperCase().replace("-", "_").replace(" ", "_"));
return split.length > 1 ? MythicLib.plugin.getVersion().getWrapper().textureItem(material, Integer.parseInt(split[1])) : new ItemStack(material);
@NotNull
public static ItemStack readIcon(String string) {
final String[] split = string.split(":");
final ItemStack item = new ItemStack(Material.valueOf(split[0].toUpperCase().replace("-", "_").replace(" ", "_")));
if (split.length > 1) {
final ItemMeta meta = item.getItemMeta();
meta.setCustomModelData(Integer.parseInt(split[1]));
item.setItemMeta(meta);
}
return item;
}
public static int getWorth(ItemStack[] items) {

View File

@ -218,22 +218,23 @@ public class SkillList extends EditableInventory {
return new ItemStack(Material.AIR);
final @Nullable ClassSkill boundSkill = inv.getPlayerData().getBoundSkill(n + 1);
ItemStack item;
if (boundSkill == null)
final ItemStack item;
final ItemMeta meta;
if (boundSkill == null) {
item = super.display(inv, n);
else if (filledItem == null)
meta = item.getItemMeta();
} else if (filledItem == null) {
item = boundSkill.getSkill().getIcon();
else {
meta = item.getItemMeta();
} else {
item = new ItemStack(filledItem);
if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13)) {
ItemMeta meta = item.getItemMeta();
meta.setCustomModelData(filledCMD);
item.setItemMeta(meta);
}
}
Placeholders holders = getPlaceholders(inv, n);
meta = item.getItemMeta();
meta.setCustomModelData(filledCMD);
}
final Placeholders holders = getPlaceholders(inv, n);
final ItemMeta meta = item.getItemMeta();
meta.setDisplayName(MMOCore.plugin.placeholderParser.parse(inv.getPlayerData().getPlayer(), skillSlot.getName()));
List<String> lore = new ArrayList<>(getLore());

View File

@ -167,8 +167,7 @@ public class SkillTreeViewer extends EditableInventory {
lore.add(holders.apply(inv.getPlayer(), string));
});
meta.setLore(lore);
if (MythicLib.plugin.getVersion().isStrictlyHigher(1, 13))
meta.setCustomModelData(skillTree.getCustomModelData());
meta.setCustomModelData(skillTree.getCustomModelData());
PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(new NamespacedKey(MMOCore.plugin, "skill-tree-id"), PersistentDataType.STRING, skillTree.getId());
item.setItemMeta(meta);