Hi,
I am creating a custom enchantment plugin with 10 custom enchant.
The enchantments are created. I wonder how to load them into the main class so I can use them?
I can do it for 1 enchantment, but for 10 no?
It's working for the enchantment "explosive" (id 102).
But how load the other plugin without copying everything ?
I'm on 1.12.2 spigot.
Thank's for your help.
I am creating a custom enchantment plugin with 10 custom enchant.
The enchantments are created. I wonder how to load them into the main class so I can use them?
I can do it for 1 enchantment, but for 10 no?
Code:
public class Main extends JavaPlugin implements Listener {
public Explosive ench = new Explosive(102);
@Override
public void onEnable() {
loadEnchantments();
Bukkit.getPluginManager().registerEvents(new EventListener(), this);
Bukkit.getPluginManager().registerEvents(new Explosive(101), this);
}
@SuppressWarnings("unchecked")
public void onDisable() {
try {
Field byIdField = Enchantment.class.getDeclaredField("byId");
Field byNameField = Enchantment.class.getDeclaredField("byName");
byIdField.setAccessible(true);
byNameField.setAccessible(true);
HashMap<Integer, Enchantment> byId = (HashMap<Integer, Enchantment>) byIdField.get(null);
HashMap<Integer, Enchantment> byName = (HashMap<Integer, Enchantment>) byNameField.get(null);
if(byId.containsKey(ench.getId())) {
byId.remove(ench.getId());
}
if(byName.containsKey(ench.getName())) {
byName.remove(ench.getName());
}
} catch (Exception ignored) {
}
}
private void loadEnchantments() {
try {
try {
Field f = Enchantment.class.getDeclaredField("acceptingNew");
f.setAccessible(true);
f.set(null, true);
} catch (Exception e) {
e.printStackTrace();
}
try {
Enchantment.registerEnchantment(ench);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
It's working for the enchantment "explosive" (id 102).
But how load the other plugin without copying everything ?
I'm on 1.12.2 spigot.
Thank's for your help.
