mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-26 20:27:38 +01:00
Refactoring
This commit is contained in:
parent
87a8f251af
commit
64b6183944
@ -1,8 +0,0 @@
|
||||
package com.willfp.ecoenchants.API;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public interface NMSEnchantManagerWrapper {
|
||||
void init(Enchantment enchantment);
|
||||
void debug();
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.willfp.ecoenchants.v1_15_R1;
|
||||
|
||||
import net.minecraft.server.v1_15_R1.*;
|
||||
|
||||
public class NMSEnchant extends Enchantment {
|
||||
private org.bukkit.enchantments.Enchantment enchantment;
|
||||
|
||||
public NMSEnchant(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
super(Enchantment.Rarity.COMMON, EnchantmentSlotType.BREAKABLE, new EnumItemSlot[]{});
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
public void update(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int a(int var0) {
|
||||
return Short.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return enchantment.getMaxLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasure() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean c() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatBaseComponent d(int level) {
|
||||
IChatBaseComponent var1 = new ChatMessage(this.g(), new Object[0]);
|
||||
if (this.c()) {
|
||||
var1.a(EnumChatFormat.RED);
|
||||
} else {
|
||||
var1.a(EnumChatFormat.GRAY);
|
||||
}
|
||||
|
||||
if (level != 1 || this.getMaxLevel() != 1) {
|
||||
var1.a(" ").addSibling(new ChatMessage("enchantment.level." + level, new Object[0]));
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package com.willfp.ecoenchants.v1_15_R1;
|
||||
|
||||
import com.willfp.ecoenchants.API.NMSEnchantManagerWrapper;
|
||||
import net.minecraft.server.v1_15_R1.Enchantment;
|
||||
import net.minecraft.server.v1_15_R1.Enchantments;
|
||||
import net.minecraft.server.v1_15_R1.IRegistry;
|
||||
import net.minecraft.server.v1_15_R1.MinecraftKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class NMSEnchantManager implements NMSEnchantManagerWrapper {
|
||||
private Map<org.bukkit.enchantments.Enchantment, NMSEnchant> relatedMap = new HashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void init(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
try {
|
||||
Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey");
|
||||
Field byNameField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byName");
|
||||
byIdField.setAccessible(true);
|
||||
byNameField.setAccessible(true);
|
||||
Map<NamespacedKey, org.bukkit.enchantments.Enchantment> byKey = (Map<NamespacedKey, org.bukkit.enchantments.Enchantment>) byIdField.get(null);
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byName = (Map<String, org.bukkit.enchantments.Enchantment>) byNameField.get(null);
|
||||
byKey.remove(enchantment.getKey());
|
||||
byName.remove(enchantment.getName());
|
||||
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byNameClone = new HashMap<>(byName);
|
||||
for(Map.Entry<String, org.bukkit.enchantments.Enchantment> entry : byNameClone.entrySet()) {
|
||||
if(entry.getValue().getKey().equals(enchantment.getKey())) {
|
||||
byName.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
Field f = org.bukkit.enchantments.Enchantment.class.getDeclaredField("acceptingNew");
|
||||
f.setAccessible(true);
|
||||
f.set(null, true);
|
||||
f.setAccessible(false);
|
||||
|
||||
if(IRegistry.ENCHANTMENT.keySet().contains(new MinecraftKey(enchantment.getKey().getNamespace(), enchantment.getKey().getKey()))) {
|
||||
byName.put(enchantment.getName(), enchantment);
|
||||
byKey.put(enchantment.getKey(), enchantment);
|
||||
if(relatedMap.get(enchantment) != null) {
|
||||
relatedMap.get(enchantment).update(enchantment);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
relatedMap.put(enchantment, new NMSEnchant(enchantment));
|
||||
|
||||
Enchantment nmsEnchant = new NMSEnchant(enchantment);
|
||||
|
||||
Method method = Enchantments.class.getDeclaredMethod("a", String.class, Enchantment.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(null, enchantment.getKey().getKey(), nmsEnchant);
|
||||
|
||||
CraftEnchantWrapper wrappedEnchantment = new CraftEnchantWrapper(nmsEnchant, enchantment);
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(wrappedEnchantment);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug() {
|
||||
Bukkit.getLogger().info("IRegistry: " + IRegistry.ENCHANTMENT.keySet().toString());
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package com.willfp.ecoenchants.v1_16_R1;
|
||||
|
||||
import net.minecraft.server.v1_16_R1.*;
|
||||
|
||||
public class NMSEnchant extends Enchantment {
|
||||
private org.bukkit.enchantments.Enchantment enchantment;
|
||||
|
||||
public NMSEnchant(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
super(Enchantment.Rarity.COMMON, EnchantmentSlotType.BREAKABLE, new EnumItemSlot[]{});
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
public void update(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int a(int var0) {
|
||||
return Short.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return enchantment.getMaxLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasure() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean c() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean h() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean i() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatBaseComponent d(int level) {
|
||||
IChatMutableComponent var1 = new ChatMessage(enchantment.getName());
|
||||
var1.a(EnumChatFormat.WHITE);
|
||||
|
||||
if (level != 1 || this.getMaxLevel() != 1) {
|
||||
var1.c(" ").addSibling(new ChatMessage("enchantment.level." + level));
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package com.willfp.ecoenchants.v1_16_R1;
|
||||
|
||||
import com.willfp.ecoenchants.API.NMSEnchantManagerWrapper;
|
||||
import net.minecraft.server.v1_16_R1.Enchantment;
|
||||
import net.minecraft.server.v1_16_R1.Enchantments;
|
||||
import net.minecraft.server.v1_16_R1.IRegistry;
|
||||
import net.minecraft.server.v1_16_R1.MinecraftKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class NMSEnchantManager implements NMSEnchantManagerWrapper {
|
||||
private Map<org.bukkit.enchantments.Enchantment, NMSEnchant> relatedMap = new HashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void init(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
try {
|
||||
Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey");
|
||||
Field byNameField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byName");
|
||||
byIdField.setAccessible(true);
|
||||
byNameField.setAccessible(true);
|
||||
Map<NamespacedKey, org.bukkit.enchantments.Enchantment> byKey = (Map<NamespacedKey, org.bukkit.enchantments.Enchantment>) byIdField.get(null);
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byName = (Map<String, org.bukkit.enchantments.Enchantment>) byNameField.get(null);
|
||||
byKey.remove(enchantment.getKey());
|
||||
byName.remove(enchantment.getName());
|
||||
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byNameClone = new HashMap<>(byName);
|
||||
for(Map.Entry<String, org.bukkit.enchantments.Enchantment> entry : byNameClone.entrySet()) {
|
||||
if(entry.getValue().getKey().equals(enchantment.getKey())) {
|
||||
byName.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
Field f = org.bukkit.enchantments.Enchantment.class.getDeclaredField("acceptingNew");
|
||||
f.setAccessible(true);
|
||||
f.set(null, true);
|
||||
f.setAccessible(false);
|
||||
|
||||
if(IRegistry.ENCHANTMENT.keySet().contains(new MinecraftKey(enchantment.getKey().getNamespace(), enchantment.getKey().getKey()))) {
|
||||
byName.put(enchantment.getName(), enchantment);
|
||||
byKey.put(enchantment.getKey(), enchantment);
|
||||
if(relatedMap.get(enchantment) != null) {
|
||||
relatedMap.get(enchantment).update(enchantment);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
relatedMap.put(enchantment, new NMSEnchant(enchantment));
|
||||
|
||||
Enchantment nmsEnchant = new NMSEnchant(enchantment);
|
||||
|
||||
Method method = Enchantments.class.getDeclaredMethod("a", String.class, Enchantment.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(null, enchantment.getKey().getKey(), nmsEnchant);
|
||||
|
||||
CraftEnchantWrapper wrappedEnchantment = new CraftEnchantWrapper(nmsEnchant, enchantment);
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(wrappedEnchantment);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug() {
|
||||
Bukkit.getLogger().info("IRegistry: " + IRegistry.ENCHANTMENT.keySet().toString());
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package com.willfp.ecoenchants.v1_16_R2;
|
||||
|
||||
import net.minecraft.server.v1_16_R2.*;
|
||||
|
||||
public class NMSEnchant extends Enchantment {
|
||||
private org.bukkit.enchantments.Enchantment enchantment;
|
||||
|
||||
public NMSEnchant(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
super(Enchantment.Rarity.COMMON, EnchantmentSlotType.BREAKABLE, new EnumItemSlot[]{});
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
public void update(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int a(int var0) {
|
||||
return Short.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return enchantment.getMaxLevel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasure() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean c() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean h() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean i() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IChatBaseComponent d(int level) {
|
||||
IChatMutableComponent var1 = new ChatMessage(enchantment.getName());
|
||||
var1.a(EnumChatFormat.WHITE);
|
||||
|
||||
if (level != 1 || this.getMaxLevel() != 1) {
|
||||
var1.c(" ").addSibling(new ChatMessage("enchantment.level." + level));
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
package com.willfp.ecoenchants.v1_16_R2;
|
||||
|
||||
import com.willfp.ecoenchants.API.NMSEnchantManagerWrapper;
|
||||
import net.minecraft.server.v1_16_R2.Enchantment;
|
||||
import net.minecraft.server.v1_16_R2.Enchantments;
|
||||
import net.minecraft.server.v1_16_R2.IRegistry;
|
||||
import net.minecraft.server.v1_16_R2.MinecraftKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class NMSEnchantManager implements NMSEnchantManagerWrapper {
|
||||
private Map<org.bukkit.enchantments.Enchantment, NMSEnchant> relatedMap = new HashMap<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void init(org.bukkit.enchantments.Enchantment enchantment) {
|
||||
try {
|
||||
Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey");
|
||||
Field byNameField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byName");
|
||||
byIdField.setAccessible(true);
|
||||
byNameField.setAccessible(true);
|
||||
Map<NamespacedKey, org.bukkit.enchantments.Enchantment> byKey = (Map<NamespacedKey, org.bukkit.enchantments.Enchantment>) byIdField.get(null);
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byName = (Map<String, org.bukkit.enchantments.Enchantment>) byNameField.get(null);
|
||||
byKey.remove(enchantment.getKey());
|
||||
byName.remove(enchantment.getName());
|
||||
|
||||
Map<String, org.bukkit.enchantments.Enchantment> byNameClone = new HashMap<>(byName);
|
||||
for(Map.Entry<String, org.bukkit.enchantments.Enchantment> entry : byNameClone.entrySet()) {
|
||||
if(entry.getValue().getKey().equals(enchantment.getKey())) {
|
||||
byName.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
Field f = org.bukkit.enchantments.Enchantment.class.getDeclaredField("acceptingNew");
|
||||
f.setAccessible(true);
|
||||
f.set(null, true);
|
||||
f.setAccessible(false);
|
||||
|
||||
if(IRegistry.ENCHANTMENT.keySet().contains(new MinecraftKey(enchantment.getKey().getNamespace(), enchantment.getKey().getKey()))) {
|
||||
byName.put(enchantment.getName(), enchantment);
|
||||
byKey.put(enchantment.getKey(), enchantment);
|
||||
if(relatedMap.get(enchantment) != null) {
|
||||
relatedMap.get(enchantment).update(enchantment);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
relatedMap.put(enchantment, new NMSEnchant(enchantment));
|
||||
|
||||
Enchantment nmsEnchant = new NMSEnchant(enchantment);
|
||||
|
||||
Method method = Enchantments.class.getDeclaredMethod("a", String.class, Enchantment.class);
|
||||
method.setAccessible(true);
|
||||
method.invoke(null, enchantment.getKey().getKey(), nmsEnchant);
|
||||
|
||||
CraftEnchantWrapper wrappedEnchantment = new CraftEnchantWrapper(nmsEnchant, enchantment);
|
||||
|
||||
org.bukkit.enchantments.Enchantment.registerEnchantment(wrappedEnchantment);
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void debug() {
|
||||
Bukkit.getLogger().info("IRegistry: " + IRegistry.ENCHANTMENT.keySet().toString());
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.willfp.ecoenchants.command;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.util.Registerable;
|
||||
import com.willfp.ecoenchants.util.interfaces.Registerable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
@ -1,15 +1,9 @@
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.command.AbstractCommand;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.willfp.ecoenchants.loader.Loader;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -20,25 +14,7 @@ public final class CommandEcoreload extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public void onExecute(CommandSender sender, List<String> args) {
|
||||
reload();
|
||||
Loader.reload();
|
||||
sender.sendMessage(ConfigManager.getLang().getMessage("reloaded"));
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
ConfigManager.updateConfigs();
|
||||
EnchantmentRarity.update();
|
||||
EnchantmentTarget.update();
|
||||
EcoEnchants.update();
|
||||
EnchantDisplay.update();
|
||||
|
||||
EcoEnchants.getAll().forEach((ecoEnchant -> {
|
||||
HandlerList.unregisterAll(ecoEnchant);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
||||
if(ecoEnchant.isEnabled()) {
|
||||
Bukkit.getPluginManager().registerEvents(ecoEnchant, EcoEnchantsPlugin.getInstance());
|
||||
}
|
||||
}, 1);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.util.Watcher;
|
||||
import com.willfp.ecoenchants.util.Registerable;
|
||||
import com.willfp.ecoenchants.util.interfaces.Registerable;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Material;
|
||||
|
@ -5,7 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.util.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.VectorUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Monster;
|
||||
|
@ -5,7 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.util.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.ItemDurability;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Repairable;
|
||||
|
@ -5,7 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.util.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.NumberUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Monster;
|
||||
|
@ -6,7 +6,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.ecoenchants.util.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.VectorUtils;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ExperienceOrb;
|
||||
|
@ -5,7 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.util.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.ItemDurability;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Repairable;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.util.Registerable;
|
||||
import com.willfp.ecoenchants.util.interfaces.Registerable;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -117,6 +117,7 @@ public class EnchantmentRarity implements Registerable {
|
||||
* Update all rarities
|
||||
* Called on /ecoreload
|
||||
*/
|
||||
|
||||
public static void update() {
|
||||
Set<String> raritiesNames = ConfigManager.getRarity().getRarities();
|
||||
raritiesNames.forEach((rarity) -> {
|
||||
|
@ -2,7 +2,7 @@ package com.willfp.ecoenchants.enchantments.meta;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.util.Registerable;
|
||||
import com.willfp.ecoenchants.util.interfaces.Registerable;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.enchantments.vanillasupport.merging.anvil;
|
||||
package com.willfp.ecoenchants.enchantments.support.merging.anvil;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.util.Pair;
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.enchantments.vanillasupport.merging.anvil;
|
||||
package com.willfp.ecoenchants.enchantments.support.merging.anvil;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.enchantments.vanillasupport.merging.grindstone;
|
||||
package com.willfp.ecoenchants.enchantments.support.merging.grindstone;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import org.bukkit.Bukkit;
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.enchantments.vanillasupport.merging.grindstone;
|
||||
package com.willfp.ecoenchants.enchantments.support.merging.grindstone;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.enchantments.vanillasupport.obtaining;
|
||||
package com.willfp.ecoenchants.enchantments.support.obtaining;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.enchantments.vanillasupport.obtaining;
|
||||
package com.willfp.ecoenchants.enchantments.support.obtaining;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.enchantments.vanillasupport.obtaining;
|
||||
package com.willfp.ecoenchants.enchantments.support.obtaining;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
@ -50,6 +50,8 @@ public class VillagerListeners implements Listener {
|
||||
continue;
|
||||
if (!enchantment.canGetFromVillager())
|
||||
continue;
|
||||
if(!enchantment.isEnabled())
|
||||
continue;
|
||||
|
||||
int level;
|
||||
|
@ -5,9 +5,9 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.HashMap;
|
||||
@ -29,53 +29,64 @@ public class ExtensionManager {
|
||||
}
|
||||
|
||||
File[] extensionJars = dir.listFiles();
|
||||
if(extensionJars != null) {
|
||||
for (File extensionJar : extensionJars) {
|
||||
try {
|
||||
if (extensionJar.isFile()) {
|
||||
try {
|
||||
URL url = extensionJar.toURI().toURL();
|
||||
URL[] urls = {url};
|
||||
|
||||
ClassLoader cl = new URLClassLoader(urls, EcoEnchantsPlugin.class.getClassLoader());
|
||||
if(extensionJars == null)
|
||||
return;
|
||||
|
||||
InputStream ymlIn = cl.getResourceAsStream("extension.yml");
|
||||
URL extensionYmlUrl = cl.getResource("extension.yml");
|
||||
for (File extensionJar : extensionJars) {
|
||||
if(!extensionJar.isFile()) continue;
|
||||
|
||||
if (extensionYmlUrl == null || ymlIn == null) {
|
||||
throw new MalformedExtensionException("No extension.yml found in " + extensionJar.getName());
|
||||
}
|
||||
|
||||
YamlConfiguration extensionYml = YamlConfiguration.loadConfiguration(new InputStreamReader(ymlIn));
|
||||
if (!extensionYml.getKeys(false).contains("main") || !extensionYml.getKeys(false).contains("name")) {
|
||||
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName());
|
||||
}
|
||||
|
||||
String mainClass = extensionYml.getString("main");
|
||||
String name = extensionYml.getString("name");
|
||||
|
||||
Class<?> cls = cl.loadClass(mainClass);
|
||||
|
||||
Object object = cls.newInstance();
|
||||
|
||||
if (object instanceof Extension) {
|
||||
Extension extension = (Extension) object;
|
||||
extension.onEnable();
|
||||
extensions.put(extension, name);
|
||||
} else {
|
||||
throw new MalformedExtensionException(extensionJar.getName() + " is invalid");
|
||||
}
|
||||
} catch (IllegalAccessException | InstantiationException | IOException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (MalformedExtensionException e) {
|
||||
Bukkit.getLogger().info(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
|
||||
}
|
||||
try {
|
||||
loadExtension(extensionJar);
|
||||
} catch (MalformedExtensionException e) {
|
||||
Bukkit.getLogger().info(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadExtension(File extensionJar) throws MalformedExtensionException {
|
||||
URL url = null;
|
||||
try {
|
||||
url = extensionJar.toURI().toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
URL[] urls = {url};
|
||||
|
||||
ClassLoader cl = new URLClassLoader(urls, EcoEnchantsPlugin.class.getClassLoader());
|
||||
|
||||
InputStream ymlIn = cl.getResourceAsStream("extension.yml");
|
||||
URL extensionYmlUrl = cl.getResource("extension.yml");
|
||||
|
||||
if (extensionYmlUrl == null || ymlIn == null) {
|
||||
throw new MalformedExtensionException("No extension.yml found in " + extensionJar.getName());
|
||||
}
|
||||
|
||||
YamlConfiguration extensionYml = YamlConfiguration.loadConfiguration(new InputStreamReader(ymlIn));
|
||||
if (!extensionYml.getKeys(false).contains("main") || !extensionYml.getKeys(false).contains("name")) {
|
||||
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName());
|
||||
}
|
||||
|
||||
String mainClass = extensionYml.getString("main");
|
||||
String name = extensionYml.getString("name");
|
||||
|
||||
Class<?> cls = null;
|
||||
Object object = null;
|
||||
try {
|
||||
object = cls.newInstance();
|
||||
cls = cl.loadClass(mainClass);
|
||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(!(object instanceof Extension))
|
||||
throw new MalformedExtensionException(extensionJar.getName() + " is invalid");
|
||||
|
||||
Extension extension = (Extension) object;
|
||||
extension.onEnable();
|
||||
extensions.put(extension, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unload all extensions
|
||||
*/
|
||||
|
@ -2,7 +2,6 @@ package com.willfp.ecoenchants.loader;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.vanillasupport.merging.anvil.AnvilListeners;
|
||||
import com.willfp.ecoenchants.command.commands.CommandEcodebug;
|
||||
import com.willfp.ecoenchants.command.commands.CommandEcoreload;
|
||||
import com.willfp.ecoenchants.command.commands.CommandEnchantinfo;
|
||||
@ -16,16 +15,17 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
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.vanillasupport.obtaining.EnchantingListeners;
|
||||
import com.willfp.ecoenchants.enchantments.vanillasupport.obtaining.LootPopulator;
|
||||
import com.willfp.ecoenchants.enchantments.vanillasupport.obtaining.VillagerListeners;
|
||||
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;
|
||||
import com.willfp.ecoenchants.enchantments.support.obtaining.LootPopulator;
|
||||
import com.willfp.ecoenchants.enchantments.support.obtaining.VillagerListeners;
|
||||
import com.willfp.ecoenchants.enchantments.util.WatcherTriggers;
|
||||
import com.willfp.ecoenchants.events.armorequip.ArmorListener;
|
||||
import com.willfp.ecoenchants.events.armorequip.DispenserArmorListener;
|
||||
import com.willfp.ecoenchants.events.entitydeathbyentity.EntityDeathByEntityListeners;
|
||||
import com.willfp.ecoenchants.events.naturalexpgainevent.NaturalExpGainListeners;
|
||||
import com.willfp.ecoenchants.extensions.ExtensionManager;
|
||||
import com.willfp.ecoenchants.enchantments.vanillasupport.merging.grindstone.GrindstoneListeners;
|
||||
import com.willfp.ecoenchants.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.ecoenchants.integrations.anticheat.plugins.AnticheatAAC;
|
||||
import com.willfp.ecoenchants.integrations.anticheat.plugins.AnticheatMatrix;
|
||||
@ -40,13 +40,14 @@ import com.willfp.ecoenchants.listeners.PlayerJoinListener;
|
||||
import com.willfp.ecoenchants.nms.BlockBreak;
|
||||
import com.willfp.ecoenchants.nms.Cooldown;
|
||||
import com.willfp.ecoenchants.nms.TridentStack;
|
||||
import com.willfp.ecoenchants.util.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
|
||||
import com.willfp.ecoenchants.util.Logger;
|
||||
import com.willfp.ecoenchants.util.UpdateChecker;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -432,4 +433,25 @@ public class Loader {
|
||||
ExtensionManager.unloadExtensions();
|
||||
Logger.info("§fBye! :)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by /ecoreload
|
||||
*/
|
||||
public static void reload() {
|
||||
ConfigManager.updateConfigs();
|
||||
EnchantmentRarity.update();
|
||||
EnchantmentTarget.update();
|
||||
EcoEnchants.update();
|
||||
EnchantDisplay.update();
|
||||
|
||||
EcoEnchants.getAll().forEach((ecoEnchant -> {
|
||||
HandlerList.unregisterAll(ecoEnchant);
|
||||
|
||||
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
||||
if(ecoEnchant.isEnabled()) {
|
||||
Bukkit.getPluginManager().registerEvents(ecoEnchant, EcoEnchantsPlugin.getInstance());
|
||||
}
|
||||
}, 1);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
package com.willfp.ecoenchants.nms;
|
||||
|
||||
|
||||
import com.willfp.ecoenchants.API.NMSEnchantManagerWrapper;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public class NMSEnchantManager {
|
||||
private static NMSEnchantManagerWrapper nmsEnchantManagerWrapper;
|
||||
|
||||
private static final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
public static boolean init() {
|
||||
try {
|
||||
final Class<?> class2 = Class.forName("com.willfp.ecoenchants." + version + ".NMSEnchantManager");
|
||||
if (NMSEnchantManagerWrapper.class.isAssignableFrom(class2)) {
|
||||
nmsEnchantManagerWrapper = (NMSEnchantManagerWrapper) class2.getConstructor().newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
nmsEnchantManagerWrapper = null;
|
||||
}
|
||||
return nmsEnchantManagerWrapper != null;
|
||||
}
|
||||
|
||||
public static void registerNMS(Enchantment enchantment) {
|
||||
nmsEnchantManagerWrapper.init(enchantment);
|
||||
}
|
||||
|
||||
public static void printDebug() {
|
||||
nmsEnchantManagerWrapper.debug();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.util;
|
||||
package com.willfp.ecoenchants.util.interfaces;
|
||||
|
||||
/**
|
||||
* Interface for Enchantments with tasks
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoenchants.util;
|
||||
package com.willfp.ecoenchants.util.interfaces;
|
||||
|
||||
public interface Registerable {
|
||||
void register();
|
Loading…
Reference in New Issue
Block a user