diff --git a/config/checkstyle/suppression.xml b/config/checkstyle/suppression.xml index a6f64c54..051c2ea7 100644 --- a/config/checkstyle/suppression.xml +++ b/config/checkstyle/suppression.xml @@ -7,4 +7,5 @@ + \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java index f8075960..a6438d4c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEnchantinfo.java @@ -84,12 +84,12 @@ public class CommandEnchantinfo extends AbstractCommand { allConflicts = StringUtils.translate(Configs.LANG.getString("no-conflicts")); } - Set targets = enchantment.getTarget(); + Set targets = enchantment.getTargetMaterials(); Set applicableItemsSet = new HashSet<>(); if (Configs.CONFIG.getBool("commands.enchantinfo.show-target-group")) { - enchantment.getRawTargets().forEach(target -> { + enchantment.getTargets().forEach(target -> { String targetName = target.getName(); targetName = targetName.toLowerCase(); targetName = targetName.replace("_", " "); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java index a802154c..40e9f7e9 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/EnchantmentCache.java @@ -75,7 +75,7 @@ public class EnchantmentCache implements Updatable { List description; if (EcoEnchants.getFromEnchantment(enchantment) != null) { EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment); - description = ecoEnchant.getDescription(); + description = ecoEnchant.getWrappedDescription(); name = ecoEnchant.getName(); type = ecoEnchant.getType(); rarity = ecoEnchant.getRarity(); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index 298ef60d..30df8548 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -13,6 +13,9 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import com.willfp.ecoenchants.enchantments.util.Watcher; +import lombok.AccessLevel; +import lombok.EqualsAndHashCode; +import lombok.Getter; import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -23,9 +26,7 @@ import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.reflect.Field; import java.util.ArrayList; @@ -38,29 +39,114 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; -@SuppressWarnings({"unchecked", "deprecation"}) +@EqualsAndHashCode(callSuper = false) +@SuppressWarnings("unchecked") public abstract class EcoEnchant extends Enchantment implements Listener, Registerable, Watcher { + /** + * Instance of EcoEnchants for enchantments to be able to access. + */ + @Getter(AccessLevel.PROTECTED) private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance(); + /** + * The display name of the enchantment. + */ + @Getter private String name; + + /** + * The description of the enchantment. + */ + @Getter private String description; + + /** + * The permission/config name of the enchantment. + */ + @Getter private final String permissionName; + + /** + * The type of the enchantment. + */ + @Getter private final EnchantmentType type; + /** + * The enchantment's config. + */ + @Getter private final EnchantmentConfig config; + /** + * If the enchantment can be removed in a grindstone. + */ + @Getter private boolean grindstoneable; - private boolean canGetFromTable; - private boolean canGetFromVillager; - private boolean canGetFromLoot; - private int maxLvl; + + /** + * If the enchantment can be obtained from an enchanting table. + */ + @Getter + private boolean availableFromTable; + + /** + * If the enchantment can be obtained from a villager. + */ + @Getter + private boolean availableFromVillager; + + /** + * If the enchantment can be obtained from a loot chest. + */ + @Getter + private boolean availableFromLoot; + + /** + * The maximum level for the enchantment to be obtained naturally. + */ + private int maxLevel; + + /** + * The enchantments that conflict with this enchantment. + */ + @Getter private Set conflicts; + + /** + * The rarity of the enchantment. + */ + @Getter private EnchantmentRarity rarity; - private final Set target = new HashSet<>(); + + /** + * The targets of the enchantment. + */ + @Getter + private final Set targets = new HashSet<>(); + + /** + * The materials of the targets. + */ + @Getter private final Set targetMaterials = new HashSet<>(); + + /** + * The names of the worlds that this enchantment is disabled in. + */ + @Getter private final Set disabledWorldNames = new HashSet<>(); + + /** + * The worlds that this enchantment is disabled in. + */ + @Getter private final List disabledWorlds = new ArrayList<>(); + /** + * If the enchantment is enabled. + */ + @Getter private boolean enabled; /** @@ -105,18 +191,18 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist } /** - * Update the enchantment based off config values - * This can be overriden but may lead to unexpected behavior + * Update the enchantment based off config values. + * This can be overridden but may lead to unexpected behavior. */ public void update() { config.loadFromLang(); rarity = config.getRarity(); conflicts = config.getEnchantments(EcoEnchants.GENERAL_LOCATION + "conflicts"); grindstoneable = config.getBool(EcoEnchants.GENERAL_LOCATION + "grindstoneable"); - canGetFromTable = config.getBool(EcoEnchants.OBTAINING_LOCATION + "table"); - canGetFromVillager = config.getBool(EcoEnchants.OBTAINING_LOCATION + "villager"); - canGetFromLoot = config.getBool(EcoEnchants.OBTAINING_LOCATION + "loot"); - maxLvl = config.getInt(EcoEnchants.GENERAL_LOCATION + "maximum-level", 1); + availableFromTable = config.getBool(EcoEnchants.OBTAINING_LOCATION + "table"); + availableFromVillager = config.getBool(EcoEnchants.OBTAINING_LOCATION + "villager"); + availableFromLoot = config.getBool(EcoEnchants.OBTAINING_LOCATION + "loot"); + maxLevel = config.getInt(EcoEnchants.GENERAL_LOCATION + "maximum-level", 1); name = StringUtils.translate(config.getString("name")); description = StringUtils.translate(config.getString("description")); disabledWorldNames.clear(); @@ -125,11 +211,11 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist List worldNames = Bukkit.getWorlds().stream().map(World::getName).map(String::toLowerCase).collect(Collectors.toList()); List disabledExistingWorldNames = disabledWorldNames.stream().filter(s -> worldNames.contains(s.toLowerCase())).collect(Collectors.toList()); disabledWorlds.addAll(Bukkit.getWorlds().stream().filter(world -> disabledExistingWorldNames.contains(world.getName().toLowerCase())).collect(Collectors.toList())); - target.clear(); + targets.clear(); targetMaterials.clear(); - target.addAll(config.getTargets()); - target.forEach(enchantmentTarget -> targetMaterials.addAll(enchantmentTarget.getMaterials())); - enabled = config.getBool("enabled", true); + targets.addAll(config.getTargets()); + targets.forEach(enchantmentTarget -> targetMaterials.addAll(enchantmentTarget.getMaterials())); + enabled = config.getBool("enabled"); EnchantmentUtils.registerPlaceholders(this); postUpdate(); @@ -140,14 +226,9 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist // Unused as some enchantments may have postUpdate tasks, however most won't. } - @ApiStatus.Internal - protected AbstractEcoPlugin getPlugin() { - return this.plugin; - } - /** - * Register the enchantment with spigot - * Only used internally + * Register the enchantment with spigot. + * Only used internally. */ @Override public void register() { @@ -179,179 +260,41 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist } /** - * Get if enchantment can be removed in grindstone + * Get description of enchantment line-wrapped. * - * @return Whether the enchantment can be removed + * @return The description. */ - public boolean isGrindstoneable() { - return grindstoneable; - } - - /** - * Get {@link EnchantmentType} of enchantment - * - * @return The {@link EnchantmentType} - */ - public EnchantmentType getType() { - return this.type; - } - - /** - * Get a set of all conflicts - * - * @return Conflicts - */ - public Set getConflicts() { - return this.conflicts; - } - - /** - * Get if enchantment is enabled - * - * @return If enabled - */ - public boolean isEnabled() { - return this.enabled; - } - - /** - * Get permission name of enchantment - * - * @return The permission name - */ - public String getPermissionName() { - return permissionName; - } - - /** - * Get description of enchantment - * - * @return The description - */ - public List getDescription() { + public List getWrappedDescription() { return Arrays.asList(WordUtils.wrap(description, Configs.CONFIG.getInt("lore.describe.wrap"), "\n", false).split("\\r?\\n")); } /** - * Get if enchantment can be obtained from an enchanting table + * If enchantment conflicts with any enchantment in set. * - * @return If can be obtained - */ - public boolean canGetFromTable() { - return canGetFromTable; - } - - /** - * Get if enchantment can be obtained from a villager - * - * @return If can be obtained - */ - public boolean canGetFromVillager() { - return canGetFromVillager; - } - - /** - * Get if enchantment can be obtained from chest loot - * - * @return If can be obtained - */ - public boolean canGetFromLoot() { - return canGetFromLoot; - } - - /** - * Get {@link EnchantmentRarity} of enchantment - * - * @return The enchantment rarity - */ - public EnchantmentRarity getRarity() { - return rarity; - } - - /** - * If enchantment conflicts with any enchantment in set - * - * @param enchantments The set to test against - * - * @return If there are any conflicts + * @param enchantments The set to test against. + * @return If there are any conflicts. */ public boolean conflictsWithAny(@NotNull final Set enchantments) { return conflicts.stream().anyMatch(enchantments::contains); } /** - * Get enchantment cast to {@link Enchantment} + * Get enchantment cast to {@link Enchantment}. * - * @return The enchantment + * @return The enchantment. */ public Enchantment getEnchantment() { return this; } /** - * Get the target of enchantment + * Get max level of enchantment. * - * @return Set of enchantable items - */ - public Set getTarget() { - return targetMaterials; - } - - /** - * Get raw target of enchantment - * - * @return {@link com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget} - */ - public Set getRawTargets() { - return target; - } - - /** - * Get {@link EnchantmentConfig} of enchantment - * - * @return The config - */ - public EnchantmentConfig getConfig() { - return config; - } - - /** - * Get worlds that the enchantment is disabled in - * - * @return A list of all disabled worlds - */ - public List getDisabledWorlds() { - return disabledWorlds; - } - - /** - * Get world names that the enchantment is disabled in - * - * @return A list of all disabled world names - */ - public Set getDisabledWorldNames() { - return disabledWorldNames; - } - - /** - * Get display name of enchantment. - * Not deprecated, unlike {@link Enchantment#getName()} - * - * @return The display name - */ - @Override - public @NotNull String getName() { - return name; - } - - /** - * Get max level of enchantment - * - * @return The max level + * @return The max level. */ @Override public int getMaxLevel() { - return maxLvl; + return maxLevel; } /** @@ -364,11 +307,10 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist /** * Do not use this method. - * Only here for compatibility with {@link Enchantment} + * Only here for compatibility with {@link Enchantment}. * * @return Returns {@link EnchantmentTarget#ALL}. Do not use. - * - * @deprecated {@link EnchantmentTarget} is not supported due to its lack of flexibility. Use {@link EcoEnchant#getTarget()} instead. + * @deprecated {@link EnchantmentTarget} is not supported due to its lack of flexibility. Use {@link EcoEnchant#getTargets()} instead. */ @Override @Deprecated @@ -377,11 +319,10 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist } /** - * Treasure enchantments do not exist in EcoEnchants + * Treasure enchantments do not exist in EcoEnchants. + * + * @return false. * @see EnchantmentType#SPECIAL - * - * @return false - * * @deprecated Treasure enchantments do not exist. Use {@link EcoEnchant#getType()} instead. */ @Override @@ -392,10 +333,9 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist /** * While this method works, it is not recommended to use it. - * @see EnchantmentType#CURSE * * @return Returns if enchantment is cursed. - * + * @see EnchantmentType#CURSE * @deprecated Use {@link EcoEnchant#getType()} instead. */ @Override @@ -405,11 +345,10 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist } /** - * Get if enchantment conflicts with specified enchantment + * Get if enchantment conflicts with specified enchantment. * - * @param enchantment The enchantment to test against - * - * @return If conflicts + * @param enchantment The enchantment to test against. + * @return If conflicts. */ @Override public boolean conflictsWith(@NotNull final Enchantment enchantment) { @@ -417,34 +356,13 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist } /** - * If enchantment can be applied to item + * If enchantment can be applied to item. * - * @param itemStack The {@link ItemStack} to test against - * - * @return If can be applied + * @param itemStack The {@link ItemStack} to test against. + * @return If can be applied. */ @Override public boolean canEnchantItem(@NotNull final ItemStack itemStack) { return targetMaterials.contains(itemStack.getType()) || itemStack.getType().equals(Material.BOOK) || itemStack.getType().equals(Material.ENCHANTED_BOOK); } - - @Override - public boolean equals(@Nullable final Object o) { - if (this == o) { - return true; - } - if (!(o instanceof EcoEnchant)) { - return false; - } - if (!super.equals(o)) { - return false; - } - EcoEnchant enchant = (EcoEnchant) o; - return enchant.getKey().equals(((EcoEnchant) o).getKey()); - } - - @Override - public int hashCode() { - return Objects.hash(this.getKey()); - } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index a6543e38..9d7bb175 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -227,6 +227,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Missile; import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Quake; import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Vitalize; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import lombok.experimental.UtilityClass; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; @@ -238,11 +239,9 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; -/** - * Contains general methods for EcoEnchants - */ -@SuppressWarnings("unused") -public final class EcoEnchants implements Updatable { +@UtilityClass +@SuppressWarnings({"unused", "checkstyle:JavadocVariable"}) +public class EcoEnchants implements Updatable { public static final String CONFIG_LOCATION = "config."; public static final String OBTAINING_LOCATION = "obtaining."; public static final String GENERAL_LOCATION = "general-config."; @@ -471,19 +470,18 @@ public final class EcoEnchants implements Updatable { public static final EcoEnchant ASCEND = new Ascend(); /** - * Get all registered {@link EcoEnchant}s + * Get all registered {@link EcoEnchant}s. * - * @return A list of all {@link EcoEnchant}s + * @return A list of all {@link EcoEnchant}s. */ public static List values() { return ImmutableList.copyOf(BY_KEY.values()); } /** - * Gets {@link EcoEnchant} from {@link Enchantment} - * - * @param enchantment The enchantment + * Gets {@link EcoEnchant} from {@link Enchantment}. * + * @param enchantment The enchantment. * @return The matching {@link EcoEnchant}, or null if not found. */ public static EcoEnchant getFromEnchantment(@NotNull final Enchantment enchantment) { @@ -491,10 +489,9 @@ public final class EcoEnchants implements Updatable { } /** - * Get {@link EcoEnchant} matching display name - * - * @param name The display name to search for + * Get {@link EcoEnchant} matching display name. * + * @param name The display name to search for. * @return The matching {@link EcoEnchant}, or null if not found. */ public static EcoEnchant getByName(@NotNull final String name) { @@ -503,10 +500,9 @@ public final class EcoEnchants implements Updatable { } /** - * Get {@link EcoEnchant} matching permission name - * - * @param permissionName The permission name to search for + * Get {@link EcoEnchant} matching permission name. * + * @param permissionName The permission name to search for. * @return The matching {@link EcoEnchant}, or null if not found. */ public static EcoEnchant getByPermission(@NotNull final String permissionName) { @@ -515,10 +511,9 @@ public final class EcoEnchants implements Updatable { } /** - * Get {@link EcoEnchant} matching key - * - * @param key The NamespacedKey to search for + * Get {@link EcoEnchant} matching key. * + * @param key The NamespacedKey to search for. * @return The matching {@link EcoEnchant}, or null if not found. */ public static EcoEnchant getByKey(@NotNull final NamespacedKey key) { @@ -526,11 +521,10 @@ public final class EcoEnchants implements Updatable { } /** - * Get if {@link ItemStack} has any {@link EcoEnchant} matching specified {@link EnchantmentType} - * - * @param item The {@link ItemStack} to check - * @param type The {@link EnchantmentType} to match + * Get if {@link ItemStack} has any {@link EcoEnchant} matching specified {@link EnchantmentType}. * + * @param item The {@link ItemStack} to check. + * @param type The {@link EnchantmentType} to match. * @return True if has, false if doesn't have. */ public static boolean hasAnyOfType(@NotNull final ItemStack item, @@ -554,8 +548,7 @@ public final class EcoEnchants implements Updatable { } /** - * Update all {@link EcoEnchant}s - * Called on /ecoreload + * Update all {@link EcoEnchant}s. */ @ConfigUpdater public static void update() { @@ -565,10 +558,11 @@ public final class EcoEnchants implements Updatable { } /** - * Add new {@link EcoEnchant} to EcoEnchants + * Add new {@link EcoEnchant} to EcoEnchants. + *

* Only for internal use, enchantments are automatically added in the constructor. * - * @param enchant The {@link EcoEnchant} to add + * @param enchant The {@link EcoEnchant} to add. */ public static void addNewEcoEnchant(@NotNull final EcoEnchant enchant) { BY_KEY.remove(enchant.getKey()); @@ -576,15 +570,11 @@ public final class EcoEnchants implements Updatable { } /** - * Remove {@link EcoEnchant} from EcoEnchants + * Remove {@link EcoEnchant} from EcoEnchants. * - * @param enchant The {@link EcoEnchant} to remove + * @param enchant The {@link EcoEnchant} to remove. */ public static void removeEcoEnchant(@NotNull final EcoEnchant enchant) { BY_KEY.remove(enchant.getKey()); } - - private EcoEnchants() { - throw new UnsupportedOperationException("Utility class cannot be instantiated!"); - } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java index 50a9c2f4..05a8c630 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java @@ -29,6 +29,9 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; public class EnchantingListeners extends PluginDependent implements Listener { + /** + * All enchantments that by default cannot be enchanted in a table but are in EcoEnchants. + */ private static final Set SECONDARY_ENCHANTABLE = new ImmutableSet.Builder() .add(Material.ELYTRA) .add(Material.SHIELD) @@ -36,17 +39,35 @@ public class EnchantingListeners extends PluginDependent implements Listener { .add(Material.SHEARS) .add(Material.CARROT_ON_A_STICK).build(); + /** + * All players currently enchanting a secondary item. + */ public static final Map CURRENTLY_ENCHANTING_SECONDARY = new HashMap<>(); + /** + * Instantiate enchanting listeners and link them to a specific plugin. + * + * @param plugin The plugin to link to. + */ public EnchantingListeners(@NotNull final AbstractEcoPlugin plugin) { super(plugin); } + /** + * Called on player leave. + * + * @param event The event to listen to. + */ @EventHandler public void onPlayerLeave(@NotNull final PlayerQuitEvent event) { CURRENTLY_ENCHANTING_SECONDARY.remove(event.getPlayer()); } + /** + * Called on player enchant item. + * + * @param event The event to listen to. + */ @EventHandler public void enchantItem(@NotNull final EnchantItemEvent event) { Player player = event.getEnchanter(); @@ -99,7 +120,7 @@ public class EnchantingListeners extends PluginDependent implements Listener { if (!enchantment.isEnabled()) { continue; } - if (!enchantment.canGetFromTable()) { + if (!enchantment.isAvailableFromTable()) { continue; } if (!player.hasPermission("ecoenchants.fromtable." + enchantment.getPermissionName())) { @@ -161,7 +182,7 @@ public class EnchantingListeners extends PluginDependent implements Listener { } toAdd.forEach(event.getEnchantsToAdd()::putIfAbsent); - if (SECONDARY_ENCHANTABLE.contains(event.getItem().getType()) && !toAdd.containsKey(EcoEnchants.INDESTRUCTIBILITY)) { + if (SECONDARY_ENCHANTABLE.contains(event.getItem().getType()) && !toAdd.containsKey(EcoEnchants.INDESTRUCTIBILITY)) { event.getEnchantsToAdd().put(Enchantment.DURABILITY, CURRENTLY_ENCHANTING_SECONDARY.get(player)[event.whichButton()]); CURRENTLY_ENCHANTING_SECONDARY.remove(player); } @@ -188,6 +209,12 @@ public class EnchantingListeners extends PluginDependent implements Listener { }, 1); } + /** + * Called on prepare enchant. + * For secondary enchantments, generates unbreaking tooltips. + * + * @param event The event to listen to. + */ @EventHandler public void secondaryEnchant(@NotNull final PrepareItemEnchantEvent event) { int maxLevel = Configs.CONFIG.getInt("enchanting-table.maximum-obtainable-level"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java index e53a62b2..c7d252f7 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java @@ -28,9 +28,16 @@ import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; public class LootPopulator extends BlockPopulator { + /** + * Populate a chunk's loot chests. + * + * @param world The world to populate. + * @param random Bukkit parity. + * @param chunk The chunk to populate. + */ public void populate(@NotNull final World world, - final @NotNull Random random, - final @NotNull Chunk chunk) { + @NotNull final Random random, + @NotNull final Chunk chunk) { if (!Configs.CONFIG.getBool("loot.enabled")) { return; } @@ -78,7 +85,7 @@ public class LootPopulator extends BlockPopulator { continue; } - if (!enchantment.canGetFromLoot()) { + if (!enchantment.isAvailableFromLoot()) { continue; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java index 72c79a1f..5f26e959 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java @@ -25,8 +25,11 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; public class VillagerListeners implements Listener { - - // For books + /** + * Called on villager gain trade. + * + * @param event The event to listen for. + */ @EventHandler public void onVillagerGainBookTrade(@NotNull final VillagerAcquireTradeEvent event) { if (!event.getRecipe().getResult().getType().equals(Material.ENCHANTED_BOOK)) { @@ -61,7 +64,7 @@ public class VillagerListeners implements Listener { continue; } - if (!enchantment.canGetFromVillager()) { + if (!enchantment.isAvailableFromVillager()) { continue; } @@ -97,7 +100,11 @@ public class VillagerListeners implements Listener { event.setRecipe(recipe); } - // For tools + /** + * Called on villager gain trade. + * + * @param event The event to listen for. + */ @EventHandler public void onVillagerGainItemTrade(@NotNull final VillagerAcquireTradeEvent event) { @@ -139,7 +146,7 @@ public class VillagerListeners implements Listener { continue; } - if (!enchantment.canGetFromVillager()) { + if (!enchantment.isAvailableFromVillager()) { continue; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java index 0c64f04f..98e5a52d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantChecks.java @@ -23,12 +23,12 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -/** - * Utility class to simplify enchantment fetching - */ @SuppressWarnings("unchecked") @UtilityClass public class EnchantChecks { + /** + * Proxy instance of FastGetEnchants. + */ private static final FastGetEnchantsProxy PROXY = ProxyUtils.getProxy(FastGetEnchantsProxy.class); /** @@ -36,7 +36,6 @@ public class EnchantChecks { * * @param item The {@link ItemStack} to check * @param enchantment The enchantment to query - * * @return If the item has the queried enchantment */ public static boolean item(@Nullable final ItemStack item, @@ -49,7 +48,6 @@ public class EnchantChecks { * * @param item The {@link ItemStack} to check * @param enchantment The enchantment to query - * * @return The level of the enchantment, or 0 if not found */ public static int getItemLevel(@Nullable final ItemStack item, @@ -65,11 +63,10 @@ public class EnchantChecks { } /** - * Get all {@link EcoEnchant}s on a specified ItemStack + * Get all {@link EcoEnchant}s on a specified ItemStack. * - * @param item The ItemStack to query - * - * @return A {@link HashMap} of all EcoEnchants, where the key represents the level + * @param item The ItemStack to query. + * @return A {@link HashMap} of all EcoEnchants, where the key represents the level. */ public static Map getEnchantsOnItem(@Nullable final ItemStack item) { if (item == null) { @@ -93,12 +90,11 @@ public class EnchantChecks { /** * Does the specified Arrow have a certain Enchantment present? *

- * EcoEnchants automatically gives an arrow NBT data consisting of the enchantments present to avoid switching errors + * EcoEnchants automatically gives an arrow NBT data consisting of the enchantments present to avoid switching errors. * - * @param arrow The {@link Arrow} to check - * @param enchantment The enchantment to query - * - * @return If the arrow has the queried enchantment + * @param arrow The {@link Arrow} to check. + * @param enchantment The enchantment to query. + * @return If the arrow has the queried enchantment. */ public static boolean arrow(@NotNull final Arrow arrow, @NotNull final Enchantment enchantment) { @@ -108,12 +104,11 @@ public class EnchantChecks { /** * What level specified Arrow has of a certain Enchantment present? *

- * EcoEnchants automatically gives an arrow NBT data consisting of the enchantments present to avoid switching errors + * EcoEnchants automatically gives an arrow NBT data consisting of the enchantments present to avoid switching errors. * - * @param arrow The {@link Arrow} to check - * @param enchantment The enchantment to query - * - * @return The level found on the arrow, or 0 if not found + * @param arrow The {@link Arrow} to check. + * @param enchantment The enchantment to query. + * @return The level found on the arrow, or 0 if not found. */ public static int getArrowLevel(@NotNull final Arrow arrow, @NotNull final Enchantment enchantment) { @@ -137,11 +132,10 @@ public class EnchantChecks { } /** - * Get all {@link EcoEnchant}s on a specified Arrow + * Get all {@link EcoEnchant}s on a specified Arrow. * - * @param arrow The Arrow to query - * - * @return A {@link HashMap} of all EcoEnchants, where the key represents the level + * @param arrow The Arrow to query. + * @return A {@link HashMap} of all EcoEnchants, where the key represents the level. */ public static Map getEnchantsOnArrow(@NotNull final Arrow arrow) { if (arrow.getMetadata("enchantments").isEmpty()) { @@ -166,10 +160,9 @@ public class EnchantChecks { /** * Does the specified {@link LivingEntity} have a certain Enchantment present on the item in their main hand? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return If the LivingEntity has the enchantment + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return If the LivingEntity has the enchantment. */ public static boolean mainhand(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -179,10 +172,9 @@ public class EnchantChecks { /** * What level of the specified enchantment does the queried {@link LivingEntity} have on their main hand item? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return The level found on the mainhand item, or 0 if not found + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return The level found on the mainhand item, or 0 if not found. */ public static int getMainhandLevel(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -196,11 +188,10 @@ public class EnchantChecks { } /** - * Get all {@link EcoEnchant}s on a queried {@link LivingEntity}s main hand item + * Get all {@link EcoEnchant}s on a queried {@link LivingEntity}s main hand item. * - * @param entity The entity to query - * - * @return A {@link HashMap} of all EcoEnchants, where the key represents the level + * @param entity The entity to query. + * @return A {@link HashMap} of all EcoEnchants, where the key represents the level. */ public static Map getEnchantsOnMainhand(@NotNull final LivingEntity entity) { if (entity.getEquipment() == null) { @@ -215,10 +206,9 @@ public class EnchantChecks { /** * Does the specified {@link LivingEntity} have a certain Enchantment present on the item in their offhand? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return If the LivingEntity has the enchantment + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return If the LivingEntity has the enchantment. */ public static boolean offhand(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -228,10 +218,9 @@ public class EnchantChecks { /** * What level of the specified enchantment does the queried {@link LivingEntity} have on their offhand item? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return The level found on the offhand item, or 0 if not found + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return The level found on the offhand item, or 0 if not found. */ public static int getOffhandLevel(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -245,11 +234,10 @@ public class EnchantChecks { } /** - * Get all {@link EcoEnchant}s on a queried {@link LivingEntity}s offhand item + * Get all {@link EcoEnchant}s on a queried {@link LivingEntity}s offhand item. * - * @param entity The entity to query - * - * @return A {@link HashMap} of all EcoEnchants, where the key represents the level + * @param entity The entity to query. + * @return A {@link HashMap} of all EcoEnchants, where the key represents the level. */ public static Map getEnchantsOnOffhand(@NotNull final LivingEntity entity) { if (entity.getEquipment() == null) { @@ -262,11 +250,10 @@ public class EnchantChecks { } /** - * Get a cumulative total of all levels on a {@link LivingEntity}s armor of a certain enchantment - * - * @param entity The entity to query - * @param enchantment The enchantment to check + * Get a cumulative total of all levels on a {@link LivingEntity}s armor of a certain enchantment. * + * @param entity The entity to query. + * @param enchantment The enchantment to check. * @return The cumulative total of all levels, ie 4 pieces all with level 3 returns 12 */ public static int getArmorPoints(@NotNull final LivingEntity entity, @@ -275,15 +262,14 @@ public class EnchantChecks { } /** - * Get a cumulative total of all levels on a {@link LivingEntity}s armor of a certain enchantment + * Get a cumulative total of all levels on a {@link LivingEntity}s armor of a certain enchantment. *

- * Then, apply a specified amount of damage to all items with said enchantment + * Then, apply a specified amount of damage to all items with said enchantment. * - * @param entity The entity to query - * @param enchantment The enchantment to check - * @param damage The amount of damage to deal to all armor pieces - * - * @return The cumulative total of all levels, ie 4 pieces all with level 3 returns 12 + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @param damage The amount of damage to deal to all armor pieces. + * @return The cumulative total of all levels, ie 4 pieces all with level 3 returns 12. */ public static int getArmorPoints(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment, @@ -322,11 +308,10 @@ public class EnchantChecks { } /** - * Get all {@link EcoEnchant}s on a queried {@link LivingEntity}s armor + * Get all {@link EcoEnchant}s on a queried {@link LivingEntity}s armor. * - * @param entity The entity to query - * - * @return A {@link HashMap} of all EcoEnchants, where the key represents the cumulative total levels + * @param entity The entity to query. + * @return A {@link HashMap} of all EcoEnchants, where the key represents the cumulative total levels. */ public static Map getEnchantsOnArmor(@NotNull final LivingEntity entity) { if (entity.getEquipment() == null) { @@ -347,10 +332,9 @@ public class EnchantChecks { /** * Does the specified {@link LivingEntity} have a certain Enchantment present on their helmet? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return If the LivingEntity has the enchantment + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return If the LivingEntity has the enchantment. */ public static boolean helmet(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -360,10 +344,9 @@ public class EnchantChecks { /** * What level of the specified enchantment does the queried {@link LivingEntity} have on their helmet? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return The level found, or 0 if not found + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return The level found, or 0 if not found. */ public static int getHelmetLevel(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -379,10 +362,9 @@ public class EnchantChecks { /** * Does the specified {@link LivingEntity} have a certain Enchantment present on their chestplate? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return If the LivingEntity has the enchantment + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return If the LivingEntity has the enchantment. */ public static boolean chestplate(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -392,10 +374,9 @@ public class EnchantChecks { /** * What level of the specified enchantment does the queried {@link LivingEntity} have on their chestplate? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return The level found, or 0 if not found + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return The level found, or 0 if not found. */ public static int getChestplateLevel(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -411,10 +392,9 @@ public class EnchantChecks { /** * Does the specified {@link LivingEntity} have a certain Enchantment present on their leggings? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return If the LivingEntity has the enchantment + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return If the LivingEntity has the enchantment. */ public static boolean leggings(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -424,10 +404,9 @@ public class EnchantChecks { /** * What level of the specified enchantment does the queried {@link LivingEntity} have on their leggings? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return The level found, or 0 if not found + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return The level found, or 0 if not found. */ public static int getLeggingsLevel(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -443,10 +422,9 @@ public class EnchantChecks { /** * Does the specified {@link LivingEntity} have a certain Enchantment present on their boots? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return If the LivingEntity has the enchantment + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return If the LivingEntity has the enchantment. */ public static boolean boots(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { @@ -456,10 +434,9 @@ public class EnchantChecks { /** * What level of the specified enchantment does the queried {@link LivingEntity} have on their boots? * - * @param entity The entity to query - * @param enchantment The enchantment to check - * - * @return The level found, or 0 if not found + * @param entity The entity to query. + * @param enchantment The enchantment to check. + * @return The level found, or 0 if not found. */ public static int getBootsLevel(@NotNull final LivingEntity entity, @NotNull final Enchantment enchantment) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantmentUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantmentUtils.java index 55ff5925..efa310b5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantmentUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/EnchantmentUtils.java @@ -13,11 +13,23 @@ import org.jetbrains.annotations.NotNull; @UtilityClass public class EnchantmentUtils { + /** + * If the enchantment has successfully passed its specified chance. + * + * @param enchantment The enchantment to query. + * @param level The level to base the chance off of. + * @return If the enchantment should then be executed. + */ public static boolean passedChance(@NotNull final EcoEnchant enchantment, final int level) { return NumberUtils.randFloat(0, 1) < ((enchantment.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level") * level) / 100); } + /** + * Register the placeholders for an enchantment. + * + * @param enchantment The enchantment to register placeholders for. + */ public static void registerPlaceholders(@NotNull final EcoEnchant enchantment) { PlaceholderManager.registerPlaceholder( new PlaceholderEntry( diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java index a12792a5..a407df68 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java @@ -3,41 +3,63 @@ package com.willfp.ecoenchants.enchantments.util; import com.willfp.eco.util.lambda.Callable; import com.willfp.ecoenchants.enchantments.itemtypes.Spell; +import lombok.Getter; +import lombok.Setter; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; public class SpellRunnable { + /** + * The spell that this runnable is for. + */ + @Getter private final Spell spell; + + /** + * The player that this runnable is for. + */ private final Player player; + + /** + * The end time of the runnable, in unix time. + */ + @Getter private long endTime = 0; + + /** + * The actual task to be executed. + *

+ * Must be set before execution. + */ + @Setter private Callable callable = () -> { // Empty as must be set using this#setTask }; + /** + * Create a new Spell Runnable. + * + * @param spell The spell. + * @param player The player. + */ public SpellRunnable(@NotNull final Spell spell, @NotNull final Player player) { this.spell = spell; this.player = player; } - public Spell getSpell() { - return spell; - } - + /** + * Run the runnable. + */ public void run() { callable.call(); updateEndTime(); } - public long getEndTime() { - return endTime; - } - + /** + * Update the end time of the spell runnable. + */ public void updateEndTime() { endTime = System.currentTimeMillis() + (long) ((spell.getCooldownTime() * 1000L) * Spell.getCooldownMultiplier(player)); } - - public void setTask(@NotNull final Callable callable) { - this.callable = callable; - } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java index e373337c..c5c1b7ad 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java @@ -36,14 +36,30 @@ import java.util.UUID; @SuppressWarnings("deprecation") public class WatcherTriggers extends PluginDependent implements Listener { + /** + * For jump listeners. + */ private static final Set PREVIOUS_PLAYERS_ON_GROUND = Sets.newHashSet(); + + /** + * For jump listeners. + */ private static final DecimalFormat FORMAT = new DecimalFormat("0.00"); - + /** + * Create new listener for watcher events. + * + * @param plugin The plugin to link the events to. + */ public WatcherTriggers(@NotNull final AbstractEcoPlugin plugin) { super(plugin); } + /** + * Called when an entity shoots another entity with an arrow. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onArrowDamage(@NotNull final EntityDamageByEntityEvent event) { if (McmmoManager.isFake(event)) { @@ -99,6 +115,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { })); } + /** + * Called when an entity damages another entity with a trident throw. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onTridentDamage(@NotNull final EntityDamageByEntityEvent event) { if (McmmoManager.isFake(event)) { @@ -156,6 +177,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { })); } + /** + * Called when a player jumps. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onJump(@NotNull final PlayerMoveEvent event) { if (McmmoManager.isFake(event)) { @@ -197,6 +223,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { } } + /** + * Called when an entity attacks another entity with a melee attack. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onMeleeAttack(@NotNull final EntityDamageByEntityEvent event) { if (McmmoManager.isFake(event)) { @@ -243,6 +274,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { }); } + /** + * Called when an entity shoots a bow. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onBowShoot(@NotNull final EntityShootBowEvent event) { if (McmmoManager.isFake(event)) { @@ -273,6 +309,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { }); } + /** + * Called when an entity takes fall damage. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onFallDamage(@NotNull final EntityDamageEvent event) { if (McmmoManager.isFake(event)) { @@ -306,6 +347,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { }); } + /** + * Called when an arrow hits a block or entity. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onArrowHit(@NotNull final ProjectileHitEvent event) { if (McmmoManager.isFake(event)) { @@ -340,6 +386,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { })); } + /** + * Called when a trident hits a block or entity. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onTridentHit(@NotNull final ProjectileHitEvent event) { if (McmmoManager.isFake(event)) { @@ -375,6 +426,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { })); } + /** + * Called when a player breaks a block. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onBlockBreak(@NotNull final BlockBreakEvent event) { if (McmmoManager.isFake(event)) { @@ -409,6 +465,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { }); } + /** + * Called when an entity takes damage wearing armor. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onDamageWearingArmor(@NotNull final EntityDamageEvent event) { if (McmmoManager.isFake(event)) { @@ -438,6 +499,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { }); } + /** + * Called when an entity puts on or takes off armor with an enchantment. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onArmorEquip(@NotNull final ArmorEquipEvent event) { if (McmmoManager.isFake(event)) { @@ -464,6 +530,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { }), 1); } + /** + * Called when a player damages a block. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onDamageBlock(@NotNull final BlockDamageEvent event) { if (McmmoManager.isFake(event)) { @@ -494,6 +565,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { }); } + /** + * Called when an entity throws a trident. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onTridentLaunch(@NotNull final ProjectileLaunchEvent event) { if (McmmoManager.isFake(event)) { @@ -529,6 +605,11 @@ public class WatcherTriggers extends PluginDependent implements Listener { }); } + /** + * Called when a player blocks an attack with a shield. + * + * @param event The event to listen for. + */ @EventHandler(ignoreCancelled = true) public void onDeflect(@NotNull final EntityDamageByEntityEvent event) { if (McmmoManager.isFake(event)) {