Updated to 7.10.0 and eco 5.7.0

This commit is contained in:
Auxilor 2021-07-05 18:21:30 +02:00
parent ea7cd260e8
commit 4704c1cf53
37 changed files with 766 additions and 855 deletions

View File

@ -48,7 +48,7 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:5.6.0'
compileOnly 'com.willfp:eco:5.7.0'
compileOnly 'org.jetbrains:annotations:19.0.0'

View File

@ -1,16 +1,13 @@
package com.willfp.ecoenchants;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.eco.core.display.DisplayModule;
import com.willfp.eco.core.integrations.IntegrationLoader;
import com.willfp.eco.util.TelekinesisUtils;
import com.willfp.ecoenchants.command.commands.CommandEcodebug;
import com.willfp.ecoenchants.command.commands.CommandEcoreload;
import com.willfp.ecoenchants.command.commands.CommandEnchantinfo;
import com.willfp.ecoenchants.command.commands.CommandGiverandombook;
import com.willfp.ecoenchants.command.commands.CommandRandomenchant;
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
import com.willfp.ecoenchants.command.CommandEcoEnchants;
import com.willfp.ecoenchants.command.CommandEnchantinfo;
import com.willfp.ecoenchants.command.CommandGiverandombook;
import com.willfp.ecoenchants.config.RarityYml;
import com.willfp.ecoenchants.config.TargetYml;
import com.willfp.ecoenchants.config.VanillaEnchantsYml;
@ -81,9 +78,6 @@ public class EcoEnchantsPlugin extends EcoPlugin {
vanillaEnchantsYml = new VanillaEnchantsYml(this);
}
/**
* Code executed on plugin enable.
*/
@Override
public void enable() {
this.getExtensionLoader().loadExtensions();
@ -100,9 +94,6 @@ public class EcoEnchantsPlugin extends EcoPlugin {
TelekinesisUtils.registerTest(player -> ProxyUtils.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(player.getInventory().getItemInMainHand(), EcoEnchants.TELEKINESIS) > 0);
}
/**
* Code executed on plugin disable.
*/
@Override
public void disable() {
Bukkit.getServer().getWorlds().forEach(world -> {
@ -117,9 +108,6 @@ public class EcoEnchantsPlugin extends EcoPlugin {
this.getExtensionLoader().unloadExtensions();
}
/**
* Code executed on /ecoreload.
*/
@Override
public void onReload() {
targetYml.update();
@ -140,9 +128,6 @@ public class EcoEnchantsPlugin extends EcoPlugin {
}));
}
/**
* Code executed after server is up.
*/
@Override
public void postLoad() {
if (this.getConfigYml().getBool("loot.enabled")) {
@ -159,11 +144,6 @@ public class EcoEnchantsPlugin extends EcoPlugin {
EssentialsManager.registerEnchantments();
}
/**
* EcoEnchants-specific integrations.
*
* @return A list of all integrations.
*/
@Override
public List<IntegrationLoader> getIntegrationLoaders() {
return Arrays.asList(
@ -171,19 +151,11 @@ public class EcoEnchantsPlugin extends EcoPlugin {
);
}
/**
* EcoEnchants-specific commands.
*
* @return A list of all commands.
*/
@Override
public List<AbstractCommand> getCommands() {
public List<PluginCommand> getPluginCommands() {
return Arrays.asList(
new CommandEcodebug(this),
new CommandEcoreload(this),
new CommandEnchantinfo(this),
new CommandRandomenchant(this),
new CommandGiverandombook(this)
new CommandEcoEnchants(this)
);
}
@ -211,7 +183,8 @@ public class EcoEnchantsPlugin extends EcoPlugin {
EnchantmentRarity.class,
EnchantmentTarget.class,
EcoEnchants.class,
TabCompleterEnchantinfo.class,
CommandGiverandombook.class,
CommandEnchantinfo.class,
EnchantmentType.class,
WatcherTriggers.class
);
@ -225,6 +198,11 @@ public class EcoEnchantsPlugin extends EcoPlugin {
@Override
protected String getMinimumEcoVersion() {
return "5.6.0";
return "5.7.0";
}
@Override
public EnchantDisplay getDisplayModule() {
return (EnchantDisplay) super.getDisplayModule();
}
}

View File

@ -0,0 +1,149 @@
package com.willfp.ecoenchants.command;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.eco.core.proxy.ProxyConstants;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@SuppressWarnings("unchecked")
public class CommandDebug extends Subcommand {
/**
* Instantiate a new /ecoenchants debug command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandDebug(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin, "debug", "ecoenchants.command.debug", false);
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
if (!args.isEmpty() && args.get(0).equalsIgnoreCase("full")) {
Bukkit.getLogger().info("--------------- BEGIN DEBUG ----------------");
if (sender instanceof Player player) {
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand());
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Held Item: " + player.getInventory().getItemInMainHand());
Bukkit.getLogger().info("");
}
Bukkit.getLogger().info("Running Version: " + this.getPlugin().getDescription().getVersion());
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Loaded Extensions: " + this.getPlugin().getExtensionLoader().getLoadedExtensions().stream()
.map(extension -> extension.getName() + " v" + extension.getVersion())
.collect(Collectors.joining()));
Bukkit.getLogger().info("");
Bukkit.getLogger().info("EcoEnchants.getAll(): " + EcoEnchants.values().toString());
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Enchantment.values(): " + Arrays.toString(Enchantment.values()));
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Enchantment Cache: " + EnchantmentCache.getCache().toString());
Bukkit.getLogger().info("");
try {
Field byNameField = Enchantment.class.getDeclaredField("byName");
byNameField.setAccessible(true);
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
Bukkit.getLogger().info("Enchantment.byName: " + byName.toString());
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
Bukkit.getLogger().info("");
List<Enchantment> extern = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
extern.removeAll(new ArrayList<>(EcoEnchants.values()));
extern.removeIf(enchantment -> enchantment.getClass().toString().toLowerCase().contains("craftenchantment"));
String external = extern.stream().map(enchantment -> "{" + enchantment.toString() + ", Provider: " + enchantment.getClass().toString() + "}").collect(Collectors.joining(", "));
Bukkit.getLogger().info("External Enchantments: " + external);
Bukkit.getLogger().info("");
List<Enchantment> uncached = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
uncached.removeAll(EnchantmentCache.getCache().values().stream().map(EnchantmentCache.CacheEntry::getEnchantment).collect(Collectors.toList()));
Bukkit.getLogger().info("Uncached Enchantments: " + uncached);
Bukkit.getLogger().info("");
List<Enchantment> brokenCache = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
brokenCache.removeIf(enchantment -> !(
EnchantmentCache.getEntry(enchantment).getName().equalsIgnoreCase("null")
|| EnchantmentCache.getEntry(enchantment).getRawName().equalsIgnoreCase("null")
|| EnchantmentCache.getEntry(enchantment).getStringDescription().equalsIgnoreCase("null")));
Bukkit.getLogger().info("Enchantments with broken cache: " + brokenCache);
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Installed Plugins: " + Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList()));
Bukkit.getLogger().info("");
Set<EcoEnchant> withIssues = new HashSet<>();
EcoEnchants.values().forEach(enchant -> {
if (enchant.getRarity() == null) {
withIssues.add(enchant);
}
if (enchant.getTargets().isEmpty()) {
withIssues.add(enchant);
}
});
Bukkit.getLogger().info("Enchantments with evident issues: " + withIssues);
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Packets: " + ProtocolLibrary.getProtocolManager().getPacketListeners().stream()
.filter(packetListener -> packetListener.getSendingWhitelist().getPriority().equals(ListenerPriority.MONITOR))
.collect(Collectors.toList()));
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Server Information: ");
Bukkit.getLogger().info("Players Online: " + Bukkit.getServer().getOnlinePlayers().size());
Bukkit.getLogger().info("Bukkit IP: " + Bukkit.getIp());
Bukkit.getLogger().info("Running Version: " + Bukkit.getVersion()
+ ", Bukkit Version: " + Bukkit.getBukkitVersion()
+ ", Alt Version: " + Bukkit.getServer().getVersion()
+ ", NMS: " + ProxyConstants.NMS_VERSION);
Bukkit.getLogger().info("Motd: " + Bukkit.getServer().getMotd());
Bukkit.getLogger().info("--------------- END DEBUG ----------------");
} else {
if (sender instanceof Player player) {
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand());
player.sendMessage("Lore: ");
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Held Item: " + player.getInventory().getItemInMainHand());
Bukkit.getLogger().info("Lore: ");
ItemMeta meta = player.getInventory().getItemInMainHand().getItemMeta();
if (meta != null) {
for (String s : new ArrayList<>(meta.hasLore() ? meta.getLore() : new ArrayList<>())) {
Bukkit.getLogger().info(s);
player.sendMessage(s);
}
}
Bukkit.getLogger().info("");
}
}
};
}
}

View File

@ -0,0 +1,29 @@
package com.willfp.ecoenchants.command;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import org.jetbrains.annotations.NotNull;
public class CommandEcoEnchants extends PluginCommand {
/**
* Instantiate a new /ecoenchants command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandEcoEnchants(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin, "ecoenchants", "ecoenchants.command.ecoenchants", false);
this.addSubcommand(new CommandDebug(plugin))
.addSubcommand(new CommandReload(plugin))
.addSubcommand(new CommandGiverandombook(plugin))
.addSubcommand(new CommandRandomenchant(plugin));
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
};
}
}

View File

@ -0,0 +1,179 @@
package com.willfp.ecoenchants.command;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.TabCompleteHandler;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.eco.core.config.ConfigUpdater;
import com.willfp.eco.util.StringUtils;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class CommandEnchantinfo extends PluginCommand {
/**
* The cached enchantment names.
*/
private static final List<String> ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled)
.map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).collect(Collectors.toList());
/**
* Instantiate a new /enchantinfo command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandEnchantinfo(@NotNull final EcoPlugin plugin) {
super(plugin, "enchantinfo", "ecoenchants.command.enchantinfo", false);
}
/**
* Called on reload.
*/
@ConfigUpdater
public static void reload() {
ENCHANT_NAMES.clear();
ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).collect(Collectors.toList()));
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("missing-enchant"));
return;
}
StringBuilder nameBuilder = new StringBuilder();
args.forEach(arg -> nameBuilder.append(arg).append(" "));
String searchName = nameBuilder.toString();
searchName = searchName.substring(0, searchName.length() - 1);
EcoEnchant enchantment = EcoEnchants.getByName(searchName);
if (enchantment == null) {
String finalSearchName = searchName;
enchantment = EcoEnchants.values().stream().filter(ecoEnchant -> ChatColor.stripColor(ecoEnchant.getDisplayName()).equalsIgnoreCase(finalSearchName)).findFirst().orElse(null);
}
if (enchantment == null || !enchantment.isEnabled()) {
String message = this.getPlugin().getLangYml().getMessage("not-found").replace("%name%", searchName);
sender.sendMessage(message);
return;
}
Set<String> conflictNames = new HashSet<>();
Set<Enchantment> conflicts = enchantment.getConflicts();
new HashSet<>(conflicts).forEach(enchantment1 -> {
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment1);
if (ecoEnchant != null && !ecoEnchant.isEnabled()) {
conflicts.remove(enchantment1);
}
});
conflicts.forEach((enchantment1 -> {
if (EcoEnchants.getFromEnchantment(enchantment1) != null) {
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getDisplayName());
} else {
conflictNames.add(this.getPlugin().getLangYml().getString("enchantments." + enchantment1.getKey().getKey() + ".name"));
}
}));
StringBuilder conflictNamesBuilder = new StringBuilder();
conflictNames.forEach(name1 -> conflictNamesBuilder.append(name1).append(", "));
String allConflicts = conflictNamesBuilder.toString();
if (allConflicts.length() >= 2) {
allConflicts = allConflicts.substring(0, allConflicts.length() - 2);
} else {
allConflicts = StringUtils.translate(this.getPlugin().getLangYml().getString("no-conflicts"));
}
Set<Material> targets = enchantment.getTargetMaterials();
Set<String> applicableItemsSet = new HashSet<>();
if (this.getPlugin().getConfigYml().getBool("commands.enchantinfo.show-target-group")) {
enchantment.getTargets().forEach(target -> {
String targetName = target.getName();
targetName = targetName.toLowerCase();
targetName = targetName.replace("_", " ");
targetName = WordUtils.capitalize(targetName);
applicableItemsSet.add(targetName);
});
} else {
targets.forEach(material -> {
String matName = material.toString();
matName = matName.toLowerCase();
matName = matName.replace("_", " ");
matName = WordUtils.capitalize(matName);
applicableItemsSet.add(matName);
});
}
StringBuilder targetNamesBuilder = new StringBuilder();
applicableItemsSet.forEach(name1 -> targetNamesBuilder.append(name1).append(", "));
String allTargets = targetNamesBuilder.toString();
if (allTargets.length() >= 2) {
allTargets = allTargets.substring(0, allTargets.length() - 2);
} else {
allTargets = StringUtils.translate(this.getPlugin().getLangYml().getString("no-targets"));
}
String maxLevel = String.valueOf(enchantment.getMaxLevel());
final String finalName = EnchantmentCache.getEntry(enchantment).getName();
final String finalDescription = EnchantmentCache.getEntry(enchantment).getStringDescription();
final String finalTargets = allTargets;
final String finalConflicts = allConflicts;
final String finalMaxLevel = maxLevel;
Arrays.asList(this.getPlugin().getLangYml().getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> {
string = string.replace("%name%", finalName)
.replace("%description%", finalDescription)
.replace("%target%", finalTargets)
.replace("%conflicts%", finalConflicts)
.replace("%maxlevel%", finalMaxLevel);
sender.sendMessage(string);
}));
};
}
@Override
public TabCompleteHandler getTabCompleter() {
return (sender, args) -> {
List<String> completions = new ArrayList<>();
if (args.isEmpty()) {
// Currently, this case is not ever reached
return ENCHANT_NAMES;
}
StringUtil.copyPartialMatches(String.join(" ", args), ENCHANT_NAMES, completions);
if (args.size() > 1) { // Remove all previous words from the candidate of completions
ArrayList<String> finishedArgs = new ArrayList<>(args);
finishedArgs.remove(args.size() - 1);
String prefix = String.join(" ", finishedArgs);
completions = completions.stream().map(enchantName -> StringUtils.removePrefix(enchantName, prefix).trim()).collect(Collectors.toList());
}
Collections.sort(completions);
return completions;
};
}
}

View File

@ -0,0 +1,127 @@
package com.willfp.ecoenchants.command;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.TabCompleteHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.eco.core.config.ConfigUpdater;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class CommandGiverandombook extends Subcommand {
/**
* The cached enchantment names.
*/
private static final List<String> RARITY_NAMES = EnchantmentRarity.values().stream().map(EnchantmentRarity::getName).collect(Collectors.toList());
/**
* Instantiate a new command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandGiverandombook(@NotNull final EcoPlugin plugin) {
super(plugin, "giverandombook", "ecoenchants.command.giverandombook", false);
}
/**
* Called on /reload.
*/
@ConfigUpdater
public static void reload() {
RARITY_NAMES.clear();
RARITY_NAMES.addAll(EnchantmentRarity.values().stream().map(EnchantmentRarity::getName).collect(Collectors.toList()));
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("requires-player"));
return;
}
Player player = Bukkit.getServer().getPlayer(args.get(0));
EnchantmentRarity rarity = args.size() >= 2 ? EnchantmentRarity.getByName(args.get(1).toLowerCase()) : null;
if (player == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
ItemStack itemStack = new ItemStack(Material.ENCHANTED_BOOK);
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) itemStack.getItemMeta();
List<Enchantment> allowed = Arrays.stream(Enchantment.values()).filter(enchantment -> {
if (enchantment instanceof EcoEnchant) {
return ((EcoEnchant) enchantment).isEnabled();
}
return true;
}).filter(enchantment -> {
if (rarity != null) {
if (!(enchantment instanceof EcoEnchant)) {
return false;
}
return ((EcoEnchant) enchantment).getRarity().equals(rarity);
}
return true;
}).collect(Collectors.toList());
Enchantment enchantment = allowed.get(NumberUtils.randInt(0, allowed.size() - 1));
int level = NumberUtils.randInt(1, enchantment.getMaxLevel());
meta.addStoredEnchant(enchantment, level, true);
itemStack.setItemMeta(meta);
for (ItemStack stack : player.getInventory().addItem(itemStack).values()) {
player.getWorld().dropItem(player.getLocation(), stack);
}
String message = this.getPlugin().getLangYml().getMessage("gave-random-book");
message = message.replace("%enchantment%", EnchantmentCache.getEntry(enchantment).getName() + " " + NumberUtils.toNumeral(level) + "§r");
sender.sendMessage(message);
String message2 = this.getPlugin().getLangYml().getMessage("received-random-book");
message2 = message2.replace("%enchantment%", EnchantmentCache.getEntry(enchantment).getName() + " " + NumberUtils.toNumeral(level) + "§r");
player.sendMessage(message2);
};
}
@Override
public TabCompleteHandler getTabCompleter() {
return (sender, args) -> {
List<String> completions = new ArrayList<>();
List<String> playerNames = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
if (args.isEmpty()) {
// Currently, this case is not ever reached
return playerNames;
}
if (args.size() == 1) {
StringUtil.copyPartialMatches(String.join(" ", args.get(0)), playerNames, completions);
}
if (args.size() == 2) {
StringUtil.copyPartialMatches(String.join(" ", args.get(1)), RARITY_NAMES, completions);
}
Collections.sort(completions);
return completions;
};
}
}

View File

@ -0,0 +1,145 @@
package com.willfp.ecoenchants.command;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.TabCompleteHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class CommandRandomenchant extends Subcommand {
/**
* Instantiate a new /ecoreload command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandRandomenchant(@NotNull final EcoPlugin plugin) {
super(plugin, "randomenchant", "ecoenchants.command.randomenchant", false);
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
Player player;
if ((args.isEmpty() && sender instanceof Player) || !sender.hasPermission("ecoenchants.randomenchant.others")) {
player = (Player) sender;
} else {
player = Bukkit.getServer().getPlayer(args.get(0));
}
if (player == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
ItemStack itemStack = player.getInventory().getItemInMainHand();
ItemMeta meta = itemStack.getItemMeta();
if (itemStack.getType() == Material.AIR || meta == null || !EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) {
if (player.equals(sender)) {
player.sendMessage(this.getPlugin().getLangYml().getMessage("must-hold-item"));
} else {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("must-hold-item-other"));
}
return;
}
List<EcoEnchant> ecoEnchants = new ArrayList<>(EcoEnchants.values());
Collections.shuffle(ecoEnchants);
EcoEnchant enchant = null;
List<Enchantment> onItem = new ArrayList<>();
if (meta instanceof EnchantmentStorageMeta) {
onItem.addAll(((EnchantmentStorageMeta) meta).getStoredEnchants().keySet());
} else {
onItem.addAll(meta.getEnchants().keySet());
}
for (EcoEnchant ecoEnchant : ecoEnchants) {
if (ecoEnchant.canEnchantItem(itemStack)) {
if (!ecoEnchant.conflictsWithAny(onItem)) {
if (ecoEnchant.isEnabled()) {
if (onItem.stream().noneMatch(enchantment -> enchantment.conflictsWith(ecoEnchant))) {
if (!onItem.contains(ecoEnchant)) {
boolean conflicts = false;
for (Enchantment enchantment : onItem) {
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
EcoEnchant ecoEnchantOnItem = EcoEnchants.getFromEnchantment(enchantment);
if (ecoEnchantOnItem.getType().equals(ecoEnchant.getType()) && ecoEnchantOnItem.getType().isSingular()) {
conflicts = true;
}
}
}
if (this.getPlugin().getConfigYml().getBool("anvil.hard-cap.enabled")
&& !player.hasPermission("ecoenchants.randomenchant.bypasshardcap")
&& onItem.size() >= this.getPlugin().getConfigYml().getInt("anvil.hard-cap.cap")) {
conflicts = true;
}
if (!conflicts) {
enchant = ecoEnchant;
}
}
}
}
}
}
}
if (enchant == null) {
player.sendMessage(this.getPlugin().getLangYml().getMessage("no-enchants-available"));
return;
}
if (meta instanceof EnchantmentStorageMeta) {
((EnchantmentStorageMeta) meta).addStoredEnchant(enchant, enchant.getMaxLevel(), true);
} else {
meta.addEnchant(enchant, enchant.getMaxLevel(), true);
}
itemStack.setItemMeta(meta);
String message = this.getPlugin().getLangYml().getMessage("applied-random-enchant");
message = message.replace("%enchantment%", EnchantmentCache.getEntry(enchant).getName() + "§r");
player.sendMessage(message);
};
}
@Override
public TabCompleteHandler getTabCompleter() {
return (sender, args) -> {
List<String> completions = new ArrayList<>();
List<String> playerNames = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
if (args.isEmpty() || !sender.hasPermission("ecoenchants.randomenchant.others")) {
// Currently, this case is not ever reached
return playerNames;
}
if (args.size() == 1) {
StringUtil.copyPartialMatches(String.join(" ", args), playerNames, completions);
Collections.sort(completions);
return completions;
}
return new ArrayList<>();
};
}
}

View File

@ -0,0 +1,25 @@
package com.willfp.ecoenchants.command;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import org.jetbrains.annotations.NotNull;
public class CommandReload extends Subcommand {
/**
* Instantiate a new command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandReload(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin, "reload", "ecoenchants.command.reload", false);
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
this.getPlugin().reload();
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
};
}
}

View File

@ -1,148 +0,0 @@
package com.willfp.ecoenchants.command.commands;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.proxy.ProxyConstants;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@SuppressWarnings("unchecked")
public class CommandEcodebug extends AbstractCommand {
/**
* Instantiate a new /ecodebug command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandEcodebug(@NotNull final EcoPlugin plugin) {
super(plugin, "ecodebug", "ecoenchants.ecodebug", false);
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
if (!args.isEmpty() && args.get(0).equalsIgnoreCase("full")) {
Bukkit.getLogger().info("--------------- BEGIN DEBUG ----------------");
if (sender instanceof Player player) {
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand());
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Held Item: " + player.getInventory().getItemInMainHand());
Bukkit.getLogger().info("");
}
Bukkit.getLogger().info("Running Version: " + this.getPlugin().getDescription().getVersion());
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Loaded Extensions: " + this.getPlugin().getExtensionLoader().getLoadedExtensions().stream()
.map(extension -> extension.getName() + " v" + extension.getVersion())
.collect(Collectors.joining()));
Bukkit.getLogger().info("");
Bukkit.getLogger().info("EcoEnchants.getAll(): " + EcoEnchants.values().toString());
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Enchantment.values(): " + Arrays.toString(Enchantment.values()));
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Enchantment Cache: " + EnchantmentCache.getCache().toString());
Bukkit.getLogger().info("");
try {
Field byNameField = Enchantment.class.getDeclaredField("byName");
byNameField.setAccessible(true);
Map<String, Enchantment> byName = (Map<String, Enchantment>) byNameField.get(null);
Bukkit.getLogger().info("Enchantment.byName: " + byName.toString());
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
Bukkit.getLogger().info("");
List<Enchantment> extern = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
extern.removeAll(new ArrayList<>(EcoEnchants.values()));
extern.removeIf(enchantment -> enchantment.getClass().toString().toLowerCase().contains("craftenchantment"));
String external = extern.stream().map(enchantment -> "{" + enchantment.toString() + ", Provider: " + enchantment.getClass().toString() + "}").collect(Collectors.joining(", "));
Bukkit.getLogger().info("External Enchantments: " + external);
Bukkit.getLogger().info("");
List<Enchantment> uncached = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
uncached.removeAll(EnchantmentCache.getCache().values().stream().map(EnchantmentCache.CacheEntry::getEnchantment).collect(Collectors.toList()));
Bukkit.getLogger().info("Uncached Enchantments: " + uncached);
Bukkit.getLogger().info("");
List<Enchantment> brokenCache = Arrays.stream(Enchantment.values()).collect(Collectors.toList());
brokenCache.removeIf(enchantment -> !(
EnchantmentCache.getEntry(enchantment).getName().equalsIgnoreCase("null")
|| EnchantmentCache.getEntry(enchantment).getRawName().equalsIgnoreCase("null")
|| EnchantmentCache.getEntry(enchantment).getStringDescription().equalsIgnoreCase("null")));
Bukkit.getLogger().info("Enchantments with broken cache: " + brokenCache);
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Installed Plugins: " + Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toList()));
Bukkit.getLogger().info("");
Set<EcoEnchant> withIssues = new HashSet<>();
EcoEnchants.values().forEach(enchant -> {
if (enchant.getRarity() == null) {
withIssues.add(enchant);
}
if (enchant.getTargets().isEmpty()) {
withIssues.add(enchant);
}
});
Bukkit.getLogger().info("Enchantments with evident issues: " + withIssues);
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Packets: " + ProtocolLibrary.getProtocolManager().getPacketListeners().stream()
.filter(packetListener -> packetListener.getSendingWhitelist().getPriority().equals(ListenerPriority.MONITOR))
.collect(Collectors.toList()));
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Server Information: ");
Bukkit.getLogger().info("Players Online: " + Bukkit.getServer().getOnlinePlayers().size());
Bukkit.getLogger().info("Bukkit IP: " + Bukkit.getIp());
Bukkit.getLogger().info("Running Version: " + Bukkit.getVersion()
+ ", Bukkit Version: " + Bukkit.getBukkitVersion()
+ ", Alt Version: " + Bukkit.getServer().getVersion()
+ ", NMS: " + ProxyConstants.NMS_VERSION);
Bukkit.getLogger().info("Motd: " + Bukkit.getServer().getMotd());
Bukkit.getLogger().info("--------------- END DEBUG ----------------");
} else {
if (sender instanceof Player player) {
player.sendMessage("Held Item: " + player.getInventory().getItemInMainHand());
player.sendMessage("Lore: ");
Bukkit.getLogger().info("");
Bukkit.getLogger().info("Held Item: " + player.getInventory().getItemInMainHand());
Bukkit.getLogger().info("Lore: ");
ItemMeta meta = player.getInventory().getItemInMainHand().getItemMeta();
if (meta != null) {
for (String s : new ArrayList<>(meta.hasLore() ? meta.getLore() : new ArrayList<>())) {
Bukkit.getLogger().info(s);
player.sendMessage(s);
}
}
Bukkit.getLogger().info("");
}
}
}
}

View File

@ -1,26 +0,0 @@
package com.willfp.ecoenchants.command.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class CommandEcoreload extends AbstractCommand {
/**
* Instantiate a new /ecoreload command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandEcoreload(@NotNull final EcoPlugin plugin) {
super(plugin, "ecoreload", "ecoenchants.reload", false);
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
this.getPlugin().reload();
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
}
}

View File

@ -1,139 +0,0 @@
package com.willfp.ecoenchants.command.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.AbstractTabCompleter;
import com.willfp.eco.util.StringUtils;
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterEnchantinfo;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.apache.commons.lang.WordUtils;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class CommandEnchantinfo extends AbstractCommand {
/**
* Instantiate a new /enchantinfo command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandEnchantinfo(@NotNull final EcoPlugin plugin) {
super(plugin, "enchantinfo", "ecoenchants.enchantinfo", false);
}
@Override
public AbstractTabCompleter getTab() {
return new TabCompleterEnchantinfo(this);
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("missing-enchant"));
return;
}
StringBuilder nameBuilder = new StringBuilder();
args.forEach(arg -> nameBuilder.append(arg).append(" "));
String searchName = nameBuilder.toString();
searchName = searchName.substring(0, searchName.length() - 1);
EcoEnchant enchantment = EcoEnchants.getByName(searchName);
if (enchantment == null) {
String finalSearchName = searchName;
enchantment = EcoEnchants.values().stream().filter(ecoEnchant -> ChatColor.stripColor(ecoEnchant.getDisplayName()).equalsIgnoreCase(finalSearchName)).findFirst().orElse(null);
}
if (enchantment == null || !enchantment.isEnabled()) {
String message = this.getPlugin().getLangYml().getMessage("not-found").replace("%name%", searchName);
sender.sendMessage(message);
return;
}
Set<String> conflictNames = new HashSet<>();
Set<Enchantment> conflicts = enchantment.getConflicts();
new HashSet<>(conflicts).forEach(enchantment1 -> {
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment1);
if (ecoEnchant != null && !ecoEnchant.isEnabled()) {
conflicts.remove(enchantment1);
}
});
conflicts.forEach((enchantment1 -> {
if (EcoEnchants.getFromEnchantment(enchantment1) != null) {
conflictNames.add(EcoEnchants.getFromEnchantment(enchantment1).getDisplayName());
} else {
conflictNames.add(this.getPlugin().getLangYml().getString("enchantments." + enchantment1.getKey().getKey() + ".name"));
}
}));
StringBuilder conflictNamesBuilder = new StringBuilder();
conflictNames.forEach(name1 -> conflictNamesBuilder.append(name1).append(", "));
String allConflicts = conflictNamesBuilder.toString();
if (allConflicts.length() >= 2) {
allConflicts = allConflicts.substring(0, allConflicts.length() - 2);
} else {
allConflicts = StringUtils.translate(this.getPlugin().getLangYml().getString("no-conflicts"));
}
Set<Material> targets = enchantment.getTargetMaterials();
Set<String> applicableItemsSet = new HashSet<>();
if (this.getPlugin().getConfigYml().getBool("commands.enchantinfo.show-target-group")) {
enchantment.getTargets().forEach(target -> {
String targetName = target.getName();
targetName = targetName.toLowerCase();
targetName = targetName.replace("_", " ");
targetName = WordUtils.capitalize(targetName);
applicableItemsSet.add(targetName);
});
} else {
targets.forEach(material -> {
String matName = material.toString();
matName = matName.toLowerCase();
matName = matName.replace("_", " ");
matName = WordUtils.capitalize(matName);
applicableItemsSet.add(matName);
});
}
StringBuilder targetNamesBuilder = new StringBuilder();
applicableItemsSet.forEach(name1 -> targetNamesBuilder.append(name1).append(", "));
String allTargets = targetNamesBuilder.toString();
if (allTargets.length() >= 2) {
allTargets = allTargets.substring(0, allTargets.length() - 2);
} else {
allTargets = StringUtils.translate(this.getPlugin().getLangYml().getString("no-targets"));
}
String maxLevel = String.valueOf(enchantment.getMaxLevel());
final String finalName = EnchantmentCache.getEntry(enchantment).getName();
final String finalDescription = EnchantmentCache.getEntry(enchantment).getStringDescription();
final String finalTargets = allTargets;
final String finalConflicts = allConflicts;
final String finalMaxLevel = maxLevel;
Arrays.asList(this.getPlugin().getLangYml().getMessage("enchantinfo").split("\\r?\\n")).forEach((string -> {
string = string.replace("%name%", finalName)
.replace("%description%", finalDescription)
.replace("%target%", finalTargets)
.replace("%conflicts%", finalConflicts)
.replace("%maxlevel%", finalMaxLevel);
sender.sendMessage(string);
}));
}
}

View File

@ -1,89 +0,0 @@
package com.willfp.ecoenchants.command.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.AbstractTabCompleter;
import com.willfp.eco.util.NumberUtils;
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterGiverandombook;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class CommandGiverandombook extends AbstractCommand {
/**
* Instantiate a new /ecoreload command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandGiverandombook(@NotNull final EcoPlugin plugin) {
super(plugin, "giverandombook", "ecoenchants.randombook", false);
}
@Override
public AbstractTabCompleter getTab() {
return new TabCompleterGiverandombook(this);
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("requires-player"));
return;
}
Player player = Bukkit.getServer().getPlayer(args.get(0));
EnchantmentRarity rarity = args.size() >= 2 ? EnchantmentRarity.getByName(args.get(1).toLowerCase()) : null;
if (player == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
ItemStack itemStack = new ItemStack(Material.ENCHANTED_BOOK);
EnchantmentStorageMeta meta = (EnchantmentStorageMeta) itemStack.getItemMeta();
List<Enchantment> allowed = Arrays.stream(Enchantment.values()).filter(enchantment -> {
if (enchantment instanceof EcoEnchant) {
return ((EcoEnchant) enchantment).isEnabled();
}
return true;
}).filter(enchantment -> {
if (rarity != null) {
if (!(enchantment instanceof EcoEnchant)) {
return false;
}
return ((EcoEnchant) enchantment).getRarity().equals(rarity);
}
return true;
}).collect(Collectors.toList());
Enchantment enchantment = allowed.get(NumberUtils.randInt(0, allowed.size() - 1));
int level = NumberUtils.randInt(1, enchantment.getMaxLevel());
meta.addStoredEnchant(enchantment, level, true);
itemStack.setItemMeta(meta);
for (ItemStack stack : player.getInventory().addItem(itemStack).values()) {
player.getWorld().dropItem(player.getLocation(), stack);
}
String message = this.getPlugin().getLangYml().getMessage("gave-random-book");
message = message.replace("%enchantment%", EnchantmentCache.getEntry(enchantment).getName() + " " + NumberUtils.toNumeral(level) + "§r");
sender.sendMessage(message);
String message2 = this.getPlugin().getLangYml().getMessage("received-random-book");
message2 = message2.replace("%enchantment%", EnchantmentCache.getEntry(enchantment).getName() + " " + NumberUtils.toNumeral(level) + "§r");
player.sendMessage(message2);
}
}

View File

@ -1,126 +0,0 @@
package com.willfp.ecoenchants.command.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.AbstractTabCompleter;
import com.willfp.ecoenchants.command.tabcompleters.TabCompleterRandomEnchant;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class CommandRandomenchant extends AbstractCommand {
/**
* Instantiate a new /ecoreload command handler.
*
* @param plugin The plugin for the commands to listen for.
*/
public CommandRandomenchant(@NotNull final EcoPlugin plugin) {
super(plugin, "randomenchant", "ecoenchants.randomenchant", false);
}
@Override
public AbstractTabCompleter getTab() {
return new TabCompleterRandomEnchant(this);
}
@Override
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
Player player;
if ((args.isEmpty() && sender instanceof Player) || !sender.hasPermission("ecoenchants.randomenchant.others")) {
player = (Player) sender;
} else {
player = Bukkit.getServer().getPlayer(args.get(0));
}
if (player == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
ItemStack itemStack = player.getInventory().getItemInMainHand();
ItemMeta meta = itemStack.getItemMeta();
if (itemStack.getType() == Material.AIR || meta == null || !EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) {
if (player.equals(sender)) {
player.sendMessage(this.getPlugin().getLangYml().getMessage("must-hold-item"));
} else {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("must-hold-item-other"));
}
return;
}
List<EcoEnchant> ecoEnchants = new ArrayList<>(EcoEnchants.values());
Collections.shuffle(ecoEnchants);
EcoEnchant enchant = null;
List<Enchantment> onItem = new ArrayList<>();
if (meta instanceof EnchantmentStorageMeta) {
onItem.addAll(((EnchantmentStorageMeta) meta).getStoredEnchants().keySet());
} else {
onItem.addAll(meta.getEnchants().keySet());
}
for (EcoEnchant ecoEnchant : ecoEnchants) {
if (ecoEnchant.canEnchantItem(itemStack)) {
if (!ecoEnchant.conflictsWithAny(onItem)) {
if (ecoEnchant.isEnabled()) {
if (onItem.stream().noneMatch(enchantment -> enchantment.conflictsWith(ecoEnchant))) {
if (!onItem.contains(ecoEnchant)) {
boolean conflicts = false;
for (Enchantment enchantment : onItem) {
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
EcoEnchant ecoEnchantOnItem = EcoEnchants.getFromEnchantment(enchantment);
if (ecoEnchantOnItem.getType().equals(ecoEnchant.getType()) && ecoEnchantOnItem.getType().isSingular()) {
conflicts = true;
}
}
}
if (this.getPlugin().getConfigYml().getBool("anvil.hard-cap.enabled")
&& !player.hasPermission("ecoenchants.randomenchant.bypasshardcap")
&& onItem.size() >= this.getPlugin().getConfigYml().getInt("anvil.hard-cap.cap")) {
conflicts = true;
}
if (!conflicts) {
enchant = ecoEnchant;
}
}
}
}
}
}
}
if (enchant == null) {
player.sendMessage(this.getPlugin().getLangYml().getMessage("no-enchants-available"));
return;
}
if (meta instanceof EnchantmentStorageMeta) {
((EnchantmentStorageMeta) meta).addStoredEnchant(enchant, enchant.getMaxLevel(), true);
} else {
meta.addEnchant(enchant, enchant.getMaxLevel(), true);
}
itemStack.setItemMeta(meta);
String message = this.getPlugin().getLangYml().getMessage("applied-random-enchant");
message = message.replace("%enchantment%", EnchantmentCache.getEntry(enchant).getName() + "§r");
player.sendMessage(message);
}
}

View File

@ -1,74 +0,0 @@
package com.willfp.ecoenchants.command.tabcompleters;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.AbstractTabCompleter;
import com.willfp.eco.core.config.ConfigUpdater;
import com.willfp.eco.util.StringUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class TabCompleterEnchantinfo extends AbstractTabCompleter {
/**
* The cached enchantment names.
*/
private static final List<String> ENCHANT_NAMES = EcoEnchants.values().stream().filter(EcoEnchant::isEnabled)
.map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).collect(Collectors.toList());
/**
* Instantiate a new tab-completer for /enchantinfo.
*
* @param command /enchantinfo.
*/
public TabCompleterEnchantinfo(@NotNull final AbstractCommand command) {
super(command);
}
/**
* Called on /ecoreload.
*/
@ConfigUpdater
public static void reload() {
ENCHANT_NAMES.clear();
ENCHANT_NAMES.addAll(EcoEnchants.values().stream().filter(EcoEnchant::isEnabled).map(EcoEnchant::getDisplayName).map(ChatColor::stripColor).collect(Collectors.toList()));
}
/**
* The execution of the tabcompleter.
*
* @param sender The sender of the command.
* @param args The arguments of the command.
* @return A list of tab-completions.
*/
@Override
public List<String> onTab(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
List<String> completions = new ArrayList<>();
if (args.isEmpty()) {
// Currently, this case is not ever reached
return ENCHANT_NAMES;
}
StringUtil.copyPartialMatches(String.join(" ", args), ENCHANT_NAMES, completions);
if (args.size() > 1) { // Remove all previous words from the candidate of completions
ArrayList<String> finishedArgs = new ArrayList<>(args);
finishedArgs.remove(args.size() - 1);
String prefix = String.join(" ", finishedArgs);
completions = completions.stream().map(enchantName -> StringUtils.removePrefix(enchantName, prefix).trim()).collect(Collectors.toList());
}
Collections.sort(completions);
return completions;
}
}

View File

@ -1,72 +0,0 @@
package com.willfp.ecoenchants.command.tabcompleters;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.AbstractTabCompleter;
import com.willfp.eco.core.config.ConfigUpdater;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class TabCompleterGiverandombook extends AbstractTabCompleter {
/**
* The cached enchantment names.
*/
private static final List<String> RARITY_NAMES = EnchantmentRarity.values().stream().map(EnchantmentRarity::getName).collect(Collectors.toList());
/**
* Instantiate a new tab-completer for /enchantinfo.
*
* @param command /enchantinfo.
*/
public TabCompleterGiverandombook(@NotNull final AbstractCommand command) {
super(command);
}
/**
* Called on /ecoreload.
*/
@ConfigUpdater
public static void reload() {
RARITY_NAMES.clear();
RARITY_NAMES.addAll(EnchantmentRarity.values().stream().map(EnchantmentRarity::getName).collect(Collectors.toList()));
}
/**
* The execution of the tabcompleter.
*
* @param sender The sender of the command.
* @param args The arguments of the command.
* @return A list of tab-completions.
*/
@Override
public List<String> onTab(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
List<String> completions = new ArrayList<>();
List<String> playerNames = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
if (args.isEmpty()) {
// Currently, this case is not ever reached
return playerNames;
}
if (args.size() == 1) {
StringUtil.copyPartialMatches(String.join(" ", args.get(0)), playerNames, completions);
}
if (args.size() == 2) {
StringUtil.copyPartialMatches(String.join(" ", args.get(1)), RARITY_NAMES, completions);
}
Collections.sort(completions);
return completions;
}
}

View File

@ -1,53 +0,0 @@
package com.willfp.ecoenchants.command.tabcompleters;
import com.willfp.eco.core.command.AbstractCommand;
import com.willfp.eco.core.command.AbstractTabCompleter;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class TabCompleterRandomEnchant extends AbstractTabCompleter {
/**
* Instantiate a new tab-completer for /randomenchant.
*
* @param command /randomenchant.
*/
public TabCompleterRandomEnchant(@NotNull final AbstractCommand command) {
super(command);
}
/**
* The execution of the tabcompleter.
*
* @param sender The sender of the command.
* @param args The arguments of the command.
* @return A list of tab-completions.
*/
@Override
public List<String> onTab(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
List<String> completions = new ArrayList<>();
List<String> playerNames = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
if (args.isEmpty() || !sender.hasPermission("ecoenchants.randomenchant.others")) {
// Currently, this case is not ever reached
return playerNames;
}
if (args.size() == 1) {
StringUtil.copyPartialMatches(String.join(" ", args), playerNames, completions);
Collections.sort(completions);
return completions;
}
return new ArrayList<>();
}
}

View File

@ -6,7 +6,7 @@ import com.willfp.eco.util.StringUtils;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public class DescriptionOptions extends PluginDependent {
public class DescriptionOptions extends PluginDependent<EcoPlugin> {
/**
* The threshold below which to describe enchantments.
*/

View File

@ -18,7 +18,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
public class DisplayOptions extends PluginDependent {
public class DisplayOptions extends PluginDependent<EcoPlugin> {
/**
* The description options being used.
*/

View File

@ -5,7 +5,7 @@ import com.willfp.eco.core.PluginDependent;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public class NumbersOptions extends PluginDependent {
public class NumbersOptions extends PluginDependent<EcoPlugin> {
/**
* If numerals should be used.
* <p>

View File

@ -5,7 +5,7 @@ import com.willfp.eco.core.PluginDependent;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public class ShrinkOptions extends PluginDependent {
public class ShrinkOptions extends PluginDependent<EcoPlugin> {
/**
* The threshold above which enchantments will be shrunk.
*/

View File

@ -1,7 +1,7 @@
package com.willfp.ecoenchants.display.options.sorting.implementations;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
@ -10,13 +10,13 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public class AlphabeticSorter extends PluginDependent implements EnchantmentSorter {
public class AlphabeticSorter extends PluginDependent<EcoEnchantsPlugin> implements EnchantmentSorter {
/**
* Instantiate sorter.
*
* @param plugin Instance of EcoEnchants.
*/
public AlphabeticSorter(@NotNull final EcoPlugin plugin) {
public AlphabeticSorter(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin);
}

View File

@ -1,7 +1,7 @@
package com.willfp.ecoenchants.display.options.sorting.implementations;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
@ -11,13 +11,13 @@ import org.jetbrains.annotations.NotNull;
import java.util.Comparator;
import java.util.List;
public class LengthSorter extends PluginDependent implements EnchantmentSorter {
public class LengthSorter extends PluginDependent<EcoEnchantsPlugin> implements EnchantmentSorter {
/**
* Instantiate sorter.
*
* @param plugin Instance of EcoEnchants.
*/
public LengthSorter(@NotNull final EcoPlugin plugin) {
public LengthSorter(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin);
}

View File

@ -1,8 +1,7 @@
package com.willfp.ecoenchants.display.options.sorting.implementations;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.ecoenchants.display.EnchantDisplay;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
@ -12,26 +11,26 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class RarityAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
public class RarityAlphabeticSorter extends PluginDependent<EcoEnchantsPlugin> implements EnchantmentSorter {
/**
* Instantiate sorter.
*
* @param plugin Instance of EcoEnchants.
*/
public RarityAlphabeticSorter(@NotNull final EcoPlugin plugin) {
public RarityAlphabeticSorter(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin);
}
@Override
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
if (this.getPlugin().getDisplayModule().getOptions().getSortedRarities().isEmpty()
|| this.getPlugin().getDisplayModule().getOptions().getSortedTypes().isEmpty()) {
this.getPlugin().getDisplayModule().update();
}
List<Enchantment> sorted = new ArrayList<>();
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
this.getPlugin().getDisplayModule().getOptions().getSortedRarities().forEach(enchantmentRarity -> {
List<Enchantment> rarityEnchants = new ArrayList<>();
for (Enchantment enchantment : toSort) {
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {

View File

@ -1,8 +1,7 @@
package com.willfp.ecoenchants.display.options.sorting.implementations;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.ecoenchants.display.EnchantDisplay;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
@ -13,25 +12,25 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class RarityLengthSorter extends PluginDependent implements EnchantmentSorter {
public class RarityLengthSorter extends PluginDependent<EcoEnchantsPlugin> implements EnchantmentSorter {
/**
* Instantiate sorter.
*
* @param plugin Instance of EcoEnchants.
*/
public RarityLengthSorter(@NotNull final EcoPlugin plugin) {
public RarityLengthSorter(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin);
}
@Override
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
if (this.getPlugin().getDisplayModule().getOptions().getSortedRarities().isEmpty()
|| this.getPlugin().getDisplayModule().getOptions().getSortedTypes().isEmpty()) {
this.getPlugin().getDisplayModule().update();
}
List<Enchantment> sorted = new ArrayList<>();
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
this.getPlugin().getDisplayModule().getOptions().getSortedRarities().forEach(enchantmentRarity -> {
List<Enchantment> rarityEnchants = new ArrayList<>();
for (Enchantment enchantment : toSort) {
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {

View File

@ -1,8 +1,7 @@
package com.willfp.ecoenchants.display.options.sorting.implementations;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.ecoenchants.display.EnchantDisplay;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
@ -12,25 +11,25 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class RarityTypeAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
public class RarityTypeAlphabeticSorter extends PluginDependent<EcoEnchantsPlugin> implements EnchantmentSorter {
/**
* Instantiate sorter.
*
* @param plugin Instance of EcoEnchants.
*/
public RarityTypeAlphabeticSorter(@NotNull final EcoPlugin plugin) {
public RarityTypeAlphabeticSorter(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin);
}
@Override
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
if (this.getPlugin().getDisplayModule().getOptions().getSortedRarities().isEmpty()
|| this.getPlugin().getDisplayModule().getOptions().getSortedTypes().isEmpty()) {
this.getPlugin().getDisplayModule().update();
}
List<Enchantment> sorted = new ArrayList<>();
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
this.getPlugin().getDisplayModule().getOptions().getSortedTypes().forEach(enchantmentType -> {
List<Enchantment> typeEnchants = new ArrayList<>();
for (Enchantment enchantment : toSort) {
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
@ -39,7 +38,7 @@ public class RarityTypeAlphabeticSorter extends PluginDependent implements Encha
}
typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
this.getPlugin().getDisplayModule().getOptions().getSortedRarities().forEach(enchantmentRarity -> {
List<Enchantment> rarityEnchants = new ArrayList<>();
for (Enchantment enchantment : typeEnchants) {
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {

View File

@ -1,8 +1,7 @@
package com.willfp.ecoenchants.display.options.sorting.implementations;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.ecoenchants.display.EnchantDisplay;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
@ -13,25 +12,25 @@ import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class RarityTypeLengthSorter extends PluginDependent implements EnchantmentSorter {
public class RarityTypeLengthSorter extends PluginDependent<EcoEnchantsPlugin> implements EnchantmentSorter {
/**
* Instantiate sorter.
*
* @param plugin Instance of EcoEnchants.
*/
public RarityTypeLengthSorter(@NotNull final EcoPlugin plugin) {
public RarityTypeLengthSorter(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin);
}
@Override
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
if (this.getPlugin().getDisplayModule().getOptions().getSortedRarities().isEmpty()
|| this.getPlugin().getDisplayModule().getOptions().getSortedTypes().isEmpty()) {
this.getPlugin().getDisplayModule().update();
}
List<Enchantment> sorted = new ArrayList<>();
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
this.getPlugin().getDisplayModule().getOptions().getSortedTypes().forEach(enchantmentType -> {
List<Enchantment> typeEnchants = new ArrayList<>();
for (Enchantment enchantment : toSort) {
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
@ -41,7 +40,7 @@ public class RarityTypeLengthSorter extends PluginDependent implements Enchantme
typeEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
this.getPlugin().getDisplayModule().getOptions().getSortedRarities().forEach(enchantmentRarity -> {
List<Enchantment> rarityEnchants = new ArrayList<>();
for (Enchantment enchantment : typeEnchants) {
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {

View File

@ -1,8 +1,7 @@
package com.willfp.ecoenchants.display.options.sorting.implementations;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.ecoenchants.display.EnchantDisplay;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
@ -12,25 +11,25 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class TypeAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
public class TypeAlphabeticSorter extends PluginDependent<EcoEnchantsPlugin> implements EnchantmentSorter {
/**
* Instantiate sorter.
*
* @param plugin Instance of EcoEnchants.
*/
public TypeAlphabeticSorter(@NotNull final EcoPlugin plugin) {
public TypeAlphabeticSorter(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin);
}
@Override
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
if (this.getPlugin().getDisplayModule().getOptions().getSortedRarities().isEmpty()
|| this.getPlugin().getDisplayModule().getOptions().getSortedTypes().isEmpty()) {
this.getPlugin().getDisplayModule().update();
}
List<Enchantment> sorted = new ArrayList<>();
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
this.getPlugin().getDisplayModule().getOptions().getSortedTypes().forEach(enchantmentType -> {
List<Enchantment> typeEnchants = new ArrayList<>();
for (Enchantment enchantment : toSort) {
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {

View File

@ -1,8 +1,7 @@
package com.willfp.ecoenchants.display.options.sorting.implementations;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import com.willfp.ecoenchants.display.EnchantDisplay;
import com.willfp.ecoenchants.EcoEnchantsPlugin;
import com.willfp.ecoenchants.display.EnchantmentCache;
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
@ -12,25 +11,25 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class TypeLengthSorter extends PluginDependent implements EnchantmentSorter {
public class TypeLengthSorter extends PluginDependent<EcoEnchantsPlugin> implements EnchantmentSorter {
/**
* Instantiate sorter.
*
* @param plugin Instance of EcoEnchants.
*/
public TypeLengthSorter(@NotNull final EcoPlugin plugin) {
public TypeLengthSorter(@NotNull final EcoEnchantsPlugin plugin) {
super(plugin);
}
@Override
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
if (this.getPlugin().getDisplayModule().getOptions().getSortedRarities().isEmpty()
|| this.getPlugin().getDisplayModule().getOptions().getSortedTypes().isEmpty()) {
this.getPlugin().getDisplayModule().update();
}
List<Enchantment> sorted = new ArrayList<>();
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
this.getPlugin().getDisplayModule().getOptions().getSortedTypes().forEach(enchantmentType -> {
List<Enchantment> typeEnchants = new ArrayList<>();
for (Enchantment enchantment : toSort) {
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {

View File

@ -21,7 +21,7 @@ import java.util.HashMap;
import java.util.Objects;
import java.util.UUID;
public class AnvilListeners extends PluginDependent implements Listener {
public class AnvilListeners extends PluginDependent<EcoPlugin> implements Listener {
/**
* Map to prevent incrementing cost several times as inventory events are fired 3 times.
*/

View File

@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Map;
public class GrindstoneListeners extends PluginDependent implements Listener {
public class GrindstoneListeners extends PluginDependent<EcoPlugin> implements Listener {
/**
* Instantiate grindstone listeners and link them to a specific plugin.
*

View File

@ -29,7 +29,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
public class EnchantingListeners extends PluginDependent implements Listener {
public class EnchantingListeners extends PluginDependent<EcoPlugin> implements Listener {
/**
* All players currently enchanting a secondary item.
*/

View File

@ -24,7 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
public class VillagerListeners extends PluginDependent implements Listener {
public class VillagerListeners extends PluginDependent<EcoPlugin> implements Listener {
/**
* Create new villager listeners.
*

View File

@ -28,7 +28,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ItemConversions extends PluginDependent implements Listener {
public class ItemConversions extends PluginDependent<EcoPlugin> implements Listener {
/**
* Instantiate item conversions.
*

View File

@ -34,7 +34,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Map;
public class WatcherTriggers extends PluginDependent implements Listener {
public class WatcherTriggers extends PluginDependent<EcoPlugin> implements Listener {
/**
* If watchers should be triggered against npcs.
*/

View File

@ -26,19 +26,22 @@ softdepend:
commands:
ecoreload:
description: Reloads config
permission: ecoenchants.reload
permission: ecoenchants.command.reload
ecodebug:
description: Debug information
permission: ecoenchants.ecodebug
permission: ecoenchants.command.debug
enchantinfo:
description: Show information about an enchantment
permission: ecoenchants.enchantinfo
permission: ecoenchants.command.enchantinfo
randomenchant:
description: Adds a random enchantment to an item
permission: ecoenchants.randomenchant
permission: ecoenchants.command.randomenchant
giverandombook:
description: Gives a book containing a random enchantment
permission: ecoenchants.randombook
permission: ecoenchants.command.giverandombook
ecoenchants:
description: Master command for other subcommands.
permission: ecoenchants.command.ecoenchants
permissions:
ecoenchants.*:
@ -46,21 +49,27 @@ permissions:
default: op
children:
ecoenchants.fromtable.*: true
ecoenchants.reload: true
ecoenchants.updateannounce: true
ecoenchants.enchantinfo: true
ecoenchants.ecodebug: true
ecoenchants.randomenchant: true
ecoenchants.randomenchant.bypasshardcap: true
ecoenchants.randombook: true
ecoenchants.bypasslevelclamp: true
ecoenchants.anvil.*: true
ecoenchants.command.*: true
ecoenchants.anvil.*:
description: Allows all anvil permissions
default: op
children:
ecoenchants.anvil.bypasshardcap: true
ecoenchants.anvil.color: true
ecoenchants.command.*:
description: Allows all commands
default: op
children:
ecoenchants.command.reload: true
ecoenchants.command.debug: true
ecoenchants.command.enchantinfo: true
ecoenchants.command.randomenchant: true
ecoenchants.command.randomenchant.bypasshardcap: true
ecoenchants.command.giverandombook: true
ecoenchants.command.ecoenchants: true
ecoenchants.fromtable.*:
description: Allows getting all enchantments from an enchanting table
default: true
@ -68,27 +77,30 @@ permissions:
ecoenchants.updateannounce:
description: Informs admins of a new update
default: op
ecoenchants.reload:
ecoenchants.command.reload:
description: Allows reloading the config
default: op
ecoenchants.ecodebug:
description: Allows the use of /ecodebug to print verbose debug information to console
ecoenchants.command.debug:
description: Allows the use of /ecoenchants debug to print verbose debug information to console
default: op
ecoenchants.enchantinfo:
ecoenchants.command.enchantinfo:
description: Allows the use of /enchantinfo to show enchant info
default: true
ecoenchants.randombook:
description: Allows the use of /giverandombook to give a book with a random enchantment
ecoenchants.command.giverandombook:
description: Allows the use of /ecoenchants giverandombook to give a book with a random enchantment
default: op
ecoenchants.randomenchant:
description: Allows the use of /randomenchant to apply a random enchantment to an item
ecoenchants.command.randomenchant:
description: Allows the use of /ecoenchants randomenchant to apply a random enchantment to an item
default: op
ecoenchants.randomenchant.others:
description: Allows the use of /randomenchant to apply a random enchantment to an item for another player
ecoenchants.command.randomenchant.others:
description: Allows the use of /ecoenchants randomenchant to apply a random enchantment to an item for another player
default: op
ecoenchants.randomenchant.bypasshardcap:
description: Allows /randomenchant bypassing the anvil hard cap
ecoenchants.command.randomenchant.bypasshardcap:
description: Allows /ecoenchants randomenchant bypassing the anvil hard cap
default: op
ecoenchants.command.ecoenchants:
description: Allows the use of /ecoenchants
default: true
ecoenchants.anvil.bypasshardcap:
description: Allows bypassing the anvil hard cap
default: op

View File

@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.IdentityHashMap;
import java.util.Map;
public class ProxyFactory<T extends AbstractProxy> extends PluginDependent {
public class ProxyFactory<T extends AbstractProxy> extends PluginDependent<EcoPlugin> {
/**
* Cached proxy implementations in order to not perform expensive reflective class-finding.
*/

View File

@ -1,2 +1,2 @@
version = 7.9.3
version = 7.10.0
plugin-name = EcoEnchants