mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-27 06:21:59 +01:00
Updated to eco 4.0.0, updated to 6.6.0, reworked for 4.0.0 compatibility
This commit is contained in:
parent
d273a87870
commit
6a1db845b5
@ -49,7 +49,7 @@ allprojects {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'com.willfp:eco:3.8.0'
|
compileOnly 'com.willfp:eco:4.0.0'
|
||||||
|
|
||||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||||
|
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
package com.willfp.ecoenchants;
|
package com.willfp.ecoenchants;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.bukkit.scheduling.TimedRunnable;
|
||||||
import com.willfp.eco.util.command.AbstractCommand;
|
import com.willfp.eco.util.command.AbstractCommand;
|
||||||
import com.willfp.eco.util.display.Display;
|
|
||||||
import com.willfp.eco.util.display.DisplayModule;
|
import com.willfp.eco.util.display.DisplayModule;
|
||||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
|
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
|
||||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||||
import com.willfp.eco.util.interfaces.EcoRunnable;
|
|
||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||||
import com.willfp.ecoenchants.command.commands.CommandEcodebug;
|
import com.willfp.ecoenchants.command.commands.CommandEcodebug;
|
||||||
@ -38,8 +37,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -66,21 +64,6 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void enable() {
|
public void enable() {
|
||||||
Display.registerDisplayModule(new DisplayModule(itemStack -> {
|
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
boolean hideEnchants = false;
|
|
||||||
if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
|
||||||
hideEnchants = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EnchantDisplay.displayEnchantments(itemStack, hideEnchants);
|
|
||||||
}, 500, this.getPluginName()));
|
|
||||||
|
|
||||||
Display.registerRevertModule(EnchantDisplay::revertDisplay);
|
|
||||||
|
|
||||||
this.getExtensionLoader().loadExtensions();
|
this.getExtensionLoader().loadExtensions();
|
||||||
|
|
||||||
if (this.getExtensionLoader().getLoadedExtensions().isEmpty()) {
|
if (this.getExtensionLoader().getLoadedExtensions().isEmpty()) {
|
||||||
@ -132,8 +115,8 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
|||||||
if (ecoEnchant.isEnabled()) {
|
if (ecoEnchant.isEnabled()) {
|
||||||
this.getEventManager().registerListener(ecoEnchant);
|
this.getEventManager().registerListener(ecoEnchant);
|
||||||
|
|
||||||
if (ecoEnchant instanceof EcoRunnable) {
|
if (ecoEnchant instanceof TimedRunnable) {
|
||||||
this.getScheduler().syncRepeating((EcoRunnable) ecoEnchant, 5, ((EcoRunnable) ecoEnchant).getTime());
|
this.getScheduler().syncRepeating((TimedRunnable) ecoEnchant, 5, ((TimedRunnable) ecoEnchant).getTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 1);
|
}, 1);
|
||||||
@ -204,7 +187,7 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
|||||||
new AnvilListeners(this),
|
new AnvilListeners(this),
|
||||||
new WatcherTriggers(this),
|
new WatcherTriggers(this),
|
||||||
new VillagerListeners(this),
|
new VillagerListeners(this),
|
||||||
new HoldItemListener()
|
new HoldItemListener(this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,4 +204,10 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin {
|
|||||||
EnchantmentType.class
|
EnchantmentType.class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
protected DisplayModule createDisplayModule() {
|
||||||
|
return new EnchantDisplay(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class CommandRandomenchant extends AbstractCommand {
|
|||||||
for (EcoEnchant ecoEnchant : ecoEnchants) {
|
for (EcoEnchant ecoEnchant : ecoEnchants) {
|
||||||
if (ecoEnchant.canEnchantItem(itemStack)) {
|
if (ecoEnchant.canEnchantItem(itemStack)) {
|
||||||
if (!ecoEnchant.conflictsWithAny(onItem)) {
|
if (!ecoEnchant.conflictsWithAny(onItem)) {
|
||||||
if (!onItem.stream().anyMatch(enchantment -> enchantment.conflictsWith(ecoEnchant))) {
|
if (onItem.stream().noneMatch(enchantment -> enchantment.conflictsWith(ecoEnchant))) {
|
||||||
if (!onItem.contains(ecoEnchant)) {
|
if (!onItem.contains(ecoEnchant)) {
|
||||||
boolean conflicts = false;
|
boolean conflicts = false;
|
||||||
for (Enchantment enchantment : onItem) {
|
for (Enchantment enchantment : onItem) {
|
||||||
|
@ -2,16 +2,17 @@ package com.willfp.ecoenchants.display;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.willfp.eco.util.NumberUtils;
|
import com.willfp.eco.util.NumberUtils;
|
||||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
import com.willfp.eco.util.display.Display;
|
||||||
|
import com.willfp.eco.util.display.DisplayModule;
|
||||||
|
import com.willfp.eco.util.display.DisplayPriority;
|
||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
|
||||||
import com.willfp.ecoenchants.display.options.DisplayOptions;
|
import com.willfp.ecoenchants.display.options.DisplayOptions;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||||
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
import com.willfp.ecoenchants.proxy.proxies.FastGetEnchantsProxy;
|
||||||
import com.willfp.ecoenchants.util.ProxyUtils;
|
import com.willfp.ecoenchants.util.ProxyUtils;
|
||||||
import lombok.experimental.UtilityClass;
|
import lombok.Getter;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
@ -19,7 +20,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -29,116 +30,63 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* All methods and fields pertaining to showing players the enchantments on their items.
|
* All methods and fields pertaining to showing players the enchantments on their items.
|
||||||
*/
|
*/
|
||||||
@UtilityClass
|
public class EnchantDisplay extends DisplayModule {
|
||||||
public class EnchantDisplay {
|
|
||||||
/**
|
|
||||||
* Instance of EcoEnchants.
|
|
||||||
*/
|
|
||||||
private static final AbstractEcoPlugin PLUGIN = EcoEnchantsPlugin.getInstance();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The meta key to hide enchantments in lore.
|
* The meta key to hide enchantments in lore.
|
||||||
* <p>
|
* <p>
|
||||||
* EcoEnchants packet lore implementation of HideEnchants.
|
* EcoEnchants packet lore implementation of HideEnchants.
|
||||||
*/
|
*/
|
||||||
public static final NamespacedKey KEY_SKIP = PLUGIN.getNamespacedKeyFactory().create("ecoenchantlore-skip");
|
@Getter
|
||||||
|
private final NamespacedKey keySkip = this.getPlugin().getNamespacedKeyFactory().create("ecoenchantlore-skip");
|
||||||
/**
|
|
||||||
* The prefix for all enchantment lines to have in lore.
|
|
||||||
*/
|
|
||||||
public static final String PREFIX = "§w";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The configurable options for displaying enchantments.
|
* The configurable options for displaying enchantments.
|
||||||
*/
|
*/
|
||||||
public static final DisplayOptions OPTIONS = new DisplayOptions(PLUGIN);
|
@Getter
|
||||||
|
private final DisplayOptions options = new DisplayOptions(this.getPlugin());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create EcoEnchants display module.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public EnchantDisplay(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin, DisplayPriority.HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update config values.
|
* Update config values.
|
||||||
*/
|
*/
|
||||||
@ConfigUpdater
|
public void update() {
|
||||||
public static void update() {
|
options.update();
|
||||||
OPTIONS.update();
|
|
||||||
EnchantmentCache.update();
|
EnchantmentCache.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Revert display.
|
protected void display(@NotNull final ItemStack itemStack) {
|
||||||
*
|
if (!EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) {
|
||||||
* @param item The item to revert.
|
return;
|
||||||
* @return The item, updated.
|
|
||||||
*/
|
|
||||||
public static ItemStack revertDisplay(@Nullable final ItemStack item) {
|
|
||||||
if (item == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta() == null) {
|
|
||||||
return item;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
List<String> itemLore;
|
|
||||||
|
|
||||||
if (meta.hasLore()) {
|
assert meta != null;
|
||||||
itemLore = meta.getLore();
|
|
||||||
} else {
|
boolean hide = false;
|
||||||
itemLore = new ArrayList<>();
|
if (meta.hasItemFlag(ItemFlag.HIDE_ENCHANTS) || meta.hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) {
|
||||||
|
hide = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemLore == null) {
|
List<String> itemLore = null;
|
||||||
itemLore = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
itemLore.removeIf(s -> s.startsWith(PREFIX));
|
if (hide || meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER)) {
|
||||||
|
|
||||||
if (!meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
|
|
||||||
meta.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
|
||||||
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
|
|
||||||
}
|
|
||||||
meta.getPersistentDataContainer().remove(KEY_SKIP);
|
|
||||||
meta.setLore(itemLore);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show all enchantments in item lore.
|
|
||||||
*
|
|
||||||
* @param item The item to update.
|
|
||||||
* @return The item, updated.
|
|
||||||
*/
|
|
||||||
public static ItemStack displayEnchantments(@Nullable final ItemStack item) {
|
|
||||||
return displayEnchantments(item, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show all enchantments in item lore.
|
|
||||||
*
|
|
||||||
* @param item The item to update.
|
|
||||||
* @param hide If enchantments should be hidden.
|
|
||||||
* @return The item, updated.
|
|
||||||
*/
|
|
||||||
public static ItemStack displayEnchantments(@Nullable final ItemStack item,
|
|
||||||
final boolean hide) {
|
|
||||||
if (item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType())) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
revertDisplay(item);
|
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> itemLore = new ArrayList<>();
|
|
||||||
|
|
||||||
if (hide || meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
|
|
||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
if (meta instanceof EnchantmentStorageMeta) {
|
if (meta instanceof EnchantmentStorageMeta) {
|
||||||
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||||
}
|
}
|
||||||
meta.getPersistentDataContainer().set(KEY_SKIP, PersistentDataType.INTEGER, 1);
|
meta.getPersistentDataContainer().set(keySkip, PersistentDataType.INTEGER, 1);
|
||||||
item.setItemMeta(meta);
|
itemStack.setItemMeta(meta);
|
||||||
return item;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
@ -167,7 +115,7 @@ public class EnchantDisplay {
|
|||||||
|
|
||||||
HashMap<Enchantment, Integer> tempEnchantments = new HashMap<>(enchantments);
|
HashMap<Enchantment, Integer> tempEnchantments = new HashMap<>(enchantments);
|
||||||
|
|
||||||
OPTIONS.getSorter().sortEnchantments(unsorted);
|
options.getSorter().sortEnchantments(unsorted);
|
||||||
|
|
||||||
enchantments.clear();
|
enchantments.clear();
|
||||||
unsorted.forEach(enchantment -> enchantments.put(enchantment, tempEnchantments.get(enchantment)));
|
unsorted.forEach(enchantment -> enchantments.put(enchantment, tempEnchantments.get(enchantment)));
|
||||||
@ -196,21 +144,21 @@ public class EnchantDisplay {
|
|||||||
String name = EnchantmentCache.getEntry(enchantment).getName();
|
String name = EnchantmentCache.getEntry(enchantment).getName();
|
||||||
|
|
||||||
if (!(enchantment.getMaxLevel() == 1 && level == 1)) {
|
if (!(enchantment.getMaxLevel() == 1 && level == 1)) {
|
||||||
if (OPTIONS.getNumbersOptions().isUseNumerals() && ProxyUtils.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(item, enchantment) < OPTIONS.getNumbersOptions().getThreshold()) {
|
if (options.getNumbersOptions().isUseNumerals() && ProxyUtils.getProxy(FastGetEnchantsProxy.class).getLevelOnItem(itemStack, enchantment) < options.getNumbersOptions().getThreshold()) {
|
||||||
name += " " + NumberUtils.toNumeral(level);
|
name += " " + NumberUtils.toNumeral(level);
|
||||||
} else {
|
} else {
|
||||||
name += " " + level;
|
name += " " + level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lore.add(PREFIX + name);
|
lore.add(Display.PREFIX + name);
|
||||||
if (enchantments.size() <= OPTIONS.getDescriptionOptions().getThreshold() && OPTIONS.getDescriptionOptions().isEnabled()) {
|
if (enchantments.size() <= options.getDescriptionOptions().getThreshold() && options.getDescriptionOptions().isEnabled()) {
|
||||||
lore.addAll(EnchantmentCache.getEntry(enchantment).getDescription());
|
lore.addAll(EnchantmentCache.getEntry(enchantment).getDescription());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (OPTIONS.getShrinkOptions().isEnabled() && (enchantments.size() > OPTIONS.getShrinkOptions().getThreshold())) {
|
if (options.getShrinkOptions().isEnabled() && (enchantments.size() > options.getShrinkOptions().getThreshold())) {
|
||||||
List<List<String>> partitionedCombinedLoreList = Lists.partition(lore, OPTIONS.getShrinkOptions().getShrinkPerLine());
|
List<List<String>> partitionedCombinedLoreList = Lists.partition(lore, options.getShrinkOptions().getShrinkPerLine());
|
||||||
List<String> newLore = new ArrayList<>();
|
List<String> newLore = new ArrayList<>();
|
||||||
partitionedCombinedLoreList.forEach(list -> {
|
partitionedCombinedLoreList.forEach(list -> {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
@ -232,8 +180,22 @@ public class EnchantDisplay {
|
|||||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
lore.addAll(itemLore);
|
lore.addAll(itemLore);
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
item.setItemMeta(meta);
|
itemStack.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
return item;
|
@Override
|
||||||
|
protected void revert(@NotNull final ItemStack itemStack) {
|
||||||
|
if (!EnchantmentTarget.ALL.getMaterials().contains(itemStack.getType())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
|
|
||||||
|
if (!meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER)) {
|
||||||
|
meta.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
|
||||||
|
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||||
|
}
|
||||||
|
meta.getPersistentDataContainer().remove(keySkip);
|
||||||
|
itemStack.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.willfp.ecoenchants.display;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||||
|
import com.willfp.eco.util.display.Display;
|
||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
@ -88,7 +89,7 @@ public class EnchantmentCache {
|
|||||||
enchantment,
|
enchantment,
|
||||||
"&4INVALID ENCHANTMENT",
|
"&4INVALID ENCHANTMENT",
|
||||||
"INVALID",
|
"INVALID",
|
||||||
Collections.singletonList(EnchantDisplay.PREFIX + "INVALID ENCHANTMENT: " + enchantment.getClass().getName()),
|
Collections.singletonList(Display.PREFIX + "INVALID ENCHANTMENT: " + enchantment.getClass().getName()),
|
||||||
EnchantmentType.NORMAL,
|
EnchantmentType.NORMAL,
|
||||||
EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity"))
|
EnchantmentRarity.getByName(PLUGIN.getConfigYml().getString("rarity.vanilla-rarity"))
|
||||||
));
|
));
|
||||||
@ -135,7 +136,7 @@ public class EnchantmentCache {
|
|||||||
|
|
||||||
String rawName = name;
|
String rawName = name;
|
||||||
name = color + name;
|
name = color + name;
|
||||||
description.replaceAll(line -> EnchantDisplay.PREFIX + EnchantDisplay.OPTIONS.getDescriptionOptions().getColor() + line);
|
description.replaceAll(line -> Display.PREFIX + ((EnchantDisplay) PLUGIN.getDisplayModule()).getOptions().getDescriptionOptions().getColor() + line);
|
||||||
CACHE.put(enchantment.getKey(), new CacheEntry(enchantment, name, rawName, description, type, rarity));
|
CACHE.put(enchantment.getKey(), new CacheEntry(enchantment, name, rawName, description, type, rarity));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +206,7 @@ public class EnchantmentCache {
|
|||||||
|
|
||||||
String processedStringDescription = descriptionBuilder.toString();
|
String processedStringDescription = descriptionBuilder.toString();
|
||||||
processedStringDescription = processedStringDescription.replace("§w", "");
|
processedStringDescription = processedStringDescription.replace("§w", "");
|
||||||
this.stringDescription = processedStringDescription.replaceAll(EnchantDisplay.OPTIONS.getDescriptionOptions().getColor(), "");
|
this.stringDescription = processedStringDescription.replaceAll(((EnchantDisplay) PLUGIN.getDisplayModule()).getOptions().getDescriptionOptions().getColor(), "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting;
|
package com.willfp.ecoenchants.display.options.sorting;
|
||||||
|
|
||||||
|
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.implementations.AlphabeticSorter;
|
import com.willfp.ecoenchants.display.options.sorting.implementations.AlphabeticSorter;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.implementations.LengthSorter;
|
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.RarityAlphabeticSorter;
|
||||||
@ -34,17 +35,18 @@ public class SorterManager {
|
|||||||
return REGISTERED.stream()
|
return REGISTERED.stream()
|
||||||
.filter(enchantmentSorter -> Arrays.asList(enchantmentSorter.getParameters()).containsAll(Arrays.asList(parameters)) && enchantmentSorter.getParameters().length == parameters.length)
|
.filter(enchantmentSorter -> Arrays.asList(enchantmentSorter.getParameters()).containsAll(Arrays.asList(parameters)) && enchantmentSorter.getParameters().length == parameters.length)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(new AlphabeticSorter());
|
.orElse(new AlphabeticSorter(EcoEnchantsPlugin.getInstance()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
REGISTERED.add(new AlphabeticSorter());
|
EcoEnchantsPlugin instance = EcoEnchantsPlugin.getInstance(); // Really dirty and janky.
|
||||||
REGISTERED.add(new LengthSorter());
|
REGISTERED.add(new AlphabeticSorter(instance));
|
||||||
REGISTERED.add(new TypeAlphabeticSorter());
|
REGISTERED.add(new LengthSorter(instance));
|
||||||
REGISTERED.add(new TypeLengthSorter());
|
REGISTERED.add(new TypeAlphabeticSorter(instance));
|
||||||
REGISTERED.add(new RarityAlphabeticSorter());
|
REGISTERED.add(new TypeLengthSorter(instance));
|
||||||
REGISTERED.add(new RarityLengthSorter());
|
REGISTERED.add(new RarityAlphabeticSorter(instance));
|
||||||
REGISTERED.add(new RarityTypeAlphabeticSorter());
|
REGISTERED.add(new RarityLengthSorter(instance));
|
||||||
REGISTERED.add(new RarityTypeLengthSorter());
|
REGISTERED.add(new RarityTypeAlphabeticSorter(instance));
|
||||||
|
REGISTERED.add(new RarityTypeLengthSorter(instance));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||||
@ -8,7 +10,16 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AlphabeticSorter implements EnchantmentSorter {
|
public class AlphabeticSorter extends PluginDependent implements EnchantmentSorter {
|
||||||
|
/**
|
||||||
|
* Instantiate sorter.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public AlphabeticSorter(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||||
toSort.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
toSort.sort(((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName())));
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||||
@ -9,7 +11,16 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class LengthSorter implements EnchantmentSorter {
|
public class LengthSorter extends PluginDependent implements EnchantmentSorter {
|
||||||
|
/**
|
||||||
|
* Instantiate sorter.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public LengthSorter(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||||
toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
toSort.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||||
@ -10,16 +12,26 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RarityAlphabeticSorter implements EnchantmentSorter {
|
public class RarityAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
|
||||||
|
/**
|
||||||
|
* Instantiate sorter.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public RarityAlphabeticSorter(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||||
EnchantDisplay.update();
|
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||||
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Enchantment> sorted = new ArrayList<>();
|
List<Enchantment> sorted = new ArrayList<>();
|
||||||
|
|
||||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
|
||||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||||
for (Enchantment enchantment : toSort) {
|
for (Enchantment enchantment : toSort) {
|
||||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||||
@ -11,15 +13,25 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RarityLengthSorter implements EnchantmentSorter {
|
public class RarityLengthSorter extends PluginDependent implements EnchantmentSorter {
|
||||||
|
/**
|
||||||
|
* Instantiate sorter.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public RarityLengthSorter(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||||
EnchantDisplay.update();
|
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||||
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Enchantment> sorted = new ArrayList<>();
|
List<Enchantment> sorted = new ArrayList<>();
|
||||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
|
||||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||||
for (Enchantment enchantment : toSort) {
|
for (Enchantment enchantment : toSort) {
|
||||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||||
@ -10,15 +12,25 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RarityTypeAlphabeticSorter implements EnchantmentSorter {
|
public class RarityTypeAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
|
||||||
|
/**
|
||||||
|
* Instantiate sorter.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public RarityTypeAlphabeticSorter(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||||
EnchantDisplay.update();
|
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||||
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Enchantment> sorted = new ArrayList<>();
|
List<Enchantment> sorted = new ArrayList<>();
|
||||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
|
||||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||||
for (Enchantment enchantment : toSort) {
|
for (Enchantment enchantment : toSort) {
|
||||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||||
@ -27,7 +39,7 @@ public class RarityTypeAlphabeticSorter implements EnchantmentSorter {
|
|||||||
}
|
}
|
||||||
typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
typeEnchants.sort((enchantment1, enchantment2) -> EnchantmentCache.getEntry(enchantment1).getRawName().compareToIgnoreCase(EnchantmentCache.getEntry(enchantment2).getRawName()));
|
||||||
|
|
||||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
|
||||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||||
for (Enchantment enchantment : typeEnchants) {
|
for (Enchantment enchantment : typeEnchants) {
|
||||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||||
@ -11,15 +13,25 @@ import java.util.ArrayList;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RarityTypeLengthSorter implements EnchantmentSorter {
|
public class RarityTypeLengthSorter extends PluginDependent implements EnchantmentSorter {
|
||||||
|
/**
|
||||||
|
* Instantiate sorter.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public RarityTypeLengthSorter(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||||
EnchantDisplay.update();
|
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||||
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Enchantment> sorted = new ArrayList<>();
|
List<Enchantment> sorted = new ArrayList<>();
|
||||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
|
||||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||||
for (Enchantment enchantment : toSort) {
|
for (Enchantment enchantment : toSort) {
|
||||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||||
@ -29,7 +41,7 @@ public class RarityTypeLengthSorter implements EnchantmentSorter {
|
|||||||
|
|
||||||
typeEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
typeEnchants.sort(Comparator.comparingInt(enchantment -> EnchantmentCache.getEntry(enchantment).getRawName().length()));
|
||||||
|
|
||||||
EnchantDisplay.OPTIONS.getSortedRarities().forEach(enchantmentRarity -> {
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().forEach(enchantmentRarity -> {
|
||||||
List<Enchantment> rarityEnchants = new ArrayList<>();
|
List<Enchantment> rarityEnchants = new ArrayList<>();
|
||||||
for (Enchantment enchantment : typeEnchants) {
|
for (Enchantment enchantment : typeEnchants) {
|
||||||
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
if (EnchantmentCache.getEntry(enchantment).getRarity().equals(enchantmentRarity)) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||||
@ -10,15 +12,25 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypeAlphabeticSorter implements EnchantmentSorter {
|
public class TypeAlphabeticSorter extends PluginDependent implements EnchantmentSorter {
|
||||||
|
/**
|
||||||
|
* Instantiate sorter.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public TypeAlphabeticSorter(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||||
EnchantDisplay.update();
|
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||||
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Enchantment> sorted = new ArrayList<>();
|
List<Enchantment> sorted = new ArrayList<>();
|
||||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
|
||||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||||
for (Enchantment enchantment : toSort) {
|
for (Enchantment enchantment : toSort) {
|
||||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
package com.willfp.ecoenchants.display.options.sorting.implementations;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||||
import com.willfp.ecoenchants.display.EnchantmentCache;
|
import com.willfp.ecoenchants.display.EnchantmentCache;
|
||||||
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
import com.willfp.ecoenchants.display.options.sorting.EnchantmentSorter;
|
||||||
@ -10,15 +12,25 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypeLengthSorter implements EnchantmentSorter {
|
public class TypeLengthSorter extends PluginDependent implements EnchantmentSorter {
|
||||||
|
/**
|
||||||
|
* Instantiate sorter.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public TypeLengthSorter(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
public void sortEnchantments(@NotNull final List<Enchantment> toSort) {
|
||||||
if (EnchantDisplay.OPTIONS.getSortedRarities().isEmpty() || EnchantDisplay.OPTIONS.getSortedTypes().isEmpty()) {
|
if (((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedRarities().isEmpty()
|
||||||
EnchantDisplay.update();
|
|| ((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().isEmpty()) {
|
||||||
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).update();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Enchantment> sorted = new ArrayList<>();
|
List<Enchantment> sorted = new ArrayList<>();
|
||||||
EnchantDisplay.OPTIONS.getSortedTypes().forEach(enchantmentType -> {
|
((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().getSortedTypes().forEach(enchantmentType -> {
|
||||||
List<Enchantment> typeEnchants = new ArrayList<>();
|
List<Enchantment> typeEnchants = new ArrayList<>();
|
||||||
for (Enchantment enchantment : toSort) {
|
for (Enchantment enchantment : toSort) {
|
||||||
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
if (EnchantmentCache.getEntry(enchantment).getType().equals(enchantmentType)) {
|
||||||
|
@ -2,7 +2,6 @@ package com.willfp.ecoenchants.enchantments;
|
|||||||
|
|
||||||
|
|
||||||
import com.willfp.eco.util.StringUtils;
|
import com.willfp.eco.util.StringUtils;
|
||||||
import com.willfp.eco.util.interfaces.Registerable;
|
|
||||||
import com.willfp.eco.util.optional.Prerequisite;
|
import com.willfp.eco.util.optional.Prerequisite;
|
||||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
import com.willfp.ecoenchants.EcoEnchantsPlugin;
|
||||||
@ -41,7 +40,7 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "deprecation", "RedundantSuppression"})
|
@SuppressWarnings({"unchecked", "deprecation", "RedundantSuppression"})
|
||||||
public abstract class EcoEnchant extends Enchantment implements Listener, Registerable, Watcher {
|
public abstract class EcoEnchant extends Enchantment implements Listener, Watcher {
|
||||||
/**
|
/**
|
||||||
* Instance of EcoEnchants for enchantments to be able to access.
|
* Instance of EcoEnchants for enchantments to be able to access.
|
||||||
*/
|
*/
|
||||||
@ -230,7 +229,6 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
|||||||
* Register the enchantment with spigot.
|
* Register the enchantment with spigot.
|
||||||
* Only used internally.
|
* Only used internally.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void register() {
|
public void register() {
|
||||||
try {
|
try {
|
||||||
Field byIdField = Enchantment.class.getDeclaredField("byKey");
|
Field byIdField = Enchantment.class.getDeclaredField("byKey");
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||||
|
|
||||||
import com.willfp.eco.util.VectorUtils;
|
import com.willfp.eco.util.VectorUtils;
|
||||||
|
import com.willfp.eco.util.bukkit.scheduling.TimedRunnable;
|
||||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||||
import com.willfp.eco.util.interfaces.EcoRunnable;
|
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||||
@ -19,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class CallingCurse extends EcoEnchant implements EcoRunnable {
|
public class CallingCurse extends EcoEnchant implements TimedRunnable {
|
||||||
private final HashMap<Player, Integer> players = new HashMap<>();
|
private final HashMap<Player, Integer> players = new HashMap<>();
|
||||||
private double distance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance");
|
private double distance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance");
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
package com.willfp.ecoenchants.enchantments.ecoenchants.curse;
|
||||||
|
|
||||||
import com.willfp.eco.util.DurabilityUtils;
|
import com.willfp.eco.util.DurabilityUtils;
|
||||||
import com.willfp.eco.util.interfaces.EcoRunnable;
|
import com.willfp.eco.util.bukkit.scheduling.TimedRunnable;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||||
@ -21,7 +21,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DecayCurse extends EcoEnchant implements EcoRunnable {
|
public class DecayCurse extends EcoEnchant implements TimedRunnable {
|
||||||
private final Set<Player> players = new HashSet<>();
|
private final Set<Player> players = new HashSet<>();
|
||||||
private int amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
private int amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
|||||||
|
|
||||||
import com.willfp.eco.util.NumberUtils;
|
import com.willfp.eco.util.NumberUtils;
|
||||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||||
import com.willfp.eco.util.interfaces.EcoRunnable;
|
import com.willfp.eco.util.bukkit.scheduling.TimedRunnable;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||||
@ -17,7 +17,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Forcefield extends EcoEnchant implements EcoRunnable {
|
public class Forcefield extends EcoEnchant implements TimedRunnable {
|
||||||
private final HashMap<Player, Integer> players = new HashMap<>();
|
private final HashMap<Player, Integer> players = new HashMap<>();
|
||||||
private double initialDistance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance");
|
private double initialDistance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance");
|
||||||
private double bonus = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
|
private double bonus = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level");
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
package com.willfp.ecoenchants.enchantments.ecoenchants.normal;
|
||||||
|
|
||||||
import com.willfp.eco.util.VectorUtils;
|
import com.willfp.eco.util.VectorUtils;
|
||||||
|
import com.willfp.eco.util.bukkit.scheduling.TimedRunnable;
|
||||||
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
import com.willfp.eco.util.events.armorequip.ArmorEquipEvent;
|
||||||
import com.willfp.eco.util.interfaces.EcoRunnable;
|
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||||
@ -19,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Magnetic extends EcoEnchant implements EcoRunnable {
|
public class Magnetic extends EcoEnchant implements TimedRunnable {
|
||||||
private double initialDistance = 1;
|
private double initialDistance = 1;
|
||||||
private double bonus = 1;
|
private double bonus = 1;
|
||||||
private final HashMap<Player, Integer> players = new HashMap<>();
|
private final HashMap<Player, Integer> players = new HashMap<>();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
package com.willfp.ecoenchants.enchantments.ecoenchants.special;
|
||||||
|
|
||||||
import com.willfp.eco.util.DurabilityUtils;
|
import com.willfp.eco.util.DurabilityUtils;
|
||||||
import com.willfp.eco.util.interfaces.EcoRunnable;
|
import com.willfp.eco.util.bukkit.scheduling.TimedRunnable;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||||
@ -21,7 +21,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class Repairing extends EcoEnchant implements EcoRunnable {
|
public class Repairing extends EcoEnchant implements TimedRunnable {
|
||||||
private final Set<Player> players = new HashSet<>();
|
private final Set<Player> players = new HashSet<>();
|
||||||
private int amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
private int amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier");
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import com.willfp.eco.util.StringUtils;
|
|||||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||||
import com.willfp.eco.util.integrations.placeholder.PlaceholderEntry;
|
import com.willfp.eco.util.integrations.placeholder.PlaceholderEntry;
|
||||||
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||||
import com.willfp.eco.util.interfaces.Registerable;
|
|
||||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -16,7 +15,7 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EnchantmentRarity implements Registerable {
|
public class EnchantmentRarity {
|
||||||
/**
|
/**
|
||||||
* All registered rarities.
|
* All registered rarities.
|
||||||
*/
|
*/
|
||||||
@ -82,7 +81,6 @@ public class EnchantmentRarity implements Registerable {
|
|||||||
this.customColor = customColor;
|
this.customColor = customColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register() {
|
public void register() {
|
||||||
Optional<EnchantmentRarity> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
Optional<EnchantmentRarity> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||||
matching.ifPresent(REGISTERED::remove);
|
matching.ifPresent(REGISTERED::remove);
|
||||||
|
@ -2,7 +2,6 @@ package com.willfp.ecoenchants.enchantments.meta;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||||
import com.willfp.eco.util.interfaces.Registerable;
|
|
||||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -13,7 +12,7 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EnchantmentTarget implements Registerable {
|
public class EnchantmentTarget {
|
||||||
/**
|
/**
|
||||||
* All registered targets.
|
* All registered targets.
|
||||||
*/
|
*/
|
||||||
@ -49,7 +48,6 @@ public class EnchantmentTarget implements Registerable {
|
|||||||
this.materials = materials;
|
this.materials = materials;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register() {
|
public void register() {
|
||||||
Optional<EnchantmentTarget> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
Optional<EnchantmentTarget> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||||
matching.ifPresent(REGISTERED::remove);
|
matching.ifPresent(REGISTERED::remove);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.willfp.ecoenchants.enchantments.util;
|
package com.willfp.ecoenchants.enchantments.util;
|
||||||
|
|
||||||
import com.willfp.eco.util.NumberUtils;
|
import com.willfp.eco.util.NumberUtils;
|
||||||
|
import com.willfp.eco.util.internal.PluginDependent;
|
||||||
|
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||||
import com.willfp.ecoenchants.display.EnchantDisplay;
|
import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||||
@ -19,7 +21,15 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class HoldItemListener implements Listener {
|
public class HoldItemListener extends PluginDependent implements Listener {
|
||||||
|
/**
|
||||||
|
* Instantiate HoldItemListener.
|
||||||
|
*
|
||||||
|
* @param plugin Instance of EcoEnchants.
|
||||||
|
*/
|
||||||
|
public HoldItemListener(@NotNull final AbstractEcoPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On player hold item.
|
* On player hold item.
|
||||||
@ -43,7 +53,7 @@ public class HoldItemListener implements Listener {
|
|||||||
|
|
||||||
Map<Enchantment, Integer> toAdd = new HashMap<>();
|
Map<Enchantment, Integer> toAdd = new HashMap<>();
|
||||||
|
|
||||||
if (!EnchantDisplay.OPTIONS.isUseLoreGetter()) {
|
if (!((EnchantDisplay) this.getPlugin().getDisplayModule()).getOptions().isUseLoreGetter()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
version = 6.5.6
|
version = 6.6.0
|
||||||
plugin-name = EcoEnchants
|
plugin-name = EcoEnchants
|
Loading…
Reference in New Issue
Block a user