mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-25 20:17:38 +01:00
Continued overhaul
This commit is contained in:
parent
52b6744c0d
commit
1f4b54daca
@ -1,64 +0,0 @@
|
||||
package com.willfp.ecoenchants;
|
||||
|
||||
import com.willfp.ecoenchants.extensions.loader.EcoExtensionLoader;
|
||||
import com.willfp.ecoenchants.extensions.loader.ExtensionLoader;
|
||||
import com.willfp.ecoenchants.util.internal.Loader;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* The Main class for EcoEnchants
|
||||
*/
|
||||
public class EcoEnchantsPlugin extends JavaPlugin {
|
||||
/**
|
||||
* Instance of EcoEnchants
|
||||
*/
|
||||
private static EcoEnchantsPlugin instance;
|
||||
|
||||
/**
|
||||
* Extension loader
|
||||
*/
|
||||
private final ExtensionLoader loader = new EcoExtensionLoader();
|
||||
|
||||
/**
|
||||
* NMS version
|
||||
*/
|
||||
public static final String NMS_VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
/**
|
||||
* Calls {@link Loader#load()}
|
||||
*/
|
||||
public void onEnable() {
|
||||
Loader.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link Loader#unload()}
|
||||
*/
|
||||
public void onDisable() {
|
||||
Loader.unload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets instance
|
||||
*/
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension loader
|
||||
* @return The {@link ExtensionLoader} attached to EcoEnchants
|
||||
*/
|
||||
public ExtensionLoader getExtensionLoader() {
|
||||
return loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin instance
|
||||
* @return Plugin instance
|
||||
*/
|
||||
public static EcoEnchantsPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.willfp.ecoenchants.command;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.util.interfaces.Registerable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand implements CommandExecutor, Registerable {
|
||||
private final String name;
|
||||
private final String permission;
|
||||
private final boolean playersOnly;
|
||||
|
||||
protected AbstractCommand(String name, String permission, boolean playersOnly) {
|
||||
this.name = name;
|
||||
this.permission = permission;
|
||||
this.playersOnly = playersOnly;
|
||||
}
|
||||
|
||||
public AbstractTabCompleter getTab() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, Command command, @NotNull String label, String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase(name)) return false;
|
||||
|
||||
if (playersOnly && !(sender instanceof Player)) {
|
||||
sender.sendMessage(ConfigManager.getLang().getMessage("not-player"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(permission) && sender instanceof Player) {
|
||||
sender.sendMessage(ConfigManager.getLang().getNoPermission());
|
||||
return true;
|
||||
}
|
||||
|
||||
onExecute(sender, Arrays.asList(args));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void register() {
|
||||
PluginCommand command = Bukkit.getPluginCommand(name);
|
||||
assert command != null;
|
||||
command.setExecutor(this);
|
||||
|
||||
AbstractTabCompleter tabCompleter = this.getTab();
|
||||
if (tabCompleter != null) {
|
||||
command.setTabCompleter(tabCompleter);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void onExecute(CommandSender sender, List<String> args);
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.willfp.ecoenchants.command;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractTabCompleter implements TabCompleter {
|
||||
private final AbstractCommand command;
|
||||
|
||||
protected AbstractTabCompleter(AbstractCommand command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (!command.getName().equalsIgnoreCase(this.command.getName()))
|
||||
return null;
|
||||
|
||||
if (!sender.hasPermission(this.command.getPermission()))
|
||||
return null;
|
||||
|
||||
return onTab(sender, Arrays.asList(args));
|
||||
}
|
||||
|
||||
public abstract List<String> onTab(CommandSender sender, List<String> args);
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.command.AbstractCommand;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.util.internal.Logger;
|
||||
import com.willfp.ecoenchants.util.internal.drops.FastCollatedDropQueue;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
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 {
|
||||
public CommandEcodebug() {
|
||||
super("ecodebug", "ecoenchants.ecodebug", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(CommandSender sender, List<String> args) {
|
||||
Logger.info("--------------- BEGIN DEBUG ----------------");
|
||||
if (sender instanceof Player) {
|
||||
Player player = (Player) sender;
|
||||
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand().toString());
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("Held Item: " + player.getInventory().getItemInMainHand().toString());
|
||||
Logger.info("");
|
||||
}
|
||||
|
||||
Logger.info("Running Version: " + EcoEnchantsPlugin.getInstance().getDescription().getVersion());
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("Loaded Extensions: " + EcoEnchantsPlugin.getInstance().getExtensionLoader().getLoadedExtensions().stream().map(extension -> extension.getName() + " v" + extension.getVersion()).collect(Collectors.joining()));
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("EcoEnchants.getAll(): " + EcoEnchants.getAll().toString());
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("Enchantment.values(): " + Arrays.toString(Enchantment.values()));
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("Enchantment Cache: " + EnchantmentCache.getCache().toString());
|
||||
Logger.info("");
|
||||
|
||||
try {
|
||||
Field byNameField = Enchantment.class.getDeclaredField("byName");
|
||||
byNameField.setAccessible(true);
|
||||
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
|
||||
Logger.info("Enchantment.byName: " + byName.toString());
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Logger.info("");
|
||||
|
||||
|
||||
List<Enchantment> extern = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
|
||||
extern.removeAll(EcoEnchants.getAll().stream().map(EcoEnchant::getEnchantment).collect(Collectors.toList()));
|
||||
Logger.info("External/Vanilla Enchantments: " + extern.toString());
|
||||
Logger.info("");
|
||||
|
||||
List<Enchantment> uncached = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
|
||||
uncached.removeAll(EnchantmentCache.getCache().stream().map(EnchantmentCache.CacheEntry::getEnchantment).collect(Collectors.toList()));
|
||||
Logger.info("Uncached Enchantments: " + uncached.toString());
|
||||
Logger.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")));
|
||||
Logger.info("Enchantments with broken cache: " + brokenCache.toString());
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("Installed Plugins: " + Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList()).toString());
|
||||
Logger.info("");
|
||||
|
||||
Set<EcoEnchant> withIssues = new HashSet<>();
|
||||
EcoEnchants.getAll().forEach(enchant -> {
|
||||
if (enchant.getRarity() == null) withIssues.add(enchant);
|
||||
if (enchant.getRawTargets().isEmpty()) withIssues.add(enchant);
|
||||
});
|
||||
Logger.info("Enchantments with evident issues: " + withIssues.toString());
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("Collate? " + FastCollatedDropQueue.use());
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("Packets: " + ProtocolLibrary.getProtocolManager().getPacketListeners().stream().filter(packetListener -> packetListener.getSendingWhitelist().getPriority().equals(ListenerPriority.MONITOR)).collect(Collectors.toList()).toString());
|
||||
Logger.info("");
|
||||
|
||||
Logger.info("Server Information: ");
|
||||
Logger.info("Players Online: " + Bukkit.getServer().getOnlinePlayers().size());
|
||||
Logger.info("Bukkit IP: " + Bukkit.getIp());
|
||||
Logger.info("Running Version: " + Bukkit.getVersion() + ", Bukkit Version: " + Bukkit.getBukkitVersion() + ", Alt Version: " + Bukkit.getServer().getVersion() + ", NMS: " + EcoEnchantsPlugin.NMS_VERSION);
|
||||
Logger.info("Motd: " + Bukkit.getServer().getMotd());
|
||||
Logger.info("--------------- END DEBUG ----------------");
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.willfp.ecoenchants.command.AbstractCommand;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.util.internal.Loader;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandEcoreload extends AbstractCommand {
|
||||
public CommandEcoreload() {
|
||||
super("ecoreload", "ecoenchants.reload", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(CommandSender sender, List<String> args) {
|
||||
Loader.reload();
|
||||
sender.sendMessage(ConfigManager.getLang().getMessage("reloaded"));
|
||||
}
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
package com.willfp.ecoenchants.command.commands;
|
||||
|
||||
import com.willfp.ecoenchants.command.AbstractCommand;
|
||||
import com.willfp.ecoenchants.command.AbstractTabCompleter;
|
||||
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.util.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CommandEnchantinfo extends AbstractCommand {
|
||||
public CommandEnchantinfo() {
|
||||
super("enchantinfo", "ecoenchants.enchantinfo", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractTabCompleter getTab() {
|
||||
return new TabCompleterEnchantinfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(CommandSender sender, List<String> args) {
|
||||
if (args.size() == 0) {
|
||||
sender.sendMessage(ConfigManager.getLang().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 || !enchantment.isEnabled()) {
|
||||
String message = ConfigManager.getLang().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 -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment1) != null) {
|
||||
if (!EcoEnchants.getFromEnchantment(enchantment1).isEnabled())
|
||||
conflicts.remove(enchantment1);
|
||||
}
|
||||
});
|
||||
|
||||
conflicts.forEach((enchantment1 -> {
|
||||
if (EcoEnchants.getFromEnchantment(enchantment1) != null) {
|
||||
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getName());
|
||||
} else {
|
||||
conflictNames.add(ConfigManager.getLang().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(ConfigManager.getLang().getString("no-conflicts"));
|
||||
}
|
||||
|
||||
Set<Material> targets = enchantment.getTarget();
|
||||
|
||||
Set<String> applicableItemsSet = new HashSet<>();
|
||||
|
||||
if (ConfigManager.getConfig().getBool("commands.enchantinfo.show-target-group")) {
|
||||
enchantment.getRawTargets().forEach(target -> {
|
||||
String targetName = target.getName();
|
||||
targetName = targetName.toLowerCase();
|
||||
targetName = targetName.replaceAll("_", " ");
|
||||
targetName = WordUtils.capitalize(targetName);
|
||||
applicableItemsSet.add(targetName);
|
||||
});
|
||||
} else {
|
||||
targets.forEach(material -> {
|
||||
String matName = material.toString();
|
||||
matName = matName.toLowerCase();
|
||||
matName = matName.replaceAll("_", " ");
|
||||
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(ConfigManager.getLang().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(ConfigManager.getLang().getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> {
|
||||
string = string.replaceAll("%name%", finalName)
|
||||
.replaceAll("%description%", finalDescription)
|
||||
.replaceAll("%target%", finalTargets)
|
||||
.replaceAll("%conflicts%", finalConflicts)
|
||||
.replaceAll("%maxlevel%", finalMaxLevel);
|
||||
sender.sendMessage(string);
|
||||
}));
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.willfp.ecoenchants.command.tabcompleters;
|
||||
|
||||
import com.willfp.ecoenchants.command.AbstractCommand;
|
||||
import com.willfp.ecoenchants.command.AbstractTabCompleter;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.util.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TabCompleterEnchantinfo extends AbstractTabCompleter {
|
||||
private static final List<String> enchantsNames = EcoEnchants.getAll().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList());
|
||||
|
||||
public TabCompleterEnchantinfo() {
|
||||
super((AbstractCommand) Bukkit.getPluginCommand("enchantinfo").getExecutor());
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
enchantsNames.clear();
|
||||
enchantsNames.addAll(EcoEnchants.getAll().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getName).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTab(CommandSender sender, List<String> args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
|
||||
if (args.size() == 0) {
|
||||
// Currently, this case is not ever reached
|
||||
return enchantsNames;
|
||||
}
|
||||
|
||||
StringUtil.copyPartialMatches(String.join(" ", args), enchantsNames, 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;
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.ecoenchants.config.configs.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConfigManager {
|
||||
private static final Lang LANG = new Lang();
|
||||
private static final Config CONFIG = new Config();
|
||||
private static final Target TARGET = new Target();
|
||||
private static final Rarity RARITY = new Rarity();
|
||||
private static final Set<EnchantmentConfig> enchantmentConfigs = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Update all configs
|
||||
* Called on /ecoreload
|
||||
*/
|
||||
public static void updateConfigs() {
|
||||
LANG.update();
|
||||
CONFIG.update();
|
||||
TARGET.update();
|
||||
RARITY.update();
|
||||
updateEnchantmentConfigs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update enchantment configs
|
||||
*/
|
||||
public static void updateEnchantmentConfigs() {
|
||||
enchantmentConfigs.forEach((EnchantmentYamlConfig::update));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all enchantment configs
|
||||
*
|
||||
* @return Set of all enchantment configs
|
||||
*/
|
||||
public static Set<EnchantmentConfig> getEnchantmentConfigs() {
|
||||
return enchantmentConfigs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EnchantmentConfig matching permission name
|
||||
*
|
||||
* @param permissionName The permission name to match
|
||||
*
|
||||
* @return The matching {@link EnchantmentConfig}
|
||||
*/
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
public static EnchantmentConfig getEnchantmentConfig(String permissionName) {
|
||||
return enchantmentConfigs.stream().filter(config -> config.getName().equalsIgnoreCase(permissionName)).findFirst().get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new enchantment config yml
|
||||
*
|
||||
* @param config The config to add
|
||||
*/
|
||||
public static void addEnchantmentConfig(EnchantmentConfig config) {
|
||||
enchantmentConfigs.add(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lang.yml
|
||||
*
|
||||
* @return lang.yml
|
||||
*/
|
||||
public static Lang getLang() {
|
||||
return LANG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config.yml
|
||||
*
|
||||
* @return config.yml
|
||||
*/
|
||||
public static Config getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target.yml
|
||||
*
|
||||
* @return target.yml
|
||||
*/
|
||||
public static Target getTarget() {
|
||||
return TARGET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rarity.yml
|
||||
*
|
||||
* @return rarity.yml
|
||||
*/
|
||||
public static Rarity getRarity() {
|
||||
return RARITY;
|
||||
}
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* Class implemented by enchantment configs
|
||||
*/
|
||||
public abstract class EnchantmentYamlConfig {
|
||||
|
||||
private final String name;
|
||||
public YamlConfiguration config;
|
||||
protected File configFile;
|
||||
private final File directory;
|
||||
private final Class<?> source;
|
||||
private final EcoEnchant.EnchantmentType type;
|
||||
|
||||
/**
|
||||
* Create new config yml
|
||||
*
|
||||
* @param name The config name
|
||||
* @param plugin The class of the main class of plugin or extension
|
||||
* @param type The enchantment type
|
||||
*/
|
||||
public EnchantmentYamlConfig(String name, Class<?> plugin, EcoEnchant.EnchantmentType type) {
|
||||
this.name = name;
|
||||
this.source = plugin;
|
||||
this.type = type;
|
||||
|
||||
File basedir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "enchants/");
|
||||
if (!basedir.exists()) basedir.mkdirs();
|
||||
|
||||
File dir = new File(basedir, type.getName() + "/");
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
this.directory = dir;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (!new File(directory, name + ".yml").exists()) {
|
||||
createFile();
|
||||
}
|
||||
|
||||
this.configFile = new File(directory, name + ".yml");
|
||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
private void saveResource() {
|
||||
String resourcePath = "/enchants/" + type.getName() + "/" + name + ".yml";
|
||||
|
||||
InputStream in = source.getResourceAsStream(resourcePath);
|
||||
|
||||
File outFile = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), resourcePath);
|
||||
int lastIndex = resourcePath.lastIndexOf('/');
|
||||
File outDir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), resourcePath.substring(0, Math.max(lastIndex, 0)));
|
||||
|
||||
if (!outDir.exists()) {
|
||||
outDir.mkdirs();
|
||||
}
|
||||
|
||||
try {
|
||||
if (!outFile.exists()) {
|
||||
OutputStream out = new FileOutputStream(outFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
out.close();
|
||||
in.close();
|
||||
}
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
private void createFile() {
|
||||
saveResource();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
try {
|
||||
config.load(configFile);
|
||||
|
||||
String resourcePath = "/enchants/" + type.getName() + "/" + name + ".yml";
|
||||
InputStream newIn = source.getResourceAsStream(resourcePath);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||
YamlConfiguration newConfig = new YamlConfiguration();
|
||||
newConfig.load(reader);
|
||||
|
||||
if (newConfig.getKeys(true).equals(config.getKeys(true)))
|
||||
return;
|
||||
|
||||
newConfig.getKeys(true).forEach((s -> {
|
||||
if (!config.getKeys(true).contains(s)) {
|
||||
config.set(s, newConfig.get(s));
|
||||
}
|
||||
}));
|
||||
|
||||
config.getKeys(true).forEach((s -> {
|
||||
if (!newConfig.getKeys(true).contains(s)) {
|
||||
config.set(s, null);
|
||||
}
|
||||
}));
|
||||
|
||||
config.save(configFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.util.internal.Logger;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public abstract class UpdatingYamlConfig {
|
||||
public YamlConfiguration config;
|
||||
private File configFile;
|
||||
private final String name;
|
||||
private final boolean removeUnused;
|
||||
|
||||
public UpdatingYamlConfig(String name, boolean removeUnused) {
|
||||
this.name = name + ".yml";
|
||||
this.removeUnused = removeUnused;
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
if (!new File(EcoEnchantsPlugin.getInstance().getDataFolder(), name).exists()) {
|
||||
createFile();
|
||||
}
|
||||
|
||||
this.configFile = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), name);
|
||||
this.config = YamlConfiguration.loadConfiguration(configFile);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
private void createFile() {
|
||||
EcoEnchantsPlugin.getInstance().saveResource(name, false);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
try {
|
||||
config.load(configFile);
|
||||
|
||||
InputStream newIn = EcoEnchantsPlugin.getInstance().getResource(name);
|
||||
if (newIn == null) {
|
||||
Logger.error(name + " is null?");
|
||||
return;
|
||||
}
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newIn, StandardCharsets.UTF_8));
|
||||
YamlConfiguration newConfig = new YamlConfiguration();
|
||||
newConfig.load(reader);
|
||||
|
||||
if (newConfig.getKeys(true).equals(config.getKeys(true)))
|
||||
return;
|
||||
|
||||
newConfig.getKeys(true).forEach((s -> {
|
||||
if (!config.getKeys(true).contains(s)) {
|
||||
config.set(s, newConfig.get(s));
|
||||
}
|
||||
}));
|
||||
|
||||
if (this.removeUnused) {
|
||||
config.getKeys(true).forEach((s -> {
|
||||
if (!newConfig.getKeys(true).contains(s)) {
|
||||
config.set(s, null);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
config.save(configFile);
|
||||
} catch (IOException | InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.UpdatingYamlConfig;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper for config.yml
|
||||
*/
|
||||
public class Config extends UpdatingYamlConfig {
|
||||
public Config() {
|
||||
super("config", true);
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return config.getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return config.getInt(path, def);
|
||||
}
|
||||
|
||||
public List<Integer> getInts(String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
public List<Boolean> getBools(String path) {
|
||||
return config.getBooleanList(path);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return config.getDouble(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubles(String path) {
|
||||
return config.getDoubleList(path);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(String path) {
|
||||
return config.getItemStack(path);
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.config.EnchantmentYamlConfig;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.util.internal.Logger;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrapper for enchantment-specific configs
|
||||
*/
|
||||
public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
private final String name;
|
||||
|
||||
public EnchantmentConfig(String name, Class<?> plugin, EcoEnchant.EnchantmentType type) {
|
||||
super(name, plugin, type);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return config.getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return config.getInt(path, def);
|
||||
}
|
||||
|
||||
public List<Integer> getInts(String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path, boolean def) {
|
||||
return config.getBoolean(path, def);
|
||||
}
|
||||
|
||||
public List<Boolean> getBools(String path) {
|
||||
return config.getBooleanList(path);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return config.getDouble(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubles(String path) {
|
||||
return config.getDoubleList(path);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(String path) {
|
||||
return config.getItemStack(path);
|
||||
}
|
||||
|
||||
public Set<Enchantment> getEnchantments(String path) {
|
||||
Set<Enchantment> enchantments = new HashSet<>();
|
||||
List<String> enchantmentKeys = config.getStringList(path);
|
||||
enchantmentKeys.forEach((key -> enchantments.add(Enchantment.getByKey(NamespacedKey.minecraft(key)))));
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
public EnchantmentRarity getRarity() {
|
||||
String rarityName = this.getString("obtaining.rarity");
|
||||
return EnchantmentRarity.getByName(rarityName);
|
||||
}
|
||||
|
||||
public Set<EnchantmentTarget> getTargets() {
|
||||
List<String> targetNames = config.getStringList(EcoEnchants.GENERAL_LOCATION + "targets");
|
||||
if (targetNames == null || targetNames.isEmpty()) return new HashSet<>();
|
||||
Set<EnchantmentTarget> targets = new HashSet<>();
|
||||
|
||||
targetNames.forEach((s -> {
|
||||
if (EnchantmentTarget.getByName(s) == null) {
|
||||
Logger.error(s + " is an invalid target!");
|
||||
return;
|
||||
}
|
||||
targets.add(EnchantmentTarget.getByName(s));
|
||||
}));
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
public void loadFromLang() {
|
||||
if (!ConfigManager.getLang().config.contains("enchantments." + this.getName()))
|
||||
return;
|
||||
|
||||
config.set("name", ConfigManager.getLang().getString("enchantments." + this.getName() + ".name"));
|
||||
config.set("description", ConfigManager.getLang().getString("enchantments." + this.getName() + ".description"));
|
||||
try {
|
||||
this.config.save(this.configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.UpdatingYamlConfig;
|
||||
import com.willfp.ecoenchants.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Wrapper for lang.yml
|
||||
*/
|
||||
public class Lang extends UpdatingYamlConfig {
|
||||
public Lang() {
|
||||
super("lang", false);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return StringUtils.translate(String.valueOf(config.getString(path)));
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
|
||||
public String getPrefix() {
|
||||
return StringUtils.translate(config.getString("messages.prefix"));
|
||||
}
|
||||
|
||||
public String getNoPermission() {
|
||||
return getPrefix() + StringUtils.translate(config.getString("messages.no-permission"));
|
||||
}
|
||||
|
||||
public String getMessage(String message) {
|
||||
return getPrefix() + StringUtils.translate(config.getString("messages." + message));
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.UpdatingYamlConfig;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrapper for config.yml
|
||||
*/
|
||||
public class Rarity extends UpdatingYamlConfig {
|
||||
public Rarity() {
|
||||
super("rarity", false);
|
||||
}
|
||||
|
||||
public Set<String> getRarities() {
|
||||
return config.getConfigurationSection("rarities").getKeys(false);
|
||||
}
|
||||
|
||||
public int getInt(String path) {
|
||||
return config.getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return config.getInt(path, def);
|
||||
}
|
||||
|
||||
public List<Integer> getInts(String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
public boolean getBool(String path) {
|
||||
return config.getBoolean(path);
|
||||
}
|
||||
|
||||
public List<Boolean> getBools(String path) {
|
||||
return config.getBooleanList(path);
|
||||
}
|
||||
|
||||
public String getString(String path) {
|
||||
return config.getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public double getDouble(String path) {
|
||||
return config.getDouble(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubles(String path) {
|
||||
return config.getDoubleList(path);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.willfp.ecoenchants.config.configs;
|
||||
|
||||
import com.willfp.ecoenchants.config.UpdatingYamlConfig;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrapper for config.yml
|
||||
*/
|
||||
public class Target extends UpdatingYamlConfig {
|
||||
public Target() {
|
||||
super("target", false);
|
||||
}
|
||||
|
||||
public Set<String> getTargets() {
|
||||
return config.getConfigurationSection("targets").getKeys(false);
|
||||
}
|
||||
|
||||
public Set<Material> getTargetMaterials(String target) {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
config.getStringList("targets." + target).forEach((materialName) -> {
|
||||
materials.add(Material.getMaterial(materialName.toUpperCase()));
|
||||
});
|
||||
|
||||
return materials;
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.willfp.ecoenchants.display;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
private final PacketType type;
|
||||
|
||||
protected AbstractPacketAdapter(PacketType type, ListenerPriority priority) {
|
||||
super(EcoEnchantsPlugin.getInstance(), priority, Collections.singletonList(type));
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
protected AbstractPacketAdapter(PacketType type) {
|
||||
super(EcoEnchantsPlugin.getInstance(), Collections.singletonList(type));
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void onReceive(PacketContainer packet) {
|
||||
}
|
||||
|
||||
public void onSend(PacketContainer packet) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPacketReceiving(PacketEvent event) {
|
||||
if (event.getPacket() == null)
|
||||
return;
|
||||
|
||||
if (!event.getPacket().getType().equals(type))
|
||||
return;
|
||||
|
||||
onReceive(event.getPacket());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPacketSending(PacketEvent event) {
|
||||
if (event.getPacket() == null)
|
||||
return;
|
||||
|
||||
if (!event.getPacket().getType().equals(type))
|
||||
return;
|
||||
|
||||
onSend(event.getPacket());
|
||||
}
|
||||
|
||||
public final void register() {
|
||||
if (!ProtocolLibrary.getProtocolManager().getPacketListeners().contains(this)) {
|
||||
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,247 +0,0 @@
|
||||
package com.willfp.ecoenchants.display;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
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.util.NumberUtils;
|
||||
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 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 {
|
||||
/**
|
||||
* The meta key to hide enchantments in lore
|
||||
* <p>
|
||||
* Only used for parity in {@link com.willfp.ecoenchants.display.packets.PacketSetCreativeSlot}.
|
||||
* More robust method to be introduced
|
||||
*
|
||||
* @deprecated Temporary fix
|
||||
*/
|
||||
@Deprecated
|
||||
public static final NamespacedKey KEY_SKIP = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-skip");
|
||||
|
||||
/**
|
||||
* The meta key to notify the server that an item is from a villager trade
|
||||
* <p>
|
||||
* Bit of a bodge - plan on making it better.
|
||||
*/
|
||||
public static final NamespacedKey KEY_V = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-v");
|
||||
|
||||
/**
|
||||
* The prefix for all enchantment lines to have in lore
|
||||
*/
|
||||
public static final String PREFIX = "§w";
|
||||
|
||||
/**
|
||||
* The configurable options for displaying enchantments
|
||||
*/
|
||||
public static final DisplayOptions OPTIONS = new DisplayOptions();
|
||||
|
||||
/**
|
||||
* Update config values
|
||||
*/
|
||||
public static void update() {
|
||||
OPTIONS.update();
|
||||
EnchantmentCache.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bodge to fix hidden enchantments from villagers.
|
||||
* <p>
|
||||
* It isn't recommended to mess with this unless you <b>really</b> know your way around EcoEnchants.
|
||||
*
|
||||
* @param item The item to modify
|
||||
*
|
||||
* @return The item, with KEY_V
|
||||
*/
|
||||
public static ItemStack addV(ItemStack item) {
|
||||
if (item == null || item.getItemMeta() == null) return item;
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.getPersistentDataContainer().set(KEY_V, PersistentDataType.INTEGER, 1);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert display
|
||||
*
|
||||
* @param item The item to revert
|
||||
*
|
||||
* @return The item, updated
|
||||
*/
|
||||
public static ItemStack revertDisplay(final ItemStack item) {
|
||||
if (item == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta() == null)
|
||||
return item;
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
List<String> itemLore;
|
||||
|
||||
if (meta.hasLore())
|
||||
itemLore = meta.getLore();
|
||||
else
|
||||
itemLore = new ArrayList<>();
|
||||
|
||||
if (itemLore == null) itemLore = new ArrayList<>();
|
||||
|
||||
if (meta.getPersistentDataContainer().has(KEY_V, PersistentDataType.INTEGER)) {
|
||||
meta.getPersistentDataContainer().remove(KEY_V);
|
||||
}
|
||||
itemLore.removeIf((s) -> s.startsWith(PREFIX));
|
||||
|
||||
if (!meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
|
||||
if (meta instanceof EnchantmentStorageMeta)
|
||||
meta.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS); // Thanks ShaneBee!
|
||||
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
meta.getPersistentDataContainer().remove(KEY_SKIP);
|
||||
meta.setLore(itemLore);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack displayEnchantments(final ItemStack item) {
|
||||
return displayEnchantments(item, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all enchantments in item lore
|
||||
*
|
||||
* @param item The item to update
|
||||
*
|
||||
* @return The item, updated
|
||||
*/
|
||||
public static ItemStack displayEnchantments(final ItemStack item, boolean hideEnchants) {
|
||||
if (item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()))
|
||||
return item;
|
||||
|
||||
if (item.getItemMeta().getPersistentDataContainer().has(KEY_V, PersistentDataType.INTEGER)) {
|
||||
if (hideEnchants)
|
||||
hideEnchants = false;
|
||||
}
|
||||
|
||||
revertDisplay(item);
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return item;
|
||||
List<String> itemLore = new ArrayList<>();
|
||||
|
||||
if (hideEnchants || meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||
meta.getPersistentDataContainer().set(KEY_SKIP, PersistentDataType.INTEGER, 1);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
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.isUseNumerals() && item.getEnchantmentLevel(enchantment) < OPTIONS.getNumbersThreshold()) {
|
||||
name += " " + NumberUtils.toNumeral(level);
|
||||
} else {
|
||||
name += " " + level;
|
||||
}
|
||||
}
|
||||
|
||||
lore.add(PREFIX + name);
|
||||
if (enchantments.size() <= OPTIONS.getDescribeThreshold() && OPTIONS.isUseDescribe())
|
||||
lore.addAll(EnchantmentCache.getEntry(enchantment).getDescription());
|
||||
});
|
||||
|
||||
if (OPTIONS.isUseShrink() && (enchantments.size() > OPTIONS.getShrinkThreshold())) {
|
||||
List<List<String>> partitionedCombinedLoreList = Lists.partition(lore, OPTIONS.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);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
package com.willfp.ecoenchants.display;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.util.internal.Logger;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class EnchantmentCache {
|
||||
private static final Set<CacheEntry> CACHE = new HashSet<>();
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
public static CacheEntry getEntry(Enchantment enchantment) {
|
||||
Optional<CacheEntry> matching = CACHE.stream().filter(entry -> entry.getEnchantment().getKey().getKey().equals(enchantment.getKey().getKey())).findFirst();
|
||||
return matching.orElse(new CacheEntry(enchantment, EnchantDisplay.PREFIX + "§7" + enchantment.getKey().getKey(), enchantment.getKey().getKey(), Collections.singletonList(EnchantDisplay.PREFIX + "No Description Found"), EcoEnchant.EnchantmentType.NORMAL, EnchantmentRarity.values().stream().findFirst().get()));
|
||||
}
|
||||
|
||||
public static Set<CacheEntry> getCache() {
|
||||
return new HashSet<>(CACHE);
|
||||
}
|
||||
|
||||
public static void update() {
|
||||
CACHE.clear();
|
||||
Arrays.asList(Enchantment.values()).parallelStream().forEach(enchantment -> {
|
||||
String name;
|
||||
String color;
|
||||
EcoEnchant.EnchantmentType type;
|
||||
EnchantmentRarity rarity;
|
||||
List<String> description;
|
||||
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
|
||||
description = ecoEnchant.getDescription();
|
||||
name = ecoEnchant.getName();
|
||||
type = ecoEnchant.getType();
|
||||
rarity = ecoEnchant.getRarity();
|
||||
} else {
|
||||
description = Arrays.asList(
|
||||
WordUtils.wrap(
|
||||
String.valueOf(ConfigManager.getLang().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".description")),
|
||||
ConfigManager.getConfig().getInt("lore.describe.wrap"),
|
||||
"\n", false
|
||||
).split("\\r?\\n")
|
||||
);
|
||||
name = String.valueOf(ConfigManager.getLang().getString("enchantments." + enchantment.getKey().getKey().toLowerCase() + ".name"));
|
||||
type = enchantment.isCursed() ? EcoEnchant.EnchantmentType.CURSE : EcoEnchant.EnchantmentType.NORMAL;
|
||||
rarity = enchantment.isTreasure() ? EnchantmentRarity.getByName(ConfigManager.getConfig().getString("rarity.vanilla-treasure-rarity")) : EnchantmentRarity.getByName(ConfigManager.getConfig().getString("rarity.vanilla-rarity"));
|
||||
}
|
||||
|
||||
color = type.getColor();
|
||||
|
||||
if (rarity != null) {
|
||||
if (rarity.hasCustomColor() && type != EcoEnchant.EnchantmentType.CURSE) {
|
||||
color = rarity.getCustomColor();
|
||||
}
|
||||
} else {
|
||||
Logger.warn("Enchantment " + enchantment.getKey().getKey() + " has an invalid rarity");
|
||||
}
|
||||
|
||||
String rawName = name;
|
||||
name = color + name;
|
||||
description.replaceAll(line -> EnchantDisplay.PREFIX + EnchantDisplay.OPTIONS.getDescriptionColor() + line);
|
||||
CACHE.add(new CacheEntry(enchantment, name, rawName, description, type, rarity));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static class CacheEntry {
|
||||
private final Enchantment enchantment;
|
||||
private final String name;
|
||||
private final String rawName;
|
||||
private final List<String> description;
|
||||
private final String stringDescription;
|
||||
private final EcoEnchant.EnchantmentType type;
|
||||
private final EnchantmentRarity rarity;
|
||||
|
||||
public CacheEntry(Enchantment enchantment, String name, String rawName, List<String> description, EcoEnchant.EnchantmentType type, 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 stringDescription = descriptionBuilder.toString();
|
||||
stringDescription = stringDescription.replaceAll("§w", "");
|
||||
this.stringDescription = stringDescription.replaceAll(EnchantDisplay.OPTIONS.getDescriptionColor(), "");
|
||||
}
|
||||
|
||||
public Enchantment getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRawName() {
|
||||
return rawName;
|
||||
}
|
||||
|
||||
public List<String> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getStringDescription() {
|
||||
return stringDescription;
|
||||
}
|
||||
|
||||
public EcoEnchant.EnchantmentType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public EnchantmentRarity getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CacheEntry{" +
|
||||
"enchantment=" + enchantment +
|
||||
"§f, name='" + name + '\'' +
|
||||
"§f, rawName='" + rawName + '\'' +
|
||||
"§f, description=" + description +
|
||||
"§f, stringDescription='" + stringDescription + '\'' +
|
||||
"§f}";
|
||||
}
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ToggleableOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
import com.willfp.ecoenchants.util.StringUtils;
|
||||
|
||||
public class DescriptionOptions implements ThresholdedOption, ToggleableOption, UpdateableOption {
|
||||
private int threshold;
|
||||
private boolean enabled;
|
||||
private String color;
|
||||
|
||||
@Override
|
||||
public int getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
threshold = ConfigManager.getConfig().getInt("lore.describe.before-lines");
|
||||
enabled = ConfigManager.getConfig().getBool("lore.describe.enabled");
|
||||
color = StringUtils.translate(ConfigManager.getLang().getString("description-color"));
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
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.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
|
||||
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 {
|
||||
private EnchantmentSorter sorter;
|
||||
private final DescriptionOptions descriptionOptions = new DescriptionOptions();
|
||||
private final NumbersOptions numbersOptions = new NumbersOptions();
|
||||
private final ShrinkOptions shrinkOptions = new ShrinkOptions();
|
||||
private final List<EcoEnchant.EnchantmentType> sortedTypes = new ArrayList<>();
|
||||
private final List<EnchantmentRarity> sortedRarities = new ArrayList<>();
|
||||
|
||||
public DisplayOptions() {
|
||||
update();
|
||||
}
|
||||
|
||||
public String getDescriptionColor() {
|
||||
return descriptionOptions.getColor();
|
||||
}
|
||||
|
||||
public int getNumbersThreshold() {
|
||||
return numbersOptions.getThreshold();
|
||||
}
|
||||
|
||||
public boolean isUseNumerals() {
|
||||
return numbersOptions.useNumerals();
|
||||
}
|
||||
|
||||
public int getDescribeThreshold() {
|
||||
return descriptionOptions.getThreshold();
|
||||
}
|
||||
|
||||
public boolean isUseDescribe() {
|
||||
return descriptionOptions.isEnabled();
|
||||
}
|
||||
|
||||
public int getShrinkThreshold() {
|
||||
return shrinkOptions.getThreshold();
|
||||
}
|
||||
|
||||
public int getShrinkPerLine() {
|
||||
return shrinkOptions.getShrinkPerLine();
|
||||
}
|
||||
|
||||
public boolean isUseShrink() {
|
||||
return shrinkOptions.isEnabled();
|
||||
}
|
||||
|
||||
public List<EcoEnchant.EnchantmentType> getSortedTypes() {
|
||||
return sortedTypes;
|
||||
}
|
||||
|
||||
public List<EnchantmentRarity> getSortedRarities() {
|
||||
return sortedRarities;
|
||||
}
|
||||
|
||||
public EnchantmentSorter getSorter() {
|
||||
return sorter;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
descriptionOptions.update();
|
||||
numbersOptions.update();
|
||||
shrinkOptions.update();
|
||||
|
||||
sortedTypes.clear();
|
||||
sortedTypes.addAll(ConfigManager.getConfig().getStrings("lore.type-ordering").stream()
|
||||
.map(typeName -> EcoEnchant.EnchantmentType.values().stream().filter(type -> type.getName().equalsIgnoreCase(typeName)).findFirst().orElse(null))
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList()));
|
||||
sortedTypes.addAll(EcoEnchant.EnchantmentType.values().stream().filter(enchantmentType -> !sortedTypes.contains(enchantmentType)).collect(Collectors.toList()));
|
||||
|
||||
sortedRarities.clear();
|
||||
sortedRarities.addAll(ConfigManager.getConfig().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()));
|
||||
|
||||
boolean byType = ConfigManager.getConfig().getBool("lore.sort-by-type");
|
||||
boolean byLength = ConfigManager.getConfig().getBool("lore.sort-by-length");
|
||||
boolean byRarity = ConfigManager.getConfig().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[]{}));
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
|
||||
public class NumbersOptions implements ThresholdedOption, UpdateableOption {
|
||||
private boolean useNumerals;
|
||||
private int threshold;
|
||||
|
||||
@Override
|
||||
public int getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
useNumerals = ConfigManager.getConfig().getBool("lore.use-numerals");
|
||||
threshold = ConfigManager.getConfig().getInt("lore.use-numbers-above-threshold");
|
||||
}
|
||||
|
||||
public boolean useNumerals() {
|
||||
return useNumerals;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ToggleableOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
|
||||
public class ShrinkOptions implements ThresholdedOption, ToggleableOption, UpdateableOption {
|
||||
private int threshold;
|
||||
private boolean enabled;
|
||||
private int shrinkPerLine;
|
||||
|
||||
@Override
|
||||
public int getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
threshold = ConfigManager.getConfig().getInt("lore.shrink.after-lines");
|
||||
enabled = ConfigManager.getConfig().getBool("lore.shrink.enabled");
|
||||
shrinkPerLine = ConfigManager.getConfig().getInt("lore.shrink.maximum-per-line");
|
||||
}
|
||||
|
||||
public int getShrinkPerLine() {
|
||||
return shrinkPerLine;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface ThresholdedOption {
|
||||
int getThreshold();
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface ToggleableOption {
|
||||
boolean isEnabled();
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface UpdateableOption {
|
||||
void update();
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EnchantmentSorter {
|
||||
void sortEnchantments(final List<Enchantment> toSort);
|
||||
SortParameters[] getParameters();
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
public enum SortParameters {
|
||||
TYPE,
|
||||
RARITY,
|
||||
LENGTH
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting;
|
||||
|
||||
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 java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class SorterManager {
|
||||
private static final Set<EnchantmentSorter> values = new HashSet<>();
|
||||
|
||||
public static EnchantmentSorter getSorter(SortParameters... parameters) {
|
||||
return values.stream()
|
||||
.filter(enchantmentSorter -> Arrays.asList(enchantmentSorter.getParameters()).containsAll(Arrays.asList(parameters)) && enchantmentSorter.getParameters().length == parameters.length)
|
||||
.findFirst()
|
||||
.orElse(new AlphabeticSorter());
|
||||
}
|
||||
|
||||
static {
|
||||
values.add(new AlphabeticSorter());
|
||||
values.add(new LengthSorter());
|
||||
values.add(new TypeAlphabeticSorter());
|
||||
values.add(new TypeLengthSorter());
|
||||
values.add(new RarityAlphabeticSorter());
|
||||
values.add(new RarityLengthSorter());
|
||||
values.add(new RarityTypeAlphabeticSorter());
|
||||
values.add(new RarityTypeLengthSorter());
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
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 java.util.List;
|
||||
|
||||
public class AlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(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];
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
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 java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class LengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.LENGTH};
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RarityAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity))
|
||||
.sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()))
|
||||
.collect(Collectors.toList());
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.RARITY};
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RarityLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity))
|
||||
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
|
||||
.collect(Collectors.toList());
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.RARITY, SortParameters.LENGTH};
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RarityTypeAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()))
|
||||
.collect(Collectors.toList());
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = typeEnchants.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity))
|
||||
.sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()))
|
||||
.collect(Collectors.toList());
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.RARITY, SortParameters.TYPE};
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RarityTypeLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
|
||||
.collect(Collectors.toList());
|
||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
||||
List<Enchantment> rarityEnchants = typeEnchants.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity))
|
||||
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
|
||||
.collect(Collectors.toList());
|
||||
sorted.addAll(rarityEnchants);
|
||||
});
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.RARITY, SortParameters.TYPE, SortParameters.LENGTH};
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TypeAlphabeticSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()))
|
||||
.collect(Collectors.toList());
|
||||
sorted.addAll(typeEnchants);
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.TYPE};
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TypeLengthSorter implements EnchantmentSorter {
|
||||
@Override
|
||||
public void sortEnchantments(final List<Enchantment> toSort) {
|
||||
List<Enchantment> sorted = new ArrayList<>();
|
||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
||||
List<Enchantment> typeEnchants = toSort.stream()
|
||||
.filter(enchantment -> EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType))
|
||||
.sorted(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()))
|
||||
.collect(Collectors.toList());
|
||||
sorted.addAll(typeEnchants);
|
||||
});
|
||||
|
||||
toSort.clear();
|
||||
toSort.addAll(sorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortParameters[] getParameters() {
|
||||
return new SortParameters[]{SortParameters.TYPE, SortParameters.LENGTH};
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.ListenerPriority;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.willfp.ecoenchants.display.AbstractPacketAdapter;
|
||||
import com.willfp.ecoenchants.nms.ChatComponent;
|
||||
|
||||
public class PacketChat extends AbstractPacketAdapter {
|
||||
public PacketChat() {
|
||||
super(PacketType.Play.Server.CHAT, ListenerPriority.MONITOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(PacketContainer packet) {
|
||||
for (int i = 0; i < packet.getChatComponents().size(); i++) {
|
||||
WrappedChatComponent component = packet.getChatComponents().read(i);
|
||||
if (component == null)
|
||||
continue;
|
||||
if (component.getHandle() == null)
|
||||
return;
|
||||
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(ChatComponent.modifyComponent(component.getHandle()));
|
||||
packet.getChatComponents().write(i, newComponent);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.display.AbstractPacketAdapter;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
public PacketOpenWindowMerchant() {
|
||||
super(PacketType.Play.Server.OPEN_WINDOW_MERCHANT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(PacketContainer packet) {
|
||||
List<MerchantRecipe> recipes = packet.getMerchantRecipeLists().readSafely(0);
|
||||
|
||||
recipes = recipes.stream().peek(merchantRecipe -> {
|
||||
try {
|
||||
if (!EnchantmentTarget.ALL.getMaterials().contains(merchantRecipe.getResult().getType()))
|
||||
return;
|
||||
|
||||
// Enables removing final modifier
|
||||
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||
modifiersField.setAccessible(true);
|
||||
|
||||
// Bukkit MerchantRecipe result
|
||||
Field fResult = merchantRecipe.getClass().getSuperclass().getDeclaredField("result");
|
||||
fResult.setAccessible(true);
|
||||
ItemStack result = EnchantDisplay.displayEnchantments(merchantRecipe.getResult());
|
||||
result = EnchantDisplay.addV(result);
|
||||
fResult.set(merchantRecipe, result);
|
||||
|
||||
// Get NMS MerchantRecipe from CraftMerchantRecipe
|
||||
Field fHandle = merchantRecipe.getClass().getDeclaredField("handle");
|
||||
fHandle.setAccessible(true);
|
||||
Object handle = fHandle.get(merchantRecipe); // NMS Recipe
|
||||
modifiersField.setInt(fHandle, fHandle.getModifiers() & ~Modifier.FINAL); // Remove final
|
||||
|
||||
// NMS MerchantRecipe
|
||||
Field fSelling = fHandle.get(merchantRecipe).getClass().getDeclaredField("sellingItem");
|
||||
fSelling.setAccessible(true);
|
||||
Object selling = fSelling.get(handle); // NMS Selling ItemStack
|
||||
modifiersField.setInt(fSelling, fSelling.getModifiers() & ~Modifier.FINAL);
|
||||
|
||||
// Reflectively access CraftItemStack.class for respective version
|
||||
Class<?> craftItemStack = Class.forName("org.bukkit.craftbukkit." + EcoEnchantsPlugin.NMS_VERSION + ".inventory.CraftItemStack");
|
||||
|
||||
// Bukkit Result ItemStack from NMS Result ItemStack
|
||||
ItemStack nmsSelling = (ItemStack) craftItemStack.getMethod("asBukkitCopy", selling.getClass()).invoke(null, selling);
|
||||
nmsSelling = EnchantDisplay.displayEnchantments(nmsSelling);
|
||||
nmsSelling = EnchantDisplay.addV(nmsSelling);
|
||||
fSelling.set(handle, craftItemStack.getMethod("asNMSCopy", ItemStack.class).invoke(null, nmsSelling));
|
||||
|
||||
} catch (IllegalAccessException | NoSuchFieldException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
packet.getMerchantRecipeLists().writeSafely(0, recipes);
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.ecoenchants.display.AbstractPacketAdapter;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
|
||||
public class PacketSetCreativeSlot extends AbstractPacketAdapter {
|
||||
public PacketSetCreativeSlot() {
|
||||
super(PacketType.Play.Client.SET_CREATIVE_SLOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(PacketContainer packet) {
|
||||
packet.getItemModifier().modify(0, (item) -> {
|
||||
item = EnchantDisplay.revertDisplay(item);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.ecoenchants.display.AbstractPacketAdapter;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public class PacketSetSlot extends AbstractPacketAdapter {
|
||||
public PacketSetSlot() {
|
||||
super(PacketType.Play.Server.SET_SLOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(PacketContainer packet) {
|
||||
packet.getItemModifier().modify(0, (item) -> {
|
||||
boolean hideEnchants = false;
|
||||
|
||||
if (item == null)
|
||||
return item;
|
||||
|
||||
if (item.getItemMeta() != null) {
|
||||
hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
item = EnchantDisplay.displayEnchantments(item, hideEnchants);
|
||||
return item;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.packets;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.willfp.ecoenchants.display.AbstractPacketAdapter;
|
||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
|
||||
public class PacketWindowItems extends AbstractPacketAdapter {
|
||||
public PacketWindowItems() {
|
||||
super(PacketType.Play.Server.WINDOW_ITEMS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSend(PacketContainer packet) {
|
||||
packet.getItemListModifier().modify(0, (itemStacks) -> {
|
||||
if (itemStacks == null) return null;
|
||||
itemStacks.forEach(item -> {
|
||||
if (item == null)
|
||||
return;
|
||||
|
||||
boolean hideEnchants = false;
|
||||
|
||||
if (item.getItemMeta() != null) {
|
||||
hideEnchants = item.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ENCHANTS);
|
||||
}
|
||||
|
||||
EnchantDisplay.displayEnchantments(item, hideEnchants);
|
||||
});
|
||||
return itemStacks;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,555 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments;
|
||||
|
||||
import com.willfp.ecoenchants.config.ConfigManager;
|
||||
import com.willfp.ecoenchants.config.configs.EnchantmentConfig;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.enchantments.util.Watcher;
|
||||
import com.willfp.ecoenchants.util.StringUtils;
|
||||
import com.willfp.ecoenchants.util.interfaces.ObjectCallable;
|
||||
import com.willfp.ecoenchants.util.interfaces.Registerable;
|
||||
import com.willfp.ecoenchants.util.internal.Logger;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
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.enchantments.EnchantmentTarget;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionDefault;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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"})
|
||||
public abstract class EcoEnchant extends Enchantment implements Listener, Registerable, Watcher {
|
||||
private String name;
|
||||
private String description;
|
||||
private final String permissionName;
|
||||
private final EnchantmentType type;
|
||||
|
||||
private final EnchantmentConfig config;
|
||||
|
||||
private boolean grindstoneable;
|
||||
private boolean canGetFromTable;
|
||||
private boolean canGetFromVillager;
|
||||
private boolean canGetFromLoot;
|
||||
private int maxLvl;
|
||||
private Set<Enchantment> conflicts;
|
||||
private EnchantmentRarity rarity;
|
||||
private final Set<com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget> target = new HashSet<>();
|
||||
private final Set<Material> targetMaterials = new HashSet<>();
|
||||
private final Set<String> disabledWorldNames = new HashSet<>();
|
||||
private final List<World> disabledWorlds = new ArrayList<>();
|
||||
|
||||
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(String key, EcoEnchant.EnchantmentType type, Prerequisite... prerequisites) {
|
||||
super(NamespacedKey.minecraft(key));
|
||||
|
||||
this.type = type;
|
||||
this.permissionName = key.replaceAll("_", "");
|
||||
ConfigManager.addEnchantmentConfig(new EnchantmentConfig(this.permissionName, this.getClass(), this.type));
|
||||
this.config = ConfigManager.getEnchantmentConfig(this.permissionName);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//WorldguardManager.registerFlag(this.getPermissionName() + "-enabled", true);
|
||||
|
||||
if(type.getRequiredToExtend() != null && !type.getRequiredToExtend().isInstance(this)) {
|
||||
Logger.error("Enchantment " + key + " has type " + this.getType().getName() + " but doesn't extend " + type.getRequiredToExtend().getName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Prerequisite.areMet(prerequisites))
|
||||
return;
|
||||
|
||||
this.update();
|
||||
EcoEnchants.addNewEcoEnchant(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new EcoEnchant that exists within an extension or external plugin
|
||||
*
|
||||
* @param key The key name of the enchantment
|
||||
* @param type The type of the enchantment
|
||||
* @param plugin Unused value
|
||||
* @param prerequisites Optional {@link Prerequisite}s that must be met
|
||||
*
|
||||
* @deprecated Specifying the source class is no longer needed
|
||||
*/
|
||||
@Deprecated
|
||||
@ApiStatus.ScheduledForRemoval(inVersion = "6.0.0")
|
||||
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin, Prerequisite... prerequisites) {
|
||||
this(key, type, prerequisites);
|
||||
|
||||
Logger.warn("Enchantment " + key + " (Generated by " + plugin.getName() + ") is using a legacy constructor!");
|
||||
Logger.warn("Update your extensions - support for legacy enchantments will be removed in subsequent versions.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the enchantment based off config values
|
||||
* This can be overriden but may lead to unexpected behavior
|
||||
*/
|
||||
public void update() {
|
||||
config.loadFromLang();
|
||||
rarity = config.getRarity();
|
||||
conflicts = config.getEnchantments(EcoEnchants.GENERAL_LOCATION + "conflicts");
|
||||
grindstoneable = config.getBool(EcoEnchants.GENERAL_LOCATION + "grindstoneable");
|
||||
canGetFromTable = config.getBool(EcoEnchants.OBTAINING_LOCATION + "table");
|
||||
canGetFromVillager = config.getBool(EcoEnchants.OBTAINING_LOCATION + "villager");
|
||||
canGetFromLoot = config.getBool(EcoEnchants.OBTAINING_LOCATION + "loot");
|
||||
maxLvl = 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()));
|
||||
target.clear();
|
||||
targetMaterials.clear();
|
||||
target.addAll(config.getTargets());
|
||||
target.forEach(enchantmentTarget -> targetMaterials.addAll(enchantmentTarget.getMaterials()));
|
||||
enabled = config.getBool("enabled", true);
|
||||
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
|
||||
*/
|
||||
@Override
|
||||
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 if enchantment can be removed in grindstone
|
||||
*
|
||||
* @return Whether the enchantment can be removed
|
||||
*/
|
||||
public boolean isGrindstoneable() {
|
||||
return grindstoneable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link EnchantmentType} of enchantment
|
||||
*
|
||||
* @return The {@link EnchantmentType}
|
||||
*/
|
||||
public EnchantmentType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a set of all conflicts
|
||||
*
|
||||
* @return Conflicts
|
||||
*/
|
||||
public Set<Enchantment> getConflicts() {
|
||||
return this.conflicts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if enchantment is enabled
|
||||
*
|
||||
* @return If enabled
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get permission name of enchantment
|
||||
*
|
||||
* @return The permission name
|
||||
*/
|
||||
public String getPermissionName() {
|
||||
return permissionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get description of enchantment
|
||||
*
|
||||
* @return The description
|
||||
*/
|
||||
public List<String> getDescription() {
|
||||
return Arrays.asList(WordUtils.wrap(description, ConfigManager.getConfig().getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if enchantment can be obtained from an enchanting table
|
||||
*
|
||||
* @return If can be obtained
|
||||
*/
|
||||
public boolean canGetFromTable() {
|
||||
return canGetFromTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if enchantment can be obtained from a villager
|
||||
*
|
||||
* @return If can be obtained
|
||||
*/
|
||||
public boolean canGetFromVillager() {
|
||||
return canGetFromVillager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if enchantment can be obtained from chest loot
|
||||
*
|
||||
* @return If can be obtained
|
||||
*/
|
||||
public boolean canGetFromLoot() {
|
||||
return canGetFromLoot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link EnchantmentRarity} of enchantment
|
||||
*
|
||||
* @return The enchantment rarity
|
||||
*/
|
||||
public EnchantmentRarity getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* If enchantment conflicts with any enchantment in set
|
||||
*
|
||||
* @param enchantments The set to test against
|
||||
*
|
||||
* @return If there are any conflicts
|
||||
*/
|
||||
public boolean conflictsWithAny(Set<? 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 target of enchantment
|
||||
*
|
||||
* @return Set of enchantable items
|
||||
*/
|
||||
public Set<Material> getTarget() {
|
||||
return targetMaterials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get raw target of enchantment
|
||||
*
|
||||
* @return {@link com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget}
|
||||
*/
|
||||
public Set<com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget> getRawTargets() {
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get {@link EnchantmentConfig} of enchantment
|
||||
*
|
||||
* @return The config
|
||||
*/
|
||||
public EnchantmentConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get worlds that the enchantment is disabled in
|
||||
*
|
||||
* @return A list of all disabled worlds
|
||||
*/
|
||||
public List<World> getDisabledWorlds() {
|
||||
return disabledWorlds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get world names that the enchantment is disabled in
|
||||
*
|
||||
* @return A list of all disabled world names
|
||||
*/
|
||||
public Set<String> getDisabledWorldNames() {
|
||||
return disabledWorldNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get display name of enchantment.
|
||||
* Not deprecated, unlike {@link Enchantment#getName()}
|
||||
*
|
||||
* @return The display name
|
||||
*/
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get max level of enchantment
|
||||
*
|
||||
* @return The max level
|
||||
*/
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return maxLvl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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#getTarget()} instead.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public @NotNull EnchantmentTarget getItemTarget() {
|
||||
return EnchantmentTarget.ALL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Treasure enchantments do not exist in EcoEnchants
|
||||
* @see EnchantmentType#SPECIAL
|
||||
*
|
||||
* @return false
|
||||
*
|
||||
* @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.
|
||||
* @see EnchantmentType#CURSE
|
||||
*
|
||||
* @return Returns if enchantment is cursed.
|
||||
*
|
||||
* @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 Enchantment enchantment) {
|
||||
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(ItemStack itemStack) {
|
||||
return targetMaterials.contains(itemStack.getType()) || itemStack.getType().equals(Material.BOOK) || itemStack.getType().equals(Material.ENCHANTED_BOOK);
|
||||
}
|
||||
|
||||
public static class EnchantmentType {
|
||||
private static final List<EnchantmentType> values = new ArrayList<>();
|
||||
|
||||
public static final EnchantmentType NORMAL = new EnchantmentType("normal", false, () -> ConfigManager.getLang().getString("not-curse-color"));
|
||||
public static final EnchantmentType CURSE = new EnchantmentType("curse", false, () -> ConfigManager.getLang().getString("curse-color"));
|
||||
public static final EnchantmentType SPECIAL = new EnchantmentType("special", () -> !ConfigManager.getConfig().getBool("types.special.allow-multiple"), () -> ConfigManager.getLang().getString("special-color"));
|
||||
public static final EnchantmentType ARTIFACT = new EnchantmentType("artifact", () -> !ConfigManager.getConfig().getBool("types.artifact.allow-multiple"), () -> ConfigManager.getLang().getString("artifact-color"), Artifact.class);
|
||||
public static final EnchantmentType SPELL = new EnchantmentType("spell", true, () -> ConfigManager.getLang().getString("spell-color"), Spell.class);
|
||||
|
||||
private boolean singular;
|
||||
private String color;
|
||||
private final String name;
|
||||
private final ObjectCallable<String> colorCallable;
|
||||
private final ObjectCallable<Boolean> singularCallable;
|
||||
private final Class<? extends EcoEnchant> requiredToExtend;
|
||||
|
||||
/**
|
||||
* Create simple EnchantmentType
|
||||
* <p>
|
||||
* Singularity and Color will not be updated using this constructor
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singular Whether an item can have several enchantments of this type
|
||||
* @param color The color for enchantments with this type in lore to have
|
||||
*/
|
||||
public EnchantmentType(String name, boolean singular, String color) {
|
||||
this(name, () -> singular, () -> color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EnchantmentType with updatable color
|
||||
* <p>
|
||||
* Singularity will not be updated using this constructor
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singular Whether an item can have several enchantments of this type
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
*/
|
||||
public EnchantmentType(String name, boolean singular, ObjectCallable<String> colorCallable) {
|
||||
this(name, () -> singular, colorCallable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EnchantmentType with updatable color that <b>must</b> extend a specified class
|
||||
* <p>
|
||||
* Singularity will not be updated using this constructor
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singular Whether an item can have several enchantments of this type
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required
|
||||
*/
|
||||
public EnchantmentType(String name, boolean singular, ObjectCallable<String> colorCallable, Class<? extends EcoEnchant> requiredToExtend) {
|
||||
this(name, () -> singular, colorCallable, requiredToExtend);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EnchantmentType with updatable color and singularity
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
*/
|
||||
public EnchantmentType(String name, ObjectCallable<Boolean> singularCallable, ObjectCallable<String> colorCallable) {
|
||||
this(name, singularCallable, colorCallable, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EnchantmentType with updatable color and singularity that <b>must</b> extend a specified class
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required
|
||||
*/
|
||||
public EnchantmentType(String name, ObjectCallable<Boolean> singularCallable, ObjectCallable<String> colorCallable, Class<? extends EcoEnchant> requiredToExtend) {
|
||||
this.name = name;
|
||||
this.singularCallable = singularCallable;
|
||||
this.colorCallable = colorCallable;
|
||||
this.requiredToExtend = requiredToExtend;
|
||||
color = colorCallable.call();
|
||||
singular = singularCallable.call();
|
||||
values.add(this);
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
this.color = colorCallable.call();
|
||||
this.singular = singularCallable.call();
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isSingular() {
|
||||
return singular;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class<? extends EcoEnchant> getRequiredToExtend() {
|
||||
return requiredToExtend;
|
||||
}
|
||||
|
||||
public static void update() {
|
||||
values.forEach(EnchantmentType::refresh);
|
||||
}
|
||||
|
||||
public static List<EnchantmentType> values() {
|
||||
return new ArrayList<>(values);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,384 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.artifact.*;
|
||||
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.*;
|
||||
import com.willfp.ecoenchants.enchantments.ecoenchants.special.*;
|
||||
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 org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Contains general methods for EcoEnchants
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
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 List<EcoEnchant> ecoEnchants = new ArrayList<>();
|
||||
private static final Map<NamespacedKey, EcoEnchant> byKey = new HashMap<>();
|
||||
|
||||
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();
|
||||
|
||||
/**
|
||||
* Get all registered {@link EcoEnchant}s
|
||||
*
|
||||
* @return A list of all {@link EcoEnchant}s
|
||||
*/
|
||||
public static List<EcoEnchant> getAll() {
|
||||
return ImmutableList.copyOf(ecoEnchants);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets {@link EcoEnchant} from {@link Enchantment}
|
||||
*
|
||||
* @param enchantment The enchantment
|
||||
*
|
||||
* @return The matching {@link EcoEnchant}, or null if not found.
|
||||
*/
|
||||
public static EcoEnchant getFromEnchantment(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(String name) {
|
||||
Optional<EcoEnchant> matching = getAll().stream().filter(enchant -> enchant.getName().equalsIgnoreCase(name)).findFirst();
|
||||
return matching.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(String permissionName) {
|
||||
Optional<EcoEnchant> matching = getAll().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(NamespacedKey key) {
|
||||
return byKey.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if {@link ItemStack} has any {@link EcoEnchant} matching specified {@link com.willfp.ecoenchants.enchantments.EcoEnchant.EnchantmentType}
|
||||
*
|
||||
* @param item The {@link ItemStack} to check
|
||||
* @param type The {@link com.willfp.ecoenchants.enchantments.EcoEnchant.EnchantmentType} to match
|
||||
*
|
||||
* @return True if has, false if doesn't have.
|
||||
*/
|
||||
public static boolean hasAnyOfType(ItemStack item, EcoEnchant.EnchantmentType type) {
|
||||
if (item == null) return false;
|
||||
|
||||
AtomicBoolean hasOfType = new AtomicBoolean(false);
|
||||
|
||||
if (item.getItemMeta() instanceof EnchantmentStorageMeta) {
|
||||
((EnchantmentStorageMeta) item.getItemMeta()).getStoredEnchants().forEach(((enchantment, integer) -> {
|
||||
if (getFromEnchantment(enchantment) != null) {
|
||||
if (getFromEnchantment(enchantment).getType().equals(type)) hasOfType.set(true);
|
||||
}
|
||||
}));
|
||||
} else {
|
||||
item.getEnchantments().forEach(((enchantment, integer) -> {
|
||||
if (getFromEnchantment(enchantment) != null) {
|
||||
if (getFromEnchantment(enchantment).getType().equals(type)) hasOfType.set(true);
|
||||
}
|
||||
}));
|
||||
}
|
||||
return hasOfType.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all {@link EcoEnchant}s
|
||||
* Called on /ecoreload
|
||||
*/
|
||||
public static void update() {
|
||||
for (EcoEnchant ecoEnchant : new HashSet<>(getAll())) {
|
||||
ecoEnchant.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new {@link EcoEnchant} to EcoEnchants
|
||||
* Only for internal use, enchantments are automatically added in the constructor.
|
||||
*
|
||||
* @param enchant The {@link EcoEnchant} to add
|
||||
*/
|
||||
public static void addNewEcoEnchant(EcoEnchant enchant) {
|
||||
ecoEnchants.remove(enchant);
|
||||
ecoEnchants.add(enchant);
|
||||
byKey.remove(enchant.getKey());
|
||||
byKey.put(enchant.getKey(), enchant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove {@link EcoEnchant} from EcoEnchants
|
||||
*
|
||||
* @param enchant The {@link EcoEnchant} to remove
|
||||
*/
|
||||
public static void removeEcoEnchant(EcoEnchant enchant) {
|
||||
ecoEnchants.remove(enchant);
|
||||
byKey.remove(enchant.getKey());
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class AshArtifact extends Artifact {
|
||||
public AshArtifact() {
|
||||
super(
|
||||
"ash_artifact",
|
||||
Prerequisite.MinVer1_16
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.WHITE_ASH;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
public class CloudsArtifact extends Artifact {
|
||||
public CloudsArtifact() {
|
||||
super(
|
||||
"clouds_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.REDSTONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.AQUA, 1.0f);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class CrimsonArtifact extends Artifact {
|
||||
public CrimsonArtifact() {
|
||||
super(
|
||||
"crimson_artifact",
|
||||
Prerequisite.MinVer1_16
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.CRIMSON_SPORE;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class DamageArtifact extends Artifact {
|
||||
public DamageArtifact() {
|
||||
super(
|
||||
"damage_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.DAMAGE_INDICATOR;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class DragonArtifact extends Artifact {
|
||||
public DragonArtifact() {
|
||||
super(
|
||||
"dragon_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.DRAGON_BREATH;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class DustArtifact extends Artifact {
|
||||
public DustArtifact() {
|
||||
super(
|
||||
"dust_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.CRIT;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class EmeraldArtifact extends Artifact {
|
||||
public EmeraldArtifact() {
|
||||
super(
|
||||
"emerald_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.COMPOSTER;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class EnchantmentArtifact extends Artifact {
|
||||
public EnchantmentArtifact() {
|
||||
super(
|
||||
"enchantment_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.ENCHANTMENT_TABLE;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class EndArtifact extends Artifact {
|
||||
public EndArtifact() {
|
||||
super(
|
||||
"end_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.END_ROD;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class FireArtifact extends Artifact {
|
||||
public FireArtifact() {
|
||||
super(
|
||||
"fire_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.FLAME;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class HeartArtifact extends Artifact {
|
||||
public HeartArtifact() {
|
||||
super(
|
||||
"heart_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.HEART;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class HoneyArtifact extends Artifact {
|
||||
public HoneyArtifact() {
|
||||
super(
|
||||
"honey_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.FALLING_HONEY;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class InkArtifact extends Artifact {
|
||||
public InkArtifact() {
|
||||
super(
|
||||
"ink_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.SQUID_INK;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class LavaArtifact extends Artifact {
|
||||
public LavaArtifact() {
|
||||
super(
|
||||
"lava_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.DRIP_LAVA;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class LimeArtifact extends Artifact {
|
||||
public LimeArtifact() {
|
||||
super(
|
||||
"lime_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.REDSTONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.fromRGB(3, 252, 140), 1.0f);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class MagicArtifact extends Artifact {
|
||||
public MagicArtifact() {
|
||||
super(
|
||||
"magic_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.CRIT_MAGIC;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class MagmaArtifact extends Artifact {
|
||||
public MagmaArtifact() {
|
||||
super(
|
||||
"magma_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.LAVA;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class MusicArtifact extends Artifact {
|
||||
public MusicArtifact() {
|
||||
super(
|
||||
"music_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.NOTE;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class NetherArtifact extends Artifact {
|
||||
public NetherArtifact() {
|
||||
super(
|
||||
"nether_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.PORTAL;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
public class RedstoneArtifact extends Artifact {
|
||||
public RedstoneArtifact() {
|
||||
super(
|
||||
"redstone_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.REDSTONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.RED, 1.0f);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class SmokeArtifact extends Artifact {
|
||||
public SmokeArtifact() {
|
||||
super(
|
||||
"smoke_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.CAMPFIRE_COSY_SMOKE;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class SnowArtifact extends Artifact {
|
||||
public SnowArtifact() {
|
||||
super(
|
||||
"snow_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.SNOWBALL;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class SoulArtifact extends Artifact {
|
||||
public SoulArtifact() {
|
||||
super(
|
||||
"soul_artifact",
|
||||
Prerequisite.MinVer1_16
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.SOUL;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class SoulFireArtifact extends Artifact {
|
||||
public SoulFireArtifact() {
|
||||
super(
|
||||
"soul_fire_artifact",
|
||||
Prerequisite.MinVer1_16
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.SOUL_FIRE_FLAME;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class SparkleArtifact extends Artifact {
|
||||
public SparkleArtifact() {
|
||||
super(
|
||||
"sparkle_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.FIREWORKS_SPARK;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class TearArtifact extends Artifact {
|
||||
public TearArtifact() {
|
||||
super(
|
||||
"tear_artifact",
|
||||
Prerequisite.MinVer1_16
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.DRIPPING_OBSIDIAN_TEAR;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class TotemArtifact extends Artifact {
|
||||
public TotemArtifact() {
|
||||
super(
|
||||
"totem_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.TOTEM;
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.util.optional.Prerequisite;
|
||||
import org.bukkit.Particle;
|
||||
|
||||
public class WarpedArtifact extends Artifact {
|
||||
public WarpedArtifact() {
|
||||
super(
|
||||
"warped_artifact",
|
||||
Prerequisite.MinVer1_16
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.WARPED_SPORE;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class WaterArtifact extends Artifact {
|
||||
public WaterArtifact() {
|
||||
super(
|
||||
"water_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.DRIP_WATER;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Particle;
|
||||
public class WitchArtifact extends Artifact {
|
||||
public WitchArtifact() {
|
||||
super(
|
||||
"witch_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.SPELL_WITCH;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.artifact;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Particle;
|
||||
public class ZapArtifact extends Artifact {
|
||||
public ZapArtifact() {
|
||||
super(
|
||||
"zap_artifact"
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle getParticle() {
|
||||
return Particle.REDSTONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Particle.DustOptions getDustOptions() {
|
||||
return new Particle.DustOptions(Color.YELLOW, 1.0f);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockDamageEvent;
|
||||
|
||||
public class BreaklessnessCurse extends EcoEnchant {
|
||||
public BreaklessnessCurse() {
|
||||
super(
|
||||
"breaklessness_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onDamageBlock(Player player, Block block, int level, BlockDamageEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent;
|
||||
import com.willfp.ecoenchants.util.VectorUtils;
|
||||
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
|
||||
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 java.util.HashMap;
|
||||
|
||||
public class CallingCurse extends EcoEnchant implements EcoRunnable {
|
||||
public CallingCurse() {
|
||||
super(
|
||||
"calling_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
private final HashMap<Player, Integer> players = new HashMap<>();
|
||||
|
||||
@EventHandler
|
||||
public void onArmorEquip(ArmorEquipEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
players.clear();
|
||||
EcoEnchantsPlugin.getInstance().getServer().getOnlinePlayers().forEach(player -> {
|
||||
int level = EnchantChecks.getArmorPoints(player, this, 0);
|
||||
if (level > 0) {
|
||||
players.put(player, level);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
players.forEach((player, level) -> {
|
||||
double distance = EcoEnchants.CALLING_CURSE.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance");
|
||||
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");
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.util.DurabilityUtils;
|
||||
import com.willfp.ecoenchants.util.interfaces.EcoRunnable;
|
||||
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 java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DecayCurse extends EcoEnchant implements EcoRunnable {
|
||||
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(EntityPickupItemEvent event) {
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
return;
|
||||
refreshPlayer((Player) event.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(PlayerQuitEvent event) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryDrop(EntityDropItemEvent event) {
|
||||
if (!(event.getEntity() instanceof Player))
|
||||
return;
|
||||
refreshPlayer((Player) event.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player))
|
||||
return;
|
||||
refreshPlayer((Player) event.getWhoClicked());
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
players.clear();
|
||||
EcoEnchantsPlugin.getInstance().getServer().getOnlinePlayers().forEach(player -> {
|
||||
if (Arrays.stream(player.getInventory().getContents()).parallel().anyMatch(item -> EnchantChecks.item(item, this)))
|
||||
players.add(player);
|
||||
});
|
||||
amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
}
|
||||
|
||||
private void refreshPlayer(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);
|
||||
player.updateInventory();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTime() {
|
||||
return this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "repeat-ticks");
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.util.NumberUtils;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class FragilityCurse extends EcoEnchant {
|
||||
public FragilityCurse() {
|
||||
super(
|
||||
"fragility_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onItemDamage(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));
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class HarmlessnessCurse extends EcoEnchant {
|
||||
public HarmlessnessCurse() {
|
||||
super(
|
||||
"harmlessness_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
return;
|
||||
|
||||
event.setDamage(0);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
|
||||
public class HungerCurse extends EcoEnchant {
|
||||
public HungerCurse() {
|
||||
super(
|
||||
"hunger_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onHunger(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);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.util.NumberUtils;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class InaccuracyCurse extends EcoEnchant {
|
||||
public InaccuracyCurse() {
|
||||
super(
|
||||
"inaccuracy_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onBowShoot(LivingEntity shooter, Arrow arrow, int level, 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);
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
public class MisfortuneCurse extends EcoEnchant {
|
||||
public MisfortuneCurse() {
|
||||
super(
|
||||
"misfortune_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) {
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
return;
|
||||
|
||||
event.setDropItems(false);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
|
||||
public class PermanenceCurse extends EcoEnchant {
|
||||
public PermanenceCurse() {
|
||||
super(
|
||||
"permanence_curse", EnchantmentType.CURSE
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
// Listeners are in anvil listeners
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class Abattoir extends EcoEnchant {
|
||||
public Abattoir() {
|
||||
super(
|
||||
"abattoir", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, EntityDamageByEntityEvent event) {
|
||||
if(victim instanceof Monster) return;
|
||||
|
||||
double damage = event.getDamage();
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
double bonus = (multiplier * (level + 1)) + 1;
|
||||
event.setDamage(damage * bonus);
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.nms.Cooldown;
|
||||
import com.willfp.ecoenchants.util.DurabilityUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
public class Abrasion extends EcoEnchant {
|
||||
public Abrasion() {
|
||||
super(
|
||||
"abrasion", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity uncastVictim, int level, EntityDamageByEntityEvent event) {
|
||||
if(!(uncastVictim instanceof Player)) return;
|
||||
Player victim = (Player) uncastVictim;
|
||||
|
||||
boolean notcharged = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged");
|
||||
if (attacker instanceof Player && Cooldown.getCooldown((Player) attacker) != 1.0f && !notcharged)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
public class Aerial extends EcoEnchant {
|
||||
public Aerial() {
|
||||
super(
|
||||
"aerial", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onBowShoot(LivingEntity shooter, Arrow arrow, int level, EntityShootBowEvent event) {
|
||||
if (!(event.getProjectile() instanceof Arrow)) return;
|
||||
|
||||
if (shooter.isOnGround()) return;
|
||||
|
||||
event.getProjectile().setMetadata("shot-in-air", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, 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);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
public class Aquatic extends EcoEnchant {
|
||||
public Aquatic() {
|
||||
super(
|
||||
"aquatic", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, 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);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Spider;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
|
||||
public class Arachnid extends EcoEnchant {
|
||||
public Arachnid() {
|
||||
super(
|
||||
"arachnid", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, 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);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
public class Arcanic extends EcoEnchant {
|
||||
public Arcanic() {
|
||||
super(
|
||||
"arcanic", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onDamageWearingArmor(LivingEntity victim, int level, 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);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Trident;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
public class Atmospheric extends EcoEnchant {
|
||||
public Atmospheric() {
|
||||
super(
|
||||
"atmospheric", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onTridentLaunch(LivingEntity shooter, Trident trident, int level, ProjectileLaunchEvent event) {
|
||||
if(shooter.isOnGround()) return;
|
||||
|
||||
trident.setMetadata("shot-in-air", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTridentDamage(LivingEntity attacker, LivingEntity victim, Trident trident, int level, 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);
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Backstab extends EcoEnchant {
|
||||
public Backstab() {
|
||||
super(
|
||||
"backstab", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, 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);
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.util.internal.DropQueue;
|
||||
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;
|
||||
|
||||
public class Beheading extends EcoEnchant {
|
||||
public Beheading() {
|
||||
super(
|
||||
"beheading", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
// START OF LISTENERS
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(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);
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.integrations.anticheat.AnticheatManager;
|
||||
import com.willfp.ecoenchants.integrations.antigrief.AntigriefManager;
|
||||
import com.willfp.ecoenchants.nms.BlockBreak;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class BlastMining extends EcoEnchant {
|
||||
public BlastMining() {
|
||||
super(
|
||||
"blast_mining", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(Player player, Block block, int level, BlockBreakEvent event) {
|
||||
if (block.hasMetadata("block-ignore"))
|
||||
return;
|
||||
|
||||
if(player.isSneaking() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "disable-on-sneak")) return;
|
||||
|
||||
boolean hasExploded = false;
|
||||
|
||||
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", new FixedMetadataValue(EcoEnchantsPlugin.getInstance(), true));
|
||||
BlockBreak.breakBlock(player, block1);
|
||||
block1.removeMetadata("block-ignore", EcoEnchantsPlugin.getInstance());
|
||||
}));
|
||||
|
||||
AnticheatManager.unexemptPlayer(player);
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import com.willfp.ecoenchants.nms.Cooldown;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Bleed extends EcoEnchant {
|
||||
public Bleed() {
|
||||
super(
|
||||
"bleed", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if (attacker instanceof Player && Cooldown.getCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged"))
|
||||
return;
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
return;
|
||||
|
||||
double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage");
|
||||
|
||||
int bleedCount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "amount-per-level");
|
||||
bleedCount *= level;
|
||||
final int finalBleedCount = bleedCount;
|
||||
|
||||
AtomicInteger currentBleedCount = new AtomicInteger(0);
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
currentBleedCount.addAndGet(1);
|
||||
|
||||
victim.damage(bleedDamage);
|
||||
|
||||
if (currentBleedCount.get() >= finalBleedCount) this.cancel();
|
||||
}
|
||||
}.runTaskTimer(EcoEnchantsPlugin.getInstance(), 0, 10);
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
public class Blind extends EcoEnchant {
|
||||
public Blind() {
|
||||
super(
|
||||
"blind", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {
|
||||
|
||||
if (!EnchantmentUtils.passedChance(this, level))
|
||||
return;
|
||||
|
||||
int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level");
|
||||
|
||||
victim.setVelocity(new Vector(0, 0, 0));
|
||||
victim.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, duration * level, level));
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class BlockBreather extends EcoEnchant {
|
||||
public BlockBreather() {
|
||||
super(
|
||||
"block_breather", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) {
|
||||
if(!event.getCause().equals(EntityDamageEvent.DamageCause.SUFFOCATION))
|
||||
return;
|
||||
|
||||
|
||||
if(!EnchantmentUtils.passedChance(this, level))
|
||||
return;
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Boss;
|
||||
import org.bukkit.entity.ElderGuardian;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
public class BossHunter extends EcoEnchant {
|
||||
public BossHunter() {
|
||||
super(
|
||||
"boss_hunter", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {
|
||||
if(!(victim instanceof Boss || victim instanceof ElderGuardian)) return;
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||
|
||||
double damageMultiplier = (level * multiplier) + 1;
|
||||
|
||||
event.setDamage(event.getDamage() * damageMultiplier);
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.util.NumberUtils;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.SoundCategory;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.AbstractArrow;
|
||||
import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
public class Buckshot extends EcoEnchant {
|
||||
public Buckshot() {
|
||||
super(
|
||||
"buckshot", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
@Override
|
||||
public void onBowShoot(LivingEntity shooter, Arrow arrow, int level, EntityShootBowEvent event) {
|
||||
event.getProjectile().remove();
|
||||
if(shooter instanceof Player) {
|
||||
((Player) shooter).playSound(shooter.getLocation(), Sound.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
int numberPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "amount-per-level");
|
||||
int number = numberPerLevel * level;
|
||||
double spread = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "spread-per-level");
|
||||
spread *= level;
|
||||
|
||||
for (int i = 0; i < number; i += 1) {
|
||||
|
||||
Vector velocity = event.getProjectile().getVelocity().clone();
|
||||
|
||||
velocity.add(new Vector(NumberUtils.randFloat(-spread, spread), NumberUtils.randFloat(-spread, spread), NumberUtils.randFloat(-spread, spread)));
|
||||
|
||||
Arrow arrow1 = shooter.launchProjectile(Arrow.class, velocity);
|
||||
if(EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE)) arrow1.setFireTicks(Integer.MAX_VALUE);
|
||||
if(EnchantChecks.mainhand(shooter, EcoEnchants.MARKSMAN)) arrow1.setGravity(false);
|
||||
arrow1.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Monster;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
public class Butchering extends EcoEnchant {
|
||||
public Butchering() {
|
||||
super(
|
||||
"butchering", EnchantmentType.NORMAL
|
||||
);
|
||||
}
|
||||
|
||||
// START OF LISTENERS
|
||||
|
||||
|
||||
@Override
|
||||
public void onMeleeAttack(LivingEntity attacker, LivingEntity victim, int level, EntityDamageByEntityEvent event) {
|
||||
if(victim instanceof Monster) return;
|
||||
|
||||
double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
|
||||
event.setDamage(event.getDamage() + (level * multiplier));
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user