From 1afb803494e37ced7a041250aac0227275fd3de4 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 7 Aug 2021 15:00:34 +0100 Subject: [PATCH] Updated to eco 6.3.0 and began using FastItemStack --- build.gradle | 2 +- .../proxy/v1_16_R3/FastGetEnchants.java | 61 ------------------- .../proxy/v1_17_R1/FastGetEnchants.java | 57 ----------------- .../willfp/ecoenchants/EcoEnchantsPlugin.java | 4 +- .../ecoenchants/display/EnchantDisplay.java | 29 ++++----- .../support/merging/anvil/AnvilMerge.java | 6 +- .../enchantments/util/EnchantChecks.java | 12 +--- .../enchantments/util/ItemConversions.java | 5 +- .../proxy/proxies/FastGetEnchantsProxy.java | 54 ---------------- 9 files changed, 23 insertions(+), 207 deletions(-) delete mode 100644 eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/FastGetEnchants.java delete mode 100644 eco-core/core-nms/v1_17_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_17_R1/FastGetEnchants.java delete mode 100644 eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/FastGetEnchantsProxy.java diff --git a/build.gradle b/build.gradle index a04d68e9..fb865ade 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:6.0.0' + compileOnly 'com.willfp:eco:6.3.0' compileOnly 'org.jetbrains:annotations:19.0.0' diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/FastGetEnchants.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/FastGetEnchants.java deleted file mode 100644 index ab68b7c2..00000000 --- a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R3/FastGetEnchants.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R3; - -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; -import net.minecraft.server.v1_16_R3.ItemEnchantedBook; -import net.minecraft.server.v1_16_R3.Items; -import net.minecraft.server.v1_16_R3.NBTBase; -import net.minecraft.server.v1_16_R3.NBTTagCompound; -import net.minecraft.server.v1_16_R3.NBTTagList; -import org.bukkit.Material; -import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public final class FastGetEnchants implements FastGetEnchantsProxy { - @Override - public Map getEnchantmentsOnItem(@NotNull final ItemStack itemStack, - final boolean checkStored) { - net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagList enchantmentNBT = checkStored && nmsStack.getItem() == Items.ENCHANTED_BOOK ? ItemEnchantedBook.d(nmsStack) : nmsStack.getEnchantments(); - Map foundEnchantments = new HashMap<>(); - - for (NBTBase base : enchantmentNBT) { - NBTTagCompound compound = (NBTTagCompound) base; - String key = compound.getString("id"); - int level = '\uffff' & compound.getShort("lvl"); - - Enchantment found = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(key)); - if (found != null) { - foundEnchantments.put(found, level); - } - } - return foundEnchantments; - } - - @Override - public int getLevelOnItem(@NotNull final ItemStack itemStack, - @NotNull final Enchantment enchantment, - final boolean checkStored) { - net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagList enchantmentNBT = checkStored && nmsStack.getItem() == Items.ENCHANTED_BOOK ? ItemEnchantedBook.d(nmsStack) : nmsStack.getEnchantments(); - - for (NBTBase base : enchantmentNBT) { - NBTTagCompound compound = (NBTTagCompound) base; - String key = compound.getString("id"); - if (!key.equals(enchantment.getKey().toString())) { - continue; - } - - return '\uffff' & compound.getShort("lvl"); - } - return 0; - } -} diff --git a/eco-core/core-nms/v1_17_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_17_R1/FastGetEnchants.java b/eco-core/core-nms/v1_17_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_17_R1/FastGetEnchants.java deleted file mode 100644 index 56a02877..00000000 --- a/eco-core/core-nms/v1_17_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_17_R1/FastGetEnchants.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_17_R1; - -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; -import net.minecraft.nbt.NBTBase; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.world.item.ItemEnchantedBook; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_17_R1.util.CraftNamespacedKey; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; - -public final class FastGetEnchants implements FastGetEnchantsProxy { - @Override - public Map getEnchantmentsOnItem(@NotNull final ItemStack itemStack, - final boolean checkStored) { - net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagList enchantmentNBT = checkStored && itemStack.getType() == Material.ENCHANTED_BOOK ? ItemEnchantedBook.d(nmsStack) : nmsStack.getEnchantments(); - Map foundEnchantments = new HashMap<>(); - - for (NBTBase base : enchantmentNBT) { - NBTTagCompound compound = (NBTTagCompound) base; - String key = compound.getString("id"); - int level = '\uffff' & compound.getShort("lvl"); - - Enchantment found = Enchantment.getByKey(CraftNamespacedKey.fromStringOrNull(key)); - if (found != null) { - foundEnchantments.put(found, level); - } - } - return foundEnchantments; - } - - @Override - public int getLevelOnItem(@NotNull final ItemStack itemStack, - @NotNull final Enchantment enchantment, - final boolean checkStored) { - net.minecraft.world.item.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagList enchantmentNBT = checkStored && itemStack.getType() == Material.ENCHANTED_BOOK ? ItemEnchantedBook.d(nmsStack) : nmsStack.getEnchantments(); - - for (NBTBase base : enchantmentNBT) { - NBTTagCompound compound = (NBTTagCompound) base; - String key = compound.getString("id"); - if (!key.equals(enchantment.getKey().toString())) { - continue; - } - - return '\uffff' & compound.getShort("lvl"); - } - return 0; - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java index 3c829d1f..ede884a7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java @@ -3,6 +3,7 @@ package com.willfp.ecoenchants; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.command.impl.PluginCommand; import com.willfp.eco.core.display.DisplayModule; +import com.willfp.eco.core.fast.FastItemStack; import com.willfp.eco.core.integrations.IntegrationLoader; import com.willfp.eco.util.TelekinesisUtils; import com.willfp.ecoenchants.command.CommandEcoEnchants; @@ -23,7 +24,6 @@ import com.willfp.ecoenchants.enchantments.util.TimedRunnable; import com.willfp.ecoenchants.enchantments.util.WatcherTriggers; import com.willfp.ecoenchants.integrations.essentials.EssentialsManager; import com.willfp.ecoenchants.integrations.essentials.plugins.IntegrationEssentials; -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.World; @@ -76,7 +76,7 @@ public class EcoEnchantsPlugin extends EcoPlugin { protected void handleEnable() { this.getLogger().info(EcoEnchants.values().size() + " Enchantments Loaded"); - TelekinesisUtils.registerTest(player -> this.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(player.getInventory().getItemInMainHand(), EcoEnchants.TELEKINESIS) > 0); + TelekinesisUtils.registerTest(player -> FastItemStack.wrap(player.getInventory().getItemInMainHand()).getLevelOnItem(EcoEnchants.TELEKINESIS, false) > 0); } @Override diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java index d3cc6403..3d155768 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantDisplay.java @@ -5,11 +5,11 @@ import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.display.Display; import com.willfp.eco.core.display.DisplayModule; import com.willfp.eco.core.display.DisplayPriority; +import com.willfp.eco.core.fast.FastItemStack; import com.willfp.eco.util.NumberUtils; import com.willfp.ecoenchants.display.options.DisplayOptions; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.util.ItemConversionOptions; -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; import lombok.Getter; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; @@ -84,13 +84,12 @@ public class EnchantDisplay extends DisplayModule { } ItemMeta meta = itemStack.getItemMeta(); + FastItemStack fastItemStack = FastItemStack.wrap(itemStack); assert meta != null; boolean hide = (boolean) args[0]; - List itemLore = null; - if (hide || meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER)) { meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); if (meta instanceof EnchantmentStorageMeta) { @@ -101,17 +100,11 @@ public class EnchantDisplay extends DisplayModule { return; } - if (meta.hasLore()) { - itemLore = meta.getLore(); - } - - if (itemLore == null) { - itemLore = new ArrayList<>(); - } + List itemLore = fastItemStack.getLore(); List lore = new ArrayList<>(); - LinkedHashMap enchantments = new LinkedHashMap<>(this.getPlugin().getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(itemStack, true)); + LinkedHashMap enchantments = new LinkedHashMap<>(fastItemStack.getEnchantmentsOnItem(true)); enchantments.entrySet().removeIf(enchantmentIntegerEntry -> enchantmentIntegerEntry.getValue().equals(0)); @@ -175,8 +168,8 @@ public class EnchantDisplay extends DisplayModule { meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); lore.addAll(itemLore); - meta.setLore(lore); itemStack.setItemMeta(meta); + fastItemStack.setLore(lore); } @Override @@ -184,16 +177,18 @@ public class EnchantDisplay extends DisplayModule { if (!EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) { return; } + FastItemStack fastItemStack = FastItemStack.wrap(itemStack); + + List lore = fastItemStack.getLore(); + + lore.removeIf(s -> s.startsWith("§w")); + + fastItemStack.setLore(lore); ItemMeta meta = itemStack.getItemMeta(); assert meta != null; - List lore = meta.getLore() == null ? new ArrayList<>() : new ArrayList<>(meta.getLore()); - - lore.removeIf(s -> s.startsWith("§w")); - meta.setLore(lore); - meta.getPersistentDataContainer().remove(legacyV); if (!meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER)) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java index e3b9ef28..c181d032 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java @@ -1,5 +1,6 @@ package com.willfp.ecoenchants.enchantments.support.merging.anvil; +import com.willfp.eco.core.fast.FastItemStack; import com.willfp.eco.core.tuples.Pair; import com.willfp.eco.util.StringUtils; import com.willfp.ecoenchants.EcoEnchantsPlugin; @@ -7,7 +8,6 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; import lombok.experimental.UtilityClass; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -130,8 +130,8 @@ public class AnvilMerge { Map outEnchants = new HashMap<>(); - HashMap leftEnchants = new HashMap<>(PLUGIN.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(left, true)); - HashMap rightEnchants = new HashMap<>(PLUGIN.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(right, true)); + HashMap leftEnchants = new HashMap<>(FastItemStack.wrap(left).getEnchantmentsOnItem(true)); + HashMap rightEnchants = new HashMap<>(FastItemStack.wrap(right).getEnchantmentsOnItem(true)); leftEnchants.forEach(((enchantment, integer) -> { int level = integer; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java index 4e5a0d37..7afa2520 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java @@ -1,11 +1,10 @@ package com.willfp.ecoenchants.enchantments.util; +import com.willfp.eco.core.fast.FastItemStack; import com.willfp.eco.util.ArrowUtils; import com.willfp.eco.util.DurabilityUtils; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; import lombok.experimental.UtilityClass; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -24,11 +23,6 @@ import java.util.concurrent.atomic.AtomicInteger; @UtilityClass public class EnchantChecks { - /** - * Proxy instance of FastGetEnchants. - */ - private static final FastGetEnchantsProxy PROXY = EcoEnchantsPlugin.getInstance().getProxy(FastGetEnchantsProxy.class); - /** * Does the specified ItemStack have a certain Enchantment present? * @@ -57,7 +51,7 @@ public class EnchantChecks { return 0; } - return PROXY.getLevelOnItem(item, enchantment); + return FastItemStack.wrap(item).getLevelOnItem(enchantment, false); } /** @@ -75,7 +69,7 @@ public class EnchantChecks { } Map ecoEnchants = new HashMap<>(); - for (Map.Entry enchantmentIntegerEntry : PROXY.getEnchantmentsOnItem(item).entrySet()) { + for (Map.Entry enchantmentIntegerEntry : FastItemStack.wrap(item).getEnchantmentsOnItem(false).entrySet()) { if (enchantmentIntegerEntry.getKey() instanceof EcoEnchant enchant) { ecoEnchants.put(enchant, enchantmentIntegerEntry.getValue()); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java index f39e3758..cee4f989 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/ItemConversions.java @@ -2,11 +2,11 @@ package com.willfp.ecoenchants.enchantments.util; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.PluginDependent; +import com.willfp.eco.core.fast.FastItemStack; import com.willfp.eco.util.NumberUtils; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -385,8 +385,7 @@ public class ItemConversions extends PluginDependent implements Liste return; } - Map enchants = this.getPlugin().getProxy(FastGetEnchantsProxy.class) - .getEnchantmentsOnItem(itemStack, true); + Map enchants = FastItemStack.wrap(itemStack).getEnchantmentsOnItem(true); for (Enchantment enchantment : new HashSet<>(enchants.keySet())) { if (enchantment instanceof EcoEnchant enchant) { diff --git a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/FastGetEnchantsProxy.java b/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/FastGetEnchantsProxy.java deleted file mode 100644 index 430c85d4..00000000 --- a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/proxies/FastGetEnchantsProxy.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.willfp.ecoenchants.proxy.proxies; - -import com.willfp.eco.core.proxy.AbstractProxy; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - -public interface FastGetEnchantsProxy extends AbstractProxy { - - /** - * Get all enchantments on an {@link ItemStack}. - * - * @param itemStack The item to query. - * @return A map of all enchantments, where the value represents the level present. - */ - default Map getEnchantmentsOnItem(@NotNull ItemStack itemStack) { - return getEnchantmentsOnItem(itemStack, false); - } - - /** - * Get all enchantments on an {@link ItemStack}. - * - * @param itemStack The item to query. - * @param checkStored Check stored enchantments in the enchanted book if true. - * @return A map of all enchantments, where the value represents the level present. - */ - Map getEnchantmentsOnItem(@NotNull ItemStack itemStack, boolean checkStored); - - /** - * Get the level of a specified enchantment on an item. - * - * @param itemStack The item to query. - * @param enchantment The enchantment to query. - * @return The level found, or 0 if not present. - */ - default int getLevelOnItem(@NotNull ItemStack itemStack, - @NotNull Enchantment enchantment) { - return getLevelOnItem(itemStack, enchantment, false); - } - - /** - * Get the level of a specified enchantment on an item. - * - * @param itemStack The item to query. - * @param enchantment The enchantment to query. - * @param checkStored Check stored enchantments in the enchanted book if true. - * @return The level found, or 0 if not present. - */ - int getLevelOnItem(@NotNull ItemStack itemStack, - @NotNull Enchantment enchantment, - boolean checkStored); -}