diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java index eb7f6c9da..2fab48e81 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java @@ -67,7 +67,6 @@ public class SoulboundRune extends SimpleSlimefunItem { e.setCancelled(true); ItemMeta enchMeta = ench.getItemMeta(); - List lore = enchMeta.hasLore() ? enchMeta.getLore() : new ArrayList<>(); // This lightning is just an effect, it deals no damage. l.getWorld().strikeLightningEffect(l); @@ -80,9 +79,8 @@ public class SoulboundRune extends SimpleSlimefunItem { l.getWorld().createExplosion(l, 0.0F); l.getWorld().playSound(l, Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1F); - lore.add(ChatColor.GRAY + "Soulbound"); + SlimefunUtils.setSoulbound(ench); - enchMeta.setLore(lore); ench.setItemMeta(enchMeta); ent.remove(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java index 4a6f39798..b62fcc7fa 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/SlimefunUtils.java @@ -2,15 +2,18 @@ package io.github.thebusybiscuit.slimefun4.utils; import java.util.List; import java.util.Optional; +import javax.annotation.Nonnull; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Item; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; +import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI; import io.github.thebusybiscuit.cscorelib2.item.ImmutableItemMeta; import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound; import io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientPedestal; @@ -36,6 +39,8 @@ public final class SlimefunUtils { private static final String SOULBOUND_LORE = ChatColor.GRAY + "Soulbound"; private static final String NO_PICKUP_METADATA = "no_pickup"; + private static final NamespacedKey SOULBOUND_KEY = new NamespacedKey(SlimefunPlugin.instance, "soulbound"); + private SlimefunUtils() {} /** @@ -75,6 +80,9 @@ public final class SlimefunUtils { return false; } else { + if (PersistentDataAPI.getOptionalBoolean(item.getItemMeta(), SOULBOUND_KEY).isPresent()) + return true; + SlimefunItem backpack = SlimefunItems.BOUND_BACKPACK.getItem(); if (backpack != null && backpack.isItem(item)) { @@ -104,6 +112,16 @@ public final class SlimefunUtils { } } + public static void setSoulbound(@Nonnull ItemStack item) { + final ItemMeta meta = item.getItemMeta(); + final List lore = meta.getLore(); + lore.add(SOULBOUND_LORE); + meta.setLore(lore); + + PersistentDataAPI.setBoolean(item.getItemMeta(), SOULBOUND_KEY, true); + item.setItemMeta(meta); + } + public static boolean containsSimilarItem(Inventory inventory, ItemStack itemStack, boolean checkLore) { if (inventory == null || itemStack == null) return false;