diff --git a/api/build.gradle.kts b/api/build.gradle.kts index f24b88c..003ee8f 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -1,7 +1,7 @@ plugins { java `maven-publish` - kotlin("jvm") version "2.0.0" + kotlin("jvm") version "2.0.20" id("org.jetbrains.dokka") version ("1.9.20") } @@ -11,6 +11,7 @@ version = rootProject.version repositories { mavenCentral() maven("https://repo.skyslycer.de/jitpack") + maven("https://repo.skyslycer.de/mirrors") maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") maven("https://oss.sonatype.org/content/repositories/snapshots/") maven("https://oss.sonatype.org/content/groups/public") @@ -18,7 +19,8 @@ repositories { maven("https://repo.dmulloy2.net/repository/public/") maven("https://repo.codemc.io/repository/maven-snapshots/") maven("https://repo.codemc.io/repository/maven-public/") - maven("https://nexuslite.gcnt.net/repos/other/") + maven("https://repo.triumphteam.dev/snapshots") + maven("https://repo.nexomc.com/snapshots/") } dependencies { diff --git a/api/src/main/java/de/skyslycer/hmcwraps/itemhook/DefaultItemHook.java b/api/src/main/java/de/skyslycer/hmcwraps/itemhook/DefaultItemHook.java index 5ebac33..31a43a4 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/itemhook/DefaultItemHook.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/itemhook/DefaultItemHook.java @@ -2,10 +2,12 @@ import org.bukkit.Color; import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; -public class DefaultItemHook implements ItemHook { +public class DefaultItemHook extends ItemHook { @Override @Nullable @@ -45,4 +47,16 @@ public String getTrimMaterial(String id) { return null; } + @Override + @Nullable + public EquipmentSlot getEquippableSlot(String id) { + return null; + } + + @Override + @Nullable + public NamespacedKey getEquippableModel(String id) { + return null; + } + } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/itemhook/HookAccessor.java b/api/src/main/java/de/skyslycer/hmcwraps/itemhook/HookAccessor.java index 34d0bcc..9db1a74 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/itemhook/HookAccessor.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/itemhook/HookAccessor.java @@ -1,6 +1,8 @@ package de.skyslycer.hmcwraps.itemhook; import org.bukkit.Color; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; @@ -8,6 +10,7 @@ public class HookAccessor { + private final DefaultItemHook defaultHook = new DefaultItemHook(); private final Set hooks; public HookAccessor(Set hooks) { @@ -24,7 +27,7 @@ public HookAccessor(Set hooks) { public ItemStack getItemFromHook(String id) { var possible = hooks.stream().filter(it -> id.startsWith(it.getPrefix())).findFirst(); if (possible.isEmpty()) { - return ItemHook.defaultHook.get(id); + return this.defaultHook.get(id); } else { return possible.get().get(id.replace(possible.get().getPrefix(), "")); } @@ -69,4 +72,16 @@ public String getTrimMaterialFromHook(String id) { return possible.map(itemHook -> itemHook.getTrimMaterial(id.replace(possible.get().getPrefix(), ""))).orElse(null); } + @Nullable + public EquipmentSlot getEquippableSlotFromHook(String id) { + var possible = hooks.stream().filter(it -> id.startsWith(it.getPrefix())).findFirst(); + return possible.map(itemHook -> itemHook.getEquippableSlot(id.replace(possible.get().getPrefix(), ""))).orElse(null); + } + + @Nullable + public NamespacedKey getEquippableModelFromHook(String id) { + var possible = hooks.stream().filter(it -> id.startsWith(it.getPrefix())).findFirst(); + return possible.map(itemHook -> itemHook.getEquippableModel(id.replace(possible.get().getPrefix(), ""))).orElse(null); + } + } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemHook.java b/api/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemHook.java index 22d4da9..cda5b86 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemHook.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemHook.java @@ -1,20 +1,22 @@ package de.skyslycer.hmcwraps.itemhook; +import de.skyslycer.hmcwraps.util.VersionUtil; import org.bukkit.Color; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ArmorMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; import org.jetbrains.annotations.Nullable; -public interface ItemHook { - - - DefaultItemHook defaultHook = new DefaultItemHook(); +public abstract class ItemHook { /** * Get the hook prefix. * * @return The hook prefix */ - String getPrefix(); + abstract String getPrefix(); /** * Get an item stack based on the input. @@ -23,7 +25,7 @@ public interface ItemHook { * @return The item stack */ @Nullable - ItemStack get(String id); + abstract ItemStack get(String id); /** * Get the model id corresponding to the input. @@ -31,7 +33,13 @@ public interface ItemHook { * @param id The input * @return The model id */ - int getModelId(String id); + public int getModelId(String id) { + var stack = get(id); + if (stack != null && stack.getItemMeta().hasCustomModelData()) { + return stack.getItemMeta().getCustomModelData(); + } + return -1; + } /** * Get the color corresponding to the input. @@ -40,7 +48,13 @@ public interface ItemHook { * @return The color */ @Nullable - Color getColor(String id); + public Color getColor(String id) { + var stack = get(id); + if (stack != null && stack.getItemMeta() instanceof LeatherArmorMeta meta) { + return meta.getColor(); + } + return null; + } /** * Get the trim pattern corresponding to the input. @@ -49,7 +63,13 @@ public interface ItemHook { * @return The trim pattern */ @Nullable - String getTrimPattern(String id); + public String getTrimPattern(String id) { + var stack = get(id); + if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) { + return meta.getTrim().getPattern().getKey().toString(); + } + return null; + } /** * Get the trim material corresponding to the input. @@ -58,6 +78,42 @@ public interface ItemHook { * @return The trim material */ @Nullable - String getTrimMaterial(String id); + public String getTrimMaterial(String id) { + var stack = get(id); + if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) { + return meta.getTrim().getMaterial().getKey().toString(); + } + return null; + } + + /** + * Get the equippable slot corresponding to the input. + * + * @param id The input + * @return The equippable slot + */ + @Nullable + public EquipmentSlot getEquippableSlot(String id) { + var stack = get(id); + if (VersionUtil.equippableSupported() && stack != null && stack.getItemMeta().hasEquippable()) { + return stack.getItemMeta().getEquippable().getSlot(); + } + return null; + } + + /** + * Get the equippable key corresponding to the input. + * + * @param id The input + * @return The equippable key + */ + @Nullable + public NamespacedKey getEquippableModel(String id) { + var stack = get(id); + if (VersionUtil.equippableSupported() && stack != null && stack.getItemMeta().hasEquippable()) { + return stack.getItemMeta().getEquippable().getModel(); + } + return null; + } } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/preview/floating/FloatingPreview.java b/api/src/main/java/de/skyslycer/hmcwraps/preview/floating/FloatingPreview.java index 6ccdef3..b2065b7 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/preview/floating/FloatingPreview.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/preview/floating/FloatingPreview.java @@ -52,9 +52,9 @@ public void preview() { sendTeleportPacket(); sendEquipPacket(); - task = plugin.getFoliaLib().getImpl().runTimerAsync(new RotateRunnable(player, entityId, plugin), 3, 1); + task = plugin.getFoliaLib().getScheduler().runTimerAsync(new RotateRunnable(player, entityId, plugin), 3, 1); - cancelTask = plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> plugin.getPreviewManager().remove(player.getUniqueId(), true), + cancelTask = plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> plugin.getPreviewManager().remove(player.getUniqueId(), true), plugin.getConfiguration().getPreview().getDuration() * 20L); } @@ -64,10 +64,10 @@ public void cancel(boolean open) { if (open && onClose != null) { onClose.accept(player); } - plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> { + plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> { PacketEvents.getAPI().getPlayerManager().sendPacket(player, new WrapperPlayServerDestroyEntities(entityId)); if (plugin.getConfiguration().getPreview().getSneakCancel().isActionBar()) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(" ")); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacy(" ")); } }, 1L); } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/preview/hand/HandPreview.java b/api/src/main/java/de/skyslycer/hmcwraps/preview/hand/HandPreview.java index ce06e7d..d3b777c 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/preview/hand/HandPreview.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/preview/hand/HandPreview.java @@ -41,12 +41,12 @@ public void preview() { slot = 36 + player.getInventory().getHeldItemSlot(); sendFakeItem(item); - task = plugin.getFoliaLib().getImpl().runTimerAsync(() -> { + task = plugin.getFoliaLib().getScheduler().runTimerAsync(() -> { if (plugin.getConfiguration().getPreview().getSneakCancel().isActionBar() && plugin.getConfiguration().getPreview().getSneakCancel().isEnabled()) { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, StringUtil.parse(player, plugin.getMessageHandler().get(Messages.PREVIEW_BAR))); } }, 3, 1); - cancelTask = plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> plugin.getPreviewManager().remove(player.getUniqueId(), true), + cancelTask = plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> plugin.getPreviewManager().remove(player.getUniqueId(), true), plugin.getConfiguration().getPreview().getDuration() * 20L); } @@ -56,10 +56,10 @@ public void cancel(boolean open) { if (open && onClose != null) { onClose.accept(player); } - plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> { + plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> { sendFakeItem(oldItem); if (plugin.getConfiguration().getPreview().getSneakCancel().isActionBar()) { - player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(" ")); + player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacy(" ")); } }, 1L); } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/serialization/globaldisable/GlobalDisable.java b/api/src/main/java/de/skyslycer/hmcwraps/serialization/globaldisable/GlobalDisable.java index 46811ff..2d2ce17 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/serialization/globaldisable/GlobalDisable.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/serialization/globaldisable/GlobalDisable.java @@ -12,6 +12,7 @@ public class GlobalDisable { private List oraxen; private List itemsadder; private List mythic; + private List nexo; public List getModelId() { return modelId; @@ -33,4 +34,8 @@ public List getMythicId() { return mythic; } + public List getNexoId() { + return nexo; + } + } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/serialization/inventory/Inventory.java b/api/src/main/java/de/skyslycer/hmcwraps/serialization/inventory/Inventory.java index ca215a7..595ccbf 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/serialization/inventory/Inventory.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/serialization/inventory/Inventory.java @@ -21,6 +21,7 @@ public class Inventory { private int targetItemSlot; private Map items; private @Nullable HashMap>> actions; + private @Nullable HashMap>> lockedActions; public String getTitle() { return title; @@ -51,6 +52,11 @@ public HashMap>> getActions() { return actions; } + @Nullable + public HashMap>> getLockedActions() { + return lockedActions; + } + public boolean isItemChangeEnabled() { return itemChangeEnabled; } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/serialization/inventory/InventoryItem.java b/api/src/main/java/de/skyslycer/hmcwraps/serialization/inventory/InventoryItem.java index cd0ee52..5669de3 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/serialization/inventory/InventoryItem.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/serialization/inventory/InventoryItem.java @@ -17,8 +17,8 @@ public class InventoryItem extends SerializableItem { public InventoryItem(String id, String name, @Nullable Boolean glow, @Nullable List lore, @Nullable List flags, @Nullable Integer modelId, @Nullable Map enchantments, @Nullable Integer amount, @Nullable String color, @Nullable String nbt, @Nullable Integer durability, @Nullable String skullOwner, @Nullable String skullTexture, - @Nullable String trim, @Nullable String trimMaterial) { - super(id, name, glow, lore, flags, modelId, enchantments, amount, color, nbt, durability, skullOwner, skullTexture, trim, trimMaterial); + @Nullable String trim, @Nullable String trimMaterial, @Nullable String equippableSlot, @Nullable String equippableModel) { + super(id, name, glow, lore, flags, modelId, enchantments, amount, color, nbt, durability, skullOwner, skullTexture, trim, trimMaterial, equippableSlot, equippableModel); } public InventoryItem() { diff --git a/api/src/main/java/de/skyslycer/hmcwraps/serialization/item/SerializableItem.java b/api/src/main/java/de/skyslycer/hmcwraps/serialization/item/SerializableItem.java index 2a265c3..044a4f4 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/serialization/item/SerializableItem.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/serialization/item/SerializableItem.java @@ -11,6 +11,7 @@ import org.bukkit.*; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ArmorMeta; @@ -43,10 +44,14 @@ public class SerializableItem { private @Nullable String skullTexture; private @Nullable String trim; private @Nullable String trimMaterial; + private @Nullable String equippableSlot; + private @Nullable String equippableModel; public SerializableItem(String id, String name, @Nullable Boolean glow, @Nullable List lore, @Nullable List flags, @Nullable Integer modelId, @Nullable Map enchantments, @Nullable Integer amount, - @Nullable String color, @Nullable String nbt, @Nullable Integer durability, @Nullable String skullOwner, @Nullable String skullTexture, @Nullable String trim, @Nullable String trimMaterial) { + @Nullable String color, @Nullable String nbt, @Nullable Integer durability, @Nullable String skullOwner, + @Nullable String skullTexture, @Nullable String trim, @Nullable String trimMaterial, + @Nullable String equippableSlot, @Nullable String equippableModel) { this.id = id; this.name = name; this.glow = glow; @@ -62,6 +67,22 @@ public SerializableItem(String id, String name, @Nullable Boolean glow, @Nullabl this.skullTexture = skullTexture; this.trim = trim; this.trimMaterial = trimMaterial; + this.equippableSlot = equippableSlot; + this.equippableModel = equippableModel; + } + + public SerializableItem(String id, String name, @Nullable Boolean glow, @Nullable List lore, @Nullable List flags, + @Nullable Integer modelId, @Nullable Map enchantments, @Nullable Integer amount, + @Nullable String color) { + this.id = id; + this.name = name; + this.glow = glow; + this.lore = lore; + this.flags = flags; + this.modelId = modelId; + this.enchantments = enchantments; + this.amount = amount; + this.color = color; } public SerializableItem() { @@ -240,4 +261,25 @@ public String getTrimMaterial() { return trimMaterial; } + @Nullable + public EquipmentSlot getEquippableSlot() { + if (equippableSlot == null) { + return ((HMCWraps) Bukkit.getPluginManager().getPlugin("HMCWraps")).getHookAccessor().getEquippableSlotFromHook(getId()); + } + try { + return EquipmentSlot.valueOf(equippableSlot); + } catch (IllegalArgumentException e) { + Bukkit.getLogger().warning("Failed to parse equippable slot " + equippableSlot + "! It seems to not be a valid slot. Please check your configuration!"); + } + return null; + } + + @Nullable + public NamespacedKey getEquippableModel() { + if (equippableModel == null) { + return ((HMCWraps) Bukkit.getPluginManager().getPlugin("HMCWraps")).getHookAccessor().getEquippableModelFromHook(getId()); + } + return NamespacedKey.fromString(equippableModel); + } + } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/PhysicalWrap.java b/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/PhysicalWrap.java index 4397300..48c19d6 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/PhysicalWrap.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/PhysicalWrap.java @@ -13,7 +13,7 @@ public class PhysicalWrap extends SerializableItem { public PhysicalWrap(String id, String name, @Nullable Boolean glow, @Nullable List lore, @Nullable Integer modelId) { - super(id, name, glow, lore, null, modelId, null, null, null, null, null, null, null, null, null); + super(id, name, glow, lore, null, modelId, null, null, null); this.keepAfterUnwrap = true; } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/Wrap.java b/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/Wrap.java index 6f229af..7332fee 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/Wrap.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/Wrap.java @@ -8,8 +8,10 @@ import dev.triumphteam.gui.builder.item.ItemBuilder; import org.bukkit.Color; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.Nullable; @@ -46,7 +48,7 @@ public class Wrap extends SerializableItem { public Wrap(String id, String name, @Nullable Boolean glow, @Nullable List lore, @Nullable Integer modelId, String uuid, @Nullable PhysicalWrap physical, @Nullable String permission, @Nullable InventoryItem lockedItem) { - super(id, name, glow, lore, null, modelId, null, null, null, null, null, null, null, null, null); + super(id, name, glow, lore, null, modelId, null, null, null); this.preview = true; this.uuid = uuid; this.physical = physical; @@ -57,7 +59,7 @@ public Wrap(String id, String name, @Nullable Boolean glow, @Nullable List lore, @Nullable Integer modelId, String uuid, @Nullable String color, Integer amount, @Nullable List flags, @Nullable Map enchantments) { - super(id, name, null, lore, flags, modelId, enchantments, amount, color, null, null, null, null, null, null); + super(id, name, null, lore, flags, modelId, enchantments, amount, color); this.uuid = uuid; } @@ -196,7 +198,8 @@ public ItemStack toPermissionItem(HMCWraps plugin, Material type, Player player) } public record WrapValues(int modelId, Color color, String name, List lore, List flags, String itemsAdder, - String oraxen, String mythic, String material, String trim, String trimMaterial) { + String oraxen, String mythic, String nexo, String material, String trim, String trimMaterial, + NamespacedKey equippableModel, EquipmentSlot equippableSlot) { } } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/range/RangeSettings.java b/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/range/RangeSettings.java index 913910d..ecb55e7 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/range/RangeSettings.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/serialization/wrap/range/RangeSettings.java @@ -10,13 +10,16 @@ public class RangeSettings { private ValueRangeSettings itemsadder; private ValueRangeSettings oraxen; private ValueRangeSettings mythic; + private ValueRangeSettings nexo; - public RangeSettings(ValueRangeSettings modelId, ValueRangeSettings color, ValueRangeSettings itemsAdder, ValueRangeSettings oraxen, ValueRangeSettings mythic) { + public RangeSettings(ValueRangeSettings modelId, ValueRangeSettings color, ValueRangeSettings itemsAdder, + ValueRangeSettings oraxen, ValueRangeSettings mythic, ValueRangeSettings nexo) { this.modelId = modelId; this.color = color; this.itemsadder = itemsAdder; this.oraxen = oraxen; this.mythic = mythic; + this.nexo = nexo; } public RangeSettings() {} @@ -41,9 +44,13 @@ public ValueRangeSettings getMythic() { return mythic; } + public ValueRangeSettings getNexo() { + return nexo; + } + public static RangeSettings empty() { return new RangeSettings(new ValueRangeSettings<>(), new ValueRangeSettings<>(), new ValueRangeSettings<>(), - new ValueRangeSettings<>(), new ValueRangeSettings<>()); + new ValueRangeSettings<>(), new ValueRangeSettings<>(), new ValueRangeSettings<>()); } } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/util/VersionUtil.java b/api/src/main/java/de/skyslycer/hmcwraps/util/VersionUtil.java index 6721037..4364bff 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/util/VersionUtil.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/util/VersionUtil.java @@ -15,6 +15,17 @@ public static int getMinorMinecraftVersion() { return Integer.parseInt(split[1]); } + /** + * Get the patch Minecraft version. + * 1.20.4 -> 4 + * + * @return The minor Minecraft version + */ + public static int getPatchMinecraftVersion() { + var split = Bukkit.getBukkitVersion().split("-")[0].split("\\."); + return Integer.parseInt(split[2]); + } + /** * Check if trims are supported. * @@ -24,4 +35,16 @@ public static boolean trimsSupported() { return getMinorMinecraftVersion() >= 20; } + /** + * Check if the equippable component is supported. + * + * @return If the equippable component is supported + */ + public static boolean equippableSupported() { + if (getMinorMinecraftVersion() > 21) { + return true; + } + return getMinorMinecraftVersion() == 21 && getPatchMinecraftVersion() >= 3; + } + } diff --git a/api/src/main/java/de/skyslycer/hmcwraps/wrap/Wrapper.java b/api/src/main/java/de/skyslycer/hmcwraps/wrap/Wrapper.java index 6fa1c07..7a11a7d 100644 --- a/api/src/main/java/de/skyslycer/hmcwraps/wrap/Wrapper.java +++ b/api/src/main/java/de/skyslycer/hmcwraps/wrap/Wrapper.java @@ -135,6 +135,23 @@ public interface Wrapper { */ ItemStack setPhysicalWrapper(ItemStack item, Wrap wrap); + /** + * Set the item to be using trims. This will prevent the item from being used in a smithing table. + * + * @param item The item + * @param used If the item is using trims + * @return The changed item + */ + ItemStack setTrimsUsed(ItemStack item, boolean used); + + /** + * Check if the item is using trims. + * + * @param item The item + * @return If the item is using trims + */ + boolean isTrimsUsed(ItemStack item); + /** * Get the saved data of the item. * diff --git a/build.gradle.kts b/build.gradle.kts index 4aac212..6dbbe75 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,18 +3,19 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription.Permission.Default plugins { java id("net.minecrell.plugin-yml.bukkit") version "0.6.0" - id("com.github.johnrengelman.shadow") version "8.1.1" + id("io.github.goooler.shadow") version "8.1.8" id("xyz.jpenilla.run-paper") version "2.3.0" } group = "de.skyslycer" -version = "1.5.0" +version = "1.5.1" val shadePattern = "$group.hmcwraps.shade" repositories { mavenCentral() maven("https://repo.skyslycer.de/jitpack") + maven("https://repo.skyslycer.de/mirrors") maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") maven("https://oss.sonatype.org/content/repositories/snapshots/") maven("https://oss.sonatype.org/content/groups/public") @@ -24,7 +25,8 @@ repositories { maven("https://repo.bytecode.space/repository/maven-public/") maven("https://mvn.lumine.io/repository/maven-public/") maven("https://repo.codemc.io/repository/maven-public/") - maven("https://nexuslite.gcnt.net/repos/other/") + maven("https://repo.triumphteam.dev/snapshots") + maven("https://repo.nexomc.com/snapshots/") } dependencies { @@ -46,6 +48,7 @@ dependencies { } compileOnly(depends.spigot) compileOnly(depends.placeholderapi) + compileOnly(depends.nexo) compileOnly(depends.oraxen) compileOnly(depends.itemsadder) compileOnly(depends.mythicmobs) @@ -99,11 +102,11 @@ tasks { options.compilerArgs.add("-parameters") options.encoding = "UTF-8" options.isFork = true - options.release = 17 + options.release = 21 } runServer { - minecraftVersion("1.21") + minecraftVersion("1.21.1") } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3cf1f5d..66176f1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index 5f784eb..96d1b20 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,33 +4,34 @@ include("api") dependencyResolutionManagement { versionCatalogs { create("depends") { - library("spigot", "org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT") - library("placeholderapi", "me.clip:placeholderapi:2.11.2") + library("spigot", "org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT") + library("placeholderapi", "me.clip:placeholderapi:2.11.6") + library("nexo", "com.nexomc:nexo:0.1.0-dev.14") library("oraxen", "com.github.oraxen:oraxen:-SNAPSHOT") library("itemsadder", "com.github.LoneDev6:API-ItemsAdder:3.6.1") - library("mythicmobs", "io.lumine:Mythic-Dist:5.6.2") - library("annotations", "org.jetbrains:annotations:24.1.0") + library("mythicmobs", "io.lumine:Mythic-Dist:5.7.1") + library("annotations", "org.jetbrains:annotations:26.0.1") } create("libs") { - library("packets", "com.github.retrooper:packetevents-spigot:2.4.0") + library("packets", "com.github.retrooper:packetevents-spigot:2.7.0") library("particles", "com.owen1212055:particlehelper:1.5.0-SNAPSHOT") library("configupdater", "com.github.BG-Software-LLC:CommentedConfiguration:-SNAPSHOT") library("bstats", "org.bstats:bstats-bukkit:3.0.2") - library("gui", "dev.triumphteam:triumph-gui:3.1.10") + library("gui", "dev.triumphteam:triumph-gui:3.1.11-SNAPSHOT") library("configurate", "org.spongepowered:configurate-yaml:4.1.2") library("mclogs", "gs.mclo:java:2.2.1") - library("nbtapi", "de.tr7zw:item-nbt-api:2.13.2") - library("folialib", "com.tcoded:FoliaLib:0.3.1") + library("nbtapi", "de.tr7zw:item-nbt-api:2.14.0") + library("folialib", "com.tcoded:FoliaLib:0.4.2") library("adventure-api", "net.kyori", "adventure-api").versionRef("adventure") library("minimessage", "net.kyori", "adventure-text-minimessage").versionRef("adventure") - library("adventure-bukkit", "net.kyori:adventure-platform-bukkit:4.3.2") - version("adventure", "4.12.0") + library("adventure-bukkit", "net.kyori:adventure-platform-bukkit:4.3.4") + version("adventure", "4.17.0") bundle("adventure", listOf("adventure-api", "minimessage", "adventure-bukkit")) library("lamp-common", "com.github.Revxrsal.Lamp", "common").versionRef("lamp") library("lamp-bukkit", "com.github.Revxrsal.Lamp", "bukkit").versionRef("lamp") - version("lamp", "3.1.1") + version("lamp", "3.3.0") bundle("lamp", listOf("lamp-common", "lamp-bukkit")) } } diff --git a/src/main/java/de/skyslycer/hmcwraps/HMCWrapsPlugin.java b/src/main/java/de/skyslycer/hmcwraps/HMCWrapsPlugin.java index 8c88215..89a520c 100644 --- a/src/main/java/de/skyslycer/hmcwraps/HMCWrapsPlugin.java +++ b/src/main/java/de/skyslycer/hmcwraps/HMCWrapsPlugin.java @@ -90,6 +90,9 @@ public void onEnable() { if (checkDependency("Oraxen", false)) { hooks.add(new OraxenItemHook()); } + if (checkDependency("Nexo", false)) { + hooks.add(new NexoItemHook()); + } if (checkDependency("MythicCrucible", false)) { var mythicMobs = Bukkit.getPluginManager().getPlugin("MythicMobs"); if (mythicMobs != null) { @@ -131,7 +134,9 @@ public void onEnable() { CommandRegister.registerCommands(this); new DefaultActionRegister(this).register(); - new PluginMetrics(this).init(); + if (!this.getDescription().getVersion().contains("-b")) { // Don't send metrics for beta versions + new PluginMetrics(this).init(); + } if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new HMCWrapsPlaceholders(this).register(); @@ -244,10 +249,10 @@ private void startCheckTask() { return; } if (foliaLib.isFolia()) { - checkTask = foliaLib.getImpl().runTimer(() -> Bukkit.getOnlinePlayers().forEach((player) -> foliaLib.getImpl().runAtEntity(player, (ignored) -> checkInventory(player))), + checkTask = foliaLib.getScheduler().runTimer(() -> Bukkit.getOnlinePlayers().forEach((player) -> foliaLib.getScheduler().runAtEntity(player, (ignored) -> checkInventory(player))), 0L, config.getPermissions().getInventoryCheckInterval() < 1 ? 10L * 20 * 60 : config.getPermissions().getInventoryCheckInterval() * 20L * 60L); } else { - checkTask = foliaLib.getImpl().runTimerAsync(() -> Bukkit.getOnlinePlayers().forEach(this::checkInventory), + checkTask = foliaLib.getScheduler().runTimerAsync(() -> Bukkit.getOnlinePlayers().forEach(this::checkInventory), 0L, config.getPermissions().getInventoryCheckInterval() < 1 ? 10L * 20 * 60 : config.getPermissions().getInventoryCheckInterval() * 20L * 60L); } } @@ -264,7 +269,7 @@ private void checkInventory(Player player) { } if (!PermissionUtil.hasPermission(this, wrap, item, player)) { int finalI = i; // ;( - getFoliaLib().getImpl().runAtEntity(player, (ignored) -> { + getFoliaLib().getScheduler().runAtEntity(player, (ignored) -> { var newItem = getWrapper().removeWrap(item, player); player.getInventory().setItem(finalI, newItem); }); diff --git a/src/main/java/de/skyslycer/hmcwraps/commands/DebugCommand.java b/src/main/java/de/skyslycer/hmcwraps/commands/DebugCommand.java index f8ae633..63c5976 100644 --- a/src/main/java/de/skyslycer/hmcwraps/commands/DebugCommand.java +++ b/src/main/java/de/skyslycer/hmcwraps/commands/DebugCommand.java @@ -130,7 +130,7 @@ private void uploadAndSend(CommandSender sender, Debuggable debuggable, boolean plugin.getLogger().info("Debug information (" + debuggable.getClass().getSimpleName() + "): \n" + DebugCreator.debugToJson(debuggable)); StringUtil.sendComponent(sender, Component.text("Debug information (" + debuggable.getClass().getSimpleName() + ") printed to console.").color(NamedTextColor.GREEN)); if (upload) { - plugin.getFoliaLib().getImpl().runAsync((ignored) -> { + plugin.getFoliaLib().getScheduler().runAsync((ignored) -> { var link = DebugCreator.upload(DebugCreator.debugToJson(debuggable), "json"); handleLink(sender, link.orElse(null), debuggable.getClass().getSimpleName()); }); diff --git a/src/main/java/de/skyslycer/hmcwraps/commands/WrapCommand.java b/src/main/java/de/skyslycer/hmcwraps/commands/WrapCommand.java index f14bff0..ded233d 100644 --- a/src/main/java/de/skyslycer/hmcwraps/commands/WrapCommand.java +++ b/src/main/java/de/skyslycer/hmcwraps/commands/WrapCommand.java @@ -67,7 +67,7 @@ public WrapCommand(HMCWrapsPlugin plugin) { this.plugin = plugin; } - @Default + @DefaultFor("wraps") @Description("Open the wrap inventory.") public void onWraps(Player player) { if (plugin.getConfiguration().getPermissions().isInventoryPermission() && !player.hasPermission(WRAPS_PERMISSION)) { @@ -117,13 +117,13 @@ public void onOpen(CommandSender sender, Player player) { public void onReload(CommandSender sender) { var current = System.nanoTime(); for (Player player : plugin.getServer().getOnlinePlayers()) { - plugin.getFoliaLib().getImpl().runAtEntity(player, (ignored) -> { + plugin.getFoliaLib().getScheduler().runAtEntity(player, (ignored) -> { if (player.getOpenInventory().getTopInventory().getHolder() instanceof BaseGui) { player.closeInventory(); } }); } - plugin.getFoliaLib().getImpl().runAsync((ignored) -> { + plugin.getFoliaLib().getScheduler().runAsync((ignored) -> { plugin.unload(); plugin.load(); plugin.getMessageHandler().send(sender, Messages.COMMAND_RELOAD, diff --git a/src/main/java/de/skyslycer/hmcwraps/converter/ItemSkinsFile.java b/src/main/java/de/skyslycer/hmcwraps/converter/ItemSkinsFile.java index 8c7b087..c5f6a50 100644 --- a/src/main/java/de/skyslycer/hmcwraps/converter/ItemSkinsFile.java +++ b/src/main/java/de/skyslycer/hmcwraps/converter/ItemSkinsFile.java @@ -76,7 +76,8 @@ public List getLore() { } public InventoryItem toItem() { - return new InventoryItem(material, displayName, glowing, lore, null, customModelData, null, 1, null, null, null, null, null, null, null); + return new InventoryItem(material, displayName, glowing, lore, null, customModelData, null, + 1, null, null, null, null, null, null, null, null, null); } } diff --git a/src/main/java/de/skyslycer/hmcwraps/gui/GuiBuilder.java b/src/main/java/de/skyslycer/hmcwraps/gui/GuiBuilder.java index a61cc3e..bda1146 100644 --- a/src/main/java/de/skyslycer/hmcwraps/gui/GuiBuilder.java +++ b/src/main/java/de/skyslycer/hmcwraps/gui/GuiBuilder.java @@ -170,8 +170,11 @@ private static void populate(HMCWrapsPlugin plugin, ItemStack item, Player playe if (wrap.getInventoryActions() != null) { actions(plugin, new WrapGuiActionInformation(gui, wrap, player, slot, ""), wrap.getInventoryActions(), click); } - } else if (wrap.getLockedItem() != null && wrap.getLockedItem().getActions() != null) { - actions(plugin, new WrapGuiActionInformation(gui, wrap, player, slot, ""), wrap.getLockedItem().getActions(), click); + } else { + actions(plugin, new WrapGuiActionInformation(gui, wrap, player, slot, ""), plugin.getConfiguration().getInventory().getLockedActions(), click); + if (wrap.getLockedItem() != null && wrap.getLockedItem().getActions() != null) { + actions(plugin, new WrapGuiActionInformation(gui, wrap, player, slot, ""), wrap.getLockedItem().getActions(), click); + } } }); gui.addItem(guiItem); diff --git a/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemsAdderItemHook.java b/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemsAdderItemHook.java index 7724144..e8b62ea 100644 --- a/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemsAdderItemHook.java +++ b/src/main/java/de/skyslycer/hmcwraps/itemhook/ItemsAdderItemHook.java @@ -1,15 +1,10 @@ package de.skyslycer.hmcwraps.itemhook; -import de.skyslycer.hmcwraps.util.VersionUtil; import dev.lone.itemsadder.api.CustomStack; -import org.bukkit.Color; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ArmorMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.jetbrains.annotations.Nullable; -public class ItemsAdderItemHook implements ItemHook { +public class ItemsAdderItemHook extends ItemHook { @Override public String getPrefix() { @@ -25,43 +20,4 @@ public ItemStack get(String id) { return stack.getItemStack().clone(); } - @Override - public int getModelId(String id) { - var stack = get(id); - if (stack != null && stack.getItemMeta().hasCustomModelData()) { - return stack.getItemMeta().getCustomModelData(); - } - return -1; - } - - @Override - @Nullable - public Color getColor(String id) { - var stack = get(id); - if (stack != null && stack.getItemMeta() instanceof LeatherArmorMeta meta) { - return meta.getColor(); - } - return null; - } - - @Override - @Nullable - public String getTrimPattern(String id) { - var stack = get(id); - if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) { - return meta.getTrim().getPattern().getKey().toString(); - } - return null; - } - - @Override - @Nullable - public String getTrimMaterial(String id) { - var stack = get(id); - if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) { - return meta.getTrim().getMaterial().getKey().toString(); - } - return null; - } - } diff --git a/src/main/java/de/skyslycer/hmcwraps/itemhook/MythicItemHook.java b/src/main/java/de/skyslycer/hmcwraps/itemhook/MythicItemHook.java index eff45d2..153893c 100644 --- a/src/main/java/de/skyslycer/hmcwraps/itemhook/MythicItemHook.java +++ b/src/main/java/de/skyslycer/hmcwraps/itemhook/MythicItemHook.java @@ -1,14 +1,9 @@ package de.skyslycer.hmcwraps.itemhook; -import de.skyslycer.hmcwraps.util.VersionUtil; import io.lumine.mythic.bukkit.MythicBukkit; -import org.bukkit.Color; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ArmorMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; -import org.jetbrains.annotations.Nullable; -public class MythicItemHook implements ItemHook { +public class MythicItemHook extends ItemHook { @Override public String getPrefix() { @@ -23,43 +18,4 @@ public ItemStack get(String id) { return MythicBukkit.inst().getItemManager().getItemStack(id); } - @Override - public int getModelId(String id) { - var stack = get(id); - if (stack != null && stack.getItemMeta().hasCustomModelData()) { - return stack.getItemMeta().getCustomModelData(); - } - return -1; - } - - @Override - @Nullable - public Color getColor(String id) { - var stack = get(id); - if (stack != null && stack.getItemMeta() instanceof LeatherArmorMeta meta) { - return meta.getColor(); - } - return null; - } - - @Override - @Nullable - public String getTrimPattern(String id) { - var stack = get(id); - if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) { - return meta.getTrim().getPattern().getKey().toString(); - } - return null; - } - - @Override - @Nullable - public String getTrimMaterial(String id) { - var stack = get(id); - if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) { - return meta.getTrim().getMaterial().getKey().toString(); - } - return null; - } - } diff --git a/src/main/java/de/skyslycer/hmcwraps/itemhook/NexoItemHook.java b/src/main/java/de/skyslycer/hmcwraps/itemhook/NexoItemHook.java new file mode 100644 index 0000000..b6f09a2 --- /dev/null +++ b/src/main/java/de/skyslycer/hmcwraps/itemhook/NexoItemHook.java @@ -0,0 +1,21 @@ +package de.skyslycer.hmcwraps.itemhook; + +import com.nexomc.nexo.api.NexoItems; +import org.bukkit.inventory.ItemStack; + +public class NexoItemHook extends ItemHook { + + @Override + public String getPrefix() { + return "nexo:"; + } + + @Override + public ItemStack get(String id) { + if (NexoItems.itemFromId(id) == null) { + return null; + } + return NexoItems.itemFromId(id).build(); + } + +} diff --git a/src/main/java/de/skyslycer/hmcwraps/itemhook/OraxenItemHook.java b/src/main/java/de/skyslycer/hmcwraps/itemhook/OraxenItemHook.java index 77c48ab..09857cc 100644 --- a/src/main/java/de/skyslycer/hmcwraps/itemhook/OraxenItemHook.java +++ b/src/main/java/de/skyslycer/hmcwraps/itemhook/OraxenItemHook.java @@ -1,14 +1,10 @@ package de.skyslycer.hmcwraps.itemhook; -import de.skyslycer.hmcwraps.util.VersionUtil; import io.th0rgal.oraxen.api.OraxenItems; -import org.bukkit.Color; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ArmorMeta; -import org.bukkit.inventory.meta.LeatherArmorMeta; import org.jetbrains.annotations.Nullable; -public class OraxenItemHook implements ItemHook { +public class OraxenItemHook extends ItemHook { @Override public String getPrefix() { @@ -23,35 +19,6 @@ public ItemStack get(String id) { return OraxenItems.getItemById(id).build(); } - @Override - public int getModelId(String id) { - var stack = get(id); - if (stack != null && stack.getItemMeta().hasCustomModelData()) { - return stack.getItemMeta().getCustomModelData(); - } - return -1; - } - - @Override - @Nullable - public Color getColor(String id) { - var stack = get(id); - if (stack != null && stack.getItemMeta() instanceof LeatherArmorMeta meta) { - return meta.getColor(); - } - return null; - } - - @Override - @Nullable - public String getTrimPattern(String id) { - var stack = get(id); - if (VersionUtil.trimsSupported() && stack != null && stack.getItemMeta() instanceof ArmorMeta meta && meta.getTrim() != null) { - return meta.getTrim().getPattern().getKey().toString(); - } - return null; - } - @Override @Nullable public String getTrimMaterial(String id) { diff --git a/src/main/java/de/skyslycer/hmcwraps/listener/DurabilityChangeListener.java b/src/main/java/de/skyslycer/hmcwraps/listener/DurabilityChangeListener.java index 725132e..ac8293e 100644 --- a/src/main/java/de/skyslycer/hmcwraps/listener/DurabilityChangeListener.java +++ b/src/main/java/de/skyslycer/hmcwraps/listener/DurabilityChangeListener.java @@ -19,21 +19,23 @@ public DurabilityChangeListener(HMCWrapsPlugin plugin) { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onItemDamage(PlayerItemDamageEvent event) { - var item = event.getItem(); - updateDurability(item, -event.getDamage()); + if (updateDurability(event.getItem(), -event.getDamage())) { + event.setDamage(0); + } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onItemMend(PlayerItemMendEvent event) { - var item = event.getItem(); - updateDurability(item, event.getRepairAmount()); + if (updateDurability(event.getItem(), event.getRepairAmount())) { + event.setRepairAmount(0); + } } - private void updateDurability(ItemStack item, int changed) { + private boolean updateDurability(ItemStack item, int changed) { var durability = plugin.getWrapper().getFakeDurability(item); var maxDurability = plugin.getWrapper().getFakeMaxDurability(item); if (plugin.getWrapper().getWrap(item) == null || plugin.getWrapper().getFakeDurability(item) == -1 || durability == -1) { - return; + return false; } var newDurability = Math.min(durability + changed, maxDurability); var modelDurability = ((double) newDurability / maxDurability) * item.getType().getMaxDurability(); @@ -42,11 +44,12 @@ private void updateDurability(ItemStack item, int changed) { } plugin.getWrapper().setFakeDurability(item, newDurability); var meta = (Damageable) item.getItemMeta(); - meta.setDamage(item.getType().getMaxDurability() - (int) modelDurability); + meta.setDamage((int) (item.getType().getMaxDurability() - Math.round(modelDurability))); item.setItemMeta(meta); if (newDurability <= 0) { item.setAmount(0); } + return true; } } diff --git a/src/main/java/de/skyslycer/hmcwraps/listener/InventoryClickListener.java b/src/main/java/de/skyslycer/hmcwraps/listener/InventoryClickListener.java index 67e0cb8..1949662 100644 --- a/src/main/java/de/skyslycer/hmcwraps/listener/InventoryClickListener.java +++ b/src/main/java/de/skyslycer/hmcwraps/listener/InventoryClickListener.java @@ -43,6 +43,12 @@ public void onInventoryClick(InventoryClickEvent event) { return; } + if (player.getOpenInventory().getType() == InventoryType.SMITHING && (plugin.getWrapper().isTrimsUsed(event.getCurrentItem()) || plugin.getWrapper().isTrimsUsed(event.getCursor()))) { + event.setCancelled(true); + plugin.getMessageHandler().send(player, Messages.ARMOR_IMITATION_FORBIDDEN_INVENTORY); + return; + } + // Avoid possible issues such as client server inventory desync when moving a desynced inventory if (plugin.getPreviewManager().isPreviewing(player) && plugin.getConfiguration().getPreview().getType() == PreviewType.HAND) { plugin.getPreviewManager().remove(player.getUniqueId(), false); @@ -52,13 +58,13 @@ public void onInventoryClick(InventoryClickEvent event) { switch (event.getAction()) { case PLACE_ALL, PLACE_SOME, PLACE_ONE, SWAP_WITH_CURSOR -> { var slot = event.getRawSlot(); - plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> { + plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> { var updatedItem = PermissionUtil.check(plugin, player, event.getView().getItem(slot)); if (updatedItem == null || updatedItem.equals(event.getView().getItem(slot))) return; event.getView().setItem(slot, updatedItem); }, 1); } - case MOVE_TO_OTHER_INVENTORY -> plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> { + case MOVE_TO_OTHER_INVENTORY -> plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> { if (event.getClickedInventory() == player.getInventory()) { PermissionUtil.loopThroughInventory(plugin, player, player.getOpenInventory().getTopInventory()); } else { @@ -69,7 +75,7 @@ public void onInventoryClick(InventoryClickEvent event) { if (event.getClick() == ClickType.NUMBER_KEY) { var slot = event.getHotbarButton(); - plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> { + plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> { var updatedItem = PermissionUtil.check(plugin, player, player.getInventory().getItem(slot)); if (updatedItem == null || updatedItem.equals(event.getView().getItem(slot))) return; player.getInventory().setItem(slot, updatedItem); diff --git a/src/main/java/de/skyslycer/hmcwraps/listener/PlayerJoinListener.java b/src/main/java/de/skyslycer/hmcwraps/listener/PlayerJoinListener.java index 266ccae..14257f1 100644 --- a/src/main/java/de/skyslycer/hmcwraps/listener/PlayerJoinListener.java +++ b/src/main/java/de/skyslycer/hmcwraps/listener/PlayerJoinListener.java @@ -16,8 +16,8 @@ public PlayerJoinListener(HMCWrapsPlugin plugin) { @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { - plugin.getFoliaLib().getImpl().runAtEntityLater(event.getPlayer(), () -> PermissionUtil.loopThroughInventory(plugin, event.getPlayer(), event.getPlayer().getInventory()), 1); - plugin.getFoliaLib().getImpl().runLaterAsync(() -> plugin.getUpdateChecker().checkPlayer(event.getPlayer()), 5); + plugin.getFoliaLib().getScheduler().runAtEntityLater(event.getPlayer(), () -> PermissionUtil.loopThroughInventory(plugin, event.getPlayer(), event.getPlayer().getInventory()), 1); + plugin.getFoliaLib().getScheduler().runLaterAsync(() -> plugin.getUpdateChecker().checkPlayer(event.getPlayer()), 5); } } diff --git a/src/main/java/de/skyslycer/hmcwraps/listener/PlayerPickupListener.java b/src/main/java/de/skyslycer/hmcwraps/listener/PlayerPickupListener.java index 114d1ca..4c1751d 100644 --- a/src/main/java/de/skyslycer/hmcwraps/listener/PlayerPickupListener.java +++ b/src/main/java/de/skyslycer/hmcwraps/listener/PlayerPickupListener.java @@ -21,7 +21,7 @@ public void onItemPickup(EntityPickupItemEvent event) { if (!(event.getEntity() instanceof Player player)) { return; } - plugin.getFoliaLib().getImpl().runAtEntityLater(player, () -> PermissionUtil.loopThroughInventory(plugin, player, player.getInventory()), 1L); + plugin.getFoliaLib().getScheduler().runAtEntityLater(player, () -> PermissionUtil.loopThroughInventory(plugin, player, player.getInventory()), 1L); } } diff --git a/src/main/java/de/skyslycer/hmcwraps/placeholderapi/HMCWrapsPlaceholders.java b/src/main/java/de/skyslycer/hmcwraps/placeholderapi/HMCWrapsPlaceholders.java index 2715664..1f63c94 100644 --- a/src/main/java/de/skyslycer/hmcwraps/placeholderapi/HMCWrapsPlaceholders.java +++ b/src/main/java/de/skyslycer/hmcwraps/placeholderapi/HMCWrapsPlaceholders.java @@ -52,7 +52,7 @@ public String onPlaceholderRequest(org.bukkit.entity.Player player, String ident var wrapUuid = identifier.substring(identifier.indexOf("_") + 1); var wrap = plugin.getWrapsLoader().getWraps().get(wrapUuid); switch (action) { - case "equipped" -> { + case "equipped" -> { // Check if the specified wrap is the one equipped on the item the player is wrapping in the virtual inventory if (player == null) { return null; } diff --git a/src/main/java/de/skyslycer/hmcwraps/updater/ContinuousUpdateChecker.java b/src/main/java/de/skyslycer/hmcwraps/updater/ContinuousUpdateChecker.java index 2246e4f..d6a688b 100644 --- a/src/main/java/de/skyslycer/hmcwraps/updater/ContinuousUpdateChecker.java +++ b/src/main/java/de/skyslycer/hmcwraps/updater/ContinuousUpdateChecker.java @@ -27,7 +27,7 @@ public void check() { if (task != null) { task.cancel(); } - task = plugin.getFoliaLib().getImpl().runTimerAsync(() -> { + task = plugin.getFoliaLib().getScheduler().runTimerAsync(() -> { var result = updater.check(plugin); lastResultTime = System.currentTimeMillis(); lastResult = result; diff --git a/src/main/java/de/skyslycer/hmcwraps/wrap/ArmorModifiers.java b/src/main/java/de/skyslycer/hmcwraps/wrap/ArmorModifiers.java index caaaf8b..a38242f 100644 --- a/src/main/java/de/skyslycer/hmcwraps/wrap/ArmorModifiers.java +++ b/src/main/java/de/skyslycer/hmcwraps/wrap/ArmorModifiers.java @@ -1,16 +1,22 @@ package de.skyslycer.hmcwraps.wrap; +import de.skyslycer.hmcwraps.util.VersionUtil; +import org.bukkit.Bukkit; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; import java.util.UUID; +import java.util.logging.Level; public enum ArmorModifiers { - CHAINMAIL(0, 0, new ArmorValues(1, 2, 3, 1), new ArmorValues(15, 40, 30, 15)), + LEATHER(0, 0, new ArmorValues(1, 2, 3, 1), new ArmorValues(15, 40, 30, 15)), + CHAINMAIL(0, 0, new ArmorValues(2, 5, 4, 1), new ArmorValues(45, 120, 90, 45)), IRON(0, 0, new ArmorValues(2, 5, 6, 2), new ArmorValues(45, 120, 90, 45)), GOLD(0, 0, new ArmorValues(2, 5, 3, 1), new ArmorValues(21, 56, 42, 21)), DIAMOND(2, 0, new ArmorValues(3, 8, 6, 3), new ArmorValues(99, 264, 198, 99)), @@ -38,53 +44,32 @@ public static ArmorModifiers getFromMaterial(String material) { if (material.contains("DIAMOND")) return DIAMOND; if (material.contains("TURTLE")) return TURTLE; if (material.contains("NETHERITE")) return NETHERITE; + if (material.contains("LEATHER")) return LEATHER; return null; } public static void applyAttributes(ItemStack item, EquipmentSlot slot, int toughness, int knockback, int defense) { var meta = item.getItemMeta(); - if (meta.getAttributeModifiers(Attribute.GENERIC_ARMOR_TOUGHNESS) == null) { - addModifier(meta, slot, Attribute.GENERIC_ARMOR_TOUGHNESS, toughness); - } else { - meta.getAttributeModifiers(Attribute.GENERIC_ARMOR_TOUGHNESS).stream().findFirst().ifPresent(modifier -> { - meta.removeAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS, modifier); - addModifier(meta, slot, Attribute.GENERIC_ARMOR_TOUGHNESS, toughness); - }); - } + VersionAttribute.removeAttributeModifier(meta, VersionAttribute.ARMOR_TOUGHNESS); + VersionAttribute.addAttributeModifier(meta, slot, VersionAttribute.ARMOR_TOUGHNESS, toughness); + VersionAttribute.removeAttributeModifier(meta, VersionAttribute.ARMOR); + VersionAttribute.addAttributeModifier(meta, slot, VersionAttribute.ARMOR, defense); if (knockback != 0) { - if (meta.getAttributeModifiers(Attribute.GENERIC_KNOCKBACK_RESISTANCE) == null) { - addModifier(meta, slot, Attribute.GENERIC_KNOCKBACK_RESISTANCE, knockback / 10d); - } else { - meta.getAttributeModifiers(Attribute.GENERIC_KNOCKBACK_RESISTANCE).stream().findFirst().ifPresent(modifier -> { - meta.removeAttributeModifier(Attribute.GENERIC_KNOCKBACK_RESISTANCE, modifier); - addModifier(meta, slot, Attribute.GENERIC_KNOCKBACK_RESISTANCE, knockback / 10d); // divided by 10 because Minecraft decided so - }); - } - } - if (meta.getAttributeModifiers(Attribute.GENERIC_ARMOR) == null) { - addModifier(meta, slot, Attribute.GENERIC_ARMOR, defense); - } else { - meta.getAttributeModifiers(Attribute.GENERIC_ARMOR).stream().findFirst().ifPresent(modifier -> { - meta.removeAttributeModifier(Attribute.GENERIC_ARMOR, modifier); - addModifier(meta, slot, Attribute.GENERIC_ARMOR, defense); - }); + VersionAttribute.removeAttributeModifier(meta, VersionAttribute.KNOCKBACK_RESISTANCE); + VersionAttribute.addAttributeModifier(meta, slot, VersionAttribute.KNOCKBACK_RESISTANCE, knockback / 10d); // divided by 10 because Minecraft decided so } item.setItemMeta(meta); } public static ItemStack removeAttributes(ItemStack item) { var meta = item.getItemMeta(); - meta.removeAttributeModifier(Attribute.GENERIC_ARMOR_TOUGHNESS); - meta.removeAttributeModifier(Attribute.GENERIC_KNOCKBACK_RESISTANCE); - meta.removeAttributeModifier(Attribute.GENERIC_ARMOR); + VersionAttribute.removeAttributeModifier(meta, VersionAttribute.ARMOR_TOUGHNESS); + VersionAttribute.removeAttributeModifier(meta, VersionAttribute.KNOCKBACK_RESISTANCE); + VersionAttribute.removeAttributeModifier(meta, VersionAttribute.ARMOR); item.setItemMeta(meta); return item; } - private static void addModifier(ItemMeta meta, EquipmentSlot slot, Attribute attribute, double amount) { - meta.addAttributeModifier(attribute, new AttributeModifier(UUID.randomUUID(), attribute.getKey().getKey(), amount, AttributeModifier.Operation.ADD_NUMBER, slot)); - } - public int getToughness() { return toughness; } @@ -101,4 +86,108 @@ public ArmorValues getDurability() { return durability; } + private enum VersionAttribute { + ARMOR_TOUGHNESS("ARMOR_TOUGHNESS", "GENERIC_ARMOR_TOUGHNESS"), + KNOCKBACK_RESISTANCE("KNOCKBACK_RESISTANCE", "GENERIC_KNOCKBACK_RESISTANCE"), + ARMOR("ARMOR", "GENERIC_ARMOR"); + + private final String modernAttribute; + private final String legacyAttribute; + + VersionAttribute(String modernAttribute, String legacyAttribute) { + this.modernAttribute = modernAttribute; + this.legacyAttribute = legacyAttribute; + } + + public Object getAttribute() { + if (VersionUtil.equippableSupported()) { + try { + return Attribute.valueOf(modernAttribute); + } catch (IllegalArgumentException exception) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to get modern attribute: " + modernAttribute, exception); + } + } else { + try { + Class attributeClass = Class.forName("org.bukkit.attribute.Attribute"); + Method valueOfMethod = attributeClass.getMethod("valueOf", String.class); + return valueOfMethod.invoke(null, legacyAttribute); + } catch (Exception exception) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to get legacy attribute: " + legacyAttribute, exception); + } + } + return null; + } + + public static void removeAttributeModifier(ItemMeta meta, VersionAttribute attribute) { + var attributeObject = attribute.getAttribute(); + if (VersionUtil.equippableSupported()) { + try { + meta.removeAttributeModifier((Attribute) attributeObject); + } catch (IllegalArgumentException exception) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to remove modern attribute: " + attribute.name(), exception); + } + } else { + try { + Class attributeClass = Class.forName("org.bukkit.attribute.Attribute"); + if (!attributeClass.isInstance(attributeObject)) { + throw new IllegalArgumentException("Provided object is not a valid Attribute instance"); + } + Object castedAttribute = attributeClass.cast(attributeObject); + Method removeModifierMethod = ItemMeta.class.getMethod("removeAttributeModifier", attributeClass); + removeModifierMethod.invoke(meta, castedAttribute); + } catch (Exception exception) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to remove legacy attribute: " + attribute.name(), exception); + } + } + } + + public static void addAttributeModifier(ItemMeta meta, EquipmentSlot slot, VersionAttribute attribute, double amount) { + var attributeObject = attribute.getAttribute(); + if (VersionUtil.equippableSupported()) { + var modernAttribute = (Attribute) attributeObject; + try { + meta.addAttributeModifier(modernAttribute, new AttributeModifier(modernAttribute.getKey(), amount, AttributeModifier.Operation.ADD_NUMBER, slot.getGroup())); + } catch (IllegalArgumentException exception) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to add modern attribute: " + attribute.name(), exception); + } + } else { + try { + Class attributeClass = Class.forName("org.bukkit.attribute.Attribute"); + if (!attributeClass.isInstance(attributeObject)) { + throw new IllegalArgumentException("Provided object is not a valid Attribute instance"); + } + Object castedAttribute = attributeClass.cast(attributeObject); + var modifier = createAttributeModifier(castedAttribute, amount, slot); + var addModifierMethod = ItemMeta.class.getMethod("addAttributeModifier", attributeClass, AttributeModifier.class); + addModifierMethod.invoke(meta, castedAttribute, modifier); + } catch (Exception exception) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to add legacy attribute: " + attribute.name(), exception); + } + } + } + + public static Object createAttributeModifier(Object attributeObject, double amount, EquipmentSlot slot) { + try { + Class attributeModifierClass = Class.forName("org.bukkit.attribute.AttributeModifier"); + Constructor constructor = attributeModifierClass.getConstructor( + UUID.class, + String.class, + double.class, + AttributeModifier.Operation.class, + EquipmentSlot.class + ); + return constructor.newInstance( + UUID.randomUUID(), + attributeObject.toString(), + amount, + AttributeModifier.Operation.ADD_NUMBER, + slot + ); + } catch (Exception exception) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to create legacy attribute modifier!", exception); + } + return null; + } + } + } diff --git a/src/main/java/de/skyslycer/hmcwraps/wrap/WrapperImpl.java b/src/main/java/de/skyslycer/hmcwraps/wrap/WrapperImpl.java index 7def6ae..81e2dd5 100644 --- a/src/main/java/de/skyslycer/hmcwraps/wrap/WrapperImpl.java +++ b/src/main/java/de/skyslycer/hmcwraps/wrap/WrapperImpl.java @@ -1,5 +1,6 @@ package de.skyslycer.hmcwraps.wrap; +import com.nexomc.nexo.api.NexoItems; import de.skyslycer.hmcwraps.HMCWrapsPlugin; import de.skyslycer.hmcwraps.events.ItemUnwrapEvent; import de.skyslycer.hmcwraps.events.ItemWrapEvent; @@ -46,13 +47,16 @@ public class WrapperImpl implements Wrapper { private final NamespacedKey originalItemsAdderKey; private final NamespacedKey originalOraxenKey; private final NamespacedKey originalMythicKey; + private final NamespacedKey originalNexoKey; private final NamespacedKey originalMaterialKey; private final NamespacedKey originalTrimKey; private final NamespacedKey originalTrimMaterialKey; - private final NamespacedKey originalHideTrimKey; private final NamespacedKey fakeDurabilityKey; private final NamespacedKey fakeMaxDurabilityKey; - private final NamespacedKey customAttributes; + private final NamespacedKey customAttributesKey; + private final NamespacedKey trimsUsedKey; + private final NamespacedKey originalEquippableSlotKey; + private final NamespacedKey originalEquippableModelKey; public WrapperImpl(HMCWrapsPlugin plugin) { this.plugin = plugin; @@ -69,13 +73,16 @@ public WrapperImpl(HMCWrapsPlugin plugin) { originalItemsAdderKey = new NamespacedKey(plugin, "original-itemsadder-id"); originalOraxenKey = new NamespacedKey(plugin, "original-oraxen-id"); originalMythicKey = new NamespacedKey(plugin, "original-mythic-id"); + originalNexoKey = new NamespacedKey(plugin, "original-nexo-id"); originalMaterialKey = new NamespacedKey(plugin, "original-material"); originalTrimKey = new NamespacedKey(plugin, "original-trim"); originalTrimMaterialKey = new NamespacedKey(plugin, "original-trim-material"); - originalHideTrimKey = new NamespacedKey(plugin, "original-hide-trim"); fakeDurabilityKey = new NamespacedKey(plugin, "fake-durability"); fakeMaxDurabilityKey = new NamespacedKey(plugin, "fake-max-durability"); - customAttributes = new NamespacedKey(plugin, "custom-attributes"); + customAttributesKey = new NamespacedKey(plugin, "custom-attributes"); + trimsUsedKey = new NamespacedKey(plugin, "trims-used"); + originalEquippableSlotKey = new NamespacedKey(plugin, "original-equippable-slot"); + originalEquippableModelKey = new NamespacedKey(plugin, "original-equippable-model"); } @Override @@ -120,16 +127,24 @@ private ItemStack setWrapPrivate(@Nullable Wrap wrap, ItemStack item, boolean ph var originalItemsAdderId = getOriginalItemsAdderId(item); var originalOraxenId = getOriginalOraxenId(item); var originalMythicId = getOriginalMythicId(item); + var originalNexoId = getOriginalNexoId(item); String originalTrimMaterial = null; String originalTrim = null; if (VersionUtil.trimsSupported() && meta instanceof ArmorMeta armorMeta && armorMeta.getTrim() != null) { originalTrim = armorMeta.getTrim().getPattern().getKey().toString(); originalTrimMaterial = armorMeta.getTrim().getMaterial().getKey().toString(); } + NamespacedKey originalEquippableModel = null; + EquipmentSlot originalEquippableSlot = null; + if (VersionUtil.equippableSupported() && meta.hasEquippable()) { + originalEquippableModel = meta.getEquippable().getModel(); + originalEquippableSlot = meta.getEquippable().getSlot(); + } Color originalColor = null; if (meta.hasCustomModelData()) { originalModelId = meta.getCustomModelData(); } + meta.getPersistentDataContainer().remove(trimsUsedKey); meta.getPersistentDataContainer().set(wrapIdKey, PersistentDataType.STRING, wrap == null ? "-" : wrap.getUuid()); meta.getPersistentDataContainer().remove(playerKey); meta.setCustomModelData(wrap == null ? originalData.modelId() : wrap.getModelId()); @@ -180,7 +195,7 @@ private ItemStack setWrapPrivate(@Nullable Wrap wrap, ItemStack item, boolean ph newMeta.setDamage(newDurability - (int) modelDurability); newMeta.getPersistentDataContainer().set(fakeDurabilityKey, PersistentDataType.INTEGER, currentDurability); newMeta.getPersistentDataContainer().set(fakeMaxDurabilityKey, PersistentDataType.INTEGER, (int) maxDurability); - newMeta.getPersistentDataContainer().set(customAttributes, PersistentDataType.BOOLEAN, attributeModifiers != null); + newMeta.getPersistentDataContainer().set(customAttributesKey, PersistentDataType.BOOLEAN, attributeModifiers != null); editing.setItemMeta(newMeta); originalMaterial = temp; changedDurability = true; @@ -212,11 +227,20 @@ private ItemStack setWrapPrivate(@Nullable Wrap wrap, ItemStack item, boolean ph try { armorMeta.setTrim(new ArmorTrim(Registry.TRIM_MATERIAL.get(NamespacedKey.fromString(wrap.getTrimMaterial())), Registry.TRIM_PATTERN.get(NamespacedKey.fromString(wrap.getTrim())))); armorMeta.addItemFlags(ItemFlag.HIDE_ARMOR_TRIM); + armorMeta.getPersistentDataContainer().set(trimsUsedKey, PersistentDataType.BOOLEAN, true); editing.setItemMeta(armorMeta); } catch (IllegalArgumentException exception) { plugin.getLogger().warning("Failed to set trim for item " + wrap.getUuid() + " with trim " + wrap.getTrim() + " and material " + wrap.getTrimMaterial() + "! It seems to not be a valid trim. Please check your configuration!"); } } + if (VersionUtil.equippableSupported() && wrap.getEquippableSlot() != null && wrap.getEquippableModel() != null) { + var newMeta = editing.getItemMeta(); + var equippable = newMeta.getEquippable(); + equippable.setSlot(wrap.getEquippableSlot()); + equippable.setModel(wrap.getEquippableModel()); + newMeta.setEquippable(equippable); + editing.setItemMeta(newMeta); + } if (wrap.getWrapNbt() != null) { WrapNBTUtil.wrap(editing, StringUtil.replacePlaceholders(player, wrap.getWrapNbt())); } @@ -243,6 +267,18 @@ private ItemStack setWrapPrivate(@Nullable Wrap wrap, ItemStack item, boolean ph plugin.getLogger().warning("Failed to set trim for player " + player.getName() + " with trim " + originalData.trim() + " and material " + originalData.trimMaterial() + "! It seems to not be a valid trim. This is being set while unwrapping to preserve the original trim, which has since been removed."); } } + if (VersionUtil.equippableSupported()) { + var newMeta = editing.getItemMeta(); + if (originalData.equippableSlot() != null && originalData.equippableModel() != null) { + var equippable = newMeta.getEquippable(); + equippable.setSlot(originalData.equippableSlot()); + equippable.setModel(originalData.equippableModel()); + newMeta.setEquippable(equippable); + } else { + newMeta.setEquippable(null); + } + editing.setItemMeta(newMeta); + } if (originalData.material() != null && !originalData.material().isBlank()) { switchFromAlternative(editing, originalData.material()); } @@ -257,7 +293,8 @@ private ItemStack setWrapPrivate(@Nullable Wrap wrap, ItemStack item, boolean ph return editing; } return setOriginalData(editing, new WrapValues(originalModelId, originalColor, originalName, originalLore, - originalFlags, originalItemsAdderId, originalOraxenId, originalMythicId, originalMaterial, originalTrim, originalTrimMaterial)); + originalFlags, originalItemsAdderId, originalOraxenId, originalMythicId, originalNexoId, originalMaterial, + originalTrim, originalTrimMaterial, originalEquippableModel, originalEquippableSlot)); } private void setItemsAdderNBT(ItemStack item, String id) { @@ -423,11 +460,30 @@ public String getPhysicalWrapper(ItemStack item) { return meta.getPersistentDataContainer().get(physicalWrapperKey, PersistentDataType.STRING); } + @Override + public ItemStack setTrimsUsed(ItemStack item, boolean used) { + var editing = item.clone(); + var meta = editing.getItemMeta(); + meta.getPersistentDataContainer().set(trimsUsedKey, PersistentDataType.BOOLEAN, used); + editing.setItemMeta(meta); + return editing; + } + + @Override + public boolean isTrimsUsed(ItemStack item) { + var meta = item.getItemMeta(); + if (meta == null) { + return false; + } + return meta.getPersistentDataContainer().has(trimsUsedKey, PersistentDataType.BOOLEAN); + } + @Override public WrapValues getOriginalData(ItemStack item) { return new WrapValues(getOriginalModelId(item), getOriginalColor(item), getOriginalName(item), getOriginalLore(item), getOriginalFlags(item), getOriginalItemsAdderId(item), getOriginalOraxenId(item), - getOriginalMythicId(item), getOriginalMaterial(item), getOriginalTrim(item), getOriginalTrimMaterial(item)); + getOriginalMythicId(item), getOriginalNexoId(item), getOriginalMaterial(item), getOriginalTrim(item), getOriginalTrimMaterial(item), + getOriginalEquippableModel(item), getOriginalEquippableSlot(item)); } private String getOriginalTrim(ItemStack item) { @@ -440,6 +496,24 @@ private String getOriginalTrimMaterial(ItemStack item) { return container.get(originalTrimMaterialKey, PersistentDataType.STRING); } + private EquipmentSlot getOriginalEquippableSlot(ItemStack item) { + PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer(); + var data = container.get(originalEquippableSlotKey, PersistentDataType.STRING); + if (data == null) { + return null; + } + return EquipmentSlot.valueOf(data); + } + + private NamespacedKey getOriginalEquippableModel(ItemStack item) { + PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer(); + var data = container.get(originalEquippableModelKey, PersistentDataType.STRING); + if (data == null) { + return null; + } + return NamespacedKey.fromString(data); + } + private int getOriginalModelId(ItemStack item) { var meta = item.getItemMeta(); var modelData = -1; @@ -589,6 +663,11 @@ private String getOriginalMythicId(ItemStack item) { return container.get(originalMythicKey, PersistentDataType.STRING); } + private String getOriginalNexoId(ItemStack item) { + PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer(); + return container.get(originalNexoKey, PersistentDataType.STRING); + } + private String getOriginalMaterial(ItemStack item) { PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer(); var value = container.get(originalMaterialKey, PersistentDataType.STRING); @@ -623,6 +702,9 @@ public ItemStack setOriginalData(ItemStack item, WrapValues wrapValues) { if (wrapValues.mythic() != null) { meta.getPersistentDataContainer().set(originalMythicKey, PersistentDataType.STRING, wrapValues.mythic()); } + if (wrapValues.nexo() != null) { + meta.getPersistentDataContainer().set(originalNexoKey, PersistentDataType.STRING, wrapValues.nexo()); + } if (wrapValues.material() != null) { meta.getPersistentDataContainer().set(originalMaterialKey, PersistentDataType.STRING, wrapValues.material()); } @@ -632,6 +714,12 @@ public ItemStack setOriginalData(ItemStack item, WrapValues wrapValues) { if (wrapValues.trimMaterial() != null) { meta.getPersistentDataContainer().set(originalTrimMaterialKey, PersistentDataType.STRING, wrapValues.trimMaterial()); } + if (wrapValues.equippableSlot() != null) { + meta.getPersistentDataContainer().set(originalEquippableSlotKey, PersistentDataType.STRING, wrapValues.equippableSlot().name()); + } + if (wrapValues.equippableModel() != null) { + meta.getPersistentDataContainer().set(originalEquippableModelKey, PersistentDataType.STRING, wrapValues.equippableModel().toString()); + } editing.setItemMeta(meta); return editing; } @@ -686,7 +774,7 @@ public ItemStack setPhysical(ItemStack item, boolean physical) { @Override public boolean isCustomAttributes(ItemStack item) { PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer(); - var data = container.get(customAttributes, PersistentDataType.BOOLEAN); + var data = container.get(customAttributesKey, PersistentDataType.BOOLEAN); if (data == null) { return false; } @@ -696,7 +784,10 @@ public boolean isCustomAttributes(ItemStack item) { @Override public boolean isValid(ItemStack item, Wrap wrap) { return wrap.getRange() == null || (isValidType(wrap.getRange().getModelId(), getRealModelId(item)) && isValidColor(wrap.getRange().getColor(), getRealColor(item)) && - isValidType(wrap.getRange().getItemsAdder(), getRealItemsAdderId(item)) && isValidType(wrap.getRange().getOraxen(), getRealOraxenId(item)) && isValidType(wrap.getRange().getMythic(), getRealMythicId(item))); + isValidType(wrap.getRange().getItemsAdder(), getRealItemsAdderId(item)) + && isValidType(wrap.getRange().getOraxen(), getRealOraxenId(item)) + && isValidType(wrap.getRange().getMythic(), getRealMythicId(item)) + && isValidType(wrap.getRange().getNexo(), getRealNexoId(item))); } private boolean isValidType(ValueRangeSettings settings, T value) { @@ -789,6 +880,19 @@ private String getRealMythicId(ItemStack item) { return mythicId; } + private String getRealNexoId(ItemStack item) { + String nexoId = null; + if (getWrap(item) != null) { + nexoId = getOriginalNexoId(item); + } else if (Bukkit.getPluginManager().getPlugin("Nexo") != null) { + var id = NexoItems.idFromItem(item); + if (id != null) { + nexoId = id; + } + } + return nexoId; + } + @Override public boolean isGloballyDisabled(ItemStack item) { if (plugin.getConfiguration().getGlobalDisable().getModelId().contains(getRealModelId(item))) { @@ -806,6 +910,9 @@ public boolean isGloballyDisabled(ItemStack item) { if (plugin.getConfiguration().getGlobalDisable().getMythicId().contains(getRealMythicId(item))) { return true; } + if (plugin.getConfiguration().getGlobalDisable().getNexoId().contains(getRealNexoId(item))) { + return true; + } return false; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 994f8cf..506b427 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -48,6 +48,7 @@ global-disable: model-id: [ ] # You can use hex or rgb, check the documentation. If you want to disable items with no color, use 'none'. color: [ ] + nexo: [ ] oraxen: [ ] itemsadder: [ ] mythic: [] @@ -235,7 +236,7 @@ inventory: # The sort order by which the wraps in the inventory will be sorted sort-order: - 'PERMISSION' # The items the player has access to will be shown first - - 'SORT_ID' # You can define a sort id on a wrap, lower numbers will be shown first. Example: 'sort: 3' + - 'SORT_ID' # You can define a sort id on a wrap, lower numbers will be shown first. Example: sort: 3 - 'MODEL_ID' # Sorted by model id, lower numbers will be shown first # Shortcut settings shortcut: @@ -263,6 +264,11 @@ inventory: right: PREVIEW: - '' + # Executed when clicking a wrap the player doesn't have permission for + locked-actions: + right: + PREVIEW: + - '' # The slot to set the item the player is holding to (-1 to disable) target-item-slot: 49 # The set items in the inventory, every empty slot will be filled with wraps