mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-01-23 00:31:20 +01:00
Javadoc (2/?)
This commit is contained in:
parent
6c47f38cb7
commit
d3f76ad128
@ -37,7 +37,7 @@ public class EcoEnchantsConfigs implements Updatable {
|
||||
public void updateConfigs() {
|
||||
TARGET.update();
|
||||
RARITY.update();
|
||||
enchantmentConfigs.forEach((EnchantmentYamlConfig::update));
|
||||
enchantmentConfigs.forEach(EnchantmentYamlConfig::update);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoenchants.config;
|
||||
|
||||
import com.willfp.eco.util.config.ValueGetter;
|
||||
import com.willfp.eco.util.injection.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
@ -17,11 +18,13 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Class implemented by enchantment configs
|
||||
*/
|
||||
public abstract class EnchantmentYamlConfig extends PluginDependent {
|
||||
public abstract class EnchantmentYamlConfig extends PluginDependent implements ValueGetter {
|
||||
private final String name;
|
||||
|
||||
@Getter
|
||||
@ -133,4 +136,112 @@ public abstract class EnchantmentYamlConfig extends PluginDependent {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get an integer from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or 0 if not found.
|
||||
*/
|
||||
@Override
|
||||
public int getInt(@NotNull final String path) {
|
||||
return config.getInt(path, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer from config with a specified default (not found) value.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @param def The value to default to if not found.
|
||||
* @return The found value, or the default.
|
||||
*/
|
||||
@Override
|
||||
public int getInt(@NotNull final String path,
|
||||
final int def) {
|
||||
return config.getInt(path, def);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of integers from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Integer> getInts(@NotNull final String path) {
|
||||
return config.getIntegerList(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boolean from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or false if not found.
|
||||
*/
|
||||
@Override
|
||||
public boolean getBool(@NotNull final String path) {
|
||||
return config.getBoolean(path, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of booleans from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Boolean> getBools(@NotNull final String path) {
|
||||
return config.getBooleanList(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string from config.C
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or an empty string if not found.
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public String getString(@NotNull final String path) {
|
||||
return Objects.requireNonNull(config.getString(path, ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of strings from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public List<String> getStrings(@NotNull final String path) {
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a decimal from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or 0 if not found.
|
||||
*/
|
||||
@Override
|
||||
public double getDouble(@NotNull final String path) {
|
||||
return config.getDouble(path, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of decimals from config.
|
||||
*
|
||||
* @param path The key to fetch the value from.
|
||||
* @return The found value, or a blank {@link java.util.ArrayList} if not found.
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public List<Double> getDoubles(@NotNull final String path) {
|
||||
return config.getDoubleList(path);
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,9 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -16,12 +16,20 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrapper for enchantment-specific configs
|
||||
*/
|
||||
public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
/**
|
||||
* The name of the config.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Instantiate a new config for an enchantment.
|
||||
*
|
||||
* @param name The name of the config.
|
||||
* @param plugin The provider of the enchantment.
|
||||
* @param type The {@link EnchantmentType} of the enchantment.
|
||||
*/
|
||||
public EnchantmentConfig(@NotNull final String name,
|
||||
@NotNull final Class<?> plugin,
|
||||
@NotNull final EnchantmentType type) {
|
||||
@ -29,56 +37,12 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getInt(@NotNull final String path) {
|
||||
return this.getConfig().getInt(path);
|
||||
}
|
||||
|
||||
public int getInt(@NotNull final String path,
|
||||
final int def) {
|
||||
return this.getConfig().getInt(path, def);
|
||||
}
|
||||
|
||||
public List<Integer> getInts(@NotNull final String path) {
|
||||
return this.getConfig().getIntegerList(path);
|
||||
}
|
||||
|
||||
public boolean getBool(@NotNull final String path) {
|
||||
return this.getConfig().getBoolean(path);
|
||||
}
|
||||
|
||||
public boolean getBool(@NotNull final String path,
|
||||
final boolean def) {
|
||||
return this.getConfig().getBoolean(path, def);
|
||||
}
|
||||
|
||||
public List<Boolean> getBools(@NotNull final String path) {
|
||||
return this.getConfig().getBooleanList(path);
|
||||
}
|
||||
|
||||
public String getString(@NotNull final String path) {
|
||||
return this.getConfig().getString(path);
|
||||
}
|
||||
|
||||
public List<String> getStrings(@NotNull final String path) {
|
||||
return this.getConfig().getStringList(path);
|
||||
}
|
||||
|
||||
public double getDouble(@NotNull final String path) {
|
||||
return this.getConfig().getDouble(path);
|
||||
}
|
||||
|
||||
public List<Double> getDoubles(@NotNull final String path) {
|
||||
return this.getConfig().getDoubleList(path);
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(@NotNull final String path) {
|
||||
return this.getConfig().getItemStack(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a set of enchantments stored by key.
|
||||
*
|
||||
* @param path The location of the enchantments in the config.
|
||||
* @return A set of all enchantments.
|
||||
*/
|
||||
public Set<Enchantment> getEnchantments(@NotNull final String path) {
|
||||
Set<Enchantment> enchantments = new HashSet<>();
|
||||
List<String> enchantmentKeys = this.getConfig().getStringList(path);
|
||||
@ -86,11 +50,21 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
return enchantments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the rarity of the enchantment.
|
||||
*
|
||||
* @return The rarity, or null if invalid.
|
||||
*/
|
||||
public EnchantmentRarity getRarity() {
|
||||
String rarityName = this.getString("obtaining.rarity");
|
||||
return EnchantmentRarity.getByName(rarityName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all applicable targets.
|
||||
*
|
||||
* @return The targets.
|
||||
*/
|
||||
public Set<EnchantmentTarget> getTargets() {
|
||||
List<String> targetNames = this.getConfig().getStringList(EcoEnchants.GENERAL_LOCATION + "targets");
|
||||
if (targetNames.isEmpty()) {
|
||||
@ -108,6 +82,9 @@ public class EnchantmentConfig extends EnchantmentYamlConfig {
|
||||
return targets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load config values from lang.yml.
|
||||
*/
|
||||
public void loadFromLang() {
|
||||
if (!Configs.LANG.getConfig().contains("enchantments." + this.getName())) {
|
||||
return;
|
||||
|
@ -4,14 +4,19 @@ import com.willfp.eco.util.config.BaseConfig;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrapper for config.yml
|
||||
*/
|
||||
public class Rarity extends BaseConfig {
|
||||
/**
|
||||
* Instantiate rarity.yml.
|
||||
*/
|
||||
public Rarity() {
|
||||
super("rarity", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rarity names.
|
||||
*
|
||||
* @return Set of all rarity names.
|
||||
*/
|
||||
public Set<String> getRarities() {
|
||||
return this.getConfig().getConfigurationSection("rarities").getKeys(false);
|
||||
}
|
||||
|
@ -7,18 +7,29 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Wrapper for config.yml
|
||||
*/
|
||||
public class Target extends BaseConfig {
|
||||
/**
|
||||
* Instantiate target.yml.
|
||||
*/
|
||||
public Target() {
|
||||
super("target", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all target names.
|
||||
*
|
||||
* @return Set of all names.
|
||||
*/
|
||||
public Set<String> getTargets() {
|
||||
return this.getConfig().getConfigurationSection("targets").getKeys(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all materials from a target name.
|
||||
*
|
||||
* @param target The name of the target.
|
||||
* @return All materials.
|
||||
*/
|
||||
public Set<Material> getTargetMaterials(@NotNull final String target) {
|
||||
Set<Material> materials = new HashSet<>();
|
||||
this.getConfig().getStringList("targets." + target).forEach(materialName -> {
|
||||
|
@ -30,34 +30,37 @@ import java.util.List;
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@UtilityClass
|
||||
public class EnchantDisplay implements Updatable {
|
||||
/**
|
||||
* Instance of EcoEnchants.
|
||||
*/
|
||||
private static final AbstractEcoPlugin PLUGIN = AbstractEcoPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* The meta key to hide enchantments in lore
|
||||
* The meta key to hide enchantments in lore.
|
||||
* <p>
|
||||
* EcoEnchants packet lore implementation of HideEnchants.
|
||||
*/
|
||||
public static final NamespacedKey KEY_SKIP = PLUGIN.getNamespacedKeyFactory().create("ecoenchantlore-skip");
|
||||
|
||||
/**
|
||||
* The meta key to notify the server that an item is from a villager trade
|
||||
* The meta key to notify the server that an item is from a villager trade.
|
||||
* <p>
|
||||
* Bit of a bodge - plan on making it better.
|
||||
*/
|
||||
public static final NamespacedKey KEY_V = PLUGIN.getNamespacedKeyFactory().create("ecoenchantlore-v");
|
||||
|
||||
/**
|
||||
* The prefix for all enchantment lines to have in lore
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Update config values
|
||||
* Update config values.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
@ -70,8 +73,8 @@ public class EnchantDisplay implements Updatable {
|
||||
* <p>
|
||||
* It isn't recommended to mess with this unless you <b>really</b> know your way around EcoEnchants.
|
||||
*
|
||||
* @param item The item to modify
|
||||
* @return The item, with KEY_V
|
||||
* @param item The item to modify.
|
||||
* @return The item, with KEY_V.
|
||||
*/
|
||||
public static ItemStack addV(@Nullable final ItemStack item) {
|
||||
if (item == null || item.getItemMeta() == null) {
|
||||
@ -85,10 +88,10 @@ public class EnchantDisplay implements Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Revert display
|
||||
* Revert display.
|
||||
*
|
||||
* @param item The item to revert
|
||||
* @return The item, updated
|
||||
* @param item The item to revert.
|
||||
* @return The item, updated.
|
||||
*/
|
||||
public static ItemStack revertDisplay(@Nullable final ItemStack item) {
|
||||
if (item == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta() == null) {
|
||||
@ -126,19 +129,25 @@ public class EnchantDisplay implements Updatable {
|
||||
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
|
||||
* Show all enchantments in item lore.
|
||||
*
|
||||
* @param item The item to update
|
||||
* @return The item, updated
|
||||
* @param item The item to update.
|
||||
* @param hideEnchants If enchantments should be hidden.
|
||||
* @return The item, updated.
|
||||
*/
|
||||
public static ItemStack displayEnchantments(@Nullable final ItemStack item,
|
||||
final boolean hideEnchants) {
|
||||
|
||||
boolean hide = hideEnchants;
|
||||
if (item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType())) {
|
||||
return item;
|
||||
@ -222,7 +231,7 @@ public class EnchantDisplay implements Updatable {
|
||||
String name = EnchantmentCache.getEntry(enchantment).getName();
|
||||
|
||||
if (!(enchantment.getMaxLevel() == 1 && level == 1)) {
|
||||
if (OPTIONS.isUseNumerals() && item.getEnchantmentLevel(enchantment) < OPTIONS.getNumbersThreshold()) {
|
||||
if (OPTIONS.getNumbersOptions().isUseNumerals() && item.getEnchantmentLevel(enchantment) < OPTIONS.getNumbersOptions().getThreshold()) {
|
||||
name += " " + NumberUtils.toNumeral(level);
|
||||
} else {
|
||||
name += " " + level;
|
||||
@ -230,13 +239,13 @@ public class EnchantDisplay implements Updatable {
|
||||
}
|
||||
|
||||
lore.add(PREFIX + name);
|
||||
if (enchantments.size() <= OPTIONS.getDescribeThreshold() && OPTIONS.isUseDescribe()) {
|
||||
if (enchantments.size() <= OPTIONS.getDescriptionOptions().getThreshold() && OPTIONS.getDescriptionOptions().isEnabled()) {
|
||||
lore.addAll(EnchantmentCache.getEntry(enchantment).getDescription());
|
||||
}
|
||||
});
|
||||
|
||||
if (OPTIONS.isUseShrink() && (enchantments.size() > OPTIONS.getShrinkThreshold())) {
|
||||
List<List<String>> partitionedCombinedLoreList = Lists.partition(lore, OPTIONS.getShrinkPerLine());
|
||||
if (OPTIONS.getShrinkOptions().isEnabled() && (enchantments.size() > OPTIONS.getShrinkOptions().getThreshold())) {
|
||||
List<List<String>> partitionedCombinedLoreList = Lists.partition(lore, OPTIONS.getShrinkOptions().getShrinkPerLine());
|
||||
List<String> newLore = new ArrayList<>();
|
||||
partitionedCombinedLoreList.forEach(list -> {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoenchants.display;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.config.annotations.ConfigUpdater;
|
||||
import com.willfp.eco.util.interfaces.Updatable;
|
||||
@ -7,6 +8,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
@ -23,9 +25,19 @@ import java.util.Set;
|
||||
@UtilityClass
|
||||
@SuppressWarnings("deprecation")
|
||||
public class EnchantmentCache implements Updatable {
|
||||
/**
|
||||
* The physical cache.
|
||||
*/
|
||||
private static final Set<CacheEntry> CACHE = new HashSet<>();
|
||||
|
||||
@SuppressWarnings("OptionalGetWithoutIsPresent")
|
||||
/**
|
||||
* Get the {@link CacheEntry} for a specific enchantment.
|
||||
* <p>
|
||||
* Returns a default "broken" cache entry if not cached.
|
||||
*
|
||||
* @param enchantment The enchantment to query.
|
||||
* @return The found cache entry.
|
||||
*/
|
||||
public static CacheEntry getEntry(@NotNull final Enchantment enchantment) {
|
||||
Optional<CacheEntry> matching = CACHE.stream().filter(entry -> entry.getEnchantment().getKey().getKey().equals(enchantment.getKey().getKey())).findFirst();
|
||||
return matching.orElse(
|
||||
@ -40,10 +52,18 @@ public class EnchantmentCache implements Updatable {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entire cache.
|
||||
*
|
||||
* @return An immutable set of the cache.
|
||||
*/
|
||||
public static Set<CacheEntry> getCache() {
|
||||
return new HashSet<>(CACHE);
|
||||
return ImmutableSet.copyOf(CACHE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the cache.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
CACHE.clear();
|
||||
@ -84,22 +104,56 @@ public class EnchantmentCache implements Updatable {
|
||||
|
||||
String rawName = name;
|
||||
name = color + name;
|
||||
description.replaceAll(line -> EnchantDisplay.PREFIX + EnchantDisplay.OPTIONS.getDescriptionColor() + line);
|
||||
description.replaceAll(line -> EnchantDisplay.PREFIX + EnchantDisplay.OPTIONS.getDescriptionOptions().getColor() + line);
|
||||
CACHE.add(new CacheEntry(enchantment, name, rawName, description, type, rarity));
|
||||
});
|
||||
}
|
||||
|
||||
@ToString
|
||||
public static class CacheEntry {
|
||||
/**
|
||||
* The enchantment that this cache is for.
|
||||
*/
|
||||
@Getter
|
||||
private final Enchantment enchantment;
|
||||
|
||||
/**
|
||||
* The formatted name of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The raw (unformatted) name of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final String rawName;
|
||||
|
||||
/**
|
||||
* The description, line-wrapped.
|
||||
*/
|
||||
@Getter
|
||||
private final List<String> description;
|
||||
|
||||
/**
|
||||
* The description, not line-wrapped or colorized.
|
||||
*/
|
||||
@Getter
|
||||
private final String stringDescription;
|
||||
|
||||
/**
|
||||
* The type of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final EnchantmentType type;
|
||||
|
||||
/**
|
||||
* The rarity of the enchantment.
|
||||
*/
|
||||
@Getter
|
||||
private final EnchantmentRarity rarity;
|
||||
|
||||
public CacheEntry(@NotNull final Enchantment enchantment,
|
||||
private CacheEntry(@NotNull final Enchantment enchantment,
|
||||
@NotNull final String name,
|
||||
@NotNull final String rawName,
|
||||
@NotNull final List<String> description,
|
||||
@ -121,35 +175,7 @@ public class EnchantmentCache implements Updatable {
|
||||
|
||||
String processedStringDescription = descriptionBuilder.toString();
|
||||
processedStringDescription = processedStringDescription.replace("§w", "");
|
||||
this.stringDescription = processedStringDescription.replaceAll(EnchantDisplay.OPTIONS.getDescriptionColor(), "");
|
||||
}
|
||||
|
||||
public Enchantment getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRawName() {
|
||||
return rawName;
|
||||
}
|
||||
|
||||
public List<String> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getStringDescription() {
|
||||
return stringDescription;
|
||||
}
|
||||
|
||||
public EnchantmentType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public EnchantmentRarity getRarity() {
|
||||
return rarity;
|
||||
this.stringDescription = processedStringDescription.replaceAll(EnchantDisplay.OPTIONS.getDescriptionOptions().getColor(), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,9 @@ package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ToggleableOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
import lombok.Getter;
|
||||
|
||||
public class DescriptionOptions implements ThresholdedOption, ToggleableOption, UpdateableOption {
|
||||
public class DescriptionOptions {
|
||||
/**
|
||||
* The threshold below which to describe enchantments.
|
||||
*/
|
||||
@ -29,7 +26,6 @@ public class DescriptionOptions implements ThresholdedOption, ToggleableOption,
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
threshold = Configs.CONFIG.getInt("lore.describe.before-lines");
|
||||
enabled = Configs.CONFIG.getBool("lore.describe.enabled");
|
||||
|
@ -6,6 +6,8 @@ import com.willfp.ecoenchants.display.options.sorting.SortParameters;
|
||||
import com.willfp.ecoenchants.display.options.sorting.SorterManager;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -15,61 +17,53 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DisplayOptions {
|
||||
/**
|
||||
* The enchantment sorter being used.
|
||||
*/
|
||||
@Getter
|
||||
private EnchantmentSorter sorter;
|
||||
|
||||
/**
|
||||
* The description options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final DescriptionOptions descriptionOptions = new DescriptionOptions();
|
||||
|
||||
/**
|
||||
* The enchantment level options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final NumbersOptions numbersOptions = new NumbersOptions();
|
||||
|
||||
/**
|
||||
* The shrink options being used.
|
||||
*/
|
||||
@Getter
|
||||
private final ShrinkOptions shrinkOptions = new ShrinkOptions();
|
||||
|
||||
/**
|
||||
* The enchantment types, sorted according to config.
|
||||
*/
|
||||
@Getter
|
||||
private final List<EnchantmentType> sortedTypes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The enchantment rarities, sorted according to config.
|
||||
*/
|
||||
@Getter
|
||||
private final List<EnchantmentRarity> sortedRarities = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Instantiate new display options.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public DisplayOptions() {
|
||||
update();
|
||||
}
|
||||
|
||||
public String getDescriptionColor() {
|
||||
return descriptionOptions.getColor();
|
||||
}
|
||||
|
||||
public int getNumbersThreshold() {
|
||||
return numbersOptions.getThreshold();
|
||||
}
|
||||
|
||||
public boolean isUseNumerals() {
|
||||
return numbersOptions.useNumerals();
|
||||
}
|
||||
|
||||
public int getDescribeThreshold() {
|
||||
return descriptionOptions.getThreshold();
|
||||
}
|
||||
|
||||
public boolean isUseDescribe() {
|
||||
return descriptionOptions.isEnabled();
|
||||
}
|
||||
|
||||
public int getShrinkThreshold() {
|
||||
return shrinkOptions.getThreshold();
|
||||
}
|
||||
|
||||
public int getShrinkPerLine() {
|
||||
return shrinkOptions.getShrinkPerLine();
|
||||
}
|
||||
|
||||
public boolean isUseShrink() {
|
||||
return shrinkOptions.isEnabled();
|
||||
}
|
||||
|
||||
public List<EnchantmentType> getSortedTypes() {
|
||||
return sortedTypes;
|
||||
}
|
||||
|
||||
public List<EnchantmentRarity> getSortedRarities() {
|
||||
return sortedRarities;
|
||||
}
|
||||
|
||||
public EnchantmentSorter getSorter() {
|
||||
return sorter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all options.
|
||||
*/
|
||||
public void update() {
|
||||
descriptionOptions.update();
|
||||
numbersOptions.update();
|
||||
|
@ -1,25 +1,28 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
import lombok.Getter;
|
||||
|
||||
public class NumbersOptions implements ThresholdedOption, UpdateableOption {
|
||||
public class NumbersOptions {
|
||||
/**
|
||||
* If numerals should be used.
|
||||
* <p>
|
||||
* If false then numbers will be used instead.
|
||||
*/
|
||||
@Getter
|
||||
private boolean useNumerals;
|
||||
|
||||
/**
|
||||
* The threshold above which numbers will be used instead.
|
||||
*/
|
||||
@Getter
|
||||
private int threshold;
|
||||
|
||||
@Override
|
||||
public int getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
public void update() {
|
||||
useNumerals = Configs.CONFIG.getBool("lore.use-numerals");
|
||||
threshold = Configs.CONFIG.getInt("lore.use-numbers-above-threshold");
|
||||
}
|
||||
|
||||
public boolean useNumerals() {
|
||||
return useNumerals;
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,33 @@
|
||||
package com.willfp.ecoenchants.display.options;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ThresholdedOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.ToggleableOption;
|
||||
import com.willfp.ecoenchants.display.options.interfaces.UpdateableOption;
|
||||
import lombok.Getter;
|
||||
|
||||
public class ShrinkOptions implements ThresholdedOption, ToggleableOption, UpdateableOption {
|
||||
public class ShrinkOptions {
|
||||
/**
|
||||
* The threshold above which enchantments will be shrunk.
|
||||
*/
|
||||
@Getter
|
||||
private int threshold;
|
||||
|
||||
/**
|
||||
* If shrinking is enabled.
|
||||
*/
|
||||
@Getter
|
||||
private boolean enabled;
|
||||
|
||||
/**
|
||||
* The amount of enchantments to have per-line.
|
||||
*/
|
||||
@Getter
|
||||
private int shrinkPerLine;
|
||||
|
||||
@Override
|
||||
public int getThreshold() {
|
||||
return threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* Update the options.
|
||||
*/
|
||||
public void update() {
|
||||
threshold = Configs.CONFIG.getInt("lore.shrink.after-lines");
|
||||
enabled = Configs.CONFIG.getBool("lore.shrink.enabled");
|
||||
shrinkPerLine = Configs.CONFIG.getInt("lore.shrink.maximum-per-line");
|
||||
}
|
||||
|
||||
public int getShrinkPerLine() {
|
||||
return shrinkPerLine;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface ThresholdedOption {
|
||||
int getThreshold();
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface ToggleableOption {
|
||||
boolean isEnabled();
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.willfp.ecoenchants.display.options.interfaces;
|
||||
|
||||
public interface UpdateableOption {
|
||||
void update();
|
||||
}
|
@ -11,6 +11,11 @@ import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketChat extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#CHAT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketChat(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.CHAT, ListenerPriority.MONITOR, true);
|
||||
}
|
||||
|
@ -18,6 +18,11 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#OPEN_WINDOW_MERCHANT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketOpenWindowMerchant(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.OPEN_WINDOW_MERCHANT, false);
|
||||
}
|
||||
|
@ -8,6 +8,11 @@ import com.willfp.ecoenchants.display.EnchantDisplay;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketSetCreativeSlot extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Client#SET_CREATIVE_SLOT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketSetCreativeSlot(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Client.SET_CREATIVE_SLOT, false);
|
||||
}
|
||||
|
@ -9,6 +9,11 @@ import org.bukkit.inventory.ItemFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketSetSlot extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#SET_SLOT}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketSetSlot(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.SET_SLOT, false);
|
||||
}
|
||||
|
@ -9,6 +9,11 @@ import org.bukkit.inventory.ItemFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PacketWindowItems extends AbstractPacketAdapter {
|
||||
/**
|
||||
* Instantiate a new listener for {@link PacketType.Play.Server#WINDOW_ITEMS}.
|
||||
*
|
||||
* @param plugin The plugin to listen through.
|
||||
*/
|
||||
public PacketWindowItems(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin, PacketType.Play.Server.WINDOW_ITEMS, false);
|
||||
}
|
||||
|
@ -27,10 +27,6 @@ import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Wrapper for Artifact enchantments
|
||||
* in order to reduce copying existing code between artifacts.
|
||||
*/
|
||||
public abstract class Artifact extends EcoEnchant {
|
||||
/**
|
||||
* The artifact particle.
|
||||
@ -45,6 +41,12 @@ public abstract class Artifact extends EcoEnchant {
|
||||
@Nullable
|
||||
private Particle.DustOptions extra;
|
||||
|
||||
/**
|
||||
* Create a new artifact enchantment.
|
||||
*
|
||||
* @param key The key name of the enchantment
|
||||
* @param prerequisites Optional {@link Prerequisite}s that must be met
|
||||
*/
|
||||
protected Artifact(@NotNull final String key,
|
||||
@NotNull final Prerequisite... prerequisites) {
|
||||
super(key, EnchantmentType.ARTIFACT, prerequisites);
|
||||
|
@ -25,30 +25,57 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Wrapper for Spell enchantments
|
||||
*/
|
||||
public abstract class Spell extends EcoEnchant {
|
||||
/**
|
||||
* {@link SpellRunnable}s linked to players.
|
||||
*/
|
||||
private final HashMap<UUID, SpellRunnable> tracker = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Players currently running spells - prevents listener firing twice.
|
||||
*/
|
||||
private final Set<UUID> runningSpell = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Items that must be left-clicked to activate spells for.
|
||||
*/
|
||||
private static final List<Material> LEFT_CLICK_ITEMS = Arrays.asList(
|
||||
Material.FISHING_ROD,
|
||||
Material.BOW
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new spell enchantment.
|
||||
*
|
||||
* @param key The key name of the enchantment
|
||||
* @param prerequisites Optional {@link Prerequisite}s that must be met
|
||||
*/
|
||||
protected Spell(@NotNull final String key,
|
||||
@NotNull final Prerequisite... prerequisites) {
|
||||
super(key, EnchantmentType.SPELL, prerequisites);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cooldown time of the spell (in seconds).
|
||||
*/
|
||||
public int getCooldownTime() {
|
||||
return this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "cooldown");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sound to be played on activation.
|
||||
*
|
||||
* @return The sound.
|
||||
*/
|
||||
public final Sound getActivationSound() {
|
||||
return Sound.valueOf(this.getConfig().getString(EcoEnchants.CONFIG_LOCATION + "activation-sound").toUpperCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener called on spell activation.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onUseEventHandler(@NotNull final PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@ -100,10 +127,24 @@ public abstract class Spell extends EcoEnchant {
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Actual spell-specific implementations; the functionality.
|
||||
*
|
||||
* @param player The player who triggered the spell.
|
||||
* @param level The level of the spell on the item.
|
||||
* @param event The event that activated the spell.
|
||||
*/
|
||||
public abstract void onUse(@NotNull Player player,
|
||||
int level,
|
||||
@NotNull PlayerInteractEvent event);
|
||||
|
||||
/**
|
||||
* Utility method to get a player's cooldown time of a specific spell.
|
||||
*
|
||||
* @param spell The spell to query.
|
||||
* @param player The player to query.
|
||||
* @return The time left in seconds before next use.
|
||||
*/
|
||||
public static int getCooldown(@NotNull final Spell spell,
|
||||
@NotNull final Player player) {
|
||||
if (!spell.tracker.containsKey(player.getUniqueId())) {
|
||||
@ -119,6 +160,13 @@ public abstract class Spell extends EcoEnchant {
|
||||
return NumberConversions.toInt(secondsLeft);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a multiplier for a spell cooldown.
|
||||
* <p>
|
||||
* Used for perks - this should be reworked as it has hardcoded permission references.
|
||||
*
|
||||
* @param player The player to query.
|
||||
*/
|
||||
public static double getCooldownMultiplier(@NotNull final Player player) {
|
||||
if (player.hasPermission("ecoenchants.cooldowntime.quarter")) {
|
||||
return 0.25;
|
||||
|
@ -8,6 +8,7 @@ import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.interfaces.Updatable;
|
||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -15,37 +16,66 @@ import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Class for storing all enchantment rarities
|
||||
*/
|
||||
public class EnchantmentRarity implements Registerable, Updatable {
|
||||
/**
|
||||
* All registered rarities.
|
||||
*/
|
||||
private static final Set<EnchantmentRarity> REGISTERED = new HashSet<>();
|
||||
|
||||
/**
|
||||
* The name of the rarity.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
private final double probability;
|
||||
|
||||
/**
|
||||
* The probability of getting an enchantment with this rarity from an enchanting table.
|
||||
*/
|
||||
@Getter
|
||||
private final double tableProbability;
|
||||
|
||||
/**
|
||||
* The minimum xp level to get an enchantment of this rarity from an enchanting table.
|
||||
*/
|
||||
@Getter
|
||||
private final int minimumLevel;
|
||||
|
||||
/**
|
||||
* The probability of a villager obtaining an enchantment with this rarity.
|
||||
*/
|
||||
@Getter
|
||||
private final double villagerProbability;
|
||||
|
||||
/**
|
||||
* The probability of an item in a loot chest having an enchantment with this rarity.
|
||||
*/
|
||||
@Getter
|
||||
private final double lootProbability;
|
||||
|
||||
/**
|
||||
* The custom display color, or null if not enabled.
|
||||
*/
|
||||
@Getter
|
||||
private final String customColor;
|
||||
|
||||
/**
|
||||
* Create new EnchantmentRarity
|
||||
* Create new EnchantmentRarity.
|
||||
*
|
||||
* @param name The name of the rarity
|
||||
* @param probability The probability
|
||||
* @param tableProbability The probability of getting an enchantment with this rarity from an enchanting table.
|
||||
* @param minimumLevel The minimum xp level
|
||||
* @param villagerProbability The probability of a villager obtaining an enchantment with this rarity
|
||||
* @param lootProbability The probability of an item in a loot chest having an enchantment with this rarity
|
||||
* @param customColor The custom display color, or null if not enabled
|
||||
*/
|
||||
public EnchantmentRarity(@NotNull final String name,
|
||||
final double probability,
|
||||
final double tableProbability,
|
||||
final int minimumLevel,
|
||||
final double villagerProbability,
|
||||
final double lootProbability,
|
||||
@Nullable final String customColor) {
|
||||
this.name = name;
|
||||
this.probability = probability;
|
||||
this.tableProbability = tableProbability;
|
||||
this.minimumLevel = minimumLevel;
|
||||
this.villagerProbability = villagerProbability;
|
||||
this.lootProbability = lootProbability;
|
||||
@ -59,7 +89,7 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
|
||||
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(
|
||||
"rarity_" + this.getName() + "_probability",
|
||||
player -> NumberUtils.format(this.probability)
|
||||
player -> NumberUtils.format(this.tableProbability)
|
||||
));
|
||||
PlaceholderManager.registerPlaceholder(new PlaceholderEntry(
|
||||
"rarity_" + this.getName() + "_minlevel",
|
||||
@ -82,74 +112,19 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the rarity
|
||||
* Is custom color enabled.
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is custom color enabled
|
||||
*
|
||||
* @return If has enabled custom color
|
||||
* @return If has enabled custom color.
|
||||
*/
|
||||
public boolean hasCustomColor() {
|
||||
return this.customColor != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom color
|
||||
* Get EnchantmentRarity matching name.
|
||||
*
|
||||
* @return The custom color
|
||||
*/
|
||||
public String getCustomColor() {
|
||||
return this.customColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the probability of obtaining enchantment with this rarity from an enchanting table
|
||||
*
|
||||
* @return The probability as a percentage
|
||||
*/
|
||||
public double getProbability() {
|
||||
return this.probability;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the probability of obtaining enchantment with this rarity from a villager
|
||||
*
|
||||
* @return The probability as a percentage
|
||||
*/
|
||||
public double getVillagerProbability() {
|
||||
return this.villagerProbability;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the probability of obtaining enchantment with this rarity from a loot chest
|
||||
*
|
||||
* @return The probability as a percentage
|
||||
*/
|
||||
public double getLootProbability() {
|
||||
return this.lootProbability;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum level required to obtain enchantment with this rarity from an enchanting table
|
||||
*
|
||||
* @return The minimum level
|
||||
*/
|
||||
public int getMinimumLevel() {
|
||||
return this.minimumLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EnchantmentRarity matching name
|
||||
*
|
||||
* @param name The name to search for
|
||||
*
|
||||
* @return The matching EnchantmentRarity, or null if not found
|
||||
* @param name The name to search for.
|
||||
* @return The matching EnchantmentRarity, or null if not found.
|
||||
*/
|
||||
public static EnchantmentRarity getByName(@NotNull final String name) {
|
||||
Optional<EnchantmentRarity> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
@ -157,8 +132,7 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update all rarities
|
||||
* Called on /ecoreload
|
||||
* Update all rarities.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
@ -178,9 +152,9 @@ public class EnchantmentRarity implements Registerable, Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rarities
|
||||
* Get all rarities.
|
||||
*
|
||||
* @return A set of all rarities
|
||||
* @return A set of all rarities.
|
||||
*/
|
||||
public static Set<EnchantmentRarity> values() {
|
||||
return REGISTERED;
|
||||
|
@ -5,6 +5,7 @@ import com.willfp.eco.util.config.annotations.ConfigUpdater;
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.interfaces.Updatable;
|
||||
import com.willfp.ecoenchants.config.EcoEnchantsConfigs;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -13,22 +14,35 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Class for storing all enchantment rarities
|
||||
*/
|
||||
public class EnchantmentTarget implements Registerable, Updatable {
|
||||
/**
|
||||
* All registered targets.
|
||||
*/
|
||||
private static final Set<EnchantmentTarget> REGISTERED = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Target containing the materials from all other targets.
|
||||
*/
|
||||
public static final EnchantmentTarget ALL = new EnchantmentTarget("all", new HashSet<>());
|
||||
|
||||
static {
|
||||
REGISTERED.add(ALL);
|
||||
}
|
||||
|
||||
/**
|
||||
* The name of the target.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The materials of the target.
|
||||
*/
|
||||
@Getter
|
||||
private final Set<Material> materials;
|
||||
|
||||
/**
|
||||
* Create new EnchantmentRarity
|
||||
* Create new rarity.
|
||||
*
|
||||
* @param name The name of the rarity
|
||||
* @param materials The items for the target
|
||||
@ -44,35 +58,16 @@ public class EnchantmentTarget implements Registerable, Updatable {
|
||||
public void register() {
|
||||
Optional<EnchantmentTarget> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
matching.ifPresent(REGISTERED::remove);
|
||||
matching.ifPresent(enchantmentTarget -> ALL.materials.removeAll(enchantmentTarget.getMaterials()));
|
||||
matching.ifPresent(enchantmentTarget -> ALL.getMaterials().removeAll(enchantmentTarget.getMaterials()));
|
||||
REGISTERED.add(this);
|
||||
ALL.materials.addAll(this.getMaterials());
|
||||
ALL.getMaterials().addAll(this.getMaterials());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the rarity
|
||||
* Get EnchantmentTarget matching name.
|
||||
*
|
||||
* @return The name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the materials of the rarity
|
||||
*
|
||||
* @return The materials
|
||||
*/
|
||||
public Set<Material> getMaterials() {
|
||||
return ImmutableSet.copyOf(this.materials);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get EnchantmentTarget matching name
|
||||
*
|
||||
* @param name The name to search for
|
||||
*
|
||||
* @return The matching EnchantmentTarget, or null if not found
|
||||
* @param name The name to search for.
|
||||
* @return The matching EnchantmentTarget, or null if not found.
|
||||
*/
|
||||
public static EnchantmentTarget getByName(@NotNull final String name) {
|
||||
Optional<EnchantmentTarget> matching = REGISTERED.stream().filter(rarity -> rarity.getName().equalsIgnoreCase(name)).findFirst();
|
||||
@ -81,7 +76,6 @@ public class EnchantmentTarget implements Registerable, Updatable {
|
||||
|
||||
/**
|
||||
* Update all targets
|
||||
* Called on /ecoreload
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
@ -94,12 +88,12 @@ public class EnchantmentTarget implements Registerable, Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rarities
|
||||
* Get all rarities.
|
||||
*
|
||||
* @return A set of all rarities
|
||||
* @return A set of all rarities.
|
||||
*/
|
||||
public static Set<EnchantmentTarget> values() {
|
||||
return REGISTERED;
|
||||
return ImmutableSet.copyOf(REGISTERED);
|
||||
}
|
||||
|
||||
static {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.willfp.ecoenchants.enchantments.meta;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.config.annotations.ConfigUpdater;
|
||||
import com.willfp.eco.util.interfaces.Updatable;
|
||||
@ -7,6 +8,7 @@ import com.willfp.eco.util.lambda.ObjectCallable;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Artifact;
|
||||
import com.willfp.ecoenchants.enchantments.itemtypes.Spell;
|
||||
import lombok.Getter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -14,29 +16,61 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EnchantmentType implements Updatable {
|
||||
/**
|
||||
* All registered types.
|
||||
*/
|
||||
private static final List<EnchantmentType> REGISTERED = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Most enchantments are like this.
|
||||
* <p>
|
||||
* eg: Arachnid, Telekinesis, Sharpness.
|
||||
*/
|
||||
public static final EnchantmentType NORMAL = new EnchantmentType(
|
||||
"normal",
|
||||
false,
|
||||
() -> Configs.LANG.getString("not-curse-color")
|
||||
);
|
||||
|
||||
/**
|
||||
* Negative enchantments.
|
||||
* <p>
|
||||
* eg: Curse of Decay, Curse of Vanishing.
|
||||
*/
|
||||
public static final EnchantmentType CURSE = new EnchantmentType(
|
||||
"curse",
|
||||
false,
|
||||
() -> Configs.LANG.getString("curse-color")
|
||||
);
|
||||
|
||||
/**
|
||||
* Extremely powerful enchantments.
|
||||
* <p>
|
||||
* eg: Razor, Force.
|
||||
*/
|
||||
public static final EnchantmentType SPECIAL = new EnchantmentType(
|
||||
"special",
|
||||
() -> !Configs.CONFIG.getBool("types.special.allow-multiple"),
|
||||
() -> Configs.LANG.getString("special-color")
|
||||
);
|
||||
|
||||
/**
|
||||
* Cosmetic enchantments.
|
||||
* <p>
|
||||
* eg: Ash Artifact, Totem Artifact.
|
||||
*/
|
||||
public static final EnchantmentType ARTIFACT = new EnchantmentType(
|
||||
"artifact",
|
||||
() -> !Configs.CONFIG.getBool("types.artifact.allow-multiple"),
|
||||
() -> Configs.LANG.getString("artifact-color"),
|
||||
Artifact.class
|
||||
);
|
||||
|
||||
/**
|
||||
* Ability enchantments.
|
||||
* <p>
|
||||
* eg: Missile, Quake.
|
||||
*/
|
||||
public static final EnchantmentType SPELL = new EnchantmentType(
|
||||
"spell",
|
||||
true,
|
||||
@ -44,21 +78,44 @@ public class EnchantmentType implements Updatable {
|
||||
Spell.class
|
||||
);
|
||||
|
||||
private boolean singular;
|
||||
private String color;
|
||||
private final String name;
|
||||
private final ObjectCallable<String> colorCallable;
|
||||
private final ObjectCallable<Boolean> singularCallable;
|
||||
|
||||
/**
|
||||
* If only one enchantment of this type is allowed on an item.
|
||||
*/
|
||||
@Getter
|
||||
private boolean singular;
|
||||
|
||||
/**
|
||||
* The color of enchantments of this type to have in lore.
|
||||
*/
|
||||
@Getter
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* The name of the type.
|
||||
*/
|
||||
@Getter
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* The class that all enchantments of this type must extend.
|
||||
* <p>
|
||||
* Null if not required.
|
||||
*/
|
||||
@Getter
|
||||
@Nullable
|
||||
private final Class<? extends EcoEnchant> requiredToExtend;
|
||||
|
||||
/**
|
||||
* Create simple EnchantmentType
|
||||
* Create simple EnchantmentType.
|
||||
* <p>
|
||||
* Singularity and Color will not be updated using this constructor
|
||||
* Singularity and Color will not be updated using this constructor.
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singular Whether an item can have several enchantments of this type
|
||||
* @param color The color for enchantments with this type in lore to have
|
||||
* @param name The name of the type.
|
||||
* @param singular Whether an item can have several enchantments of this type.
|
||||
* @param color The color for enchantments with this type in lore to have.
|
||||
*/
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
final boolean singular,
|
||||
@ -67,13 +124,13 @@ public class EnchantmentType implements Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EnchantmentType with updatable color
|
||||
* Create EnchantmentType with updatable color.
|
||||
* <p>
|
||||
* Singularity will not be updated using this constructor
|
||||
* Singularity will not be updated using this constructor.
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singular Whether an item can have several enchantments of this type
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
* @param name The name of the type.
|
||||
* @param singular Whether an item can have several enchantments of this type.
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
|
||||
*/
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
final boolean singular,
|
||||
@ -82,14 +139,14 @@ public class EnchantmentType implements Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EnchantmentType with updatable color that <b>must</b> extend a specified class
|
||||
* Create EnchantmentType with updatable color that <b>must</b> extend a specified class.
|
||||
* <p>
|
||||
* Singularity will not be updated using this constructor
|
||||
* Singularity will not be updated using this constructor.
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singular Whether an item can have several enchantments of this type
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required
|
||||
* @param name The name of the type.
|
||||
* @param singular Whether an item can have several enchantments of this type.
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
|
||||
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required.
|
||||
*/
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
final boolean singular,
|
||||
@ -99,11 +156,11 @@ public class EnchantmentType implements Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EnchantmentType with updatable color and singularity
|
||||
* Create EnchantmentType with updatable color and singularity.
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
* @param name The name of the type.
|
||||
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload.
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
|
||||
*/
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
@NotNull final ObjectCallable<Boolean> singularCallable,
|
||||
@ -112,12 +169,12 @@ public class EnchantmentType implements Updatable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create EnchantmentType with updatable color and singularity that <b>must</b> extend a specified class
|
||||
* Create EnchantmentType with updatable color and singularity that <b>must</b> extend a specified class.
|
||||
*
|
||||
* @param name The name of the type
|
||||
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload
|
||||
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required
|
||||
* @param name The name of the type.
|
||||
* @param singularCallable Lambda to fetch whether an item can have several enchantments of this type. Updates on /ecoreload.
|
||||
* @param colorCallable Lambda to fetch the color of enchantments with this type to have. Updates on /ecoreload.
|
||||
* @param requiredToExtend Class that all enchantments of this type must extend - or null if not required.
|
||||
*/
|
||||
public EnchantmentType(@NotNull final String name,
|
||||
@NotNull final ObjectCallable<Boolean> singularCallable,
|
||||
@ -137,28 +194,20 @@ public class EnchantmentType implements Updatable {
|
||||
this.singular = singularCallable.call();
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public boolean isSingular() {
|
||||
return singular;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Class<? extends EcoEnchant> getRequiredToExtend() {
|
||||
return requiredToExtend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update callables of all types.
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public static void update() {
|
||||
REGISTERED.forEach(EnchantmentType::refresh);
|
||||
}
|
||||
|
||||
/**
|
||||
* All registered enchantment types.
|
||||
*
|
||||
* @return All registered types.
|
||||
*/
|
||||
public static List<EnchantmentType> values() {
|
||||
return new ArrayList<>(REGISTERED);
|
||||
return ImmutableList.copyOf(REGISTERED);
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,20 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
public class GrindstoneListeners extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Instantiate grindstone listeners and link them to a specific plugin.
|
||||
*
|
||||
* @param plugin The plugin to link to.
|
||||
*/
|
||||
public GrindstoneListeners(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when items are grindstoned.
|
||||
*
|
||||
* @param event The event to listen to.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onGrindstone(@NotNull final InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
@ -14,6 +14,14 @@ import java.util.Map;
|
||||
@SuppressWarnings("deprecation")
|
||||
@UtilityClass
|
||||
public class GrindstoneMerge {
|
||||
|
||||
/**
|
||||
* Merge items in a grindstone.
|
||||
*
|
||||
* @param top The item at the top of the GUI.
|
||||
* @param bottom The item at the bottom of the GUI.
|
||||
* @return All enchantments for the output item to have.
|
||||
*/
|
||||
public static Map<Enchantment, Integer> doMerge(@Nullable final ItemStack top,
|
||||
@Nullable final ItemStack bottom) {
|
||||
Map<Enchantment, Integer> bottomEnchants = new HashMap<>();
|
||||
|
@ -90,7 +90,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
|
||||
if (!enchantment.canEnchantItem(item)) {
|
||||
continue;
|
||||
}
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getProbability() * multiplier) {
|
||||
if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getTableProbability() * multiplier) {
|
||||
continue;
|
||||
}
|
||||
if (enchantment.getRarity().getMinimumLevel() > cost) {
|
||||
|
Loading…
Reference in New Issue
Block a user