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

View File

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

View File

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