mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-24 15:25:18 +01:00
Updated to eco 6
This commit is contained in:
parent
a00bfdd41a
commit
ab6f52a900
@ -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.
|
@ -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'
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
|
||||
}
|
@ -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<org.bukkit.enchantments.Enchantment, VanillaEnchantmentMetadata> 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Enchantment, Integer> 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<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_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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.3-R0.1-SNAPSHOT'
|
||||
}
|
@ -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<org.bukkit.enchantments.Enchantment, VanillaEnchantmentMetadata> 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Enchantment, Integer> 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<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_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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<BlockPopulator> 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<BlockPopulator> populators = new ArrayList<>(world.getPopulators());
|
||||
@ -145,27 +126,22 @@ public class EcoEnchantsPlugin extends EcoPlugin {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IntegrationLoader> getIntegrationLoaders() {
|
||||
protected List<IntegrationLoader> loadIntegrationLoaders() {
|
||||
return Arrays.asList(
|
||||
new IntegrationLoader("Essentials", () -> EssentialsManager.register(new IntegrationEssentials()))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PluginCommand> getPluginCommands() {
|
||||
protected List<PluginCommand> loadPluginCommands() {
|
||||
return Arrays.asList(
|
||||
new CommandEnchantinfo(this),
|
||||
new CommandEcoEnchants(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* EcoEnchants-specific listeners.
|
||||
*
|
||||
* @return A list of all listeners.
|
||||
*/
|
||||
@Override
|
||||
public List<Listener> getListeners() {
|
||||
protected List<Listener> loadListeners() {
|
||||
return Arrays.asList(
|
||||
new EnchantingListeners(this),
|
||||
new GrindstoneListeners(this),
|
||||
@ -176,31 +152,12 @@ public class EcoEnchantsPlugin extends EcoPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> 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();
|
||||
|
@ -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<Material> 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());
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
)
|
||||
);
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<Enchantment> forRemoval = new ArrayList<>();
|
||||
|
||||
LinkedHashMap<Enchantment, Integer> enchantments = new LinkedHashMap<>(ProxyUtils.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(itemStack, true));
|
||||
LinkedHashMap<Enchantment, Integer> enchantments = new LinkedHashMap<>(this.getPlugin().getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(itemStack, true));
|
||||
|
||||
enchantments.entrySet().removeIf(enchantmentIntegerEntry -> enchantmentIntegerEntry.getValue().equals(0));
|
||||
|
||||
|
@ -40,6 +40,6 @@ public class DescriptionOptions extends PluginDependent<EcoPlugin> {
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
@ -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<EcoPlugin> 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<EcoPlugin> 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;
|
||||
|
@ -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<Enchantment, Integer> outEnchants = new HashMap<>();
|
||||
|
||||
HashMap<Enchantment, Integer> leftEnchants = new HashMap<>(ProxyUtils.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(left, true));
|
||||
HashMap<Enchantment, Integer> rightEnchants = new HashMap<>(ProxyUtils.getProxy(FastGetEnchantsProxy.class).getEnchantmentsOnItem(right, true));
|
||||
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));
|
||||
|
||||
leftEnchants.forEach(((enchantment, integer) -> {
|
||||
int level = integer;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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?
|
||||
|
@ -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 <T> The type of the proxy.
|
||||
* @return The proxy implementation.
|
||||
*/
|
||||
public @NotNull <T extends AbstractProxy> T getProxy(@NotNull final Class<T> proxyClass) {
|
||||
return new ProxyFactory<>(EcoEnchantsPlugin.getInstance(), proxyClass).getProxy();
|
||||
}
|
||||
}
|
@ -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<T extends AbstractProxy> extends PluginDependent<EcoPlugin> {
|
||||
/**
|
||||
* Cached proxy implementations in order to not perform expensive reflective class-finding.
|
||||
*/
|
||||
private static final Map<Class<? extends AbstractProxy>, AbstractProxy> CACHE = new IdentityHashMap<>();
|
||||
|
||||
/**
|
||||
* The class of the proxy interface.
|
||||
*/
|
||||
private final Class<T> 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<T> 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;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
group 'com.willfp'
|
||||
version '5.1.0'
|
||||
version '5.2.0'
|
||||
description = 'Sprint Artifacts Extension'
|
||||
|
||||
shadowJar {
|
||||
|
@ -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<EcoEnchant> 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()) {
|
||||
|
@ -1,2 +1,2 @@
|
||||
version = 7.13.5
|
||||
version = 8.0.0
|
||||
plugin-name = EcoEnchants
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user