Javadoc (4/?)

This commit is contained in:
Auxilor 2020-12-28 22:28:14 +00:00
parent 9379e91011
commit 0d103ee2a5
18 changed files with 129 additions and 55 deletions

View File

@ -21,27 +21,45 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
/**
* Class implemented by enchantment configs
*/
public abstract class EnchantmentYamlConfig extends PluginDependent implements ValueGetter {
/**
* The name of the config.
*/
private final String name;
/**
* The internal config that stores the values.
*/
@Getter
private YamlConfiguration config;
/**
* The physical file of the config.
*/
@Getter(AccessLevel.PROTECTED)
private File configFile;
/**
* The directory that the config is in.
*/
private final File directory;
/**
* The provider of the config.
*/
private final Class<?> source;
/**
* The type of the stored enchantment.
*/
private final EnchantmentType type;
/**
* Create new config yml
* Create new enchantment config yml.
*
* @param name The config name
* @param source The class of the main class of source or extension
* @param type The enchantment type
* @param name The config name.
* @param source The class of the main class of source or extension.
* @param type The enchantment type.
*/
protected EnchantmentYamlConfig(@NotNull final String name,
@NotNull final Class<?> source,
@ -104,6 +122,9 @@ public abstract class EnchantmentYamlConfig extends PluginDependent implements V
saveResource();
}
/**
* Update the config. Removes unneeded config keys and adds missing ones.
*/
public void update() {
try {
config.load(configFile);
@ -138,7 +159,6 @@ public abstract class EnchantmentYamlConfig extends PluginDependent implements V
}
/**
* Get an integer from config.
*
@ -199,7 +219,7 @@ public abstract class EnchantmentYamlConfig extends PluginDependent implements V
}
/**
* Get a string from config.C
* Get a string from config.
*
* @param path The key to fetch the value from.
* @return The found value, or an empty string if not found.

View File

@ -110,7 +110,7 @@ public class EnchantmentCache implements Updatable {
}
@ToString
public static class CacheEntry {
public static final class CacheEntry {
/**
* The enchantment that this cache is for.
*/

View File

@ -6,6 +6,19 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface EnchantmentSorter {
/**
* Sort list of enchantments.
* <p>
* All implementations must treat enchantments as final or effectively final.
*
* @param toSort The enchantments to sort.
*/
void sortEnchantments(@NotNull List<Enchantment> toSort);
/**
* Get the parameters that the sorter fulfills.
*
* @return Array of all parameters.
*/
SortParameters[] getParameters();
}

View File

@ -1,7 +1,18 @@
package com.willfp.ecoenchants.display.options.sorting;
public enum SortParameters {
/**
* If the sorter should sort by type or if type should be ignored.
*/
TYPE,
/**
* If the sorter should sort by rarity or if rarity should be ignored.
*/
RARITY,
/**
* If the sorter should sort by length or alphabetically.
*/
LENGTH
}

View File

@ -17,8 +17,19 @@ import java.util.Set;
@UtilityClass
public class SorterManager {
/**
* All registered enchantment sorters.
*/
private static final Set<EnchantmentSorter> REGISTERED = new HashSet<>();
/**
* Get a sorter based off of parameters.
* <p>
* Any combination of parameters is valid.
*
* @param parameters The parameters to find a sorter from.
* @return The matching sorter.
*/
public static EnchantmentSorter getSorter(@NotNull final SortParameters... parameters) {
return REGISTERED.stream()
.filter(enchantmentSorter -> Arrays.asList(enchantmentSorter.getParameters()).containsAll(Arrays.asList(parameters)) && enchantmentSorter.getParameters().length == parameters.length)

View File

@ -57,6 +57,8 @@ public abstract class Spell extends EcoEnchant {
/**
* Get the cooldown time of the spell (in seconds).
*
* @return The time, in seconds.
*/
public int getCooldownTime() {
return this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "cooldown");
@ -166,6 +168,7 @@ public abstract class Spell extends EcoEnchant {
* Used for perks - this should be reworked as it has hardcoded permission references.
*
* @param player The player to query.
* @return The multipiler.
*/
public static double getCooldownMultiplier(@NotNull final Player player) {
if (player.hasPermission("ecoenchants.cooldowntime.quarter")) {

View File

@ -75,7 +75,7 @@ public class EnchantmentTarget implements Registerable, Updatable {
}
/**
* Update all targets
* Update all targets.
*/
@ConfigUpdater
public static void update() {

View File

@ -78,7 +78,14 @@ public class EnchantmentType implements Updatable {
Spell.class
);
/**
* Lambda to fetch the color of the type.
*/
private final ObjectCallable<String> colorCallable;
/**
* Lambda to fetch the singularity of the type.
*/
private final ObjectCallable<Boolean> singularCallable;
/**

View File

@ -32,7 +32,7 @@ public class SpellRunnable {
* Must be set before execution.
*/
@Setter
private Callable callable = () -> {
private Callable task = () -> {
// Empty as must be set using this#setTask
};
@ -52,7 +52,7 @@ public class SpellRunnable {
* Run the runnable.
*/
public void run() {
callable.call();
task.call();
updateEndTime();
}

View File

@ -6,24 +6,24 @@ import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
/**
* Utility class for interfacing with EssentialsX
*/
@UtilityClass
public class EssentialsManager {
/**
* All registered essentials integrations.
*/
private static final Set<EssentialsWrapper> REGISTERED = new HashSet<>();
/**
* Register a new essentials integration
* Register a new essentials integration.
*
* @param essentials The integration to register
* @param essentials The integration to register.
*/
public static void register(@NotNull final EssentialsWrapper essentials) {
REGISTERED.add(essentials);
}
/**
* Register all {@link com.willfp.ecoenchants.enchantments.EcoEnchant}s with Essentials
* Register all {@link com.willfp.ecoenchants.enchantments.EcoEnchant}s with Essentials.
*/
public static void registerEnchantments() {
REGISTERED.forEach(EssentialsWrapper::registerAllEnchantments);

View File

@ -2,9 +2,6 @@ package com.willfp.ecoenchants.integrations.essentials;
import com.willfp.eco.util.integrations.Integration;
/**
* Interface for Essentials Integration
*/
public interface EssentialsWrapper extends Integration {
/**
* @see EssentialsManager#registerEnchantments();

View File

@ -8,9 +8,6 @@ import org.bukkit.enchantments.Enchantment;
import java.util.Map;
/**
* Concrete implementation of {@link EssentialsWrapper}
*/
@SuppressWarnings("unchecked")
public class IntegrationEssentials implements EssentialsWrapper {
@Override

View File

@ -3,11 +3,10 @@ package com.willfp.ecoenchants.integrations.mcmmo;
import com.willfp.eco.util.integrations.Integration;
import org.bukkit.event.Event;
/**
* Interface for mcMMO integrations
*/
public interface McmmoIntegration extends Integration {
/**
* @param event The event to check.
* @return If the event is fake.
* @see McmmoManager#isFake(Event)
*/
boolean isFake(Event event);

View File

@ -1,7 +1,6 @@
package com.willfp.ecoenchants.integrations.mcmmo;
import com.willfp.eco.util.ClassUtils;
import lombok.experimental.UtilityClass;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
@ -9,17 +8,16 @@ import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Utility class for interfacing with mcMMO
*/
@UtilityClass
public class McmmoManager {
/**
* All registered mcMMO integrations.
*/
private static final Set<McmmoIntegration> REGISTERED = new HashSet<>();
/**
* Register a new mcMMO integration
* Register a new mcMMO integration.
*
* @param integration The integration to register
* @param integration The integration to register.
*/
public static void registerIntegration(@NotNull final McmmoIntegration integration) {
if (!ClassUtils.exists("com.gmail.nossr50.events.fake.FakeEvent")) {
@ -29,10 +27,10 @@ public class McmmoManager {
}
/**
* Get if an event is fake
* Get if an event is fake.
*
* @param event The event to check
* @return If the event is fake
* @param event The event to check.
* @return If the event is fake.
*/
public static boolean isFake(@NotNull final Event event) {
AtomicBoolean isFake = new AtomicBoolean(false);

View File

@ -5,9 +5,6 @@ import com.willfp.ecoenchants.integrations.mcmmo.McmmoIntegration;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
/**
* Concrete implementation of {@link McmmoIntegration}
*/
public class McmmoIntegrationImpl implements McmmoIntegration {
@Override
public boolean isFake(@NotNull final Event event) {

View File

@ -12,22 +12,25 @@ import java.util.Set;
@UtilityClass
public class WorldguardManager {
/**
* All registered WorldGuard integrations.
*/
private static final Set<WorldguardWrapper> REGISTERED = new HashSet<>();
/**
* Register a new WorldGuard integration
* Register a new WorldGuard integration.
*
* @param worldguard The integration to register
* @param worldguard The integration to register.
*/
public static void register(@NotNull final WorldguardWrapper worldguard) {
REGISTERED.add(worldguard);
}
/**
* Register a new StateFlag with worldguard
* Register a new StateFlag with worldguard.
*
* @param flagName The name of the flag
* @param defaultValue The default value for the flag to have
* @param flagName The name of the flag.
* @param defaultValue The default value for the flag to have.
*/
public static void registerFlag(@NotNull final String flagName,
final boolean defaultValue) {
@ -35,11 +38,11 @@ public class WorldguardManager {
}
/**
* Get if an enchant is enabled at a player's location
* Get if an enchant is enabled at a player's location.
*
* @param enchant The enchantment to check
* @param player The player to query
* @return If the enchantment is enabled at a player's location
* @param enchant The enchantment to check.
* @param player The player to query.
* @return If the enchantment is enabled at a player's location.
*/
public static boolean enabledForPlayer(@NotNull final EcoEnchant enchant,
@NotNull final LivingEntity player) {
@ -53,12 +56,12 @@ public class WorldguardManager {
}
/**
* Get if an enchant is enabled at a specific location
* Get if an enchant is enabled at a specific location.
*
* @param enchant The enchantment to check
* @param player The player to query
* @param location The location to query
* @return If the enchantment is enabled at a player's location
* @param enchant The enchantment to check.
* @param player The player to query.
* @param location The location to query.
* @return If the enchantment is enabled at a player's location.
*/
public static boolean enabledForPlayer(@NotNull final EcoEnchant enchant,
@NotNull final LivingEntity player,

View File

@ -6,6 +6,21 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
public interface WorldguardWrapper extends Integration {
/**
* Register a flag with WorldGuard.
*
* @param name The name of the flag.
* @param def The default value for the flag to have.
*/
void registerFlag(String name, boolean def);
/**
* Get if an enchantment is available to be used at a specific location by a player.
*
* @param enchant The enchantment to query.
* @param player The player to query.
* @param location The location to query.
* @return If the enchantment is allowed to be used.
*/
boolean enabledForPlayer(EcoEnchant enchant, Player player, Location location);
}

View File

@ -12,6 +12,9 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class WorldguardIntegrationImpl implements WorldguardWrapper {
/**
* Flag registry.
*/
private static final FlagRegistry REGISTRY = WorldGuard.getInstance().getFlagRegistry();
@Override