Continued documenting and lomboking

This commit is contained in:
Auxilor 2020-12-23 15:04:31 +00:00
parent 70f40fc6bc
commit 4f15cf82e0
5 changed files with 72 additions and 48 deletions

View File

@ -2,7 +2,9 @@ package com.willfp.eco.util.config;
import com.willfp.eco.util.config.configs.Config;
import com.willfp.eco.util.config.configs.Lang;
import lombok.experimental.UtilityClass;
@UtilityClass
public final class Configs {
/**
* The {@link BaseConfig} implementation for lang.yml.
@ -19,12 +21,8 @@ public final class Configs {
*
* @see BaseConfig
*/
public static void update() {
public void update() {
LANG.update();
CONFIG.update();
}
private Configs() {
}
}

View File

@ -1,14 +1,16 @@
package com.willfp.eco.util.drops.telekinesis;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@UtilityClass
public final class TelekinesisUtils {
/**
* The test service registered to bukkit.
*/
private static TelekinesisTests tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
private TelekinesisTests tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
/**
* Test the player for telekinesis.
@ -18,18 +20,14 @@ public final class TelekinesisUtils {
* @param player The player to test.
* @return If the player is telekinetic.
*/
public static boolean testPlayer(@NotNull final Player player) {
public boolean testPlayer(@NotNull final Player player) {
return tests.testPlayer(player);
}
/**
* Update the test to use.
*/
public static void update() {
public void update() {
tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
}
private TelekinesisUtils() {
}
}

View File

@ -4,26 +4,36 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.ExpBottleEvent;
import org.bukkit.event.player.PlayerExpChangeEvent;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
public class NaturalExpGainListeners implements Listener {
/**
* The events currently being built.
*/
private final Set<NaturalExpGainBuilder> events = new HashSet<>();
/**
* Called when the player's xp level changes.
* Used to store properties.
*
* @param event The event to listen for.
*/
@EventHandler
public void playerChange(PlayerExpChangeEvent event) {
public void playerChange(@NotNull final PlayerExpChangeEvent event) {
NaturalExpGainBuilder builder = new NaturalExpGainBuilder(NaturalExpGainBuilder.BuildReason.PLAYER);
builder.setEvent(event);
NaturalExpGainBuilder toRemove = null;
for (NaturalExpGainBuilder searchBuilder : events) {
if(!searchBuilder.getLocation().getWorld().equals(event.getPlayer().getLocation().getWorld())) continue;
if(searchBuilder.getReason().equals(NaturalExpGainBuilder.BuildReason.BOTTLE) && searchBuilder.getLocation().distanceSquared(event.getPlayer().getLocation()) > 52)
if (!searchBuilder.getLocation().getWorld().equals(event.getPlayer().getLocation().getWorld())) continue;
if (searchBuilder.getReason().equals(NaturalExpGainBuilder.BuildReason.BOTTLE) && searchBuilder.getLocation().distanceSquared(event.getPlayer().getLocation()) > 52)
toRemove = searchBuilder;
}
if(toRemove != null) {
if (toRemove != null) {
events.remove(toRemove);
return;
}
@ -34,6 +44,12 @@ public class NaturalExpGainListeners implements Listener {
events.remove(builder);
}
/**
* Called when an xp bottle breaks.
* Used to remove some built events to ensure only natural events are pushed.
*
* @param event The even to listen for.
*/
@EventHandler
public void onExpBottle(ExpBottleEvent event) {
NaturalExpGainBuilder builtEvent = new NaturalExpGainBuilder(NaturalExpGainBuilder.BuildReason.BOTTLE);

View File

@ -1,24 +1,26 @@
package com.willfp.eco.util.extensions;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import lombok.AccessLevel;
import lombok.Getter;
import org.apache.commons.lang.Validate;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Extensions are a way of interfacing with the base plugin
* Syntactically similar to Bukkit Plugins.
*/
public abstract class Extension {
/**
* The {@link AbstractEcoPlugin} that this extension is for.
*/
@Getter(AccessLevel.PROTECTED)
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
/**
* Metadata containing version and name
* Metadata containing version and name.
*/
private ExtensionMetadata metadata = null;
/**
* Method to validate metadata and enable extension
* Method to validate metadata and enable extension.
*/
public final void enable() {
Validate.notNull(metadata, "Metadata cannot be null!");
@ -26,45 +28,37 @@ public abstract class Extension {
}
/**
* Method to disable extension
* Method to disable extension.
*/
public final void disable() {
this.onDisable();
}
/**
* Called on enabling Extension
* Called on enabling Extension.
*/
protected abstract void onEnable();
/**
* Called when Extension is disabled
* Called when Extension is disabled.
*/
protected abstract void onDisable();
/**
* Get instance of the owning plugin
* @return The instance to interface with
*/
protected final AbstractEcoPlugin getPlugin() {
return plugin;
}
/**
* 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(@NotNull final ExtensionMetadata metadata) {
this.metadata = metadata;
}
/**
* 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() {
Validate.notNull(metadata, "Metadata cannot be null!");
@ -72,9 +66,9 @@ 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() {
Validate.notNull(metadata, "Metadata cannot be null!");
@ -82,16 +76,30 @@ public abstract class Extension {
}
/**
* Wrapper for the string and version of the extension
* Contains versions and name
* Designed for internal use
* Wrapper for the string and version of the extension.
* Contains versions and name.
* Designed for internal use.
*/
@ApiStatus.Internal
public static final class ExtensionMetadata {
/**
* The version of the extension.
*/
private final @NotNull String version;
/**
* The extension's name.
*/
private final @NotNull String name;
public ExtensionMetadata(@NotNull String version, @NotNull String name) {
/**
* Create a new extension metadata.
*
* @param version The version for the extension to be.
* @param name The name of the extension.
*/
public ExtensionMetadata(@NotNull final String version,
@NotNull final String name) {
this.version = version;
this.name = name;
}

View File

@ -1,14 +1,18 @@
package com.willfp.eco.util.extensions;
/**
* Called when the extension is made incorrectly
* Called when the extension is made incorrectly.
*/
public class MalformedExtensionException extends RuntimeException {
/**
* Create a new MalformedExtensionException
* Create a new MalformedExtensionException.
* <p>
* Potential causes include:
* Missing or invalid extension.yml.
* Invalid filetype.
*
* @param errorMessage The error message to show
* @param errorMessage The error message to show.
*/
public MalformedExtensionException(String errorMessage) {
super(errorMessage);