mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-22 15:05:18 +01:00
parent
2bc70e53aa
commit
8b5139a1b0
9
eco-core/core-nms/build.gradle
Normal file
9
eco-core/core-nms/build.gradle
Normal file
@ -0,0 +1,9 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
subprojects {
|
||||
dependencies {
|
||||
compileOnly project(':eco-core:core-proxy')
|
||||
compileOnly project(':eco-core:core-plugin')
|
||||
}
|
||||
}
|
6
eco-core/core-nms/v1_16_R1/build.gradle
Normal file
6
eco-core/core-nms/v1_16_R1/build.gradle
Normal file
@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.1-R0.1-SNAPSHOT'
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R1;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
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) {
|
||||
net.minecraft.server.v1_16_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBTTagList enchantmentNBT = 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) {
|
||||
net.minecraft.server.v1_16_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBTTagList enchantmentNBT = 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
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();
|
||||
}
|
||||
}
|
6
eco-core/core-nms/v1_16_R2/build.gradle
Normal file
6
eco-core/core-nms/v1_16_R2/build.gradle
Normal file
@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.3-R0.1-SNAPSHOT'
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R2;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
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) {
|
||||
net.minecraft.server.v1_16_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBTTagList enchantmentNBT = 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) {
|
||||
net.minecraft.server.v1_16_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBTTagList enchantmentNBT = 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
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();
|
||||
}
|
||||
}
|
6
eco-core/core-nms/v1_16_R3/build.gradle
Normal file
6
eco-core/core-nms/v1_16_R3/build.gradle
Normal file
@ -0,0 +1,6 @@
|
||||
group 'com.willfp'
|
||||
version rootProject.version
|
||||
|
||||
dependencies {
|
||||
compileOnly 'org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT'
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import net.minecraft.server.v1_16_R3.NBTBase;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagCompound;
|
||||
import net.minecraft.server.v1_16_R3.NBTTagList;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.util.CraftNamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public final class FastGetEnchants implements FastGetEnchantsProxy {
|
||||
@Override
|
||||
public Map<Enchantment, Integer> getEnchantmentsOnItem(@NotNull final ItemStack itemStack) {
|
||||
net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBTTagList enchantmentNBT = 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) {
|
||||
net.minecraft.server.v1_16_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
NBTTagList enchantmentNBT = 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;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.OpenInventoryProxy;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.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;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.willfp.ecoenchants.proxy.v1_16_R3;
|
||||
|
||||
import com.willfp.ecoenchants.proxy.proxies.RepairCostProxy;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.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_R3.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_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
|
||||
return nmsStack.getRepairCost();
|
||||
}
|
||||
}
|
@ -0,0 +1,236 @@
|
||||
package com.willfp.ecoenchants;
|
||||
|
||||
import com.willfp.eco.core.AbstractPacketAdapter;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.TelekinesisUtils;
|
||||
import com.willfp.ecoenchants.command.commands.CommandEcodebug;
|
||||
import com.willfp.ecoenchants.command.commands.CommandEcoreload;
|
||||
import com.willfp.ecoenchants.command.commands.CommandEnchantinfo;
|
||||
import com.willfp.ecoenchants.command.commands.CommandGiverandombook;
|
||||
import com.willfp.ecoenchants.command.commands.CommandRandomenchant;
|
||||
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
|
||||
import com.willfp.ecoenchants.config.RarityYml;
|
||||
import com.willfp.ecoenchants.config.TargetYml;
|
||||
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;
|
||||
import com.willfp.ecoenchants.enchantments.support.obtaining.LootPopulator;
|
||||
import com.willfp.ecoenchants.enchantments.support.obtaining.VillagerListeners;
|
||||
import com.willfp.ecoenchants.enchantments.util.ItemConversions;
|
||||
import com.willfp.ecoenchants.enchantments.util.TimedRunnable;
|
||||
import com.willfp.ecoenchants.enchantments.util.WatcherTriggers;
|
||||
import com.willfp.ecoenchants.integrations.essentials.EssentialsManager;
|
||||
import com.willfp.ecoenchants.integrations.essentials.plugins.IntegrationEssentials;
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class EcoEnchantsPlugin extends EcoPlugin {
|
||||
/**
|
||||
* Instance of the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private static EcoEnchantsPlugin instance;
|
||||
|
||||
/**
|
||||
* Rarity.yml.
|
||||
*/
|
||||
@Getter
|
||||
private final RarityYml rarityYml;
|
||||
|
||||
/**
|
||||
* Target.yml.
|
||||
*/
|
||||
@Getter
|
||||
private final TargetYml targetYml;
|
||||
|
||||
/**
|
||||
* Internal constructor called by bukkit on plugin load.
|
||||
*/
|
||||
public EcoEnchantsPlugin() {
|
||||
super("EcoEnchants", 79573, 7666, "com.willfp.ecoenchants.proxy", "&a");
|
||||
instance = this;
|
||||
|
||||
rarityYml = new RarityYml(this);
|
||||
targetYml = new TargetYml(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Code executed on plugin enable.
|
||||
*/
|
||||
@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()));
|
||||
}
|
||||
|
||||
this.getLogger().info(EcoEnchants.values().size() + " Enchantments Loaded");
|
||||
|
||||
TelekinesisUtils.registerTest(player -> ProxyUtils.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(player.getInventory().getItemInMainHand(), EcoEnchants.TELEKINESIS) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Code executed on plugin disable.
|
||||
*/
|
||||
@Override
|
||||
public void disable() {
|
||||
Bukkit.getServer().getWorlds().forEach(world -> {
|
||||
List<BlockPopulator> populators = new ArrayList<>(world.getPopulators());
|
||||
populators.forEach((blockPopulator -> {
|
||||
if (blockPopulator instanceof LootPopulator) {
|
||||
world.getPopulators().remove(blockPopulator);
|
||||
}
|
||||
}));
|
||||
});
|
||||
|
||||
this.getExtensionLoader().unloadExtensions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Nothing is called on plugin load.
|
||||
*/
|
||||
@Override
|
||||
public void load() {
|
||||
// Nothing needs to be called on load
|
||||
}
|
||||
|
||||
/**
|
||||
* Code executed on /ecoreload.
|
||||
*/
|
||||
@Override
|
||||
public void onReload() {
|
||||
targetYml.update();
|
||||
rarityYml.update();
|
||||
((EnchantDisplay) this.getDisplayModule()).update();
|
||||
EcoEnchants.values().forEach((ecoEnchant -> {
|
||||
HandlerList.unregisterAll(ecoEnchant);
|
||||
|
||||
this.getScheduler().runLater(() -> {
|
||||
if (ecoEnchant.isEnabled()) {
|
||||
this.getEventManager().registerListener(ecoEnchant);
|
||||
|
||||
if (ecoEnchant instanceof TimedRunnable) {
|
||||
this.getScheduler().syncRepeating((TimedRunnable) ecoEnchant, 5, ((TimedRunnable) ecoEnchant).getTime());
|
||||
}
|
||||
}
|
||||
}, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Code executed after server is up.
|
||||
*/
|
||||
@Override
|
||||
public void postLoad() {
|
||||
if (this.getConfigYml().getBool("loot.enabled")) {
|
||||
Bukkit.getServer().getWorlds().forEach(world -> {
|
||||
List<BlockPopulator> populators = new ArrayList<>(world.getPopulators());
|
||||
populators.forEach((blockPopulator -> {
|
||||
if (blockPopulator instanceof LootPopulator) {
|
||||
world.getPopulators().remove(blockPopulator);
|
||||
}
|
||||
}));
|
||||
world.getPopulators().add(new LootPopulator(this));
|
||||
});
|
||||
}
|
||||
EssentialsManager.registerEnchantments();
|
||||
}
|
||||
|
||||
/**
|
||||
* EcoEnchants-specific integrations.
|
||||
*
|
||||
* @return A list of all integrations.
|
||||
*/
|
||||
@Override
|
||||
public List<IntegrationLoader> getIntegrationLoaders() {
|
||||
return Arrays.asList(
|
||||
new IntegrationLoader("Essentials", () -> EssentialsManager.register(new IntegrationEssentials()))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* EcoEnchants-specific commands.
|
||||
*
|
||||
* @return A list of all commands.
|
||||
*/
|
||||
@Override
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return Arrays.asList(
|
||||
new CommandEcodebug(this),
|
||||
new CommandEcoreload(this),
|
||||
new CommandEnchantinfo(this),
|
||||
new CommandRandomenchant(this),
|
||||
new CommandGiverandombook(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Packet Adapters for enchant display.
|
||||
*
|
||||
* @return A list of packet adapters.
|
||||
*/
|
||||
@Override
|
||||
public List<AbstractPacketAdapter> getPacketAdapters() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* EcoEnchants-specific listeners.
|
||||
*
|
||||
* @return A list of all listeners.
|
||||
*/
|
||||
@Override
|
||||
public List<Listener> getListeners() {
|
||||
return Arrays.asList(
|
||||
new EnchantingListeners(this),
|
||||
new GrindstoneListeners(this),
|
||||
new AnvilListeners(this),
|
||||
new WatcherTriggers(this),
|
||||
new VillagerListeners(this),
|
||||
new ItemConversions(this)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getUpdatableClasses() {
|
||||
return Arrays.asList(
|
||||
EnchantmentCache.class,
|
||||
EnchantmentRarity.class,
|
||||
EnchantmentTarget.class,
|
||||
EcoEnchants.class,
|
||||
TabCompleterEnchantinfo.class,
|
||||
EnchantmentType.class,
|
||||
WatcherTriggers.class
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected DisplayModule createDisplayModule() {
|
||||
return new EnchantDisplay(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.proxy.ProxyConstants;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class CommandEcodebug extends AbstractCommand {
|
||||
/**
|
||||
* Instantiate a new /ecodebug command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandEcodebug(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "ecodebug", "ecoenchants.ecodebug", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
if (!args.isEmpty() && args.get(0).equalsIgnoreCase("full")) {
|
||||
Bukkit.getLogger().info("--------------- BEGIN DEBUG ----------------");
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand().toString());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("Held Item: " + player.getInventory().getItemInMainHand().toString());
|
||||
Bukkit.getLogger().info("");
|
||||
}
|
||||
|
||||
Bukkit.getLogger().info("Running Version: " + this.getPlugin().getDescription().getVersion());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("Loaded Extensions: " + this.getPlugin().getExtensionLoader().getLoadedExtensions().stream()
|
||||
.map(extension -> extension.getName() + " v" + extension.getVersion())
|
||||
.collect(Collectors.joining()));
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("EcoEnchants.getAll(): " + EcoEnchants.values().toString());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("Enchantment.values(): " + Arrays.toString(Enchantment.values()));
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("Enchantment Cache: " + EnchantmentCache.getCache().toString());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
try {
|
||||
Field byNameField = Enchantment.class.getDeclaredField("byName");
|
||||
byNameField.setAccessible(true);
|
||||
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
|
||||
Bukkit.getLogger().info("Enchantment.byName: " + byName.toString());
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
|
||||
List<Enchantment> extern = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
|
||||
extern.removeAll(EcoEnchants.values().stream().map(EcoEnchant::getEnchantment).collect(Collectors.toList()));
|
||||
extern.removeIf(enchantment -> enchantment.getClass().toString().toLowerCase().contains("craftbukkit"));
|
||||
String external = extern.stream().map(enchantment -> "{" + enchantment.toString() + ", Provider: " + enchantment.getClass().toString() + "}").collect(Collectors.joining(", "));
|
||||
Bukkit.getLogger().info("External Enchantments: " + external);
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
List<Enchantment> uncached = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
|
||||
uncached.removeAll(EnchantmentCache.getCache().values().stream().map(EnchantmentCache.CacheEntry::getEnchantment).collect(Collectors.toList()));
|
||||
Bukkit.getLogger().info("Uncached Enchantments: " + uncached.toString());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
List<Enchantment> brokenCache = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
|
||||
brokenCache.removeIf(enchantment -> !(
|
||||
EnchantmentCache.getEntry(enchantment).getName().equalsIgnoreCase("null")
|
||||
|| EnchantmentCache.getEntry(enchantment).getRawName().equalsIgnoreCase("null")
|
||||
|| EnchantmentCache.getEntry(enchantment).getStringDescription().equalsIgnoreCase("null")));
|
||||
Bukkit.getLogger().info("Enchantments with broken cache: " + brokenCache.toString());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("Installed Plugins: " + Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList()).toString());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Set<EcoEnchant> withIssues = new HashSet<>();
|
||||
EcoEnchants.values().forEach(enchant -> {
|
||||
if (enchant.getRarity() == null) {
|
||||
withIssues.add(enchant);
|
||||
}
|
||||
if (enchant.getTargets().isEmpty()) {
|
||||
withIssues.add(enchant);
|
||||
}
|
||||
});
|
||||
Bukkit.getLogger().info("Enchantments with evident issues: " + withIssues.toString());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("Packets: " + ProtocolLibrary.getProtocolManager().getPacketListeners().stream()
|
||||
.filter(packetListener -> packetListener.getSendingWhitelist().getPriority().equals(ListenerPriority.MONITOR))
|
||||
.collect(Collectors.toList()).toString());
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("Server Information: ");
|
||||
Bukkit.getLogger().info("Players Online: " + Bukkit.getServer().getOnlinePlayers().size());
|
||||
Bukkit.getLogger().info("Bukkit IP: " + Bukkit.getIp());
|
||||
Bukkit.getLogger().info("Running Version: " + Bukkit.getVersion()
|
||||
+ ", Bukkit Version: " + Bukkit.getBukkitVersion()
|
||||
+ ", Alt Version: " + Bukkit.getServer().getVersion()
|
||||
+ ", NMS: " + ProxyConstants.NMS_VERSION);
|
||||
Bukkit.getLogger().info("Motd: " + Bukkit.getServer().getMotd());
|
||||
Bukkit.getLogger().info("--------------- END DEBUG ----------------");
|
||||
} else {
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand().toString());
|
||||
player.sendMessage("Lore: ");
|
||||
Bukkit.getLogger().info("");
|
||||
|
||||
Bukkit.getLogger().info("Held Item: " + player.getInventory().getItemInMainHand().toString());
|
||||
Bukkit.getLogger().info("Lore: ");
|
||||
ItemMeta meta = player.getInventory().getItemInMainHand().getItemMeta();
|
||||
if (meta != null) {
|
||||
for (String s : new ArrayList<>(meta.hasLore() ? meta.getLore() : new ArrayList<>())) {
|
||||
Bukkit.getLogger().info(s);
|
||||
player.sendMessage(s);
|
||||
}
|
||||
}
|
||||
Bukkit.getLogger().info("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.willfp.ecoskills.command;
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
@ -7,14 +7,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandEsreload extends AbstractCommand {
|
||||
public class CommandEcoreload extends AbstractCommand {
|
||||
/**
|
||||
* Instantiate a new /esreload command handler.
|
||||
* Instantiate a new /ecoreload command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandEsreload(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "esreload", "ecoskills.reload", false);
|
||||
public CommandEcoreload(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "ecoreload", "ecoenchants.reload", false);
|
||||
}
|
||||
|
||||
@Override
|
@ -0,0 +1,139 @@
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.command.AbstractTabCompleter;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandEnchantinfo extends AbstractCommand {
|
||||
/**
|
||||
* Instantiate a new /enchantinfo command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandEnchantinfo(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "enchantinfo", "ecoenchants.enchantinfo", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTabCompleter getTab() {
|
||||
return new TabCompleterEnchantinfo(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("missing-enchant"));
|
||||
return;
|
||||
}
|
||||
StringBuilder nameBuilder = new StringBuilder();
|
||||
|
||||
args.forEach(arg -> nameBuilder.append(arg).append(" "));
|
||||
String searchName = nameBuilder.toString();
|
||||
searchName = searchName.substring(0, searchName.length() - 1);
|
||||
|
||||
EcoEnchant enchantment = EcoEnchants.getByName(searchName);
|
||||
|
||||
if (enchantment == null) {
|
||||
String finalSearchName = searchName;
|
||||
enchantment = EcoEnchants.values().stream().filter(ecoEnchant -> ChatColor.stripColor(ecoEnchant.getName()).equalsIgnoreCase(finalSearchName)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
if (enchantment == null || !enchantment.isEnabled()) {
|
||||
String message = this.getPlugin().getLangYml().getMessage("not-found").replace("%name%", searchName);
|
||||
sender.sendMessage(message);
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> conflictNames = new HashSet<>();
|
||||
|
||||
Set<Enchantment> conflicts = enchantment.getConflicts();
|
||||
|
||||
new HashSet<>(conflicts).forEach(enchantment1 -> {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment1);
|
||||
if (ecoEnchant != null && !ecoEnchant.isEnabled()) {
|
||||
conflicts.remove(enchantment1);
|
||||
}
|
||||
});
|
||||
|
||||
conflicts.forEach((enchantment1 -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment1) != null) {
|
||||
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getName());
|
||||
} else {
|
||||
conflictNames.add(this.getPlugin().getLangYml().getString("enchantments." + enchantment1.getKey().getKey() + ".name"));
|
||||
}
|
||||
}));
|
||||
|
||||
StringBuilder conflictNamesBuilder = new StringBuilder();
|
||||
conflictNames.forEach(name1 -> conflictNamesBuilder.append(name1).append(", "));
|
||||
String allConflicts = conflictNamesBuilder.toString();
|
||||
if (allConflicts.length() >= 2) {
|
||||
allConflicts = allConflicts.substring(0, allConflicts.length() - 2);
|
||||
} else {
|
||||
allConflicts = StringUtils.translate(this.getPlugin().getLangYml().getString("no-conflicts"));
|
||||
}
|
||||
|
||||
Set<Material> targets = enchantment.getTargetMaterials();
|
||||
|
||||
Set<String> applicableItemsSet = new HashSet<>();
|
||||
|
||||
if (this.getPlugin().getConfigYml().getBool("commands.enchantinfo.show-target-group")) {
|
||||
enchantment.getTargets().forEach(target -> {
|
||||
String targetName = target.getName();
|
||||
targetName = targetName.toLowerCase();
|
||||
targetName = targetName.replace("_", " ");
|
||||
targetName = WordUtils.capitalize(targetName);
|
||||
applicableItemsSet.add(targetName);
|
||||
});
|
||||
} else {
|
||||
targets.forEach(material -> {
|
||||
String matName = material.toString();
|
||||
matName = matName.toLowerCase();
|
||||
matName = matName.replace("_", " ");
|
||||
matName = WordUtils.capitalize(matName);
|
||||
applicableItemsSet.add(matName);
|
||||
});
|
||||
}
|
||||
|
||||
StringBuilder targetNamesBuilder = new StringBuilder();
|
||||
applicableItemsSet.forEach(name1 -> targetNamesBuilder.append(name1).append(", "));
|
||||
String allTargets = targetNamesBuilder.toString();
|
||||
if (allTargets.length() >= 2) {
|
||||
allTargets = allTargets.substring(0, allTargets.length() - 2);
|
||||
} else {
|
||||
allTargets = StringUtils.translate(this.getPlugin().getLangYml().getString("no-targets"));
|
||||
}
|
||||
|
||||
String maxLevel = String.valueOf(enchantment.getMaxLevel());
|
||||
|
||||
final String finalName = EnchantmentCache.getEntry(enchantment).getName();
|
||||
final String finalDescription = EnchantmentCache.getEntry(enchantment).getStringDescription();
|
||||
final String finalTargets = allTargets;
|
||||
final String finalConflicts = allConflicts;
|
||||
final String finalMaxLevel = maxLevel;
|
||||
Arrays.asList(this.getPlugin().getLangYml().getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> {
|
||||
string = string.replace("%name%", finalName)
|
||||
.replace("%description%", finalDescription)
|
||||
.replace("%target%", finalTargets)
|
||||
.replace("%conflicts%", finalConflicts)
|
||||
.replace("%maxlevel%", finalMaxLevel);
|
||||
sender.sendMessage(string);
|
||||
}));
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.command.AbstractTabCompleter;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterRandomEnchant;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandGiverandombook extends AbstractCommand {
|
||||
/**
|
||||
* Instantiate a new /ecoreload command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandGiverandombook(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "giverandombook", "ecoenchants.randombook", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTabCompleter getTab() {
|
||||
return new TabCompleterRandomEnchant(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("requires-player"));
|
||||
return;
|
||||
}
|
||||
Player player = Bukkit.getServer().getPlayer(args.get(0));
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.ENCHANTED_BOOK);
|
||||
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) itemStack.getItemMeta();
|
||||
Enchantment enchantment = Enchantment.values()[NumberUtils.randInt(0, Enchantment.values().length - 1)];
|
||||
int level = NumberUtils.randInt(1, enchantment.getMaxLevel());
|
||||
meta.addStoredEnchant(enchantment, level, true);
|
||||
itemStack.setItemMeta(meta);
|
||||
|
||||
for (ItemStack stack : player.getInventory().addItem(itemStack).values()) {
|
||||
player.getWorld().dropItem(player.getLocation(), stack);
|
||||
}
|
||||
|
||||
String message = this.getPlugin().getLangYml().getMessage("gave-random-book");
|
||||
message = message.replace("%enchantment%", EnchantmentCache.getEntry(enchantment).getName() + " " + NumberUtils.toNumeral(level) + "§r");
|
||||
sender.sendMessage(message);
|
||||
|
||||
String message2 = this.getPlugin().getLangYml().getMessage("received-random-book");
|
||||
message2 = message2.replace("%enchantment%", EnchantmentCache.getEntry(enchantment).getName() + " " + NumberUtils.toNumeral(level) + "§r");
|
||||
player.sendMessage(message2);
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.command.AbstractTabCompleter;
|
||||
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterRandomEnchant;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandRandomenchant extends AbstractCommand {
|
||||
/**
|
||||
* Instantiate a new /ecoreload command handler.
|
||||
*
|
||||
* @param plugin The plugin for the commands to listen for.
|
||||
*/
|
||||
public CommandRandomenchant(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, "randomenchant", "ecoenchants.randomenchant", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTabCompleter getTab() {
|
||||
return new TabCompleterRandomEnchant(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
Player player;
|
||||
|
||||
if ((args.isEmpty() && sender instanceof Player) || !sender.hasPermission("ecoenchants.randomenchant.others")) {
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
player = Bukkit.getServer().getPlayer(args.get(0));
|
||||
}
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
if (itemStack.getType() == Material.AIR || meta == null || !EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) {
|
||||
if (player.equals(sender)) {
|
||||
player.sendMessage(this.getPlugin().getLangYml().getMessage("must-hold-item"));
|
||||
} else {
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("must-hold-item-other"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
List<EcoEnchant> ecoEnchants = new ArrayList<>(EcoEnchants.values());
|
||||
Collections.shuffle(ecoEnchants);
|
||||
EcoEnchant enchant = null;
|
||||
|
||||
List<Enchantment> onItem = new ArrayList<>();
|
||||
|
||||
if (meta instanceof EnchantmentStorageMeta) {
|
||||
onItem.addAll(((EnchantmentStorageMeta) meta).getStoredEnchants().keySet());
|
||||
} else {
|
||||
onItem.addAll(meta.getEnchants().keySet());
|
||||
}
|
||||
|
||||
for (EcoEnchant ecoEnchant : ecoEnchants) {
|
||||
if (ecoEnchant.canEnchantItem(itemStack)) {
|
||||
if (!ecoEnchant.conflictsWithAny(onItem)) {
|
||||
if (onItem.stream().noneMatch(enchantment -> enchantment.conflictsWith(ecoEnchant))) {
|
||||
if (!onItem.contains(ecoEnchant)) {
|
||||
boolean conflicts = false;
|
||||
for (Enchantment enchantment : onItem) {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant ecoEnchantOnItem = EcoEnchants.getFromEnchantment(enchantment);
|
||||
if (ecoEnchantOnItem.getType().equals(ecoEnchant.getType()) && ecoEnchantOnItem.getType().isSingular()) {
|
||||
conflicts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.getPlugin().getConfigYml().getBool("anvil.hard-cap.enabled")
|
||||
&& !player.hasPermission("ecoenchants.randomenchant.bypasshardcap")
|
||||
&& onItem.size() >= this.getPlugin().getConfigYml().getInt("anvil.hard-cap.cap")) {
|
||||
conflicts = true;
|
||||
}
|
||||
if (!conflicts) {
|
||||
enchant = ecoEnchant;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enchant == null) {
|
||||
player.sendMessage(this.getPlugin().getLangYml().getMessage("no-enchants-available"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (meta instanceof EnchantmentStorageMeta) {
|
||||
((EnchantmentStorageMeta) meta).addStoredEnchant(enchant, enchant.getMaxLevel(), true);
|
||||
} else {
|
||||
meta.addEnchant(enchant, enchant.getMaxLevel(), true);
|
||||
}
|
||||
|
||||
itemStack.setItemMeta(meta);
|
||||
String message = this.getPlugin().getLangYml().getMessage("applied-random-enchant");
|
||||
message = message.replace("%enchantment%", EnchantmentCache.getEntry(enchant).getName() + "§r");
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.willfp.ecoenchants.command.tabcompleters;
|
||||
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.command.AbstractTabCompleter;
|
||||
import com.willfp.eco.core.config.ConfigUpdater;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TabCompleterEnchantinfo extends AbstractTabCompleter {
|
||||
/**
|
||||
* The cached enchantment names.
|
||||
*/
|
||||
private static final List<String> ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).map(ChatColor::stripColor).collect(Collectors.toList());
|
||||
|
||||
/**
|
||||
* Instantiate a new tab-completer for /enchantinfo.
|
||||
*
|
||||
* @param command /enchantinfo.
|
||||
*/
|
||||
public TabCompleterEnchantinfo(@NotNull final AbstractCommand command) {
|
||||
super(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on /ecoreload.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void reload() {
|
||||
ENCHANT_NAMES.clear();
|
||||
ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).map(ChatColor::stripColor).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The execution of the tabcompleter.
|
||||
*
|
||||
* @param sender The sender of the command.
|
||||
* @param args The arguments of the command.
|
||||
* @return A list of tab-completions.
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTab(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (args.isEmpty()) {
|
||||
// Currently, this case is not ever reached
|
||||
return ENCHANT_NAMES;
|
||||
}
|
||||
|
||||
StringUtil.copyPartialMatches(String.join(" ", args), ENCHANT_NAMES, completions);
|
||||
|
||||
if (args.size() > 1) { // Remove all previous words from the candidate of completions
|
||||
ArrayList<String> finishedArgs = new ArrayList<>(args);
|
||||
finishedArgs.remove(args.size() - 1);
|
||||
|
||||
String prefix = String.join(" ", finishedArgs);
|
||||
completions = completions.stream().map(enchantName -> StringUtils.removePrefix(enchantName, prefix).trim()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
Collections.sort(completions);
|
||||
return completions;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoenchants.command.tabcompleters;
|
||||
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.command.AbstractTabCompleter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TabCompleterRandomEnchant extends AbstractTabCompleter {
|
||||
/**
|
||||
* Instantiate a new tab-completer for /randomenchant.
|
||||
*
|
||||
* @param command /randomenchant.
|
||||
*/
|
||||
public TabCompleterRandomEnchant(@NotNull final AbstractCommand command) {
|
||||
super(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* The execution of the tabcompleter.
|
||||
*
|
||||
* @param sender The sender of the command.
|
||||
* @param args The arguments of the command.
|
||||
* @return A list of tab-completions.
|
||||
*/
|
||||
@Override
|
||||
public List<String> onTab(@NotNull final CommandSender sender,
|
||||
@NotNull final List<String> args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
List<String> playerNames = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
|
||||
|
||||
if (args.isEmpty() || !sender.hasPermission("ecoenchants.randomenchant.others")) {
|
||||
// Currently, this case is not ever reached
|
||||
return playerNames;
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
StringUtil.copyPartialMatches(String.join(" ", args), playerNames, completions);
|
||||
Collections.sort(completions);
|
||||
return completions;
|
||||
}
|
||||
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.BaseConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RarityYml extends BaseConfig {
|
||||
/**
|
||||
* Instantiate rarity.yml.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public RarityYml(@NotNull final EcoPlugin plugin) {
|
||||
super("rarity", false, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rarity names.
|
||||
*
|
||||
* @return Set of all rarity names.
|
||||
*/
|
||||
public List<String> getRarities() {
|
||||
return this.getSubsection("rarities").getKeys(false);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.config.BaseConfig;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TargetYml extends BaseConfig {
|
||||
/**
|
||||
* Instantiate target.yml.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public TargetYml(@NotNull final EcoPlugin plugin) {
|
||||
super("target", false, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all target names.
|
||||
*
|
||||
* @return Set of all names.
|
||||
*/
|
||||
public List<String> getTargets() {
|
||||
return this.getSubsection("targets").getKeys(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all materials from a target name.
|
||||
*
|
||||
* @param target The name of the target.
|
||||
* @return All materials.
|
||||
*/
|
||||
public Set<Material> getTargetMaterials(@NotNull final String target) {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
this.getStrings("targets." + target).forEach(materialName -> {
|
||||
materials.add(Material.getMaterial(materialName.toUpperCase()));
|
||||
});
|
||||
|
||||
return materials;
|
||||
}
|
||||
}
|
@ -0,0 +1,103 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.eco.core.config.ExtendableConfig;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
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 lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class EnchantmentConfig extends ExtendableConfig {
|
||||
/**
|
||||
* The name of the config.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Instantiate a new config for an enchantment.
|
||||
*
|
||||
* @param name The name of the config.
|
||||
* @param plugin The provider of the enchantment.
|
||||
* @param type The {@link EnchantmentType} of the enchantment.
|
||||
*/
|
||||
public EnchantmentConfig(@NotNull final String name,
|
||||
@NotNull final Class<?> plugin,
|
||||
@NotNull final EnchantmentType type) {
|
||||
super(name, true, EcoEnchantsPlugin.getInstance(), plugin, "enchants/" + type.getName() + "/");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a set of enchantments stored by key.
|
||||
*
|
||||
* @param path The location of the enchantments in the config.
|
||||
* @return A set of all enchantments.
|
||||
*/
|
||||
public Set<Enchantment> getEnchantments(@NotNull final String path) {
|
||||
Set<Enchantment> enchantments = new HashSet<>();
|
||||
List<String> enchantmentKeys = this.getStrings(path);
|
||||
enchantmentKeys.forEach((key -> enchantments.add(Enchantment.getByKey(NamespacedKey.minecraft(key)))));
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rarity of the enchantment.
|
||||
*
|
||||
* @return The rarity, or null if invalid.
|
||||
*/
|
||||
public EnchantmentRarity getRarity() {
|
||||
String rarityName = this.getString("obtaining.rarity");
|
||||
return EnchantmentRarity.getByName(rarityName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all applicable targets.
|
||||
*
|
||||
* @return The targets.
|
||||
*/
|
||||
public Set<EnchantmentTarget> getTargets() {
|
||||
List<String> targetNames = this.getStrings(EcoEnchants.GENERAL_LOCATION + "targets");
|
||||
if (targetNames.isEmpty()) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
Set<EnchantmentTarget> targets = new HashSet<>();
|
||||
|
||||
targetNames.forEach((s -> {
|
||||
if (EnchantmentTarget.getByName(s) == null) {
|
||||
Bukkit.getLogger().warning("Target specified in " + name + " is invalid!");
|
||||
return;
|
||||
}
|
||||
targets.add(EnchantmentTarget.getByName(s));
|
||||
}));
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load config values from lang.yml.
|
||||
*/
|
||||
public void loadFromLang() {
|
||||
if (!this.getPlugin().getLangYml().has("enchantments." + this.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.set("name", this.getPlugin().getLangYml().getString("enchantments." + this.getName() + ".name"));
|
||||
this.set("description", this.getPlugin().getLangYml().getString("enchantments." + this.getName() + ".description"));
|
||||
try {
|
||||
this.save();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,253 @@
|
||||
package com.willfp.ecoenchants.display;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.display.DisplayPriority;
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoenchants.display.options.DisplayOptions;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* All methods and fields pertaining to showing players the enchantments on their items.
|
||||
*/
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
public class EnchantDisplay extends DisplayModule {
|
||||
/**
|
||||
* The meta key to hide enchantments in lore.
|
||||
* <p>
|
||||
* EcoEnchants packet lore implementation of HideEnchants.
|
||||
*/
|
||||
@Getter
|
||||
private final NamespacedKey keySkip;
|
||||
|
||||
/**
|
||||
* The legacy V key.
|
||||
* <p>
|
||||
* Exists for backwards compatibility.
|
||||
*/
|
||||
@Getter
|
||||
@Deprecated
|
||||
private final NamespacedKey legacyV;
|
||||
|
||||
/**
|
||||
* The configurable options for displaying enchantments.
|
||||
*/
|
||||
@Getter
|
||||
private final DisplayOptions options;
|
||||
|
||||
/**
|
||||
* Create EcoEnchants display module.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public EnchantDisplay(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin, DisplayPriority.HIGH);
|
||||
keySkip = this.getPlugin().getNamespacedKeyFactory().create("ecoenchantlore-skip");
|
||||
legacyV = this.getPlugin().getNamespacedKeyFactory().create("ecoenchantlore-v");
|
||||
options = new DisplayOptions(this.getPlugin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update config values.
|
||||
*/
|
||||
public void update() {
|
||||
options.update();
|
||||
EnchantmentCache.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void display(@NotNull final ItemStack itemStack,
|
||||
@NotNull final Object... args) {
|
||||
if (options.isRequireTarget()) {
|
||||
if (!EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
assert meta != null;
|
||||
|
||||
boolean hide = (boolean) args[0];
|
||||
|
||||
List<String> itemLore = null;
|
||||
|
||||
if (hide || meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER)) {
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
if (meta instanceof EnchantmentStorageMeta) {
|
||||
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||
}
|
||||
meta.getPersistentDataContainer().set(keySkip, PersistentDataType.INTEGER, 1);
|
||||
itemStack.setItemMeta(meta);
|
||||
return;
|
||||
}
|
||||
|
||||
if (meta.hasLore()) {
|
||||
itemLore = meta.getLore();
|
||||
}
|
||||
|
||||
if (itemLore == null) {
|
||||
itemLore = new ArrayList<>();
|
||||
}
|
||||
|
||||
List<String> lore = new ArrayList<>();
|
||||
|
||||
LinkedHashMap<Enchantment, Integer> enchantments = new LinkedHashMap<>();
|
||||
List<Enchantment> forRemoval = new ArrayList<>();
|
||||
|
||||
if (meta instanceof EnchantmentStorageMeta) {
|
||||
enchantments.putAll(((EnchantmentStorageMeta) meta).getStoredEnchants());
|
||||
} else {
|
||||
enchantments.putAll(meta.getEnchants());
|
||||
}
|
||||
|
||||
enchantments.entrySet().removeIf(enchantmentIntegerEntry -> enchantmentIntegerEntry.getValue().equals(0));
|
||||
|
||||
List<Enchantment> unsorted = new ArrayList<>();
|
||||
enchantments.forEach((enchantment, integer) -> unsorted.add(enchantment));
|
||||
|
||||
HashMap<Enchantment, Integer> tempEnchantments = new HashMap<>(enchantments);
|
||||
|
||||
options.getSorter().sortEnchantments(unsorted);
|
||||
|
||||
enchantments.clear();
|
||||
unsorted.forEach(enchantment -> enchantments.put(enchantment, tempEnchantments.get(enchantment)));
|
||||
|
||||
enchantments.forEach((enchantment, level) -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
|
||||
if (!ecoEnchant.isEnabled()) {
|
||||
forRemoval.add(enchantment);
|
||||
}
|
||||
});
|
||||
|
||||
forRemoval.forEach(enchantment -> {
|
||||
enchantments.remove(enchantment);
|
||||
if (meta instanceof EnchantmentStorageMeta) {
|
||||
((EnchantmentStorageMeta) meta).removeStoredEnchant(enchantment);
|
||||
} else {
|
||||
meta.removeEnchant(enchantment);
|
||||
}
|
||||
});
|
||||
|
||||
enchantments.forEach((enchantment, level) -> {
|
||||
String name = EnchantmentCache.getEntry(enchantment).getName();
|
||||
|
||||
if (!(enchantment.getMaxLevel() == 1 && level == 1)) {
|
||||
if (options.getNumbersOptions().isUseNumerals() && ProxyUtils.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(itemStack, enchantment) < options.getNumbersOptions().getThreshold()) {
|
||||
name += " " + NumberUtils.toNumeral(level);
|
||||
} else {
|
||||
name += " " + level;
|
||||
}
|
||||
}
|
||||
|
||||
lore.add(Display.PREFIX + name);
|
||||
if (enchantments.size() <= options.getDescriptionOptions().getThreshold() && options.getDescriptionOptions().isEnabled()) {
|
||||
lore.addAll(EnchantmentCache.getEntry(enchantment).getDescription());
|
||||
}
|
||||
});
|
||||
|
||||
if (options.getShrinkOptions().isEnabled() && (enchantments.size() > options.getShrinkOptions().getThreshold())) {
|
||||
List<List<String>> partitionedCombinedLoreList = Lists.partition(lore, options.getShrinkOptions().getShrinkPerLine());
|
||||
List<String> newLore = new ArrayList<>();
|
||||
partitionedCombinedLoreList.forEach(list -> {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String s : list) {
|
||||
builder.append(s);
|
||||
builder.append(", ");
|
||||
}
|
||||
String line = builder.toString();
|
||||
line = line.substring(0, line.length() - 2);
|
||||
newLore.add(line);
|
||||
});
|
||||
lore.clear();
|
||||
lore.addAll(newLore);
|
||||
}
|
||||
|
||||
if (meta instanceof EnchantmentStorageMeta) {
|
||||
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||
}
|
||||
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
lore.addAll(itemLore);
|
||||
meta.setLore(lore);
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void revert(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
|
||||
assert meta != null;
|
||||
|
||||
List<String> lore = meta.getLore() == null ? new ArrayList<>() : new ArrayList<>(meta.getLore());
|
||||
|
||||
lore.removeIf(s -> s.startsWith("§w"));
|
||||
meta.setLore(lore);
|
||||
|
||||
meta.getPersistentDataContainer().remove(legacyV);
|
||||
|
||||
if (!meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER)) {
|
||||
meta.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
meta.getPersistentDataContainer().remove(keySkip);
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object[] generateVarArgs(@NotNull final ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return new Object[]{false};
|
||||
}
|
||||
boolean hideEnchants = false;
|
||||
|
||||
if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
||||
hideEnchants = true;
|
||||
}
|
||||
|
||||
if (meta.getPersistentDataContainer().has(legacyV, PersistentDataType.INTEGER)) {
|
||||
hideEnchants = false;
|
||||
}
|
||||
|
||||
if (Display.isFinalized(itemStack)) {
|
||||
hideEnchants = false;
|
||||
}
|
||||
|
||||
if (options.isUsingExperimentalHideFixer() && options.isUsingForceHideFixer()) {
|
||||
hideEnchants = false;
|
||||
}
|
||||
|
||||
if (options.isUsingExperimentalHideFixer() && meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) && meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
||||
hideEnchants = false;
|
||||
}
|
||||
|
||||
return new Object[]{hideEnchants};
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
package com.willfp.ecoenchants.display;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.willfp.eco.core.config.ConfigUpdater;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
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.EnchantmentType;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.enchantments.EnchantmentWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class EnchantmentCache {
|
||||
/**
|
||||
* Instance of EcoEnchants.
|
||||
*/
|
||||
public static final EcoEnchantsPlugin PLUGIN = EcoEnchantsPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The physical cache.
|
||||
*/
|
||||
private static final Map<NamespacedKey, CacheEntry> CACHE = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Get the {@link CacheEntry} for a specific enchantment.
|
||||
* <p>
|
||||
* Returns a default "broken" cache entry if not cached.
|
||||
*
|
||||
* @param enchantment The enchantment to query.
|
||||
* @return The found cache entry.
|
||||
*/
|
||||
public static CacheEntry getEntry(@NotNull final Enchantment enchantment) {
|
||||
CacheEntry matching = CACHE.get(enchantment.getKey());
|
||||
if (matching != null) {
|
||||
return matching;
|
||||
} else {
|
||||
updateEnchantment(enchantment);
|
||||
Bukkit.getLogger().warning(enchantment.getKey() + " (from class " + enchantment.getClass() + ") was not cached! Trying to fix...");
|
||||
return getEntry(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entire cache.
|
||||
*
|
||||
* @return An immutable map of the cache.
|
||||
*/
|
||||
public static Map<NamespacedKey, CacheEntry> getCache() {
|
||||
return ImmutableMap.copyOf(CACHE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the cache.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
CACHE.clear();
|
||||
Arrays.asList(Enchantment.values()).forEach(EnchantmentCache::updateEnchantment);
|
||||
}
|
||||
|
||||
private static void updateEnchantment(@NotNull final Enchantment enchantment) {
|
||||
CACHE.remove(enchantment.getKey());
|
||||
|
||||
if (enchantment instanceof EnchantmentWrapper) {
|
||||
Bukkit.getLogger().severe("Found erroneous enchantment registration!");
|
||||
Bukkit.getLogger().severe("Enchantment " + enchantment.getKey()
|
||||
+ " (Found in class " + enchantment.getClass().getName() + ", Path: " + enchantment.getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + ")"
|
||||
);
|
||||
Bukkit.getLogger().severe("Tell the author to lean how enchantments are stored internally.");
|
||||
Bukkit.getLogger().severe("Hint: Extend Enchantment instead of EnchantmentWrapper.");
|
||||
CACHE.put(enchantment.getKey(), new CacheEntry(
|
||||
enchantment,
|
||||
"&4INVALID ENCHANTMENT",
|
||||
"INVALID",
|
||||
Collections.singletonList(Display.PREFIX + "INVALID ENCHANTMENT: " + enchantment.getClass().getName()),
|
||||
EnchantmentType.NORMAL,
|
||||
EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity"))
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
String name;
|
||||
String color;
|
||||
EnchantmentType type;
|
||||
EnchantmentRarity rarity;
|
||||
List<String> description;
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
description = ecoEnchant.getWrappedDescription();
|
||||
name = ecoEnchant.getName();
|
||||
type = ecoEnchant.getType();
|
||||
rarity = ecoEnchant.getRarity();
|
||||
} else {
|
||||
description = Arrays.asList(
|
||||
WordUtils.wrap(
|
||||
String.valueOf(PLUGIN.getLangYml().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".description")),
|
||||
PLUGIN.getConfigYml().getInt("lore.describe.wrap"),
|
||||
"\n", false
|
||||
).split("\\r?\\n")
|
||||
);
|
||||
name = String.valueOf(PLUGIN.getLangYml().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".name"));
|
||||
type = enchantment.isCursed() ? EnchantmentType.CURSE : EnchantmentType.NORMAL;
|
||||
if (enchantment.isTreasure()) {
|
||||
rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-treasure-rarity"));
|
||||
} else {
|
||||
rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity"));
|
||||
}
|
||||
}
|
||||
|
||||
color = type.getColor();
|
||||
|
||||
if (rarity != null && rarity.hasCustomColor() && type != EnchantmentType.CURSE) {
|
||||
color = rarity.getCustomColor();
|
||||
}
|
||||
|
||||
if (rarity == null) {
|
||||
rarity = EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity"));
|
||||
}
|
||||
|
||||
String rawName = name;
|
||||
name = color + name;
|
||||
description.replaceAll(line -> Display.PREFIX + ((EnchantDisplay) PLUGIN.getDisplayModule()).getOptions().getDescriptionOptions().getColor() + line);
|
||||
CACHE.put(enchantment.getKey(), new CacheEntry(enchantment, name, rawName, description, type, rarity));
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static final class CacheEntry {
|
||||
/**
|
||||
* The enchantment that this cache is for.
|
||||
*/
|
||||
@Getter
|
||||
private final Enchantment enchantment;
|
||||
|
||||
/**
|
||||
* The formatted name of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The raw (unformatted) name of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final String rawName;
|
||||
|
||||
/**
|
||||
* The description, line-wrapped.
|
||||
*/
|
||||
@Getter
|
||||
private final List<String> description;
|
||||
|
||||
/**
|
||||
* The description, not line-wrapped or colorized.
|
||||
*/
|
||||
@Getter
|
||||
private final String stringDescription;
|
||||
|
||||
/**
|
||||
* The type of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final EnchantmentType type;
|
||||
|
||||
/**
|
||||
* The rarity of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final EnchantmentRarity rarity;
|
||||
|
||||
private CacheEntry(@NotNull final Enchantment enchantment,
|
||||
@NotNull final String name,
|
||||
@NotNull final String rawName,
|
||||
@NotNull final List<String> description,
|
||||
@NotNull final EnchantmentType type,
|
||||
@NotNull final EnchantmentRarity rarity) {
|
||||
this.enchantment = enchantment;
|
||||
this.name = name;
|
||||
this.rawName = rawName;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
this.rarity = rarity;
|
||||
|
||||
StringBuilder descriptionBuilder = new StringBuilder();
|
||||
|
||||
description.forEach(s -> {
|
||||
descriptionBuilder.append(s);
|
||||
descriptionBuilder.append(" ");
|
||||
});
|
||||
|
||||
String processedStringDescription = descriptionBuilder.toString();
|
||||
processedStringDescription = processedStringDescription.replace(Display.PREFIX, "");
|
||||
this.stringDescription = processedStringDescription.replaceAll(((EnchantDisplay) PLUGIN.getDisplayModule()).getOptions().getDescriptionOptions().getColor(), "");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DescriptionOptions extends PluginDependent {
|
||||
/**
|
||||
* The threshold below which to describe enchantments.
|
||||
*/
|
||||
@Getter
|
||||
private int threshold;
|
||||
|
||||
/**
|
||||
* If the options are enabled.
|
||||
*/
|
||||
@Getter
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* The description lines color.
|
||||
*/
|
||||
@Getter
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* Create new description options.
|
||||
*
|
||||
* @param plugin EcoEnchants.
|
||||
*/
|
||||
public DescriptionOptions(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
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"));
|
||||
}
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SorterManager;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DisplayOptions extends PluginDependent {
|
||||
/**
|
||||
* The description options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final DescriptionOptions descriptionOptions = new DescriptionOptions(this.getPlugin());
|
||||
/**
|
||||
* The enchantment level options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final NumbersOptions numbersOptions = new NumbersOptions(this.getPlugin());
|
||||
/**
|
||||
* The shrink options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final ShrinkOptions shrinkOptions = new ShrinkOptions(this.getPlugin());
|
||||
/**
|
||||
* The enchantment types, sorted according to config.
|
||||
*/
|
||||
@Getter
|
||||
private final List<EnchantmentType> sortedTypes = new ArrayList<>();
|
||||
/**
|
||||
* The enchantment rarities, sorted according to config.
|
||||
*/
|
||||
@Getter
|
||||
private final List<EnchantmentRarity> sortedRarities = new ArrayList<>();
|
||||
/**
|
||||
* The enchantment sorter being used.
|
||||
*/
|
||||
@Getter
|
||||
private EnchantmentSorter sorter;
|
||||
/**
|
||||
* Allow reading enchantments from lore-based plugins.
|
||||
*/
|
||||
@Getter
|
||||
private boolean usingLoreGetter = false;
|
||||
|
||||
/**
|
||||
* Allow reading enchantments from lore-based plugins aggressively.
|
||||
*/
|
||||
@Getter
|
||||
private boolean usingAggressiveLoreGetter = false;
|
||||
|
||||
/**
|
||||
* If the experimental hide fixer is being used.
|
||||
*/
|
||||
@Getter
|
||||
private boolean usingExperimentalHideFixer = false;
|
||||
|
||||
/**
|
||||
* If the aggressive experimental hide fixer is being used.
|
||||
*/
|
||||
@Getter
|
||||
private boolean usingAggressiveExperimentalHideFixer = false;
|
||||
|
||||
/**
|
||||
* If all items should have hide enchants removed.
|
||||
*/
|
||||
@Getter
|
||||
private boolean usingForceHideFixer = false;
|
||||
|
||||
/**
|
||||
* If item must be a target.
|
||||
*/
|
||||
@Getter
|
||||
private boolean requireTarget = true;
|
||||
|
||||
/**
|
||||
* Instantiate new display options.
|
||||
*
|
||||
* @param plugin EcoEnchants.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public DisplayOptions(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all options.
|
||||
*/
|
||||
public void update() {
|
||||
descriptionOptions.update();
|
||||
numbersOptions.update();
|
||||
shrinkOptions.update();
|
||||
|
||||
sortedTypes.clear();
|
||||
sortedTypes.addAll(this.getPlugin().getConfigYml().getStrings("lore.type-ordering").stream()
|
||||
.map(typeName -> EnchantmentType.values().stream().filter(type -> type.getName().equalsIgnoreCase(typeName)).findFirst().orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
sortedTypes.addAll(EnchantmentType.values().stream().filter(enchantmentType -> !sortedTypes.contains(enchantmentType)).collect(Collectors.toList()));
|
||||
|
||||
sortedRarities.clear();
|
||||
sortedRarities.addAll(this.getPlugin().getConfigYml().getStrings("lore.rarity-ordering").stream()
|
||||
.map(rarityName -> EnchantmentRarity.values().stream().filter(rarity -> rarity.getName().equalsIgnoreCase(rarityName)).findFirst().orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
sortedRarities.addAll(EnchantmentRarity.values().stream().filter(enchantmentRarity -> !sortedRarities.contains(enchantmentRarity)).collect(Collectors.toList()));
|
||||
|
||||
usingLoreGetter = this.getPlugin().getConfigYml().getBool("advanced.lore-getter.enabled");
|
||||
usingAggressiveLoreGetter = this.getPlugin().getConfigYml().getBool("advanced.lore-getter.aggressive");
|
||||
usingExperimentalHideFixer = this.getPlugin().getConfigYml().getBool("advanced.hide-fixer.enabled");
|
||||
usingAggressiveExperimentalHideFixer = this.getPlugin().getConfigYml().getBool("advanced.hide-fixer.aggressive");
|
||||
usingForceHideFixer = this.getPlugin().getConfigYml().getBool("advanced.hide-fixer.force");
|
||||
|
||||
requireTarget = this.getPlugin().getConfigYml().getBool("lore.require-target");
|
||||
|
||||
boolean byType = this.getPlugin().getConfigYml().getBool("lore.sort-by-type");
|
||||
boolean byLength = this.getPlugin().getConfigYml().getBool("lore.sort-by-length");
|
||||
boolean byRarity = this.getPlugin().getConfigYml().getBool("lore.sort-by-rarity");
|
||||
Set<SortParameters> params = new HashSet<>();
|
||||
if (byType) {
|
||||
params.add(SortParameters.TYPE);
|
||||
}
|
||||
if (byLength) {
|
||||
params.add(SortParameters.LENGTH);
|
||||
}
|
||||
if (byRarity) {
|
||||
params.add(SortParameters.RARITY);
|
||||
}
|
||||
|
||||
sorter = SorterManager.getSorter(params.toArray(new SortParameters[]{}));
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NumbersOptions extends PluginDependent {
|
||||
/**
|
||||
* If numerals should be used.
|
||||
* <p>
|
||||
* If false then numbers will be used instead.
|
||||
*/
|
||||
@Getter
|
||||
private boolean useNumerals;
|
||||
|
||||
/**
|
||||
* The threshold above which numbers will be used instead.
|
||||
*/
|
||||
@Getter
|
||||
private int threshold;
|
||||
|
||||
/**
|
||||
* Create new numbers options.
|
||||
*
|
||||
* @param plugin EcoEnchants.
|
||||
*/
|
||||
public NumbersOptions(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
public void update() {
|
||||
useNumerals = this.getPlugin().getConfigYml().getBool("lore.use-numerals");
|
||||
threshold = this.getPlugin().getConfigYml().getInt("lore.use-numbers-above-threshold");
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ShrinkOptions extends PluginDependent {
|
||||
/**
|
||||
* The threshold above which enchantments will be shrunk.
|
||||
*/
|
||||
@Getter
|
||||
private int threshold;
|
||||
|
||||
/**
|
||||
* If shrinking is enabled.
|
||||
*/
|
||||
@Getter
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* The amount of enchantments to have per-line.
|
||||
*/
|
||||
@Getter
|
||||
private int shrinkPerLine;
|
||||
|
||||
/**
|
||||
* Create new shrink options.
|
||||
*
|
||||
* @param plugin EcoEnchants.
|
||||
*/
|
||||
public ShrinkOptions(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
public void update() {
|
||||
threshold = this.getPlugin().getConfigYml().getInt("lore.shrink.after-lines");
|
||||
enabled = this.getPlugin().getConfigYml().getBool("lore.shrink.enabled");
|
||||
shrinkPerLine = this.getPlugin().getConfigYml().getInt("lore.shrink.maximum-per-line");
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EnchantmentSorter {
|
||||
/**
|
||||
* Sort list of enchantments.
|
||||
* <p>
|
||||
* All implementations must treat enchantments as final or effectively final.
|
||||
*
|
||||
* @param toSort The enchantments to sort.
|
||||
*/
|
||||
void sortEnchantments(@NotNull List<Enchantment> toSort);
|
||||
|
||||
/**
|
||||
* Get the parameters that the sorter fulfills.
|
||||
*
|
||||
* @return Array of all parameters.
|
||||
*/
|
||||
SortParameters[] getParameters();
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
public enum SortParameters {
|
||||
/**
|
||||
* If the sorter should sort by type or if type should be ignored.
|
||||
*/
|
||||
TYPE,
|
||||
|
||||
/**
|
||||
* If the sorter should sort by rarity or if rarity should be ignored.
|
||||
*/
|
||||
RARITY,
|
||||
|
||||
/**
|
||||
* If the sorter should sort by length or alphabetically.
|
||||
*/
|
||||
LENGTH
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.AlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.LengthSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.RarityAlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.RarityLengthSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.RarityTypeAlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.RarityTypeLengthSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.TypeAlphabeticSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.implementations.TypeLengthSorter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class SorterManager {
|
||||
/**
|
||||
* All registered enchantment sorters.
|
||||
*/
|
||||
private static final Set<EnchantmentSorter> REGISTERED = new HashSet<>();
|
||||
|
||||
static {
|
||||
EcoEnchantsPlugin instance = EcoEnchantsPlugin.getInstance(); // Really dirty and janky.
|
||||
REGISTERED.add(new AlphabeticSorter(instance));
|
||||
REGISTERED.add(new LengthSorter(instance));
|
||||
REGISTERED.add(new TypeAlphabeticSorter(instance));
|
||||
REGISTERED.add(new TypeLengthSorter(instance));
|
||||
REGISTERED.add(new RarityAlphabeticSorter(instance));
|
||||
REGISTERED.add(new RarityLengthSorter(instance));
|
||||
REGISTERED.add(new RarityTypeAlphabeticSorter(instance));
|
||||
REGISTERED.add(new RarityTypeLengthSorter(instance));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a sorter based off of parameters.
|
||||
* <p>
|
||||
* Any combination of parameters is valid.
|
||||
*
|
||||
* @param parameters The parameters to find a sorter from.
|
||||
* @return The matching sorter.
|
||||
*/
|
||||
public static EnchantmentSorter getSorter(@NotNull final SortParameters... parameters) {
|
||||
return REGISTERED.stream()
|
||||
.filter(enchantmentSorter -> Arrays.asList(enchantmentSorter.getParameters()).containsAll(Arrays.asList(parameters)) && enchantmentSorter.getParameters().length == parameters.length)
|
||||
.findFirst()
|
||||
.orElse(new AlphabeticSorter(EcoEnchantsPlugin.getInstance()));
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AlphabeticSorter extends PluginDependent implements EnchantmentSorter {
|
||||
/**
|
||||
* Instantiate sorter.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public AlphabeticSorter(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
toSort.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[0];
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class LengthSorter extends PluginDependent implements EnchantmentSorter {
|
||||
/**
|
||||
* Instantiate sorter.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public LengthSorter(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.LENGTH};
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RarityAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
|
||||
/**
|
||||
* Instantiate sorter.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public RarityAlphabeticSorter(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||
rarityEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
rarityEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.RARITY};
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class RarityLengthSorter extends PluginDependent implements EnchantmentSorter {
|
||||
/**
|
||||
* Instantiate sorter.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public RarityLengthSorter(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||
rarityEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.RARITY, SortParameters.LENGTH};
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RarityTypeAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
|
||||
/**
|
||||
* Instantiate sorter.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public RarityTypeAlphabeticSorter(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : typeEnchants) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||
rarityEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
rarityEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.RARITY, SortParameters.TYPE};
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class RarityTypeLengthSorter extends PluginDependent implements EnchantmentSorter {
|
||||
/**
|
||||
* Instantiate sorter.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public RarityTypeLengthSorter(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
typeEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : typeEnchants) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||
rarityEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
rarityEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.RARITY, SortParameters.TYPE, SortParameters.LENGTH};
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TypeAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
|
||||
/**
|
||||
* Instantiate sorter.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public TypeAlphabeticSorter(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||
sorted.addAll(typeEnchants);
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.TYPE};
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.PluginDependent;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TypeLengthSorter extends PluginDependent implements EnchantmentSorter {
|
||||
/**
|
||||
* Instantiate sorter.
|
||||
*
|
||||
* @param plugin Instance of EcoEnchants.
|
||||
*/
|
||||
public TypeLengthSorter(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||
}
|
||||
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||
for (Enchantment enchantment : toSort) {
|
||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||
typeEnchants.add(enchantment);
|
||||
}
|
||||
}
|
||||
|
||||
sorted.addAll(typeEnchants);
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.TYPE, SortParameters.LENGTH};
|
||||
}
|
||||
}
|
@ -0,0 +1,367 @@
|
||||
package com.willfp.ecoenchants.enchantments;
|
||||
|
||||
import com.willfp.eco.core.Prerequisite;
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
|
||||
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.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.enchantments.util.Watcher;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings({"unchecked", "deprecation", "RedundantSuppression"})
|
||||
public abstract class EcoEnchant extends Enchantment implements Listener, Watcher {
|
||||
/**
|
||||
* Instance of EcoEnchants for enchantments to be able to access.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final EcoEnchantsPlugin plugin = EcoEnchantsPlugin.getInstance();
|
||||
/**
|
||||
* The permission/config name of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final String permissionName;
|
||||
/**
|
||||
* The type of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final EnchantmentType type;
|
||||
/**
|
||||
* The enchantment's config.
|
||||
*/
|
||||
@Getter
|
||||
private final EnchantmentConfig config;
|
||||
/**
|
||||
* The targets of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final Set<EnchantmentTarget> targets = new HashSet<>();
|
||||
/**
|
||||
* The materials of the targets.
|
||||
*/
|
||||
@Getter
|
||||
private final Set<Material> targetMaterials = new HashSet<>();
|
||||
/**
|
||||
* The names of the worlds that this enchantment is disabled in.
|
||||
*/
|
||||
@Getter
|
||||
private final Set<String> disabledWorldNames = new HashSet<>();
|
||||
/**
|
||||
* The worlds that this enchantment is disabled in.
|
||||
*/
|
||||
@Getter
|
||||
private final List<World> disabledWorlds = new ArrayList<>();
|
||||
/**
|
||||
* The display name of the enchantment.
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* The description of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private String description;
|
||||
/**
|
||||
* If the enchantment can be removed in a grindstone.
|
||||
*/
|
||||
@Getter
|
||||
private boolean grindstoneable;
|
||||
/**
|
||||
* If the enchantment can be obtained from an enchanting table.
|
||||
*/
|
||||
@Getter
|
||||
private boolean availableFromTable;
|
||||
/**
|
||||
* If the enchantment can be obtained from a villager.
|
||||
*/
|
||||
@Getter
|
||||
private boolean availableFromVillager;
|
||||
/**
|
||||
* If the enchantment can be obtained from a loot chest.
|
||||
*/
|
||||
@Getter
|
||||
private boolean availableFromLoot;
|
||||
/**
|
||||
* The maximum level for the enchantment to be obtained naturally.
|
||||
*/
|
||||
private int maxLevel;
|
||||
/**
|
||||
* The enchantments that conflict with this enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private Set<Enchantment> conflicts;
|
||||
/**
|
||||
* The rarity of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private EnchantmentRarity rarity;
|
||||
/**
|
||||
* If the enchantment is enabled.
|
||||
*/
|
||||
@Getter
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* Create a new EcoEnchant.
|
||||
*
|
||||
* @param key The key name of the enchantment
|
||||
* @param type The type of the enchantment
|
||||
* @param prerequisites Optional {@link Prerequisite}s that must be met
|
||||
*/
|
||||
protected EcoEnchant(@NotNull final String key,
|
||||
@NotNull final EnchantmentType type,
|
||||
@NotNull final Prerequisite... prerequisites) {
|
||||
super(NamespacedKey.minecraft(key));
|
||||
|
||||
this.type = type;
|
||||
this.permissionName = key.replace("_", "");
|
||||
this.config = new EnchantmentConfig(this.permissionName, this.getClass(), this.type);
|
||||
|
||||
if (Bukkit.getPluginManager().getPermission("ecoenchants.fromtable." + permissionName) == null) {
|
||||
Permission permission = new Permission(
|
||||
"ecoenchants.fromtable." + permissionName,
|
||||
"Allows getting " + permissionName + " from an Enchanting Table",
|
||||
PermissionDefault.TRUE
|
||||
);
|
||||
permission.addParent(Objects.requireNonNull(Bukkit.getPluginManager().getPermission("ecoenchants.fromtable.*")), true);
|
||||
Bukkit.getPluginManager().addPermission(permission);
|
||||
}
|
||||
|
||||
if (type.getRequiredToExtend() != null && !type.getRequiredToExtend().isInstance(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Prerequisite.areMet(prerequisites)) {
|
||||
return;
|
||||
}
|
||||
|
||||
enabled = config.getBool("enabled");
|
||||
|
||||
if (!this.isEnabled() && this.getPlugin().getConfigYml().getBool("advanced.hard-disable.enabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.update();
|
||||
|
||||
EcoEnchants.addNewEcoEnchant(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the enchantment based off config values.
|
||||
* 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!");
|
||||
conflicts = config.getEnchantments(EcoEnchants.GENERAL_LOCATION + "conflicts");
|
||||
grindstoneable = config.getBool(EcoEnchants.GENERAL_LOCATION + "grindstoneable");
|
||||
availableFromTable = config.getBool(EcoEnchants.OBTAINING_LOCATION + "table");
|
||||
availableFromVillager = config.getBool(EcoEnchants.OBTAINING_LOCATION + "villager");
|
||||
availableFromLoot = config.getBool(EcoEnchants.OBTAINING_LOCATION + "loot");
|
||||
maxLevel = config.getInt(EcoEnchants.GENERAL_LOCATION + "maximum-level", 1);
|
||||
name = StringUtils.translate(config.getString("name"));
|
||||
description = StringUtils.translate(config.getString("description"));
|
||||
disabledWorldNames.clear();
|
||||
disabledWorldNames.addAll(config.getStrings(EcoEnchants.GENERAL_LOCATION + "disabled-in-worlds"));
|
||||
disabledWorlds.clear();
|
||||
List<String> worldNames = Bukkit.getWorlds().stream().map(World::getName).map(String::toLowerCase).collect(Collectors.toList());
|
||||
List<String> disabledExistingWorldNames = disabledWorldNames.stream().filter(s -> worldNames.contains(s.toLowerCase())).collect(Collectors.toList());
|
||||
disabledWorlds.addAll(Bukkit.getWorlds().stream().filter(world -> disabledExistingWorldNames.contains(world.getName().toLowerCase())).collect(Collectors.toList()));
|
||||
targets.clear();
|
||||
targetMaterials.clear();
|
||||
targets.addAll(config.getTargets());
|
||||
targets.forEach(enchantmentTarget -> targetMaterials.addAll(enchantmentTarget.getMaterials()));
|
||||
enabled = config.getBool("enabled");
|
||||
EnchantmentUtils.registerPlaceholders(this);
|
||||
|
||||
postUpdate();
|
||||
this.register();
|
||||
}
|
||||
|
||||
protected void postUpdate() {
|
||||
// Unused as some enchantments may have postUpdate tasks, however most won't.
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the enchantment with spigot.
|
||||
* Only used internally.
|
||||
*/
|
||||
public void register() {
|
||||
try {
|
||||
Field byIdField = Enchantment.class.getDeclaredField("byKey");
|
||||
Field byNameField = Enchantment.class.getDeclaredField("byName");
|
||||
byIdField.setAccessible(true);
|
||||
byNameField.setAccessible(true);
|
||||
Map<NamespacedKey, Enchantment> byKey = (Map<NamespacedKey, Enchantment>) byIdField.get(null);
|
||||
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
|
||||
byKey.remove(this.getKey());
|
||||
byName.remove(this.getName());
|
||||
|
||||
Map<String, Enchantment> byNameClone = new HashMap<>(byName);
|
||||
for (Map.Entry<String, Enchantment> entry : byNameClone.entrySet()) {
|
||||
if (entry.getValue().getKey().equals(this.getKey())) {
|
||||
byName.remove(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
Field f = Enchantment.class.getDeclaredField("acceptingNew");
|
||||
f.setAccessible(true);
|
||||
f.set(null, true);
|
||||
f.setAccessible(false);
|
||||
|
||||
Enchantment.registerEnchantment(this);
|
||||
} catch (NoSuchFieldException | IllegalAccessException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description of enchantment line-wrapped.
|
||||
*
|
||||
* @return The description.
|
||||
*/
|
||||
public List<String> getWrappedDescription() {
|
||||
return Arrays.asList(WordUtils.wrap(description, this.getPlugin().getConfigYml().getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* If enchantment conflicts with any enchantment in collection.
|
||||
*
|
||||
* @param enchantments The collection to test against.
|
||||
* @return If there are any conflicts.
|
||||
*/
|
||||
public boolean conflictsWithAny(@NotNull final Collection<? extends Enchantment> enchantments) {
|
||||
return conflicts.stream().anyMatch(enchantments::contains);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enchantment cast to {@link Enchantment}.
|
||||
*
|
||||
* @return The enchantment.
|
||||
*/
|
||||
public Enchantment getEnchantment() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the display name of the enchantment.
|
||||
* <p>
|
||||
* Not deprecated, unlike superclass.
|
||||
*
|
||||
* @return The name.
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max level of enchantment.
|
||||
*
|
||||
* @return The max level.
|
||||
*/
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 1
|
||||
*/
|
||||
@Override
|
||||
public int getStartLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do not use this method.
|
||||
* Only here for compatibility with {@link Enchantment}.
|
||||
*
|
||||
* @return Returns {@link EnchantmentTarget#ALL}. Do not use.
|
||||
* @deprecated {@link EnchantmentTarget} is not supported due to its lack of flexibility. Use {@link EcoEnchant#getTargets()} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public @NotNull org.bukkit.enchantments.EnchantmentTarget getItemTarget() {
|
||||
return org.bukkit.enchantments.EnchantmentTarget.ALL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Treasure enchantments do not exist in EcoEnchants.
|
||||
*
|
||||
* @return false.
|
||||
* @see EnchantmentType#SPECIAL
|
||||
* @deprecated Treasure enchantments do not exist. Use {@link EcoEnchant#getType()} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isTreasure() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* While this method works, it is not recommended to use it.
|
||||
*
|
||||
* @return Returns if enchantment is cursed.
|
||||
* @see EnchantmentType#CURSE
|
||||
* @deprecated Use {@link EcoEnchant#getType()} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean isCursed() {
|
||||
return this.type.equals(EnchantmentType.CURSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if enchantment conflicts with specified enchantment.
|
||||
*
|
||||
* @param enchantment The enchantment to test against.
|
||||
* @return If conflicts.
|
||||
*/
|
||||
@Override
|
||||
public boolean conflictsWith(@NotNull final Enchantment enchantment) {
|
||||
if (enchantment instanceof EcoEnchant) {
|
||||
return conflicts.contains(enchantment) || ((EcoEnchant) enchantment).conflicts.contains(this);
|
||||
}
|
||||
return conflicts.contains(enchantment);
|
||||
}
|
||||
|
||||
/**
|
||||
* If enchantment can be applied to item.
|
||||
*
|
||||
* @param itemStack The {@link ItemStack} to test against.
|
||||
* @return If can be applied.
|
||||
*/
|
||||
@Override
|
||||
public boolean canEnchantItem(@NotNull final ItemStack itemStack) {
|
||||
return targetMaterials.contains(itemStack.getType()) || itemStack.getType().equals(Material.BOOK) || itemStack.getType().equals(Material.ENCHANTED_BOOK);
|
||||
}
|
||||
}
|
@ -0,0 +1,605 @@
|
||||
package com.willfp.ecoenchants.enchantments;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.eco.core.config.ConfigUpdater;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.AngerArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.AshArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.BarrierArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.CloudsArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.CrimsonArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.DamageArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.DragonArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.DustArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.EmeraldArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.EnchantmentArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.EndArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.FireArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.HeartArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.HoneyArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.InkArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.LavaArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.LimeArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.MagicArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.MagmaArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.MusicArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.NautilusArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.NetherArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.RedstoneArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.SmokeArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.SnowArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.SoulArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.SoulFireArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.SparkleArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.SweepArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.TearArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.TotemArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.VillagerArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.WarpedArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.WaterArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.WitchArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.ZapArtifact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.BreaklessnessCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.CallingCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.DecayCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.FragilityCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.HarmlessnessCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.HungerCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.InaccuracyCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.MisfortuneCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.curse.PermanenceCurse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Abattoir;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Abrasion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Aerial;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Aquatic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Arachnid;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Arborist;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Arcanic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Atmospheric;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Aversion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Backstab;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Beheading;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.BlastMining;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Bleed;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Blind;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.BlockBreather;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.BossHunter;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Buckshot;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Butchering;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Cerebral;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Chopless;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Cleave;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Collateral;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Conclude;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Corrosive;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Cranial;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Criticals;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Cubism;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Defender;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Deflection;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Defusion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Dexterous;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Disable;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Disappear;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Diurnal;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Diverse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Drill;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Dullness;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Dweller;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Economical;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Electroshock;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.EndInfusion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.EnderSlayer;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Enderism;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Evasion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Extinguishing;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Extract;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Famine;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Farmhand;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Fetching;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Finality;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Finishing;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.FireAffinity;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.FirstStrike;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Flinch;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Forcefield;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Freerunner;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Frozen;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Fury;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Goliath;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Graceful;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Grapple;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.GreenThumb;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Grit;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Hellish;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Hook;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Horde;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.IceShot;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Identify;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Ignite;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.IllusionAspect;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Impact;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Incandescence;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.InfernalTouch;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Inferno;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Infuriate;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Insecticide;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Instantaneous;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Introversion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Invigoration;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Kinetic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Launch;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Leeching;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Lesion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Levitate;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.LiquidShot;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.LuckyCatch;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Lumberjack;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.MagmaWalker;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Magnetic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Marking;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Marksman;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Necrotic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.NetherInfusion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Netheric;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Nocturnal;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Optics;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Oxygenate;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Pacify;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Paladin;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Paralyze;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Parasitic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Parry;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Phantasm;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Plasmic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Protector;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Proximity;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Puncture;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Quadrilateralism;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Radiance;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rage;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rapid;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reaper;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rebounding;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reel;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reinforcement;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rejuvenation;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Replenish;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Respirator;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Revenant;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Sating;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Serrated;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Settle;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Shockwave;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.ShotAssist;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Sickening;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Slaughter;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Slicing;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Spearfishing;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Spiked;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Splash;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Stab;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Stalwart;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Stamina;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.StoneSwitcher;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.StrayAspect;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Succession;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Supercritical;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Sycophant;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Tectonic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Telekinesis;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Thor;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Thrive;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Tornado;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Toxic;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Transfuse;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Tripleshot;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.VampireAspect;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Vein;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Venom;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.VoidAffinity;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Voltage;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.WaterAffinity;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.WaterAspect;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Weakening;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Wisdom;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.WoodSwitcher;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Wound;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Zeus;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Aiming;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Annihilate;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Bladed;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Bolt;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Carve;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Confusion;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Energizing;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Force;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Frenzy;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Harpoon;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Indestructibility;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Instability;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Intellect;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.LifeSteal;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Pentashot;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Preservation;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Prosperity;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Razor;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Repairing;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Soulbound;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Spring;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Streamlining;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.Volatile;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Ascend;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Charge;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Dynamite;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Missile;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Quake;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Vitalize;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
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;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@UtilityClass
|
||||
@SuppressWarnings({"unused", "checkstyle:JavadocVariable"})
|
||||
public class EcoEnchants {
|
||||
public static final String CONFIG_LOCATION = "config.";
|
||||
public static final String OBTAINING_LOCATION = "obtaining.";
|
||||
public static final String GENERAL_LOCATION = "general-config.";
|
||||
|
||||
private static final BiMap<NamespacedKey, EcoEnchant> BY_KEY = HashBiMap.create();
|
||||
private static final BiMap<String, EcoEnchant> BY_NAME = HashBiMap.create();
|
||||
|
||||
public static final EcoEnchant TELEKINESIS = new Telekinesis();
|
||||
public static final EcoEnchant MARKSMAN = new Marksman();
|
||||
public static final EcoEnchant INFERNAL_TOUCH = new InfernalTouch();
|
||||
public static final EcoEnchant SPRING = new Spring();
|
||||
public static final EcoEnchant STRAY_ASPECT = new StrayAspect();
|
||||
public static final EcoEnchant ILLUSION_ASPECT = new IllusionAspect();
|
||||
public static final EcoEnchant SLICING = new Slicing();
|
||||
public static final EcoEnchant DEXTEROUS = new Dexterous();
|
||||
public static final EcoEnchant BEHEADING = new Beheading();
|
||||
public static final EcoEnchant NECROTIC = new Necrotic();
|
||||
public static final EcoEnchant MAGMA_WALKER = new MagmaWalker();
|
||||
public static final EcoEnchant TECTONIC = new Tectonic();
|
||||
public static final EcoEnchant EVASION = new Evasion();
|
||||
public static final EcoEnchant SUCCESSION = new Succession();
|
||||
public static final EcoEnchant FARMHAND = new Farmhand();
|
||||
public static final EcoEnchant WISDOM = new Wisdom();
|
||||
public static final EcoEnchant LEECHING = new Leeching();
|
||||
public static final EcoEnchant VAMPIRE_ASPECT = new VampireAspect();
|
||||
public static final EcoEnchant INSTABILITY = new Instability();
|
||||
public static final EcoEnchant THRIVE = new Thrive();
|
||||
public static final EcoEnchant DRILL = new Drill();
|
||||
public static final EcoEnchant THOR = new Thor();
|
||||
public static final EcoEnchant STREAMLINING = new Streamlining();
|
||||
public static final EcoEnchant FIRST_STRIKE = new FirstStrike();
|
||||
public static final EcoEnchant FINISHING = new Finishing();
|
||||
public static final EcoEnchant CRITICALS = new Criticals();
|
||||
public static final EcoEnchant INCANDESCENCE = new Incandescence();
|
||||
public static final EcoEnchant SUPERCRITICAL = new Supercritical();
|
||||
public static final EcoEnchant ABRASION = new Abrasion();
|
||||
public static final EcoEnchant SPLASH = new Splash();
|
||||
public static final EcoEnchant EXTINGUISHING = new Extinguishing();
|
||||
public static final EcoEnchant GOLIATH = new Goliath();
|
||||
public static final EcoEnchant OPTICS = new Optics();
|
||||
public static final EcoEnchant DEFUSION = new Defusion();
|
||||
public static final EcoEnchant CEREBRAL = new Cerebral();
|
||||
public static final EcoEnchant GRIT = new Grit();
|
||||
public static final EcoEnchant BOSS_HUNTER = new BossHunter();
|
||||
public static final EcoEnchant INVIGORATION = new Invigoration();
|
||||
public static final EcoEnchant REJUVENATION = new Rejuvenation();
|
||||
public static final EcoEnchant FRAGILITY_CURSE = new FragilityCurse();
|
||||
public static final EcoEnchant TRIPLESHOT = new Tripleshot();
|
||||
public static final EcoEnchant RAPID = new Rapid();
|
||||
public static final EcoEnchant SATING = new Sating();
|
||||
public static final EcoEnchant REINFORCEMENT = new Reinforcement();
|
||||
public static final EcoEnchant SOULBOUND = new Soulbound();
|
||||
public static final EcoEnchant RAZOR = new Razor();
|
||||
public static final EcoEnchant PROSPERITY = new Prosperity();
|
||||
public static final EcoEnchant PRESERVATION = new Preservation();
|
||||
public static final EcoEnchant FRENZY = new Frenzy();
|
||||
public static final EcoEnchant BUTCHERING = new Butchering();
|
||||
public static final EcoEnchant PROXIMITY = new Proximity();
|
||||
public static final EcoEnchant ENDER_SLAYER = new EnderSlayer();
|
||||
public static final EcoEnchant PROTECTOR = new Protector();
|
||||
public static final EcoEnchant INDESTRUCTIBILITY = new Indestructibility();
|
||||
public static final EcoEnchant ENERGIZING = new Energizing();
|
||||
public static final EcoEnchant INTELLECT = new Intellect();
|
||||
public static final EcoEnchant DEFLECTION = new Deflection();
|
||||
public static final EcoEnchant LAUNCH = new Launch();
|
||||
public static final EcoEnchant PERMANENCE_CURSE = new PermanenceCurse();
|
||||
public static final EcoEnchant SPEARFISHING = new Spearfishing();
|
||||
public static final EcoEnchant NETHER_INFUSION = new NetherInfusion();
|
||||
public static final EcoEnchant REPLENISH = new Replenish();
|
||||
public static final EcoEnchant FLINCH = new Flinch();
|
||||
public static final EcoEnchant ELECTROSHOCK = new Electroshock();
|
||||
public static final EcoEnchant NOCTURNAL = new Nocturnal();
|
||||
public static final EcoEnchant CONFUSION = new Confusion();
|
||||
public static final EcoEnchant ARCANIC = new Arcanic();
|
||||
public static final EcoEnchant PENTASHOT = new Pentashot();
|
||||
public static final EcoEnchant LUMBERJACK = new Lumberjack();
|
||||
public static final EcoEnchant STONE_SWITCHER = new StoneSwitcher();
|
||||
public static final EcoEnchant MAGNETIC = new Magnetic();
|
||||
public static final EcoEnchant REPAIRING = new Repairing();
|
||||
public static final EcoEnchant CALLING_CURSE = new CallingCurse();
|
||||
public static final EcoEnchant BLAST_MINING = new BlastMining();
|
||||
public static final EcoEnchant LIQUID_SHOT = new LiquidShot();
|
||||
public static final EcoEnchant GRAPPLE = new Grapple();
|
||||
public static final EcoEnchant HEART_ARTIFACT = new HeartArtifact();
|
||||
public static final EcoEnchant SPARKLE_ARTIFACT = new SparkleArtifact();
|
||||
public static final EcoEnchant LAVA_ARTIFACT = new LavaArtifact();
|
||||
public static final EcoEnchant DRAGON_ARTIFACT = new DragonArtifact();
|
||||
public static final EcoEnchant ENCHANTMENT_ARTIFACT = new EnchantmentArtifact();
|
||||
public static final EcoEnchant SMOKE_ARTIFACT = new SmokeArtifact();
|
||||
public static final EcoEnchant FIRE_ARTIFACT = new FireArtifact();
|
||||
public static final EcoEnchant EMERALD_ARTIFACT = new EmeraldArtifact();
|
||||
public static final EcoEnchant NETHER_ARTIFACT = new NetherArtifact();
|
||||
public static final EcoEnchant END_ARTIFACT = new EndArtifact();
|
||||
public static final EcoEnchant WATER_ARTIFACT = new WaterArtifact();
|
||||
public static final EcoEnchant TOTEM_ARTIFACT = new TotemArtifact();
|
||||
public static final EcoEnchant REDSTONE_ARTIFACT = new RedstoneArtifact();
|
||||
public static final EcoEnchant ZAP_ARTIFACT = new ZapArtifact();
|
||||
public static final EcoEnchant MUSIC_ARTIFACT = new MusicArtifact();
|
||||
public static final EcoEnchant SNOW_ARTIFACT = new SnowArtifact();
|
||||
public static final EcoEnchant WITCH_ARTIFACT = new WitchArtifact();
|
||||
public static final EcoEnchant HONEY_ARTIFACT = new HoneyArtifact();
|
||||
public static final EcoEnchant DAMAGE_ARTIFACT = new DamageArtifact();
|
||||
public static final EcoEnchant CLOUDS_ARTIFACT = new CloudsArtifact();
|
||||
public static final EcoEnchant MAGIC_ARTIFACT = new MagicArtifact();
|
||||
public static final EcoEnchant DUST_ARTIFACT = new DustArtifact();
|
||||
public static final EcoEnchant MAGMA_ARTIFACT = new MagmaArtifact();
|
||||
public static final EcoEnchant INK_ARTIFACT = new InkArtifact();
|
||||
public static final EcoEnchant ZEUS = new Zeus();
|
||||
public static final EcoEnchant KINETIC = new Kinetic();
|
||||
public static final EcoEnchant FIRE_AFFINITY = new FireAffinity();
|
||||
public static final EcoEnchant PARASITIC = new Parasitic();
|
||||
public static final EcoEnchant PARRY = new Parry();
|
||||
public static final EcoEnchant AIMING = new Aiming();
|
||||
public static final EcoEnchant HOOK = new Hook();
|
||||
public static final EcoEnchant BLEED = new Bleed();
|
||||
public static final EcoEnchant WEAKENING = new Weakening();
|
||||
public static final EcoEnchant OXYGENATE = new Oxygenate();
|
||||
public static final EcoEnchant WATER_ASPECT = new WaterAspect();
|
||||
public static final EcoEnchant STAMINA = new Stamina();
|
||||
public static final EcoEnchant COLLATERAL = new Collateral();
|
||||
public static final EcoEnchant HUNGER_CURSE = new HungerCurse();
|
||||
public static final EcoEnchant PALADIN = new Paladin();
|
||||
public static final EcoEnchant SERRATED = new Serrated();
|
||||
public static final EcoEnchant BLADED = new Bladed();
|
||||
public static final EcoEnchant INFERNO = new Inferno();
|
||||
public static final EcoEnchant STAB = new Stab();
|
||||
public static final EcoEnchant TORNADO = new Tornado();
|
||||
public static final EcoEnchant EXTRACT = new Extract();
|
||||
public static final EcoEnchant AERIAL = new Aerial();
|
||||
public static final EcoEnchant FAMINE = new Famine();
|
||||
public static final EcoEnchant ANNIHILATE = new Annihilate();
|
||||
public static final EcoEnchant RADIANCE = new Radiance();
|
||||
public static final EcoEnchant HORDE = new Horde();
|
||||
public static final EcoEnchant VEIN = new Vein();
|
||||
public static final EcoEnchant ICE_SHOT = new IceShot();
|
||||
public static final EcoEnchant PUNCTURE = new Puncture();
|
||||
public static final EcoEnchant SHOCKWAVE = new Shockwave();
|
||||
public static final EcoEnchant VOLATILE = new Volatile();
|
||||
public static final EcoEnchant INSTANTANEOUS = new Instantaneous();
|
||||
public static final EcoEnchant FREERUNNER = new Freerunner();
|
||||
public static final EcoEnchant BOLT = new Bolt();
|
||||
public static final EcoEnchant DULLNESS = new Dullness();
|
||||
public static final EcoEnchant IGNITE = new Ignite();
|
||||
public static final EcoEnchant CLEAVE = new Cleave();
|
||||
public static final EcoEnchant CARVE = new Carve();
|
||||
public static final EcoEnchant TOXIC = new Toxic();
|
||||
public static final EcoEnchant WATER_AFFINITY = new WaterAffinity();
|
||||
public static final EcoEnchant FORCEFIELD = new Forcefield();
|
||||
public static final EcoEnchant SYCOPHANT = new Sycophant();
|
||||
public static final EcoEnchant CHOPLESS = new Chopless();
|
||||
public static final EcoEnchant GREEN_THUMB = new GreenThumb();
|
||||
public static final EcoEnchant SPIKED = new Spiked();
|
||||
public static final EcoEnchant HARPOON = new Harpoon();
|
||||
public static final EcoEnchant REEL = new Reel();
|
||||
public static final EcoEnchant SHOT_ASSIST = new ShotAssist();
|
||||
public static final EcoEnchant FROZEN = new Frozen();
|
||||
public static final EcoEnchant DISAPPEAR = new Disappear();
|
||||
public static final EcoEnchant HARMLESSNESS_CURSE = new HarmlessnessCurse();
|
||||
public static final EcoEnchant FURY = new Fury();
|
||||
public static final EcoEnchant LEVITATE = new Levitate();
|
||||
public static final EcoEnchant BREAKLESSNESS_CURSE = new BreaklessnessCurse();
|
||||
public static final EcoEnchant DECAY_CURSE = new DecayCurse();
|
||||
public static final EcoEnchant MISFORTUNE_CURSE = new MisfortuneCurse();
|
||||
public static final EcoEnchant VENOM = new Venom();
|
||||
public static final EcoEnchant CRANIAL = new Cranial();
|
||||
public static final EcoEnchant AQUATIC = new Aquatic();
|
||||
public static final EcoEnchant BUCKSHOT = new Buckshot();
|
||||
public static final EcoEnchant DIVERSE = new Diverse();
|
||||
public static final EcoEnchant LIFE_STEAL = new LifeSteal();
|
||||
public static final EcoEnchant LIME_ARTIFACT = new LimeArtifact();
|
||||
public static final EcoEnchant FORCE = new Force();
|
||||
public static final EcoEnchant END_INFUSION = new EndInfusion();
|
||||
public static final EcoEnchant DIURNAL = new Diurnal();
|
||||
public static final EcoEnchant MARKING = new Marking();
|
||||
public static final EcoEnchant CORROSIVE = new Corrosive();
|
||||
public static final EcoEnchant WOUND = new Wound();
|
||||
public static final EcoEnchant FINALITY = new Finality();
|
||||
public static final EcoEnchant BLIND = new Blind();
|
||||
public static final EcoEnchant SICKENING = new Sickening();
|
||||
public static final EcoEnchant DEFENDER = new Defender();
|
||||
public static final EcoEnchant NETHERIC = new Netheric();
|
||||
public static final EcoEnchant ENDERISM = new Enderism();
|
||||
public static final EcoEnchant RAGE = new Rage();
|
||||
public static final EcoEnchant IMPACT = new Impact();
|
||||
public static final EcoEnchant PARALYZE = new Paralyze();
|
||||
public static final EcoEnchant IDENTIFY = new Identify();
|
||||
public static final EcoEnchant INFURIATE = new Infuriate();
|
||||
public static final EcoEnchant ATMOSPHERIC = new Atmospheric();
|
||||
public static final EcoEnchant REVENANT = new Revenant();
|
||||
public static final EcoEnchant INSECTICIDE = new Insecticide();
|
||||
public static final EcoEnchant SLAUGHTER = new Slaughter();
|
||||
public static final EcoEnchant SETTLE = new Settle();
|
||||
public static final EcoEnchant PHANTASM = new Phantasm();
|
||||
public static final EcoEnchant ARACHNID = new Arachnid();
|
||||
public static final EcoEnchant PACIFY = new Pacify();
|
||||
public static final EcoEnchant ABATTOIR = new Abattoir();
|
||||
public static final EcoEnchant DISABLE = new Disable();
|
||||
public static final EcoEnchant HELLISH = new Hellish();
|
||||
public static final EcoEnchant VOID_AFFINITY = new VoidAffinity();
|
||||
public static final EcoEnchant CUBISM = new Cubism();
|
||||
public static final EcoEnchant QUADRILATERALISM = new Quadrilateralism();
|
||||
public static final EcoEnchant LESION = new Lesion();
|
||||
public static final EcoEnchant CONCLUDE = new Conclude();
|
||||
public static final EcoEnchant GRACEFUL = new Graceful();
|
||||
public static final EcoEnchant BLOCK_BREATHER = new BlockBreather();
|
||||
public static final EcoEnchant VOLTAGE = new Voltage();
|
||||
public static final EcoEnchant TRANSFUSE = new Transfuse();
|
||||
public static final EcoEnchant INACCURACY_CURSE = new InaccuracyCurse();
|
||||
public static final EcoEnchant RESPIRATOR = new Respirator();
|
||||
public static final EcoEnchant FETCHING = new Fetching();
|
||||
public static final EcoEnchant ECONOMICAL = new Economical();
|
||||
public static final EcoEnchant SOUL_ARTIFACT = new SoulArtifact();
|
||||
public static final EcoEnchant SOUL_FIRE_ARTIFACT = new SoulFireArtifact();
|
||||
public static final EcoEnchant CRIMSON_ARTIFACT = new CrimsonArtifact();
|
||||
public static final EcoEnchant ASH_ARTIFACT = new AshArtifact();
|
||||
public static final EcoEnchant WARPED_ARTIFACT = new WarpedArtifact();
|
||||
public static final EcoEnchant TEAR_ARTIFACT = new TearArtifact();
|
||||
public static final EcoEnchant BACKSTAB = new Backstab();
|
||||
public static final EcoEnchant DWELLER = new Dweller();
|
||||
public static final EcoEnchant STALWART = new Stalwart();
|
||||
public static final EcoEnchant PLASMIC = new Plasmic();
|
||||
public static final EcoEnchant MISSILE = new Missile();
|
||||
public static final EcoEnchant QUAKE = new Quake();
|
||||
public static final EcoEnchant VITALIZE = new Vitalize();
|
||||
public static final EcoEnchant DYNAMITE = new Dynamite();
|
||||
public static final EcoEnchant CHARGE = new Charge();
|
||||
public static final EcoEnchant ASCEND = new Ascend();
|
||||
public static final EcoEnchant ARBORIST = new Arborist();
|
||||
public static final EcoEnchant LUCKY_CATCH = new LuckyCatch();
|
||||
public static final EcoEnchant AVERSION = new Aversion();
|
||||
public static final EcoEnchant INTROVERSION = new Introversion();
|
||||
public static final EcoEnchant BARRIER_ARTIFACT = new BarrierArtifact();
|
||||
public static final EcoEnchant VILLAGER_ARTIFACT = new VillagerArtifact();
|
||||
public static final EcoEnchant ANGER_ARTIFACT = new AngerArtifact();
|
||||
public static final EcoEnchant NAUTILUS_ARTIFACT = new NautilusArtifact();
|
||||
public static final EcoEnchant SWEEP_ARTIFACT = new SweepArtifact();
|
||||
public static final EcoEnchant REAPER = new Reaper();
|
||||
public static final EcoEnchant WOOD_SWITCHER = new WoodSwitcher();
|
||||
public static final EcoEnchant REBOUNDING = new Rebounding();
|
||||
|
||||
/**
|
||||
* Get all registered {@link EcoEnchant}s.
|
||||
*
|
||||
* @return A list of all {@link EcoEnchant}s.
|
||||
*/
|
||||
public static List<EcoEnchant> values() {
|
||||
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.
|
||||
*/
|
||||
public static EcoEnchant getFromEnchantment(@NotNull final Enchantment enchantment) {
|
||||
return getByKey(enchantment.getKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link EcoEnchant} matching display name.
|
||||
*
|
||||
* @param name The display name to search for.
|
||||
* @return The matching {@link EcoEnchant}, or null if not found.
|
||||
*/
|
||||
public static EcoEnchant getByName(@NotNull final String name) {
|
||||
return BY_NAME.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link EcoEnchant} matching permission name.
|
||||
*
|
||||
* @param permissionName The permission name to search for.
|
||||
* @return The matching {@link EcoEnchant}, or null if not found.
|
||||
*/
|
||||
public static EcoEnchant getByPermission(@NotNull final String permissionName) {
|
||||
Optional<EcoEnchant> matching = values().stream().filter(enchant -> enchant.getPermissionName().equalsIgnoreCase(permissionName)).findFirst();
|
||||
return matching.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link EcoEnchant} matching key.
|
||||
*
|
||||
* @param key The NamespacedKey to search for.
|
||||
* @return The matching {@link EcoEnchant}, or null if not found.
|
||||
*/
|
||||
public static EcoEnchant getByKey(@NotNull final NamespacedKey key) {
|
||||
return BY_KEY.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if {@link ItemStack} has any {@link EcoEnchant} matching specified {@link EnchantmentType}.
|
||||
*
|
||||
* @param item The {@link ItemStack} to check.
|
||||
* @param type The {@link EnchantmentType} to match.
|
||||
* @return True if has, false if doesn't have.
|
||||
*/
|
||||
public static boolean hasAnyOfType(@NotNull final ItemStack item,
|
||||
@NotNull final EnchantmentType type) {
|
||||
AtomicBoolean hasOfType = new AtomicBoolean(false);
|
||||
|
||||
if (item.getItemMeta() instanceof EnchantmentStorageMeta) {
|
||||
((EnchantmentStorageMeta) item.getItemMeta()).getStoredEnchants().forEach(((enchantment, integer) -> {
|
||||
if (getFromEnchantment(enchantment) != null && getFromEnchantment(enchantment).getType().equals(type)) {
|
||||
hasOfType.set(true);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
item.getEnchantments().forEach((enchantment, integer) -> {
|
||||
if (getFromEnchantment(enchantment) != null && (getFromEnchantment(enchantment).getType().equals(type))) {
|
||||
hasOfType.set(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
return hasOfType.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all {@link EcoEnchant}s.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
for (EcoEnchant ecoEnchant : new HashSet<>(values())) {
|
||||
ecoEnchant.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new {@link EcoEnchant} to EcoEnchants.
|
||||
* <p>
|
||||
* Only for internal use, enchantments are automatically added in the constructor.
|
||||
*
|
||||
* @param enchant The {@link EcoEnchant} to add.
|
||||
*/
|
||||
public static void addNewEcoEnchant(@NotNull final EcoEnchant enchant) {
|
||||
BY_KEY.remove(enchant.getKey());
|
||||
BY_NAME.inverse().remove(enchant);
|
||||
BY_KEY.put(enchant.getKey(), enchant);
|
||||
BY_NAME.put(enchant.getName(), enchant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove {@link EcoEnchant} from EcoEnchants.
|
||||
*
|
||||
* @param enchant The {@link EcoEnchant} to remove.
|
||||
*/
|
||||
public static void removeEcoEnchant(@NotNull final EcoEnchant enchant) {
|
||||
BY_KEY.remove(enchant.getKey());
|
||||
BY_NAME.inverse().remove(enchant);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AngerArtifact extends Artifact {
|
||||
public AngerArtifact() {
|
||||
super(
|
||||
"anger_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.VILLAGER_ANGRY;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AshArtifact extends Artifact {
|
||||
public AshArtifact() {
|
||||
super(
|
||||
"ash_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.WHITE_ASH;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BarrierArtifact extends Artifact {
|
||||
public BarrierArtifact() {
|
||||
super(
|
||||
"barrier_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.BARRIER;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CloudsArtifact extends Artifact {
|
||||
public CloudsArtifact() {
|
||||
super(
|
||||
"clouds_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.REDSTONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.AQUA, 1.0f);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CrimsonArtifact extends Artifact {
|
||||
public CrimsonArtifact() {
|
||||
super(
|
||||
"crimson_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.CRIMSON_SPORE;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DamageArtifact extends Artifact {
|
||||
public DamageArtifact() {
|
||||
super(
|
||||
"damage_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.DAMAGE_INDICATOR;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DragonArtifact extends Artifact {
|
||||
public DragonArtifact() {
|
||||
super(
|
||||
"dragon_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.DRAGON_BREATH;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DustArtifact extends Artifact {
|
||||
public DustArtifact() {
|
||||
super(
|
||||
"dust_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.CRIT;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EmeraldArtifact extends Artifact {
|
||||
public EmeraldArtifact() {
|
||||
super(
|
||||
"emerald_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.COMPOSTER;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EnchantmentArtifact extends Artifact {
|
||||
public EnchantmentArtifact() {
|
||||
super(
|
||||
"enchantment_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.ENCHANTMENT_TABLE;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EndArtifact extends Artifact {
|
||||
public EndArtifact() {
|
||||
super(
|
||||
"end_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.END_ROD;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FireArtifact extends Artifact {
|
||||
public FireArtifact() {
|
||||
super(
|
||||
"fire_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.FLAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HeartArtifact extends Artifact {
|
||||
public HeartArtifact() {
|
||||
super(
|
||||
"heart_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.HEART;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HoneyArtifact extends Artifact {
|
||||
public HoneyArtifact() {
|
||||
super(
|
||||
"honey_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.FALLING_HONEY;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InkArtifact extends Artifact {
|
||||
public InkArtifact() {
|
||||
super(
|
||||
"ink_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.SQUID_INK;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LavaArtifact extends Artifact {
|
||||
public LavaArtifact() {
|
||||
super(
|
||||
"lava_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.DRIP_LAVA;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LimeArtifact extends Artifact {
|
||||
public LimeArtifact() {
|
||||
super(
|
||||
"lime_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.REDSTONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.fromRGB(3, 252, 140), 1.0f);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MagicArtifact extends Artifact {
|
||||
public MagicArtifact() {
|
||||
super(
|
||||
"magic_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.CRIT_MAGIC;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MagmaArtifact extends Artifact {
|
||||
public MagmaArtifact() {
|
||||
super(
|
||||
"magma_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.LAVA;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MusicArtifact extends Artifact {
|
||||
public MusicArtifact() {
|
||||
super(
|
||||
"music_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.NOTE;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NautilusArtifact extends Artifact {
|
||||
public NautilusArtifact() {
|
||||
super(
|
||||
"nautilus_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.NAUTILUS;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class NetherArtifact extends Artifact {
|
||||
public NetherArtifact() {
|
||||
super(
|
||||
"nether_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.PORTAL;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RedstoneArtifact extends Artifact {
|
||||
public RedstoneArtifact() {
|
||||
super(
|
||||
"redstone_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.REDSTONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.RED, 1.0f);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SmokeArtifact extends Artifact {
|
||||
public SmokeArtifact() {
|
||||
super(
|
||||
"smoke_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.CAMPFIRE_COSY_SMOKE;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SnowArtifact extends Artifact {
|
||||
public SnowArtifact() {
|
||||
super(
|
||||
"snow_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.SNOWBALL;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SoulArtifact extends Artifact {
|
||||
public SoulArtifact() {
|
||||
super(
|
||||
"soul_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.SOUL;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SoulFireArtifact extends Artifact {
|
||||
public SoulFireArtifact() {
|
||||
super(
|
||||
"soul_fire_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.SOUL_FIRE_FLAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SparkleArtifact extends Artifact {
|
||||
public SparkleArtifact() {
|
||||
super(
|
||||
"sparkle_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.FIREWORKS_SPARK;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SweepArtifact extends Artifact {
|
||||
public SweepArtifact() {
|
||||
super(
|
||||
"sweep_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.SWEEP_ATTACK;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TearArtifact extends Artifact {
|
||||
public TearArtifact() {
|
||||
super(
|
||||
"tear_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.DRIPPING_OBSIDIAN_TEAR;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TotemArtifact extends Artifact {
|
||||
public TotemArtifact() {
|
||||
super(
|
||||
"totem_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.TOTEM;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class VillagerArtifact extends Artifact {
|
||||
public VillagerArtifact() {
|
||||
super(
|
||||
"villager_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.VILLAGER_HAPPY;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WarpedArtifact extends Artifact {
|
||||
public WarpedArtifact() {
|
||||
super(
|
||||
"warped_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.WARPED_SPORE;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WaterArtifact extends Artifact {
|
||||
public WaterArtifact() {
|
||||
super(
|
||||
"water_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.DRIP_WATER;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WitchArtifact extends Artifact {
|
||||
public WitchArtifact() {
|
||||
super(
|
||||
"witch_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.SPELL_WITCH;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ZapArtifact extends Artifact {
|
||||
public ZapArtifact() {
|
||||
super(
|
||||
"zap_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Particle getParticle() {
|
||||
return Particle.REDSTONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.YELLOW, 1.0f);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BreaklessnessCurse extends EcoEnchant {
|
||||
public BreaklessnessCurse() {
|
||||
super(
|
||||
"breaklessness_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDamageBlock(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockDamageEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.eco.core.events.ArmorEquipEvent;
|
||||
import com.willfp.eco.util.VectorUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.enchantments.util.TimedRunnable;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.PigZombie;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CallingCurse extends EcoEnchant implements TimedRunnable {
|
||||
private final HashMap<Player, Integer> players = new HashMap<>();
|
||||
private double distance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance");
|
||||
|
||||
public CallingCurse() {
|
||||
super(
|
||||
"calling_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(@NotNull final ArmorEquipEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(@NotNull final PlayerJoinEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(@NotNull final PlayerQuitEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
players.clear();
|
||||
this.getPlugin().getScheduler().runLater(() -> this.getPlugin().getServer().getOnlinePlayers().forEach(player -> {
|
||||
int level = EnchantChecks.getArmorPoints(player, this, 0);
|
||||
if (level > 0) {
|
||||
players.put(player, level);
|
||||
}
|
||||
}), 1);
|
||||
|
||||
distance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
players.forEach((player, level) -> {
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entity e : player.getWorld().getNearbyEntities(player.getLocation(), distance, distance, distance)) {
|
||||
if (!(e instanceof Monster)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (e instanceof PigZombie) {
|
||||
((PigZombie) e).setAngry(true);
|
||||
}
|
||||
|
||||
((Monster) e).setTarget(player);
|
||||
|
||||
Vector vector = player.getLocation().toVector().clone().subtract(e.getLocation().toVector()).normalize().multiply(0.23d);
|
||||
|
||||
if (VectorUtils.isFinite(vector)) {
|
||||
e.setVelocity(vector);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTime() {
|
||||
return this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "repeat-ticks");
|
||||
}
|
||||
}
|
@ -0,0 +1,120 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.eco.util.DurabilityUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.enchantments.util.TimedRunnable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDropItemEvent;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Repairable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DecayCurse extends EcoEnchant implements TimedRunnable {
|
||||
private final Set<Player> players = new HashSet<>();
|
||||
private int amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
public DecayCurse() {
|
||||
super(
|
||||
"decay_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemPickup(@NotNull final EntityPickupItemEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
refreshPlayer((Player) event.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(@NotNull final PlayerJoinEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(@NotNull final PlayerQuitEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryDrop(@NotNull final EntityDropItemEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
refreshPlayer((Player) event.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(@NotNull final InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
refreshPlayer((Player) event.getWhoClicked());
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
players.clear();
|
||||
this.getPlugin().getScheduler().runLater(() -> this.getPlugin().getServer().getOnlinePlayers().forEach(player -> {
|
||||
if (Arrays.stream(player.getInventory().getContents()).parallel().anyMatch(item -> EnchantChecks.item(item, this))) {
|
||||
players.add(player);
|
||||
}
|
||||
}), 1);
|
||||
amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
}
|
||||
|
||||
private void refreshPlayer(@NotNull final Player player) {
|
||||
players.remove(player);
|
||||
if (Arrays.stream(player.getInventory().getContents()).parallel().anyMatch(item -> EnchantChecks.item(item, this))) {
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
players.forEach((player -> {
|
||||
for (ItemStack item : player.getInventory().getContents()) {
|
||||
int level = EnchantChecks.getItemLevel(item, this);
|
||||
if (level == 0) {
|
||||
continue;
|
||||
}
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(item.getItemMeta() instanceof Repairable)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (player.getInventory().getItemInMainHand().equals(item)) {
|
||||
continue;
|
||||
}
|
||||
if (player.getInventory().getItemInOffHand().equals(item)) {
|
||||
continue;
|
||||
}
|
||||
if (player.getItemOnCursor().equals(item)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
DurabilityUtils.damageItemNoBreak(item, amount, player);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTime() {
|
||||
return this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "repeat-ticks");
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FragilityCurse extends EcoEnchant {
|
||||
public FragilityCurse() {
|
||||
super(
|
||||
"fragility_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemDamage(@NotNull final PlayerItemDamageEvent event) {
|
||||
ItemStack item = event.getItem();
|
||||
|
||||
if (!EnchantChecks.item(item, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(event.getPlayer().getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int min = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "minimum-extra-durability");
|
||||
int max = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "maximum-extra-durability");
|
||||
|
||||
event.setDamage(event.getDamage() * NumberUtils.randInt(min, max));
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HarmlessnessCurse extends EcoEnchant {
|
||||
public HarmlessnessCurse() {
|
||||
super(
|
||||
"harmlessness_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDamage(0);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class HungerCurse extends EcoEnchant {
|
||||
public HungerCurse() {
|
||||
super(
|
||||
"hunger_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHunger(@NotNull final FoodLevelChangeEvent event) {
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getEntity();
|
||||
|
||||
if (!EnchantChecks.helmet(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getFoodLevel() > player.getFoodLevel()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
int delta = player.getFoodLevel() - event.getFoodLevel();
|
||||
delta *= this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "times-more-hunger");
|
||||
|
||||
event.setFoodLevel(player.getFoodLevel() - delta);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.eco.util.NumberUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InaccuracyCurse extends EcoEnchant {
|
||||
public InaccuracyCurse() {
|
||||
super(
|
||||
"inaccuracy_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBowShoot(@NotNull final LivingEntity shooter,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityShootBowEvent event) {
|
||||
double spread = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "spread");
|
||||
|
||||
Vector velocity = event.getProjectile().getVelocity().clone();
|
||||
|
||||
velocity.add(new Vector(NumberUtils.randFloat(-spread, spread), NumberUtils.randFloat(-spread, spread), NumberUtils.randFloat(-spread, spread)));
|
||||
event.getProjectile().setVelocity(velocity);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisfortuneCurse extends EcoEnchant {
|
||||
public MisfortuneCurse() {
|
||||
super(
|
||||
"misfortune_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDropItems(false);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
|
||||
public class PermanenceCurse extends EcoEnchant {
|
||||
public PermanenceCurse() {
|
||||
super(
|
||||
"permanence_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
// Listeners are in anvil listeners
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Abattoir extends EcoEnchant {
|
||||
public Abattoir() {
|
||||
super(
|
||||
"abattoir", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (victim instanceof Monster) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (victim instanceof Player) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double bonus = (multiplier * (level + 1)) + 1;
|
||||
event.setDamage(damage * bonus);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.util.DurabilityUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Abrasion extends EcoEnchant {
|
||||
public Abrasion() {
|
||||
super(
|
||||
"abrasion", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity uncastVictim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(uncastVictim instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player victim = (Player) uncastVictim;
|
||||
|
||||
if (!EnchantmentUtils.isFullyChargeIfRequired(this, attacker)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<ItemStack> armor = new ArrayList<>(Arrays.asList(victim.getInventory().getArmorContents()));
|
||||
if (armor.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (ItemStack armorPiece : armor) {
|
||||
if (armorPiece == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (armorPiece.equals(victim.getInventory().getHelmet())) {
|
||||
DurabilityUtils.damageItem(victim, victim.getInventory().getHelmet(), level, 39);
|
||||
}
|
||||
if (armorPiece.equals(victim.getInventory().getChestplate())) {
|
||||
DurabilityUtils.damageItem(victim, victim.getInventory().getChestplate(), level, 38);
|
||||
}
|
||||
if (armorPiece.equals(victim.getInventory().getLeggings())) {
|
||||
DurabilityUtils.damageItem(victim, victim.getInventory().getLeggings(), level, 37);
|
||||
}
|
||||
if (armorPiece.equals(victim.getInventory().getBoots())) {
|
||||
DurabilityUtils.damageItem(victim, victim.getInventory().getBoots(), level, 36);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Aerial extends EcoEnchant {
|
||||
public Aerial() {
|
||||
super(
|
||||
"aerial", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBowShoot(@NotNull final LivingEntity shooter,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityShootBowEvent event) {
|
||||
if (!(event.getProjectile() instanceof Arrow)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shooter.isOnGround()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getProjectile().setMetadata("shot-in-air", this.getPlugin().getMetadataValueFactory().create(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Arrow arrow,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!arrow.hasMetadata("shot-in-air")) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double bonus = 1 + (multiplier * level);
|
||||
event.setDamage(damage * bonus);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Aquatic extends EcoEnchant {
|
||||
public Aquatic() {
|
||||
super(
|
||||
"aquatic", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!attacker.getLocation().getBlock().getType().equals(Material.WATER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double reduction = 1 + (multiplier * level);
|
||||
event.setDamage(damage * reduction);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Spider;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Arachnid extends EcoEnchant {
|
||||
public Arachnid() {
|
||||
super(
|
||||
"arachnid", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!(victim instanceof Spider)) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double bonus = (multiplier * (level + 1)) + 1;
|
||||
event.setDamage(damage * bonus);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.core.drops.DropQueue;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class Arborist extends EcoEnchant {
|
||||
public Arborist() {
|
||||
super(
|
||||
"arborist", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Tag.LEAVES.isTagged(block.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setDropItems(false);
|
||||
|
||||
Material toDrop;
|
||||
|
||||
List<Material> materials = new ArrayList<>();
|
||||
|
||||
for (String materialName : this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "items")) {
|
||||
Material material = Material.getMaterial(materialName.toUpperCase());
|
||||
if (material != null) {
|
||||
materials.add(material);
|
||||
}
|
||||
}
|
||||
|
||||
toDrop = materials.get(new Random().nextInt(materials.size()));
|
||||
|
||||
if (toDrop == null) {
|
||||
toDrop = block.getType();
|
||||
}
|
||||
|
||||
ItemStack item = new ItemStack(toDrop, 1);
|
||||
|
||||
new DropQueue(player)
|
||||
.setLocation(block.getLocation())
|
||||
.addItem(item)
|
||||
.push();
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Arcanic extends EcoEnchant {
|
||||
public Arcanic() {
|
||||
super(
|
||||
"arcanic", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDamageWearingArmor(@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageEvent event) {
|
||||
if (!(event.getCause().equals(EntityDamageEvent.DamageCause.POISON) || event.getCause().equals(EntityDamageEvent.DamageCause.WITHER))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Atmospheric extends EcoEnchant {
|
||||
public Atmospheric() {
|
||||
super(
|
||||
"atmospheric", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentLaunch(@NotNull final LivingEntity shooter,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final ProjectileLaunchEvent event) {
|
||||
if (shooter.isOnGround()) {
|
||||
return;
|
||||
}
|
||||
|
||||
trident.setMetadata("shot-in-air", this.getPlugin().getMetadataValueFactory().create(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
@NotNull final Trident trident,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
if (!trident.hasMetadata("shot-in-air")) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double bonus = 1 + (multiplier * level);
|
||||
event.setDamage(damage * bonus);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Aversion extends EcoEnchant {
|
||||
public Aversion() {
|
||||
super(
|
||||
"aversion", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEndermanTarget(@NotNull final EntityTargetLivingEntityEvent event) {
|
||||
if (!(event.getEntity() instanceof Enderman)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Enderman enderman = (Enderman) event.getEntity();
|
||||
LivingEntity target = event.getTarget();
|
||||
|
||||
if (event.getReason() != EntityTargetEvent.TargetReason.CLOSEST_PLAYER) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getHelmetLevel(target, this);
|
||||
|
||||
if (level == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(target.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Backstab extends EcoEnchant {
|
||||
public Backstab() {
|
||||
super(
|
||||
"backstab", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(@NotNull final LivingEntity attacker,
|
||||
@NotNull final LivingEntity victim,
|
||||
final int level,
|
||||
@NotNull final EntityDamageByEntityEvent event) {
|
||||
Vector pDir = attacker.getLocation().getDirection();
|
||||
Vector eDir = victim.getLocation().getDirection();
|
||||
double xv = pDir.getX() * eDir.getZ() - pDir.getZ() * eDir.getX();
|
||||
double zv = pDir.getX() * eDir.getX() + pDir.getZ() * eDir.getZ();
|
||||
double angle = Math.atan2(xv, zv); // Value between -π and +π
|
||||
double angleInDegrees = (angle * 180) / Math.PI;
|
||||
|
||||
if (angleInDegrees > 60 || angleInDegrees < -32) {
|
||||
return;
|
||||
}
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double bonus = 1 + (multiplier * level);
|
||||
event.setDamage(damage * bonus);
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.core.drops.DropQueue;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Beheading extends EcoEnchant {
|
||||
public Beheading() {
|
||||
super(
|
||||
"beheading", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(@NotNull final EntityDeathEvent event) {
|
||||
if (event.getEntity().getKiller() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getEntity().getKiller();
|
||||
|
||||
LivingEntity victim = event.getEntity();
|
||||
|
||||
if (!EnchantChecks.mainhand(player, this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
int level = EnchantChecks.getMainhandLevel(player, this);
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.getDisabledWorlds().contains(player.getWorld())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack item;
|
||||
|
||||
if (victim instanceof Player) {
|
||||
item = new ItemStack(Material.PLAYER_HEAD, 1);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setOwningPlayer((Player) victim);
|
||||
item.setItemMeta(meta);
|
||||
} else {
|
||||
if (event.getEntityType().equals(EntityType.ZOMBIE)) {
|
||||
item = new ItemStack(Material.ZOMBIE_HEAD, 1);
|
||||
} else if (event.getEntityType().equals(EntityType.SKELETON)) {
|
||||
item = new ItemStack(Material.SKELETON_SKULL, 1);
|
||||
} else if (event.getEntityType().equals(EntityType.CREEPER)) {
|
||||
item = new ItemStack(Material.CREEPER_HEAD, 1);
|
||||
} else if (event.getEntityType().equals(EntityType.ENDER_DRAGON)) {
|
||||
item = new ItemStack(Material.DRAGON_HEAD, 1);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
new DropQueue(player)
|
||||
.addItem(item)
|
||||
.addXP(event.getDroppedExp())
|
||||
.setLocation(victim.getLocation())
|
||||
.push();
|
||||
|
||||
event.setDroppedExp(0);
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.eco.core.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.eco.core.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.eco.util.BlockUtils;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class BlastMining extends EcoEnchant {
|
||||
public BlastMining() {
|
||||
super(
|
||||
"blast_mining", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(@NotNull final Player player,
|
||||
@NotNull final Block block,
|
||||
final int level,
|
||||
@NotNull final BlockBreakEvent event) {
|
||||
if (block.hasMetadata("block-ignore")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.isSneaking() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "disable-on-sneak")) {
|
||||
return;
|
||||
}
|
||||
|
||||
AnticheatManager.exemptPlayer(player);
|
||||
|
||||
Set<Block> toBreak = new HashSet<>();
|
||||
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int y = -1; y <= 1; y++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
if (x == 0 && y == 0 && z == 0) {
|
||||
if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "enable-sound")) {
|
||||
block.getWorld().createExplosion(block.getLocation().clone().add(0.5, 0.5, 0.5), 0, false);
|
||||
} else {
|
||||
block.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, block.getLocation().clone().add(0.5, 0.5, 0.5), 1);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Block block1 = block.getWorld().getBlockAt(block.getLocation().clone().add(x, y, z));
|
||||
|
||||
if (this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blacklisted-blocks").contains(block1.getType().name().toLowerCase())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (block1.getType().getHardness() > block.getType().getHardness() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "hardness-check")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!AntigriefManager.canBreakBlock(player, block1)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
toBreak.add(block1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toBreak.forEach((block1 -> {
|
||||
block1.setMetadata("block-ignore", this.getPlugin().getMetadataValueFactory().create(true));
|
||||
BlockUtils.breakBlock(player, block1);
|
||||
block1.removeMetadata("block-ignore", this.getPlugin());
|
||||
}));
|
||||
|
||||
AnticheatManager.unexemptPlayer(player);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user