Expanded javadoc

This commit is contained in:
Auxilor 2020-11-30 15:30:41 +00:00
parent 61106312b6
commit c4df03884b
13 changed files with 199 additions and 64 deletions

View File

@ -20,6 +20,7 @@ import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.Permission; import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault; import org.bukkit.permissions.PermissionDefault;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field; import java.lang.reflect.Field;
@ -53,10 +54,27 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
private boolean enabled; private boolean enabled;
/**
* Create a new EcoEnchant that exists within the base plugin
*
* @param key The key name of the enchantment
* @param type The type of the enchantment
* @param prerequisites Optional {@link Prerequisite}s that must be met
*/
@ApiStatus.Internal
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Prerequisite... prerequisites) { protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Prerequisite... prerequisites) {
this(key, type, EcoEnchantsPlugin.class, prerequisites); this(key, type, EcoEnchantsPlugin.class, prerequisites);
} }
/**
* Create a new EcoEnchant that exists within an extension or external plugin
*
* @param key The key name of the enchantment
* @param type The type of the enchantment
* @param plugin The Main class of the {@link org.bukkit.plugin.Plugin} or {@link com.willfp.ecoenchants.extensions.Extension} that the enchantment was created by
* @param prerequisites Optional {@link Prerequisite}s that must be met
*/
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin, Prerequisite... prerequisites) { protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin, Prerequisite... prerequisites) {
super(NamespacedKey.minecraft(key)); super(NamespacedKey.minecraft(key));
@ -84,6 +102,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
/** /**
* Update the enchantment based off config values * Update the enchantment based off config values
* This can be overriden but may lead to unexpected behavior
*/ */
public void update() { public void update() {
config.loadFromLang(); config.loadFromLang();

View File

@ -17,12 +17,29 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/**
* Utility class to simplify enchantment fetching
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class EnchantChecks { public class EnchantChecks {
/**
* Does the specified ItemStack have a certain Enchantment present?
*
* @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(ItemStack item, Enchantment enchantment) { public static boolean item(ItemStack item, Enchantment enchantment) {
return getItemLevel(item, enchantment) != 0; return getItemLevel(item, enchantment) != 0;
} }
/**
* What level of the specified enchantment does the specified ItemStack have?
*
* @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(ItemStack item, Enchantment enchantment) { public static int getItemLevel(ItemStack item, Enchantment enchantment) {
if (item == null) return 0; if (item == null) return 0;
if (item.getType().equals(Material.AIR)) return 0; if (item.getType().equals(Material.AIR)) return 0;
@ -32,6 +49,12 @@ public class EnchantChecks {
return item.getItemMeta().getEnchantLevel(enchantment); return item.getItemMeta().getEnchantLevel(enchantment);
} }
/**
* Get all {@link EcoEnchant}s on a specified ItemStack
*
* @param item The ItemStack to query
* @return A {@link HashMap<EcoEnchant, Integer>} of all EcoEnchants, where the key represents the level
*/
public static Map<EcoEnchant, Integer> getEnchantsOnItem(ItemStack item) { public static Map<EcoEnchant, Integer> getEnchantsOnItem(ItemStack item) {
if (item == null) return new HashMap<>(); if (item == null) return new HashMap<>();
if (item.getType().equals(Material.AIR)) return new HashMap<>(); if (item.getType().equals(Material.AIR)) return new HashMap<>();
@ -48,10 +71,28 @@ public class EnchantChecks {
return ecoEnchants; return ecoEnchants;
} }
/**
* Does the specified Arrow have a certain Enchantment present?
* <p>
* 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
*/
public static boolean arrow(Arrow arrow, Enchantment enchantment) { public static boolean arrow(Arrow arrow, Enchantment enchantment) {
return getArrowLevel(arrow, enchantment) != 0; return getArrowLevel(arrow, enchantment) != 0;
} }
/**
* What level specified Arrow has of a certain Enchantment present?
* <p>
* 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
*/
public static int getArrowLevel(Arrow arrow, Enchantment enchantment) { public static int getArrowLevel(Arrow arrow, Enchantment enchantment) {
if (arrow.getMetadata("enchantments").isEmpty()) return 0; if (arrow.getMetadata("enchantments").isEmpty()) return 0;
@ -65,6 +106,12 @@ public class EnchantChecks {
return enchantments.get(enchantment); return enchantments.get(enchantment);
} }
/**
* Get all {@link EcoEnchant}s on a specified Arrow
*
* @param arrow The Arrow to query
* @return A {@link HashMap<EcoEnchant, Integer>} of all EcoEnchants, where the key represents the level
*/
public static Map<EcoEnchant, Integer> getEnchantsOnArrow(Arrow arrow) { public static Map<EcoEnchant, Integer> getEnchantsOnArrow(Arrow arrow) {
if (arrow.getMetadata("enchantments").isEmpty()) return new HashMap<>(); if (arrow.getMetadata("enchantments").isEmpty()) return new HashMap<>();

View File

@ -43,6 +43,7 @@ public class EntityDeathByEntityEvent extends Event {
/** /**
* Create event based off parameters * Create event based off parameters
*
* @param victim The killed entity * @param victim The killed entity
* @param damager The killer * @param damager The killer
* @param drops The item drops * @param drops The item drops
@ -59,6 +60,7 @@ public class EntityDeathByEntityEvent extends Event {
/** /**
* Get victim * Get victim
*
* @return The victim * @return The victim
*/ */
public LivingEntity getVictim() { public LivingEntity getVictim() {
@ -67,6 +69,7 @@ public class EntityDeathByEntityEvent extends Event {
/** /**
* Get killer * Get killer
*
* @return The killer * @return The killer
*/ */
public Entity getKiller() { public Entity getKiller() {
@ -75,6 +78,7 @@ public class EntityDeathByEntityEvent extends Event {
/** /**
* Get xp amount * Get xp amount
*
* @return The xp * @return The xp
*/ */
public int getDroppedExp() { public int getDroppedExp() {
@ -83,6 +87,7 @@ public class EntityDeathByEntityEvent extends Event {
/** /**
* Get drops * Get drops
*
* @return {@link List} of drops * @return {@link List} of drops
*/ */
public List<ItemStack> getDrops() { public List<ItemStack> getDrops() {
@ -92,6 +97,7 @@ public class EntityDeathByEntityEvent extends Event {
/** /**
* Get associated {@link EntityDeathEvent} * Get associated {@link EntityDeathEvent}
* Use this to modify event parameters. * Use this to modify event parameters.
*
* @return The associated {@link EntityDeathEvent} * @return The associated {@link EntityDeathEvent}
*/ */
public EntityDeathEvent getDeathEvent() { public EntityDeathEvent getDeathEvent() {

View File

@ -18,6 +18,7 @@ public class NaturalExpGainEvent extends Event {
/** /**
* Create event based off parameters * Create event based off parameters
*
* @param event The associate PlayerExpChangeEvent * @param event The associate PlayerExpChangeEvent
*/ */
public NaturalExpGainEvent(@NotNull PlayerExpChangeEvent event) { public NaturalExpGainEvent(@NotNull PlayerExpChangeEvent event) {
@ -27,6 +28,7 @@ public class NaturalExpGainEvent extends Event {
/** /**
* Get associated {@link PlayerExpChangeEvent} * Get associated {@link PlayerExpChangeEvent}
* Use this to modify event parameters. * Use this to modify event parameters.
*
* @return The associated {@link PlayerExpChangeEvent} * @return The associated {@link PlayerExpChangeEvent}
*/ */
public PlayerExpChangeEvent getExpChangeEvent() { public PlayerExpChangeEvent getExpChangeEvent() {

View File

@ -41,8 +41,9 @@ public abstract class Extension {
/** /**
* Set the metadata of the extension * Set the metadata of the extension
* * <p>
* Must be called before enabling * Must be called before enabling
*
* @param metadata The metadata to set * @param metadata The metadata to set
*/ */
public final void setMetadata(ExtensionMetadata metadata) { public final void setMetadata(ExtensionMetadata metadata) {
@ -51,6 +52,7 @@ public abstract class Extension {
/** /**
* Get the name of the extension * Get the name of the extension
*
* @return The name of the metadata attached to the extension * @return The name of the metadata attached to the extension
*/ */
public final String getName() { public final String getName() {
@ -60,6 +62,7 @@ public abstract class Extension {
/** /**
* Get the version of the extension * Get the version of the extension
*
* @return The version of the metadata attached to the extension * @return The version of the metadata attached to the extension
*/ */
public final String getVersion() { public final String getVersion() {

View File

@ -4,6 +4,12 @@ package com.willfp.ecoenchants.extensions;
* Called when the extension is made incorrectly * Called when the extension is made incorrectly
*/ */
public class MalformedExtensionException extends RuntimeException { public class MalformedExtensionException extends RuntimeException {
/**
* Create a new MalformedExtensionException
*
* @param errorMessage The error message to show
*/
public MalformedExtensionException(String errorMessage) { public MalformedExtensionException(String errorMessage) {
super(errorMessage); super(errorMessage);
} }

View File

@ -18,14 +18,11 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* Class containing method to load extensions * Concrete implementation of {@link ExtensionLoader}
*/ */
public class EcoExtensionLoader implements ExtensionLoader { public class EcoExtensionLoader implements ExtensionLoader {
private final Set<Extension> extensions = new HashSet<>(); private final Set<Extension> extensions = new HashSet<>();
/**
* Load all extensions
*/
@Override @Override
public void loadExtensions() { public void loadExtensions() {
File dir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "/extensions"); File dir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "/extensions");
@ -97,28 +94,18 @@ public class EcoExtensionLoader implements ExtensionLoader {
extensions.add(extension); extensions.add(extension);
} }
/**
* Unload all extensions
*/
@Override @Override
public void unloadExtensions() { public void unloadExtensions() {
extensions.forEach(Extension::disable); extensions.forEach(Extension::disable);
extensions.clear(); extensions.clear();
} }
/**
* Reload all extensions
*/
@Override @Override
public void reloadExtensions() { public void reloadExtensions() {
unloadExtensions(); unloadExtensions();
loadExtensions(); loadExtensions();
} }
/**
* Get set of all loaded extensions
* @return {@link Set} of {@link Extension}s
*/
@Override @Override
public Set<Extension> getLoadedExtensions() { public Set<Extension> getLoadedExtensions() {
return extensions; return extensions;

View File

@ -4,12 +4,31 @@ import com.willfp.ecoenchants.extensions.Extension;
import java.util.Set; import java.util.Set;
/**
* Interface for extension loader
* Some external plugins may modify extension loading for internal server purposes
*/
public interface ExtensionLoader { public interface ExtensionLoader {
/**
* Load all extensions
*/
void loadExtensions(); void loadExtensions();
/**
* Unload all loaded extensions
*/
void unloadExtensions(); void unloadExtensions();
/**
* Reload all extensions
*/
void reloadExtensions(); void reloadExtensions();
/**
* Retrieve a set of all loaded extensions
*
* @return An {@link Set<Extension>} of all loaded extensions
*/
Set<Extension> getLoadedExtensions(); Set<Extension> getLoadedExtensions();
} }

View File

@ -8,9 +8,17 @@ import org.bukkit.event.Listener;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
/**
* Utility class for Anticheat Integrations
*/
public class AnticheatManager { public class AnticheatManager {
private static final Set<AnticheatWrapper> anticheats = new HashSet<>(); private static final Set<AnticheatWrapper> anticheats = new HashSet<>();
/**
* Register a new anticheat
*
* @param anticheat The anticheat to register
*/
public static void register(AnticheatWrapper anticheat) { public static void register(AnticheatWrapper anticheat) {
if (anticheat instanceof Listener) { if (anticheat instanceof Listener) {
Bukkit.getPluginManager().registerEvents((Listener) anticheat, EcoEnchantsPlugin.getInstance()); Bukkit.getPluginManager().registerEvents((Listener) anticheat, EcoEnchantsPlugin.getInstance());
@ -18,10 +26,21 @@ public class AnticheatManager {
anticheats.add(anticheat); anticheats.add(anticheat);
} }
/**
* Exempt a player from triggering anticheats
*
* @param player The player to exempt
*/
public static void exemptPlayer(Player player) { public static void exemptPlayer(Player player) {
anticheats.forEach(anticheat -> anticheat.exempt(player)); anticheats.forEach(anticheat -> anticheat.exempt(player));
} }
/**
* Unexempt a player from triggering anticheats
* This is ran a tick after it is called to ensure that there are no event timing conflicts
*
* @param player The player to remove the exemption
*/
public static void unexemptPlayer(Player player) { public static void unexemptPlayer(Player player) {
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> { Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
anticheats.forEach(anticheat -> anticheat.unexempt(player)); anticheats.forEach(anticheat -> anticheat.unexempt(player));

View File

@ -3,15 +3,20 @@ package com.willfp.ecoenchants.integrations.anticheat;
import com.willfp.ecoenchants.integrations.Integration; import com.willfp.ecoenchants.integrations.Integration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/**
* Interface for anticheat integrations
*/
public interface AnticheatWrapper extends Integration { public interface AnticheatWrapper extends Integration {
/** /**
* Exempt a player from checks * Exempt a player from checks
*
* @param player The player to exempt * @param player The player to exempt
*/ */
void exempt(Player player); void exempt(Player player);
/** /**
* Unexempt a player from checks * Unexempt a player from checks
*
* @param player The player to unexempt * @param player The player to unexempt
*/ */
void unexempt(Player player); void unexempt(Player player);

View File

@ -11,12 +11,18 @@ import java.util.Set;
public class AntigriefManager { public class AntigriefManager {
private static final Set<AntigriefWrapper> antigriefs = new HashSet<>(); private static final Set<AntigriefWrapper> antigriefs = new HashSet<>();
/**
* Register a new AntiGrief/Land Management integration
*
* @param antigrief The integration to register
*/
public static void register(AntigriefWrapper antigrief) { public static void register(AntigriefWrapper antigrief) {
antigriefs.add(antigrief); antigriefs.add(antigrief);
} }
/** /**
* Can player break block * Can player break block
*
* @param player The player * @param player The player
* @param block The block * @param block The block
* @return If player can break block * @return If player can break block
@ -27,6 +33,7 @@ public class AntigriefManager {
/** /**
* Can player create explosion at location * Can player create explosion at location
*
* @param player The player * @param player The player
* @param location The location * @param location The location
* @return If player can create explosion * @return If player can create explosion
@ -37,6 +44,7 @@ public class AntigriefManager {
/** /**
* Can player place block * Can player place block
*
* @param player The player * @param player The player
* @param block The block * @param block The block
* @return If player can place block * @return If player can place block
@ -47,6 +55,7 @@ public class AntigriefManager {
/** /**
* Can player injure living entity * Can player injure living entity
*
* @param player The player * @param player The player
* @param victim The victim * @param victim The victim
* @return If player can injure * @return If player can injure

View File

@ -6,11 +6,22 @@ import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/**
* Interface for Antigrief integrations
*/
public interface AntigriefWrapper extends Integration { public interface AntigriefWrapper extends Integration {
/**
* Can player break block
*
* @param player The player
* @param block The block
* @return If player cna break block
*/
boolean canBreakBlock(Player player, Block block); boolean canBreakBlock(Player player, Block block);
/** /**
* Can player create explosion at location * Can player create explosion at location
*
* @param player The player * @param player The player
* @param location The location * @param location The location
* @return If player can create explosion * @return If player can create explosion
@ -19,6 +30,7 @@ public interface AntigriefWrapper extends Integration {
/** /**
* Can player place block * Can player place block
*
* @param player The player * @param player The player
* @param block The block * @param block The block
* @return If player can place block * @return If player can place block
@ -27,6 +39,7 @@ public interface AntigriefWrapper extends Integration {
/** /**
* Can player injure living entity * Can player injure living entity
*
* @param player The player * @param player The player
* @param victim The victim * @param victim The victim
* @return If player can injure * @return If player can injure