mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-25 15:35:11 +01:00
Updated to eco 6.3.0 and began using FastItemStack
This commit is contained in:
parent
9174a46ce8
commit
1afb803494
@ -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'
|
||||
|
||||
|
@ -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<Enchantment, Integer> 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<Enchantment, Integer> 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;
|
||||
}
|
||||
}
|
@ -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<Enchantment, Integer> 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<Enchantment, Integer> 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;
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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<String> 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<String> itemLore = fastItemStack.getLore();
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
LinkedHashMap<Enchantment, Integer> enchantments = new LinkedHashMap<>(this.getPlugin().getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(itemStack, true));
|
||||
LinkedHashMap<Enchantment, Integer> 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<String> lore = fastItemStack.getLore();
|
||||
|
||||
lore.removeIf(s -> s.startsWith("§w"));
|
||||
|
||||
fastItemStack.setLore(lore);
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
assert meta != null;
|
||||
|
||||
List<String> 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)) {
|
||||
|
@ -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<Enchantment, Integer> outEnchants = new HashMap<>();
|
||||
|
||||
HashMap<Enchantment, Integer> leftEnchants = new HashMap<>(PLUGIN.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(left, true));
|
||||
HashMap<Enchantment, Integer> rightEnchants = new HashMap<>(PLUGIN.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(right, true));
|
||||
HashMap<Enchantment, Integer> leftEnchants = new HashMap<>(FastItemStack.wrap(left).getEnchantmentsOnItem(true));
|
||||
HashMap<Enchantment, Integer> rightEnchants = new HashMap<>(FastItemStack.wrap(right).getEnchantmentsOnItem(true));
|
||||
|
||||
leftEnchants.forEach(((enchantment, integer) -> {
|
||||
int level = integer;
|
||||
|
@ -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<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
||||
for (Map.Entry<Enchantment, Integer> enchantmentIntegerEntry : PROXY.getEnchantmentsOnItem(item).entrySet()) {
|
||||
for (Map.Entry<Enchantment, Integer> enchantmentIntegerEntry : FastItemStack.wrap(item).getEnchantmentsOnItem(false).entrySet()) {
|
||||
if (enchantmentIntegerEntry.getKey() instanceof EcoEnchant enchant) {
|
||||
ecoEnchants.put(enchant, enchantmentIntegerEntry.getValue());
|
||||
}
|
||||
|
@ -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<EcoPlugin> implements Liste
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> enchants = this.getPlugin().getProxy(FastGetEnchantsProxy.class)
|
||||
.getEnchantmentsOnItem(itemStack, true);
|
||||
Map<Enchantment, Integer> enchants = FastItemStack.wrap(itemStack).getEnchantmentsOnItem(true);
|
||||
|
||||
for (Enchantment enchantment : new HashSet<>(enchants.keySet())) {
|
||||
if (enchantment instanceof EcoEnchant enchant) {
|
||||
|
@ -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<Enchantment, Integer> 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<Enchantment, Integer> 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user