From 5a18a8c421a819841a7b0cc25bd6ffdf5723f2ea Mon Sep 17 00:00:00 2001 From: Ryder Belserion Date: Thu, 22 Aug 2024 21:46:59 -0400 Subject: [PATCH] Add changes for moving away from getItemMeta/hasItemMeta (#775) * add initial changes for moving away from getItemMeta/hasItemMeta * import persistentdatatype --------- Signed-off-by: Ryder Belserion --- CHANGELOG.md | 3 + .../api/builders/types/CrateMainMenu.java | 4 +- .../api/builders/types/CratePreviewMenu.java | 9 +-- .../api/builders/types/CrateTierMenu.java | 9 +-- .../crazycrates/api/objects/Crate.java | 7 +-- .../crazycrates/api/utils/ItemUtils.java | 3 +- .../listeners/crates/CosmicCrateListener.java | 11 +--- .../listeners/crates/MobileCrateListener.java | 12 ++-- .../listeners/crates/QuadCrateListener.java | 7 +-- .../tasks/crates/CrateManager.java | 62 +++++++------------ .../crates/other/CosmicCrateManager.java | 18 ++---- .../tasks/crates/types/CasinoCrate.java | 13 ++-- .../tasks/crates/types/QuickCrate.java | 7 +-- 13 files changed, 55 insertions(+), 110 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 563a46fb1..6793c8e43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -59,6 +59,9 @@ Crate: - Fixed an issue where CMI likely wouldn't be detected ### Changes: +- Removed all getItemMeta/hasItemMeta calls for checking PersistentDataContainer + - We now check ItemStack#PersistentDataContainerView which no longer relies on ItemStack#getItemMeta + - TLDR: stonks - Right click now opens the crate menu as well. - Checked location strings instead of object ids - Simplified multiple location getters, don't need to get the same location 3 times if we aren't changing it. diff --git a/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateMainMenu.java b/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateMainMenu.java index c114515b7..48197ff17 100644 --- a/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateMainMenu.java +++ b/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateMainMenu.java @@ -156,9 +156,7 @@ public void run(InventoryClickEvent event) { if (item == null || item.getType() == Material.AIR) return; - if (!item.hasItemMeta()) return; - - final Crate crate = this.crateManager.getCrateFromName(ItemUtils.getKey(item.getItemMeta().getPersistentDataContainer())); + final Crate crate = this.crateManager.getCrateFromName(ItemUtils.getKey(item.getPersistentDataContainer())); if (crate == null) return; diff --git a/src/main/java/com/badbones69/crazycrates/api/builders/types/CratePreviewMenu.java b/src/main/java/com/badbones69/crazycrates/api/builders/types/CratePreviewMenu.java index c4eb72851..321bc7fe6 100644 --- a/src/main/java/com/badbones69/crazycrates/api/builders/types/CratePreviewMenu.java +++ b/src/main/java/com/badbones69/crazycrates/api/builders/types/CratePreviewMenu.java @@ -5,14 +5,13 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.objects.Tier; import com.badbones69.crazycrates.tasks.InventoryManager; +import io.papermc.paper.persistence.PersistentDataContainerView; import net.kyori.adventure.sound.Sound; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -119,15 +118,11 @@ public void run(InventoryClickEvent event) { if (item == null || item.getType() == Material.AIR) return; - if (!item.hasItemMeta()) return; - final Crate crate = this.inventoryManager.getCratePreview(player); if (crate == null) return; - final ItemMeta itemMeta = item.getItemMeta(); - - final PersistentDataContainer container = itemMeta.getPersistentDataContainer(); + final PersistentDataContainerView container = item.getPersistentDataContainer(); if (container.has(PersistentKeys.main_menu_button.getNamespacedKey()) && this.config.getProperty(ConfigKeys.enable_crate_menu)) { // Clicked the menu button. if (this.inventoryManager.inCratePreview(player)) { diff --git a/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateTierMenu.java b/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateTierMenu.java index 81cfe819a..976ebcbd6 100644 --- a/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateTierMenu.java +++ b/src/main/java/com/badbones69/crazycrates/api/builders/types/CrateTierMenu.java @@ -7,14 +7,13 @@ import com.badbones69.crazycrates.api.objects.Tier; import com.badbones69.crazycrates.config.ConfigManager; import com.badbones69.crazycrates.config.impl.ConfigKeys; +import io.papermc.paper.persistence.PersistentDataContainerView; import net.kyori.adventure.sound.Sound; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -51,15 +50,11 @@ public void run(InventoryClickEvent event) { if (item == null || item.getType() == Material.AIR) return; - if (!item.hasItemMeta()) return; - final Crate crate = this.inventoryManager.getCratePreview(player); if (crate == null) return; - final ItemMeta itemMeta = item.getItemMeta(); - - final PersistentDataContainer container = itemMeta.getPersistentDataContainer(); + final PersistentDataContainerView container = item.getPersistentDataContainer(); if (this.config.getProperty(ConfigKeys.enable_crate_menu) && container.has(PersistentKeys.main_menu_button.getNamespacedKey())) { if (this.inventoryManager.inCratePreview(player)) { diff --git a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java index df56b640f..f21e7f580 100644 --- a/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java +++ b/src/main/java/com/badbones69/crazycrates/api/objects/Crate.java @@ -17,7 +17,6 @@ import org.bukkit.Particle; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.Nullable; import org.bukkit.configuration.ConfigurationSection; @@ -571,11 +570,7 @@ public final CrateType getCrateType() { } public final @Nullable Prize getPrize(@NotNull final ItemStack item) { - ItemMeta itemMeta = item.getItemMeta(); - - PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - - return getPrize(container.get(PersistentKeys.crate_prize.getNamespacedKey(), PersistentDataType.STRING)); + return getPrize(item.getPersistentDataContainer().get(PersistentKeys.crate_prize.getNamespacedKey(), PersistentDataType.STRING)); } /** diff --git a/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java b/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java index 78234422f..bc073878f 100644 --- a/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java +++ b/src/main/java/com/badbones69/crazycrates/api/utils/ItemUtils.java @@ -8,6 +8,7 @@ import com.badbones69.crazycrates.api.builders.ItemBuilder; import com.ryderbelserion.vital.paper.util.DyeUtil; import com.ryderbelserion.vital.paper.util.ItemUtil; +import io.papermc.paper.persistence.PersistentDataContainerView; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.block.banner.PatternType; @@ -167,7 +168,7 @@ public static boolean isSimilar(@NotNull final ItemStack itemStack, @NotNull fin * @param container the {@link PersistentDataContainer} * @return the {@link String} */ - public static String getKey(@NotNull final PersistentDataContainer container) { + public static String getKey(@NotNull final PersistentDataContainerView container) { return container.get(PersistentKeys.crate_key.getNamespacedKey(), PersistentDataType.STRING); } diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/CosmicCrateListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/CosmicCrateListener.java index a0f6fa25c..f5d0846bf 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/CosmicCrateListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/CosmicCrateListener.java @@ -6,6 +6,7 @@ import com.ryderbelserion.vital.paper.api.enums.Support; import com.ryderbelserion.vital.paper.util.AdvUtil; import com.ryderbelserion.vital.paper.util.ItemUtil; +import io.papermc.paper.persistence.PersistentDataContainerView; import me.clip.placeholderapi.PlaceholderAPI; import net.kyori.adventure.sound.Sound; import com.badbones69.crazycrates.config.ConfigManager; @@ -25,8 +26,6 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; import org.jetbrains.annotations.NotNull; import org.bukkit.configuration.file.YamlConfiguration; import us.crazycrew.crazycrates.api.enums.types.CrateType; @@ -166,9 +165,6 @@ public void onMysteryBoxClick(InventoryClickEvent event) { // Check if null or air. if (itemStack == null || itemStack.getType() == Material.AIR) return; - // If no item meta, return. - if (!itemStack.hasItemMeta()) return; - // Get crate manager. final CosmicCrateManager cosmicCrateManager = (CosmicCrateManager) crate.getManager(); @@ -178,11 +174,8 @@ public void onMysteryBoxClick(InventoryClickEvent event) { // Get picked slot. final int pickedSlot = slot+1; - // Get clicked item's item meta. - final ItemMeta itemMeta = itemStack.getItemMeta(); - // Get the pdc container. - final PersistentDataContainer container = itemMeta.getPersistentDataContainer(); + final PersistentDataContainerView container = itemStack.getPersistentDataContainer(); // Check if it has the mystery crate key otherwise check picked key. if (container.has(PersistentKeys.cosmic_mystery_crate.getNamespacedKey())) { diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/MobileCrateListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/MobileCrateListener.java index 47258542c..fdc0bd54a 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/MobileCrateListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/MobileCrateListener.java @@ -7,7 +7,9 @@ import com.badbones69.crazycrates.api.events.PlayerPrizeEvent; import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.objects.Prize; +import io.papermc.paper.persistence.PersistentDataContainerView; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -15,8 +17,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import us.crazycrew.crazycrates.api.enums.types.CrateType; @@ -41,13 +41,13 @@ public void onCrateUse(PlayerInteractEvent event) { if (item.getType() == Material.AIR) return; - if (!item.hasItemMeta()) return; + final PersistentDataContainerView container = item.getPersistentDataContainer(); - final ItemMeta itemMeta = item.getItemMeta(); + final NamespacedKey key = PersistentKeys.crate_key.getNamespacedKey(); - final PersistentDataContainer container = itemMeta.getPersistentDataContainer(); + if (!container.has(key)) return; - final Crate crate = this.crateManager.getCrateFromName(container.get(PersistentKeys.crate_key.getNamespacedKey(), PersistentDataType.STRING)); + final Crate crate = this.crateManager.getCrateFromName(container.get(key, PersistentDataType.STRING)); if (crate == null) return; diff --git a/src/main/java/com/badbones69/crazycrates/listeners/crates/QuadCrateListener.java b/src/main/java/com/badbones69/crazycrates/listeners/crates/QuadCrateListener.java index cce89f3f5..d5c456f80 100644 --- a/src/main/java/com/badbones69/crazycrates/listeners/crates/QuadCrateListener.java +++ b/src/main/java/com/badbones69/crazycrates/listeners/crates/QuadCrateListener.java @@ -30,12 +30,12 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.inventory.ItemStack; +import org.bukkit.persistence.PersistentDataType; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ThreadLocalRandom; public class QuadCrateListener implements Listener { @@ -85,10 +85,7 @@ public void onChestClick(PlayerInteractEvent event) { final ItemMeta itemMeta = display.getItemMeta(); // Access the pdc and set "crazycrates-item" - final PersistentKeys key = PersistentKeys.crate_prize; - - //noinspection unchecked - itemMeta.getPersistentDataContainer().set(key.getNamespacedKey(), key.getType(), "1"); + itemMeta.getPersistentDataContainer().set(PersistentKeys.crate_prize.getNamespacedKey(), PersistentDataType.STRING, "1"); // Set the item meta. display.setItemMeta(itemMeta); diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index 66b7c8224..6d8948d33 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -29,12 +29,12 @@ import com.ryderbelserion.vital.common.utils.FileUtil; import com.badbones69.crazycrates.api.builders.ItemBuilder; import com.ryderbelserion.vital.paper.api.enums.Support; +import io.papermc.paper.persistence.PersistentDataContainerView; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; -import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.NamespacedKey; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; -import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.Nullable; @@ -1099,13 +1099,7 @@ public final boolean isKey(@NotNull final ItemStack item) { * @return a crate if is a key from a crate otherwise null if it is not. */ public @Nullable final Crate getCrateFromKey(@NotNull final ItemStack item) { - if (!item.hasItemMeta()) return null; - - ItemMeta itemMeta = item.getItemMeta(); - - if (itemMeta == null) return null; - - return getCrateFromName(ItemUtils.getKey(itemMeta.getPersistentDataContainer())); + return getCrateFromName(ItemUtils.getKey(item.getPersistentDataContainer())); } /** @@ -1182,19 +1176,11 @@ public final boolean isKey(@NotNull final ItemStack item) { */ public final boolean isDisplayReward(@NotNull final Entity entity) { if (entity instanceof Item item) { - ItemStack itemStack = item.getItemStack(); + final ItemStack itemStack = item.getItemStack(); if (itemStack.getType() == Material.AIR) return false; - if (!itemStack.hasItemMeta()) return false; - - ItemMeta itemMeta = itemStack.getItemMeta(); - - PersistentKeys prize = PersistentKeys.crate_prize; - - PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - - return container.has(prize.getNamespacedKey()); + return itemStack.getPersistentDataContainer().has(PersistentKeys.crate_prize.getNamespacedKey()); } return false; @@ -1208,19 +1194,11 @@ public final boolean isDisplayReward(@NotNull final Entity entity) { * @return true if it belongs to that Crate and false if it does not. */ public final boolean isKeyFromCrate(@Nullable final ItemStack item, @Nullable final Crate crate) { - if (item == null) return false; - - if (crate == null) return false; - + if (item == null || crate == null) return false; if (crate.getCrateType() == CrateType.menu) return false; - if (item.getType() == Material.AIR) return false; - if (!item.hasItemMeta()) return false; - - final ItemMeta itemMeta = item.getItemMeta(); - - final PersistentDataContainer container = itemMeta.getPersistentDataContainer(); + final PersistentDataContainerView container = item.getPersistentDataContainer(); if (!container.has(PersistentKeys.crate_key.getNamespacedKey())) return false; @@ -1288,7 +1266,7 @@ private ItemBuilder getKey(@NotNull final FileConfiguration file) { final boolean glowing = file.getBoolean("Crate.PhysicalKey.Glowing", true); final boolean hideFlags = file.getBoolean("Crate.PhysicalKey.HideItemFlags", false); - final ItemBuilder itemBuilder = file.contains("Crate.PhysicalKey.Data") ? new ItemBuilder().fromBase64(file.getString("Crate.PhysicalKey.Data")) : new ItemBuilder().withType(file.getString("Crate.PhysicalKey.Item", "tripwire_hook")); + final ItemBuilder itemBuilder = file.contains("Crate.PhysicalKey.Data") ? new ItemBuilder().fromBase64(file.getString("Crate.PhysicalKey.Data", "")) : new ItemBuilder().withType(file.getString("Crate.PhysicalKey.Item", "tripwire_hook")); return itemBuilder.setDisplayName(name).setDisplayLore(lore).setGlowing(glowing).setHidingItemFlags(hideFlags).setCustomModelData(customModelData); } @@ -1426,22 +1404,28 @@ public void endQuickCrate(@NotNull final Player player, @NotNull final Location } } + /** + * Purge all rewards! + */ public void purgeRewards() { if (!this.allRewards.isEmpty()) this.allRewards.stream().filter(Objects::nonNull).forEach(Entity::remove); } - public Tier getTier(final Crate crate, final ItemStack item) { - if (!item.hasItemMeta()) return null; - - ItemMeta itemMeta = item.getItemMeta(); + /** + * Gets the {@link Tier} + * + * @param crate {@link Crate} + * @param item {@link ItemStack} + * @return {@link Tier} + */ + public final Tier getTier(final Crate crate, final ItemStack item) { + final PersistentDataContainerView container = item.getPersistentDataContainer(); - PersistentDataContainer container = itemMeta.getPersistentDataContainer(); + final NamespacedKey key = PersistentKeys.crate_tier.getNamespacedKey(); - if (container.has(PersistentKeys.crate_tier.getNamespacedKey())) { - return crate.getTier(container.get(PersistentKeys.crate_tier.getNamespacedKey(), PersistentDataType.STRING)); - } + if (!container.has(key)) return null; - return null; + return crate.getTier(container.get(key, PersistentDataType.STRING)); } private final Map> slots = new HashMap<>(); diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/other/CosmicCrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/other/CosmicCrateManager.java index d053a8943..b29affc5d 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/other/CosmicCrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/other/CosmicCrateManager.java @@ -4,10 +4,9 @@ import com.badbones69.crazycrates.api.objects.Crate; import com.badbones69.crazycrates.api.objects.Tier; import com.badbones69.crazycrates.api.builders.ItemBuilder; +import io.papermc.paper.persistence.PersistentDataContainerView; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; import com.badbones69.crazycrates.api.enums.PersistentKeys; import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; @@ -92,20 +91,13 @@ public final int getTotalPrizes() { * @return the tier */ public final Tier getTier(@NotNull final ItemStack itemStack, @NotNull final Crate crate) { - if (itemStack.hasItemMeta()) { - final ItemMeta itemMeta = itemStack.getItemMeta(); + final PersistentDataContainerView container = itemStack.getPersistentDataContainer(); - final PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - - if (container.has(PersistentKeys.crate_tier.getNamespacedKey())) { - return crate.getTier(container.get(PersistentKeys.crate_tier.getNamespacedKey(), PersistentDataType.STRING)); - } - - // In case there is no tier. - return PrizeManager.getTier(crate); + if (container.has(PersistentKeys.crate_tier.getNamespacedKey())) { + return crate.getTier(container.get(PersistentKeys.crate_tier.getNamespacedKey(), PersistentDataType.STRING)); } - // In case there is no item meta. + // In case there is no tier. return PrizeManager.getTier(crate); } diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java index e335f8db0..710270996 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/CasinoCrate.java @@ -9,12 +9,11 @@ import com.ryderbelserion.vital.paper.util.scheduler.FoliaRunnable; import com.badbones69.crazycrates.tasks.BukkitUserManager; import com.badbones69.crazycrates.tasks.crates.CrateManager; +import io.papermc.paper.persistence.PersistentDataContainerView; import net.kyori.adventure.sound.Sound; import net.kyori.adventure.text.logger.slf4j.ComponentLogger; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataContainer; import org.jetbrains.annotations.NotNull; import org.bukkit.configuration.ConfigurationSection; import us.crazycrew.crazycrates.api.enums.types.KeyType; @@ -220,14 +219,10 @@ private void cycle() { final ItemStack itemStack = getInventory().getItem(index); if (itemStack != null) { - if (itemStack.hasItemMeta()) { - final ItemMeta itemMeta = itemStack.getItemMeta(); + final PersistentDataContainerView container = itemStack.getPersistentDataContainer(); - final PersistentDataContainer container = itemMeta.getPersistentDataContainer(); - - if (!container.has(PersistentKeys.crate_prize.getNamespacedKey())) { - setItem(index, getRandomGlassPane()); - } + if (!container.has(PersistentKeys.crate_prize.getNamespacedKey())) { + setItem(index, getRandomGlassPane()); } } } diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java index 73e8ab60f..33782d07a 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/types/QuickCrate.java @@ -157,11 +157,8 @@ public void open(@NotNull final KeyType type, final boolean checkHand) { // Get the item meta. ItemMeta itemMeta = display.getItemMeta(); - // Access the pdc and set "crazycrates-item" - PersistentKeys key = PersistentKeys.crate_prize; - - //noinspection unchecked - itemMeta.getPersistentDataContainer().set(key.getNamespacedKey(), key.getType(), "1"); + // Set the key + itemMeta.getPersistentDataContainer().set(PersistentKeys.crate_prize.getNamespacedKey(), PersistentDataType.STRING, "1"); // Set the item meta. display.setItemMeta(itemMeta);