diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 869c5a8e..c9085e9d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,5 +33,4 @@ ## Other - All drops **must** be sent through a DropQueue - calls to World#dropItem will get your PR rejected. -- EcoEnchants is built with java 8. Usage of J9+ will get your PR rejected. - Any non-plugin-specific changes **must** be made to eco-util, or core-proxy, rather than core-plugin. \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3eb4fda6..a04d68e9 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { } dependencies { - compileOnly 'com.willfp:eco:5.7.1' + compileOnly 'com.willfp:eco:6.0.0' compileOnly 'org.jetbrains:annotations:19.0.0' diff --git a/eco-core/core-nms/v1_16_R1/build.gradle b/eco-core/core-nms/v1_16_R1/build.gradle deleted file mode 100644 index 49623620..00000000 --- a/eco-core/core-nms/v1_16_R1/build.gradle +++ /dev/null @@ -1,6 +0,0 @@ -group 'com.willfp' -version rootProject.version - -dependencies { - compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT' -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/EcoCraftEnchantmentManager.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/EcoCraftEnchantmentManager.java deleted file mode 100644 index c3907887..00000000 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/EcoCraftEnchantmentManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R1; - -import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata; -import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantments; -import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy; -import com.willfp.ecoenchants.proxy.v1_16_R1.enchants.EcoCraftEnchantment; -import net.minecraft.server.v1_16_R1.Enchantment; -import net.minecraft.server.v1_16_R1.IRegistry; -import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_16_R1.util.CraftNamespacedKey; - -import java.util.Map; - -public final class EcoCraftEnchantmentManager implements EcoCraftEnchantmentManagerProxy { - @Override - public void registerNewCraftEnchantments() { - Map metadataMap = VanillaEnchantments.getMetadataMap(); - - for (Enchantment enchantment : IRegistry.ENCHANTMENT) { - NamespacedKey key = CraftNamespacedKey.fromMinecraft(IRegistry.ENCHANTMENT.getKey(enchantment)); - VanillaEnchantmentMetadata metadata = metadataMap.get(org.bukkit.enchantments.Enchantment.getByKey(key)); - new EcoCraftEnchantment(enchantment, metadata).register(); - } - } -} diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/FastGetEnchants.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/FastGetEnchants.java deleted file mode 100644 index 4744120c..00000000 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/FastGetEnchants.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R1; - -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; -import net.minecraft.server.v1_16_R1.Items; -import net.minecraft.server.v1_16_R1.ItemEnchantedBook; -import net.minecraft.server.v1_16_R1.NBTBase; -import net.minecraft.server.v1_16_R1.NBTTagCompound; -import net.minecraft.server.v1_16_R1.NBTTagList; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_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.server.v1_16_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagList enchantmentNBT = checkStored && nmsStack.getItem() == Items.ENCHANTED_BOOK ? ItemEnchantedBook.d(nmsStack) : nmsStack.getEnchantments(); - HashMap 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_R1.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_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/OpenInventory.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/OpenInventory.java deleted file mode 100644 index 7ed7bc16..00000000 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/OpenInventory.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R1; - -import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy; -import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public final class OpenInventory implements OpenInventoryProxy { - @Override - public Object getOpenInventory(@NotNull final Player player) { - return ((CraftPlayer) player).getHandle().activeContainer; - } -} diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/RepairCost.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/RepairCost.java deleted file mode 100644 index ffa9c164..00000000 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/RepairCost.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R1; - -import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy; -import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -public final class RepairCost implements RepairCostProxy { - @Override - public ItemStack setRepairCost(@NotNull final ItemStack itemStack, - final int cost) { - net.minecraft.server.v1_16_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - nmsStack.setRepairCost(cost); - return CraftItemStack.asBukkitCopy(nmsStack); - } - - @Override - public int getRepairCost(@NotNull final ItemStack itemStack) { - net.minecraft.server.v1_16_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - return nmsStack.getRepairCost(); - } -} diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/enchants/EcoCraftEnchantment.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/enchants/EcoCraftEnchantment.java deleted file mode 100644 index 93d3c49d..00000000 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R1/enchants/EcoCraftEnchantment.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R1.enchants; - -import com.willfp.ecoenchants.enchantments.EcoEnchant; -import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata; -import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; -import net.minecraft.server.v1_16_R1.Enchantment; -import org.bukkit.craftbukkit.v1_16_R1.enchantments.CraftEnchantment; -import org.jetbrains.annotations.NotNull; - -public class EcoCraftEnchantment extends CraftEnchantment { - private final VanillaEnchantmentMetadata metadata; - - public EcoCraftEnchantment(@NotNull final Enchantment target, - @NotNull final VanillaEnchantmentMetadata metadata) { - super(target); - this.metadata = metadata; - } - - @Override - public int getMaxLevel() { - return metadata.maxLevel() == null ? this.getHandle().getMaxLevel() : metadata.maxLevel(); - } - - @Override - public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) { - return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other); - } - - public void register() { - EnchantmentUtils.register(this); - } -} diff --git a/eco-core/core-nms/v1_16_R2/build.gradle b/eco-core/core-nms/v1_16_R2/build.gradle deleted file mode 100644 index 3f4d50cf..00000000 --- a/eco-core/core-nms/v1_16_R2/build.gradle +++ /dev/null @@ -1,6 +0,0 @@ -group 'com.willfp' -version rootProject.version - -dependencies { - compileOnly 'org.spigotmc:spigot:1.16.3-R0.1-SNAPSHOT' -} \ No newline at end of file diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/EcoCraftEnchantmentManager.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/EcoCraftEnchantmentManager.java deleted file mode 100644 index b4a0f4c6..00000000 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/EcoCraftEnchantmentManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R2; - -import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata; -import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantments; -import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy; -import com.willfp.ecoenchants.proxy.v1_16_R2.enchants.EcoCraftEnchantment; -import net.minecraft.server.v1_16_R2.Enchantment; -import net.minecraft.server.v1_16_R2.IRegistry; -import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_16_R2.util.CraftNamespacedKey; - -import java.util.Map; - -public final class EcoCraftEnchantmentManager implements EcoCraftEnchantmentManagerProxy { - @Override - public void registerNewCraftEnchantments() { - Map metadataMap = VanillaEnchantments.getMetadataMap(); - - for (Enchantment enchantment : IRegistry.ENCHANTMENT) { - NamespacedKey key = CraftNamespacedKey.fromMinecraft(IRegistry.ENCHANTMENT.getKey(enchantment)); - VanillaEnchantmentMetadata metadata = metadataMap.get(org.bukkit.enchantments.Enchantment.getByKey(key)); - new EcoCraftEnchantment(enchantment, metadata).register(); - } - } -} diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/FastGetEnchants.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/FastGetEnchants.java deleted file mode 100644 index b365d15f..00000000 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/FastGetEnchants.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R2; - -import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; -import net.minecraft.server.v1_16_R2.Items; -import net.minecraft.server.v1_16_R2.ItemEnchantedBook; -import net.minecraft.server.v1_16_R2.NBTBase; -import net.minecraft.server.v1_16_R2.NBTTagCompound; -import net.minecraft.server.v1_16_R2.NBTTagList; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_16_R2.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.server.v1_16_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - NBTTagList enchantmentNBT = checkStored && nmsStack.getItem() == Items.ENCHANTED_BOOK ? ItemEnchantedBook.d(nmsStack) : nmsStack.getEnchantments(); - HashMap 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_R2.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_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/OpenInventory.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/OpenInventory.java deleted file mode 100644 index ff876898..00000000 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/OpenInventory.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R2; - -import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy; -import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public final class OpenInventory implements OpenInventoryProxy { - @Override - public Object getOpenInventory(@NotNull final Player player) { - return ((CraftPlayer) player).getHandle().activeContainer; - } -} diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/RepairCost.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/RepairCost.java deleted file mode 100644 index fd0cc8c5..00000000 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/RepairCost.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R2; - -import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy; -import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; -import org.jetbrains.annotations.NotNull; - -public final class RepairCost implements RepairCostProxy { - @Override - public ItemStack setRepairCost(@NotNull final ItemStack itemStack, - final int cost) { - net.minecraft.server.v1_16_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - nmsStack.setRepairCost(cost); - return CraftItemStack.asBukkitCopy(nmsStack); - } - - @Override - public int getRepairCost(@NotNull final ItemStack itemStack) { - net.minecraft.server.v1_16_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack); - return nmsStack.getRepairCost(); - } -} diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/enchants/EcoCraftEnchantment.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/enchants/EcoCraftEnchantment.java deleted file mode 100644 index eee7a3f6..00000000 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/ecoenchants/proxy/v1_16_R2/enchants/EcoCraftEnchantment.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.willfp.ecoenchants.proxy.v1_16_R2.enchants; - -import com.willfp.ecoenchants.enchantments.EcoEnchant; -import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantmentMetadata; -import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; -import net.minecraft.server.v1_16_R2.Enchantment; -import org.bukkit.craftbukkit.v1_16_R2.enchantments.CraftEnchantment; -import org.jetbrains.annotations.NotNull; - -public class EcoCraftEnchantment extends CraftEnchantment { - private final VanillaEnchantmentMetadata metadata; - - public EcoCraftEnchantment(@NotNull final Enchantment target, - @NotNull final VanillaEnchantmentMetadata metadata) { - super(target); - this.metadata = metadata; - } - - @Override - public int getMaxLevel() { - return metadata.maxLevel() == null ? this.getHandle().getMaxLevel() : metadata.maxLevel(); - } - - @Override - public boolean conflictsWith(@NotNull final org.bukkit.enchantments.Enchantment other) { - return other instanceof EcoEnchant ? other.conflictsWith(this) : super.conflictsWith(other); - } - - public void register() { - EnchantmentUtils.register(this); - } -} 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 ef219551..32cdc541 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 @@ -7,16 +7,11 @@ import com.willfp.eco.core.integrations.IntegrationLoader; import com.willfp.eco.util.TelekinesisUtils; import com.willfp.ecoenchants.command.CommandEcoEnchants; import com.willfp.ecoenchants.command.CommandEnchantinfo; -import com.willfp.ecoenchants.command.CommandGiverandombook; import com.willfp.ecoenchants.config.RarityYml; import com.willfp.ecoenchants.config.TargetYml; import com.willfp.ecoenchants.config.VanillaEnchantsYml; import com.willfp.ecoenchants.display.EnchantDisplay; -import com.willfp.ecoenchants.display.EnchantmentCache; import com.willfp.ecoenchants.enchantments.EcoEnchants; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.support.merging.anvil.AnvilListeners; import com.willfp.ecoenchants.enchantments.support.merging.grindstone.GrindstoneListeners; import com.willfp.ecoenchants.enchantments.support.obtaining.EnchantingListeners; @@ -28,7 +23,6 @@ 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 com.willfp.ecoenchants.util.ProxyUtils; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; @@ -70,7 +64,7 @@ public class EcoEnchantsPlugin extends EcoPlugin { * Internal constructor called by bukkit on plugin load. */ public EcoEnchantsPlugin() { - super(79573, 7666, "com.willfp.ecoenchants.proxy", "&a"); + super(79573, 7666, "com.willfp.ecoenchants.proxy", "&a", true); instance = this; rarityYml = new RarityYml(this); @@ -79,23 +73,14 @@ public class EcoEnchantsPlugin extends EcoPlugin { } @Override - public void enable() { - this.getExtensionLoader().loadExtensions(); - - if (this.getExtensionLoader().getLoadedExtensions().isEmpty()) { - this.getLogger().info("&cNo extensions found"); - } else { - this.getLogger().info("Extensions Loaded:"); - this.getExtensionLoader().getLoadedExtensions().forEach(extension -> this.getLogger().info("- " + extension.getName() + " v" + extension.getVersion())); - } - + protected void handleEnable() { this.getLogger().info(EcoEnchants.values().size() + " Enchantments Loaded"); - TelekinesisUtils.registerTest(player -> ProxyUtils.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(player.getInventory().getItemInMainHand(), EcoEnchants.TELEKINESIS) > 0); + TelekinesisUtils.registerTest(player -> this.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(player.getInventory().getItemInMainHand(), EcoEnchants.TELEKINESIS) > 0); } @Override - public void disable() { + protected void handleDisable() { Bukkit.getServer().getWorlds().forEach(world -> { List populators = new ArrayList<>(world.getPopulators()); populators.forEach((blockPopulator -> { @@ -104,14 +89,10 @@ public class EcoEnchantsPlugin extends EcoPlugin { } })); }); - - this.getExtensionLoader().unloadExtensions(); } @Override - public void onReload() { - targetYml.update(); - rarityYml.update(); + protected void handleReload() { this.getDisplayModule().update(); EcoEnchants.values().forEach((ecoEnchant -> { HandlerList.unregisterAll(ecoEnchant); @@ -129,7 +110,7 @@ public class EcoEnchantsPlugin extends EcoPlugin { } @Override - public void postLoad() { + protected void handleAfterLoad() { if (this.getConfigYml().getBool("loot.enabled")) { Bukkit.getServer().getWorlds().forEach(world -> { List populators = new ArrayList<>(world.getPopulators()); @@ -145,27 +126,22 @@ public class EcoEnchantsPlugin extends EcoPlugin { } @Override - public List getIntegrationLoaders() { + protected List loadIntegrationLoaders() { return Arrays.asList( new IntegrationLoader("Essentials", () -> EssentialsManager.register(new IntegrationEssentials())) ); } @Override - public List getPluginCommands() { + protected List loadPluginCommands() { return Arrays.asList( new CommandEnchantinfo(this), new CommandEcoEnchants(this) ); } - /** - * EcoEnchants-specific listeners. - * - * @return A list of all listeners. - */ @Override - public List getListeners() { + protected List loadListeners() { return Arrays.asList( new EnchantingListeners(this), new GrindstoneListeners(this), @@ -176,31 +152,12 @@ public class EcoEnchantsPlugin extends EcoPlugin { ); } - @Override - public List> getUpdatableClasses() { - return Arrays.asList( - EnchantmentCache.class, - EnchantmentRarity.class, - EnchantmentTarget.class, - EcoEnchants.class, - CommandGiverandombook.class, - CommandEnchantinfo.class, - EnchantmentType.class, - WatcherTriggers.class - ); - } - @Override @Nullable protected DisplayModule createDisplayModule() { return new EnchantDisplay(this); } - @Override - protected String getMinimumEcoVersion() { - return "5.7.0"; - } - @Override public EnchantDisplay getDisplayModule() { return (EnchantDisplay) super.getDisplayModule(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEnchantinfo.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEnchantinfo.java index 14e62675..4d662f3c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEnchantinfo.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandEnchantinfo.java @@ -4,7 +4,7 @@ import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.command.CommandHandler; import com.willfp.eco.core.command.TabCompleteHandler; import com.willfp.eco.core.command.impl.PluginCommand; -import com.willfp.eco.core.config.ConfigUpdater; +import com.willfp.eco.core.config.updating.ConfigUpdater; import com.willfp.eco.util.StringUtils; import com.willfp.ecoenchants.display.EnchantmentCache; import com.willfp.ecoenchants.enchantments.EcoEnchant; @@ -101,7 +101,7 @@ public class CommandEnchantinfo extends PluginCommand { if (allConflicts.length() >= 2) { allConflicts = allConflicts.substring(0, allConflicts.length() - 2); } else { - allConflicts = StringUtils.translate(this.getPlugin().getLangYml().getString("no-conflicts")); + allConflicts = StringUtils.format(this.getPlugin().getLangYml().getString("no-conflicts")); } Set targets = enchantment.getTargetMaterials(); @@ -132,7 +132,7 @@ public class CommandEnchantinfo extends PluginCommand { if (allTargets.length() >= 2) { allTargets = allTargets.substring(0, allTargets.length() - 2); } else { - allTargets = StringUtils.translate(this.getPlugin().getLangYml().getString("no-targets")); + allTargets = StringUtils.format(this.getPlugin().getLangYml().getString("no-targets")); } String maxLevel = String.valueOf(enchantment.getMaxLevel()); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandGiverandombook.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandGiverandombook.java index 2ebdabd1..3a980e1d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandGiverandombook.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandGiverandombook.java @@ -4,7 +4,7 @@ import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.command.CommandHandler; import com.willfp.eco.core.command.TabCompleteHandler; import com.willfp.eco.core.command.impl.Subcommand; -import com.willfp.eco.core.config.ConfigUpdater; +import com.willfp.eco.core.config.updating.ConfigUpdater; import com.willfp.eco.core.items.builder.EnchantedBookBuilder; import com.willfp.eco.util.NumberUtils; import com.willfp.ecoenchants.display.EnchantmentCache; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleExport.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleExport.java index 8bd39567..cfd625c5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleExport.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/CommandLocaleExport.java @@ -32,11 +32,13 @@ public class CommandLocaleExport extends Subcommand { Paste paste = new Paste(configuration.saveToString()); - sender.sendMessage( - this.getPlugin().getLangYml().getMessage("link-to-locale").replace( - "%token%", paste.getHastebinToken() - ) - ); + paste.getHastebinToken(token -> { + sender.sendMessage( + this.getPlugin().getLangYml().getMessage("link-to-locale").replace( + "%token%", token + ) + ); + }); }; } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/RarityYml.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/RarityYml.java index 86a63bac..b958e9df 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/RarityYml.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/RarityYml.java @@ -1,12 +1,12 @@ package com.willfp.ecoenchants.config; import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.config.BaseConfig; +import com.willfp.eco.core.config.yaml.YamlBaseConfig; import org.jetbrains.annotations.NotNull; import java.util.List; -public class RarityYml extends BaseConfig { +public class RarityYml extends YamlBaseConfig { /** * Instantiate rarity.yml. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/TargetYml.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/TargetYml.java index b32e51eb..d24e9b5f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/TargetYml.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/TargetYml.java @@ -1,7 +1,7 @@ package com.willfp.ecoenchants.config; import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.config.BaseConfig; +import com.willfp.eco.core.config.yaml.YamlBaseConfig; import org.bukkit.Material; import org.jetbrains.annotations.NotNull; @@ -9,7 +9,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class TargetYml extends BaseConfig { +public class TargetYml extends YamlBaseConfig { /** * Instantiate target.yml. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/VanillaEnchantsYml.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/VanillaEnchantsYml.java index f14aeb16..5e1d5ff4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/VanillaEnchantsYml.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/VanillaEnchantsYml.java @@ -1,10 +1,10 @@ package com.willfp.ecoenchants.config; import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.config.BaseConfig; +import com.willfp.eco.core.config.yaml.YamlBaseConfig; import org.jetbrains.annotations.NotNull; -public class VanillaEnchantsYml extends BaseConfig { +public class VanillaEnchantsYml extends YamlBaseConfig { /** * Instantiate target.yml. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/EnchantmentConfig.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/EnchantmentConfig.java index 42995cfb..6343783c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/EnchantmentConfig.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/EnchantmentConfig.java @@ -1,6 +1,7 @@ package com.willfp.ecoenchants.config.configs; -import com.willfp.eco.core.config.ExtendableConfig; +import com.willfp.eco.core.EcoPlugin; +import com.willfp.eco.core.config.yaml.YamlExtendableConfig; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; @@ -17,7 +18,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -public class EnchantmentConfig extends ExtendableConfig { +public class EnchantmentConfig extends YamlExtendableConfig { /** * The name of the config. */ @@ -30,6 +31,12 @@ public class EnchantmentConfig extends ExtendableConfig { @Getter private final EcoEnchant enchant; + /** + * Instance of EcoEnchants. + */ + @Getter + private final EcoPlugin plugin; + /** * Instantiate a new config for an enchantment. * @@ -38,11 +45,13 @@ public class EnchantmentConfig extends ExtendableConfig { * @param enchant The enchantment. */ public EnchantmentConfig(@NotNull final String name, - @NotNull final Class plugin, - @NotNull final EcoEnchant enchant) { - super(name, true, EcoEnchantsPlugin.getInstance(), plugin, "enchants/" + enchant.getType().getName() + "/"); + @NotNull final Class source, + @NotNull final EcoEnchant enchant, + @NotNull final EcoPlugin plugin) { + super(name, true, EcoEnchantsPlugin.getInstance(), source, "enchants/" + enchant.getType().getName() + "/"); this.name = name; this.enchant = enchant; + this.plugin = plugin; } /** 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 5e12c6a4..1f7d2489 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 @@ -10,7 +10,6 @@ import com.willfp.ecoenchants.display.options.DisplayOptions; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy; -import com.willfp.ecoenchants.util.ProxyUtils; import lombok.Getter; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; @@ -113,7 +112,7 @@ public class EnchantDisplay extends DisplayModule { List forRemoval = new ArrayList<>(); - LinkedHashMap enchantments = new LinkedHashMap<>(ProxyUtils.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(itemStack, true)); + LinkedHashMap enchantments = new LinkedHashMap<>(this.getPlugin().getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(itemStack, true)); enchantments.entrySet().removeIf(enchantmentIntegerEntry -> enchantmentIntegerEntry.getValue().equals(0)); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java index c3dbe7cc..6ae8c927 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/DescriptionOptions.java @@ -40,6 +40,6 @@ public class DescriptionOptions extends PluginDependent { public void update() { threshold = this.getPlugin().getConfigYml().getInt("lore.describe.before-lines"); enabled = this.getPlugin().getConfigYml().getBool("lore.describe.enabled"); - color = StringUtils.translate(this.getPlugin().getLangYml().getString("description-color")); + color = StringUtils.format(this.getPlugin().getLangYml().getString("description-color")); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index 2ff1bef9..129d0b59 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -161,7 +161,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche this.type = type; this.permissionName = key.replace("_", ""); - this.config = new EnchantmentConfig(this.permissionName, this.getClass(), this); + this.config = new EnchantmentConfig(this.permissionName, this.getClass(), this, this.getPlugin()); if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable." + permissionName) == null) { Permission permission = new Permission( @@ -197,7 +197,6 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche * This can be overridden but may lead to unexpected behavior. */ public void update() { - config.update(); config.loadFromLang(); rarity = config.getRarity(); Validate.notNull(rarity, "Rarity specified in " + this.permissionName + " is invalid!"); @@ -207,8 +206,8 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche availableFromVillager = config.getBool(EcoEnchants.OBTAINING_LOCATION + "villager"); availableFromLoot = config.getBool(EcoEnchants.OBTAINING_LOCATION + "loot"); maxLevel = config.getInt(EcoEnchants.GENERAL_LOCATION + "maximum-level", 1); - displayName = StringUtils.translate(config.getString("name")); - description = StringUtils.translate(config.getString("description")); + displayName = StringUtils.format(config.getString("name")); + description = StringUtils.format(config.getString("description")); disabledWorldNames.clear(); disabledWorldNames.addAll(config.getStrings(EcoEnchants.GENERAL_LOCATION + "disabled-in-worlds")); disabledWorlds.clear(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index 1f2b7c63..21f3e016 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -248,7 +248,6 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.support.vanilla.VanillaEnchantments; import lombok.experimental.UtilityClass; import org.bukkit.NamespacedKey; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.jetbrains.annotations.NotNull; @@ -517,18 +516,6 @@ public class EcoEnchants { return ImmutableList.copyOf(BY_KEY.values()); } - /** - * Gets {@link EcoEnchant} from {@link Enchantment}. - * - * @param enchantment The enchantment. - * @return The matching {@link EcoEnchant}, or null if not found. - * @deprecated Use a typecast. - */ - @Deprecated - public static EcoEnchant getFromEnchantment(@NotNull final Enchantment enchantment) { - return enchantment instanceof EcoEnchant ? (EcoEnchant) enchantment : null; - } - /** * Get {@link EcoEnchant} matching display name. * diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java index 22836cb9..54809b9f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java @@ -1,6 +1,6 @@ package com.willfp.ecoenchants.enchantments.meta; -import com.willfp.eco.core.config.ConfigUpdater; +import com.willfp.eco.core.config.updating.ConfigUpdater; import com.willfp.eco.util.StringUtils; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.config.RarityYml; @@ -106,7 +106,7 @@ public class EnchantmentRarity { double lootProbability = rarityYml.getDouble("rarities." + rarity + ".loot-probability"); String customColor = null; if (rarityYml.getBool("rarities." + rarity + ".custom-color.enabled")) { - customColor = StringUtils.translate(rarityYml.getString("rarities." + rarity + ".custom-color.color")); + customColor = StringUtils.format(rarityYml.getString("rarities." + rarity + ".custom-color.color")); } new EnchantmentRarity(rarity, probability, minimumLevel, villagerProbability, lootProbability, customColor).register(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java index 335b6889..2c19ae8f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java @@ -7,7 +7,6 @@ import com.willfp.eco.core.tuples.Pair; import com.willfp.eco.util.NumberUtils; import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy; import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy; -import com.willfp.ecoenchants.util.ProxyUtils; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -75,7 +74,7 @@ public class AnvilListeners extends PluginDependent implements Listen event.getInventory().setItem(2, null); Player player = (Player) event.getViewers().get(0); - if (ProxyUtils.getProxy(OpenInventoryProxy.class).getOpenInventory(player).getClass().toString().equals(ANVIL_GUI_CLASS)) { + if (this.getPlugin().getProxy(OpenInventoryProxy.class).getOpenInventory(player).getClass().toString().equals(ANVIL_GUI_CLASS)) { return; } @@ -123,14 +122,14 @@ public class AnvilListeners extends PluginDependent implements Listen } if (this.getPlugin().getConfigYml().getBool("anvil.rework-cost")) { - int repairCost = ProxyUtils.getProxy(RepairCostProxy.class).getRepairCost(item); + int repairCost = this.getPlugin().getProxy(RepairCostProxy.class).getRepairCost(item); int reworkCount = NumberUtils.log2(repairCost + 1); if (repairCost == 0) { reworkCount = 0; } reworkCount++; repairCost = (int) Math.pow(2, reworkCount) - 1; - item = ProxyUtils.getProxy(RepairCostProxy.class).setRepairCost(item, repairCost); + item = this.getPlugin().getProxy(RepairCostProxy.class).setRepairCost(item, repairCost); } int cost; 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 8c0b8a37..e3b9ef28 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 @@ -8,7 +8,6 @@ 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 com.willfp.ecoenchants.util.ProxyUtils; import lombok.experimental.UtilityClass; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -79,7 +78,7 @@ public class AnvilMerge { name = name.replace("ยง", "&"); if (player.hasPermission("ecoenchants.anvil.color")) { - name = StringUtils.translate(name); + name = StringUtils.format(name); } if (!EnchantmentTarget.ALL.getMaterials().contains(left.getType()) || right == null || !EnchantmentTarget.ALL.getMaterials().contains(right.getType())) { @@ -131,8 +130,8 @@ public class AnvilMerge { Map outEnchants = new HashMap<>(); - HashMap leftEnchants = new HashMap<>(ProxyUtils.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(left, true)); - HashMap rightEnchants = new HashMap<>(ProxyUtils.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(right, true)); + HashMap leftEnchants = new HashMap<>(PLUGIN.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(left, true)); + HashMap rightEnchants = new HashMap<>(PLUGIN.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(right, true)); leftEnchants.forEach(((enchantment, integer) -> { int level = integer; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java index 3ff5b424..80ae250d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/vanilla/VanillaEnchantments.java @@ -2,7 +2,6 @@ package com.willfp.ecoenchants.enchantments.support.vanilla; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.proxy.proxies.EcoCraftEnchantmentManagerProxy; -import com.willfp.ecoenchants.util.ProxyUtils; import lombok.experimental.UtilityClass; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; @@ -58,7 +57,7 @@ public class VanillaEnchantments { MAP.putAll(map); if (plugin.getVanillaEnchantsYml().getBool("enabled")) { - ProxyUtils.getProxy(EcoCraftEnchantmentManagerProxy.class).registerNewCraftEnchantments(); + plugin.getProxy(EcoCraftEnchantmentManagerProxy.class).registerNewCraftEnchantments(); } } } 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 a1c3502e..71de5073 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 @@ -2,9 +2,9 @@ package com.willfp.ecoenchants.enchantments.util; 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 com.willfp.ecoenchants.util.ProxyUtils; import lombok.experimental.UtilityClass; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -27,7 +27,7 @@ public class EnchantChecks { /** * Proxy instance of FastGetEnchants. */ - private static final FastGetEnchantsProxy PROXY = ProxyUtils.getProxy(FastGetEnchantsProxy.class); + private static final FastGetEnchantsProxy PROXY = EcoEnchantsPlugin.getInstance().getProxy(FastGetEnchantsProxy.class); /** * Does the specified ItemStack have a certain Enchantment present? diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/util/ProxyUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/util/ProxyUtils.java deleted file mode 100644 index 9a75d687..00000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/util/ProxyUtils.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.willfp.ecoenchants.util; - -import com.willfp.eco.core.proxy.AbstractProxy; -import com.willfp.ecoenchants.EcoEnchantsPlugin; -import com.willfp.ecoenchants.proxy.util.ProxyFactory; -import lombok.experimental.UtilityClass; -import org.jetbrains.annotations.NotNull; - -@UtilityClass -public class ProxyUtils { - /** - * Get the implementation of a specified proxy. - * - * @param proxyClass The proxy interface. - * @param The type of the proxy. - * @return The proxy implementation. - */ - public @NotNull T getProxy(@NotNull final Class proxyClass) { - return new ProxyFactory<>(EcoEnchantsPlugin.getInstance(), proxyClass).getProxy(); - } -} diff --git a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/util/ProxyFactory.java b/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/util/ProxyFactory.java deleted file mode 100644 index eb665a09..00000000 --- a/eco-core/core-proxy/src/main/java/com/willfp/ecoenchants/proxy/util/ProxyFactory.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.willfp.ecoenchants.proxy.util; - -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.PluginDependent; -import com.willfp.eco.core.proxy.AbstractProxy; -import com.willfp.eco.core.proxy.ProxyConstants; -import com.willfp.eco.core.proxy.UnsupportedVersionException; -import org.jetbrains.annotations.NotNull; - -import java.util.IdentityHashMap; -import java.util.Map; - -public class ProxyFactory extends PluginDependent { - /** - * Cached proxy implementations in order to not perform expensive reflective class-finding. - */ - private static final Map, AbstractProxy> CACHE = new IdentityHashMap<>(); - - /** - * The class of the proxy interface. - */ - private final Class proxyClass; - - /** - * Create a new Proxy Factory for a specific type. - * - * @param plugin The plugin to create proxies for. - * @param proxyClass The class of the proxy interface. - */ - public ProxyFactory(@NotNull final EcoPlugin plugin, - @NotNull final Class proxyClass) { - super(plugin); - this.proxyClass = proxyClass; - } - - /** - * Get the implementation of a proxy. - * - * @return The proxy implementation. - */ - public @NotNull T getProxy() { - try { - T cachedProxy = attemptCache(); - if (cachedProxy != null) { - return cachedProxy; - } - - String className = this.getPlugin().getProxyPackage() + "." + ProxyConstants.NMS_VERSION + "." + proxyClass.getSimpleName().replace("Proxy", ""); - final Class class2 = Class.forName(className); - Object instance = class2.getConstructor().newInstance(); - if (proxyClass.isAssignableFrom(class2) && proxyClass.isInstance(instance)) { - T proxy = proxyClass.cast(instance); - CACHE.put(proxyClass, proxy); - return proxy; - } - } catch (Exception e) { - // If not returned, then throw error - } - - throw new UnsupportedVersionException("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION); - } - - private T attemptCache() { - Object proxy = CACHE.get(proxyClass); - if (proxy == null) { - return null; - } - - if (proxyClass.isInstance(proxy)) { - return proxyClass.cast(proxy); - } - - return null; - } -} diff --git a/eco-extensions/sprint-artifacts/build.gradle b/eco-extensions/sprint-artifacts/build.gradle index 11ef232f..e3058be0 100644 --- a/eco-extensions/sprint-artifacts/build.gradle +++ b/eco-extensions/sprint-artifacts/build.gradle @@ -1,5 +1,5 @@ group 'com.willfp' -version '5.1.0' +version '5.2.0' description = 'Sprint Artifacts Extension' shadowJar { diff --git a/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsListener.java b/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsListener.java index 3947e99a..4d28b992 100644 --- a/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsListener.java +++ b/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsListener.java @@ -12,7 +12,6 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; -import java.util.Objects; import java.util.Optional; @SuppressWarnings("deprecation") @@ -39,8 +38,8 @@ public class SprintArtifactsListener implements Listener { } Optional matching = bootsMeta.getEnchants().keySet().stream() + .filter(enchantment -> enchantment instanceof EcoEnchant) .map(enchant -> (EcoEnchant) enchant) - .filter(Objects::nonNull) .filter(enchantment -> enchantment.getType().equals(EnchantmentType.ARTIFACT)) .findFirst(); if (matching.isEmpty()) { diff --git a/gradle.properties b/gradle.properties index a54005f3..4d55ceb6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 7.13.5 +version = 8.0.0 plugin-name = EcoEnchants \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 6debe263..b5b8e784 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,8 +3,6 @@ rootProject.name = 'EcoEnchants' // Core include ':eco-core' include ':eco-core:core-nms' -include ':eco-core:core-nms:v1_16_R1' -include ':eco-core:core-nms:v1_16_R2' include ':eco-core:core-nms:v1_16_R3' include ':eco-core:core-nms:v1_17_R1' include ':eco-core:core-proxy'