Began using lombok

This commit is contained in:
Auxilor
2020-12-23 14:11:17 +00:00
parent 195a1e1fff
commit 75507c3967
14 changed files with 219 additions and 206 deletions

View File

@@ -49,6 +49,12 @@ allprojects {
dependencies {
compileOnly 'org.jetbrains:annotations:19.0.0'
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testCompileOnly 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
}
tasks.withType(JavaCompile) {

View File

@@ -8,72 +8,75 @@ import com.willfp.eco.util.drops.internal.InternalDropQueue;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/**
* All drops should be sent through a {@link DropQueue}
*/
public class DropQueue {
/**
* The internally used {@link AbstractDropQueue}.
*/
private final AbstractDropQueue handle;
/**
* Create {@link DropQueue} linked to player
* <p>
* All drops should be passed through a drop queue for telekinesis integration.
*
* @param player The player
* @param player The player.
*/
public DropQueue(Player player) {
public DropQueue(@NotNull final Player player) {
handle = DropManager.getType() == DropQueueType.COLLATED ? new FastCollatedDropQueue(player) : new InternalDropQueue(player);
}
/**
* Add item to queue
* Add item to queue.
*
* @param item The item to add
* @return The DropQueue
* @param item The item to add.
* @return The DropQueue.
*/
public DropQueue addItem(ItemStack item) {
public DropQueue addItem(@NotNull final ItemStack item) {
handle.addItem(item);
return this;
}
/**
* Add multiple items to queue
* Add multiple items to queue.
*
* @param itemStacks The items to add
* @return The DropQueue
* @param itemStacks The items to add.
* @return The DropQueue.
*/
public DropQueue addItems(Collection<ItemStack> itemStacks) {
public DropQueue addItems(@NotNull final Collection<ItemStack> itemStacks) {
handle.addItems(itemStacks);
return this;
}
/**
* Add xp to queue
* Add xp to queue.
*
* @param amount The amount to add
* @return The DropQueue
* @param amount The amount to add.
* @return The DropQueue.
*/
public DropQueue addXP(int amount) {
public DropQueue addXP(final int amount) {
handle.addXP(amount);
return this;
}
/**
* Set location of the origin of the drops
* Set location of the origin of the drops.
*
* @param location The location
* @return The DropQueue
* @param location The location.
* @return The DropQueue.
*/
public DropQueue setLocation(Location location) {
public DropQueue setLocation(@NotNull final Location location) {
handle.setLocation(location);
return this;
}
/**
* Force the queue to act as if player is telekinetic
* Force the queue to act as if player is telekinetic.
*
* @return The DropQueue
* @return The DropQueue.
*/
public DropQueue forceTelekinesis() {
handle.forceTelekinesis();
@@ -81,9 +84,9 @@ public class DropQueue {
}
/**
* Push the queue
* Push the queue.
*/
public void push() {
handle.push();
}
}
}

View File

@@ -16,7 +16,7 @@ public interface AbstractDropQueue {
AbstractDropQueue addItem(@NotNull ItemStack item);
/**
* Add multiple items to queue
* Add multiple items to queue.
*
* @param itemStacks The items to add.
* @return The DropQueue.

View File

@@ -1,24 +1,17 @@
package com.willfp.eco.util.drops.internal;
import com.willfp.eco.util.config.Configs;
import lombok.Getter;
public final class DropManager {
/**
* The currently used type.
* The currently used type, or implementation, of {@link AbstractDropQueue}.
* <p>
* Standard by default, used if drops.collate key is not present in config.
*/
@Getter
private static DropQueueType type = DropQueueType.STANDARD;
/**
* Get the type of {@link AbstractDropQueue} that should be used.
*
* @return The chosen {@link DropQueueType}.
*/
public static DropQueueType getType() {
return type;
}
/**
* Update the type of drop queue that should be used.
*

View File

@@ -2,6 +2,10 @@ package com.willfp.eco.util.drops.internal;
import com.willfp.eco.util.injection.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -30,7 +34,7 @@ public class FastCollatedDropQueue extends InternalDropQueue {
*
* @param player The player to link the queue with.
*/
public FastCollatedDropQueue(Player player) {
public FastCollatedDropQueue(@NotNull final Player player) {
super(player);
}
@@ -39,28 +43,34 @@ public class FastCollatedDropQueue extends InternalDropQueue {
*/
@Override
public void push() {
CollatedDrops fetched = COLLATED_MAP.get(player);
CollatedDrops collatedDrops = fetched == null ? new CollatedDrops(items, loc, xp) : fetched.addDrops(items).setLocation(loc).addXp(xp);
COLLATED_MAP.put(player, collatedDrops);
CollatedDrops fetched = COLLATED_MAP.get(getPlayer());
CollatedDrops collatedDrops = fetched == null ? new CollatedDrops(getItems(), getLoc(), getXp()) : fetched.addDrops(getItems()).setLocation(getLoc()).addXp(getXp());
COLLATED_MAP.put(this.getPlayer(), collatedDrops);
}
/**
* The items, location, and xp linked to a player's drops.
*/
@ToString
private static final class CollatedDrops {
/**
* A collection of all ItemStacks to be dropped at the end of the tick.
*/
@Getter
private final List<ItemStack> drops;
/**
* The location to drop the items at.
*/
@Getter
@Setter
@Accessors(chain = true)
private Location location;
/**
* The xp to give to the player.
*/
@Getter
private int xp;
private CollatedDrops(@NotNull final List<ItemStack> drops,
@@ -71,35 +81,6 @@ public class FastCollatedDropQueue extends InternalDropQueue {
this.xp = xp;
}
/**
* Get the drops in the queue.
*
* @return A {@link List} of the drops to be given.
*/
@NotNull
public List<ItemStack> getDrops() {
return drops;
}
/**
* Get the location to drop the items and spawn the xp.
*
* @return The location.
*/
@NotNull
public Location getLocation() {
return location;
}
/**
* Get the experience to give to the player.
*
* @return The amount of experience to give.
*/
public int getXp() {
return xp;
}
/**
* Add {@link ItemStack}s to the queue.
*
@@ -111,17 +92,6 @@ public class FastCollatedDropQueue extends InternalDropQueue {
return this;
}
/**
* Set the location of the queue.
*
* @param loc The location to set.
* @return The instance of the {@link CollatedDrops}.
*/
public CollatedDrops setLocation(@NotNull final Location loc) {
this.location = loc;
return this;
}
/**
* Add xp to the queue.
*
@@ -132,21 +102,13 @@ public class FastCollatedDropQueue extends InternalDropQueue {
this.xp += xp;
return this;
}
@Override
public String toString() {
return "CollatedDrops{" +
"drops=" + drops +
", location=" + location +
", xp=" + xp +
'}';
}
}
public static class CollatedRunnable extends PluginDependent {
/**
* The {@link BukkitTask} that the runnable represents.
*/
@Getter
private final BukkitTask runnableTask;
/**
@@ -168,14 +130,5 @@ public class FastCollatedDropQueue extends InternalDropQueue {
COLLATED_MAP.clear();
}, 0, 1);
}
/**
* Get the {@link BukkitTask} that the runnable represents.
*
* @return The linked {@link BukkitTask}.
*/
public BukkitTask getRunnableTask() {
return runnableTask;
}
}
}

View File

@@ -1,6 +1,8 @@
package com.willfp.eco.util.drops.internal;
import com.willfp.eco.util.drops.telekinesis.TelekinesisUtils;
import lombok.AccessLevel;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
@@ -21,27 +23,32 @@ public class InternalDropQueue implements AbstractDropQueue {
/**
* The items that the DropQueue stores.
*/
protected final List<ItemStack> items;
@Getter(AccessLevel.PROTECTED)
private final List<ItemStack> items;
/**
* The experience to give.
*/
protected int xp;
@Getter(AccessLevel.PROTECTED)
private int xp;
/**
* The owner of the queue.
*/
protected final Player player;
@Getter(AccessLevel.PROTECTED)
private final Player player;
/**
* The location to drop the items and xp.
*/
protected Location loc;
@Getter(AccessLevel.PROTECTED)
private Location loc;
/**
* If the queue should be processed telekinetically.
*/
protected boolean hasTelekinesis = false;
@Getter(AccessLevel.PROTECTED)
private boolean hasTelekinesis = false;
/**
* Create a DropQueue linked to player.

View File

@@ -1,29 +1,42 @@
package com.willfp.eco.util.drops.telekinesis;
import com.willfp.eco.util.injection.PluginDependent;
import com.willfp.eco.util.lambda.ObjectBiCallable;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
public class EcoTelekinesisTests extends PluginDependent implements TelekinesisTests {
public class EcoTelekinesisTests implements TelekinesisTests {
/**
* Set of tests that return if the player is telekinetic.
*/
private final Set<ObjectBiCallable<Boolean, Player>> tests = new HashSet<>();
public EcoTelekinesisTests(AbstractEcoPlugin plugin) {
super(plugin);
}
/**
* Register a new test to check against.
*
* @param test The test to register, where the boolean output is if the player is telekinetic.
*/
@Override
public void registerTest(ObjectBiCallable<Boolean, Player> test) {
public void registerTest(@NotNull final ObjectBiCallable<Boolean, Player> test) {
tests.add(test);
}
/**
* Test the player for telekinesis.
* <p>
* If any test returns true, so does this.
*
* @param player The player to test.
* @return If the player is telekinetic.
*/
@Override
public boolean testPlayer(Player player) {
public boolean testPlayer(@NotNull final Player player) {
for (ObjectBiCallable<Boolean, Player> test : tests) {
if(test.call(player)) return true;
if (test.call(player)) {
return true;
}
}
return false;

View File

@@ -2,8 +2,21 @@ package com.willfp.eco.util.drops.telekinesis;
import com.willfp.eco.util.lambda.ObjectBiCallable;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public interface TelekinesisTests {
void registerTest(ObjectBiCallable<Boolean, Player> test);
boolean testPlayer(Player player);
/**
* Register a new test to check against.
*
* @param test The test to register, where the boolean output is if the player is telekinetic.
*/
void registerTest(@NotNull ObjectBiCallable<Boolean, Player> test);
/**
* Test the player for telekinesis.
*
* @param player The player to test.
* @return If the player is telekinetic.
*/
boolean testPlayer(@NotNull Player player);
}

View File

@@ -2,15 +2,34 @@ package com.willfp.eco.util.drops.telekinesis;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class TelekinesisUtils {
public final class TelekinesisUtils {
/**
* The test service registered to bukkit.
*/
private static TelekinesisTests tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
public static boolean testPlayer(Player player) {
/**
* Test the player for telekinesis.
* <p>
* If any test returns true, so does this.
*
* @param player The player to test.
* @return If the player is telekinetic.
*/
public static boolean testPlayer(@NotNull final Player player) {
return tests.testPlayer(player);
}
/**
* Update the test to use.
*/
public static void update() {
tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
}
private TelekinesisUtils() {
}
}

View File

@@ -1,5 +1,8 @@
package com.willfp.eco.util.events.entitydeathbyentity;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@@ -8,43 +11,47 @@ import org.bukkit.inventory.ItemStack;
import java.util.List;
class EntityDeathByEntityBuilder {
public class EntityDeathByEntityBuilder {
/**
* The killed {@link LivingEntity}.
*/
@Getter
@Setter
private LivingEntity victim = null;
/**
* The killer.
*/
@Getter
@Setter
private Entity damager;
/**
* The associated {@link EntityDeathEvent}.
*/
@Getter
@Setter
private EntityDeathEvent deathEvent;
/**
* The drops to create.
*/
@Getter
@Setter
private List<ItemStack> drops;
/**
* The experience to drop.
*/
@Getter
@Setter
private int xp = 0;
public LivingEntity getVictim() {
return this.victim;
}
public void setDeathEvent(EntityDeathEvent deathEvent) {
this.deathEvent = deathEvent;
}
public void setVictim(LivingEntity victim) {
this.victim = victim;
}
public void setDamager(Entity damager) {
this.damager = damager;
}
public void setDrops(List<ItemStack> drops) {
this.drops = drops;
}
public void setXp(int xp) {
this.xp = xp;
}
public void push() {
if (this.victim == null) return;
if (this.damager == null) return;
if (this.drops == null) return;
if (this.deathEvent == null) return;
Validate.notNull(victim);
Validate.notNull(damager);
Validate.notNull(drops);
Validate.notNull(deathEvent);
EntityDeathByEntityEvent event = new EntityDeathByEntityEvent(victim, damager, drops, xp, deathEvent);

View File

@@ -1,5 +1,6 @@
package com.willfp.eco.util.events.entitydeathbyentity;
import lombok.Getter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
@@ -14,35 +15,43 @@ import java.util.List;
* Event triggered when entity is killed by entity.
*/
public class EntityDeathByEntityEvent extends Event {
/**
* Internal, for bukkit.
*/
private static final HandlerList HANDLERS = new HandlerList();
/**
* The {@link LivingEntity} killed
* The {@link LivingEntity} killed.
*/
@Getter
private final LivingEntity victim;
/**
* The {@link Entity} that killed;
* The {@link Entity} that killed.
*/
@Getter
private final Entity damager;
/**
* The associated {@link EntityDeathEvent}
* The associated {@link EntityDeathEvent}.
*/
@Getter
private final EntityDeathEvent deathEvent;
/**
* The entity drops
* The entity drops.
*/
@Getter
private final List<ItemStack> drops;
/**
* The xp to drop
* The xp to drop.
*/
@Getter
private final int xp;
/**
* Create event based off parameters
* Create event based off parameters.
*
* @param victim The killed entity
* @param damager The killer
@@ -50,7 +59,11 @@ public class EntityDeathByEntityEvent extends Event {
* @param xp The amount of xp to drop
* @param deathEvent The associated {@link EntityDeathEvent}
*/
public EntityDeathByEntityEvent(@NotNull LivingEntity victim, @NotNull Entity damager, @NotNull List<ItemStack> drops, int xp, @NotNull EntityDeathEvent deathEvent) {
public EntityDeathByEntityEvent(@NotNull final LivingEntity victim,
@NotNull final Entity damager,
@NotNull final List<ItemStack> drops,
final int xp,
@NotNull final EntityDeathEvent deathEvent) {
this.victim = victim;
this.damager = damager;
this.drops = drops;
@@ -59,56 +72,18 @@ public class EntityDeathByEntityEvent extends Event {
}
/**
* Get victim
* Internal bukkit.
*
* @return The victim
* @return Get the handlers.
*/
public LivingEntity getVictim() {
return this.victim;
}
/**
* Get killer
*
* @return The killer
*/
public Entity getKiller() {
return this.damager;
}
/**
* Get xp amount
*
* @return The xp
*/
public int getDroppedExp() {
return this.xp;
}
/**
* Get drops
*
* @return {@link List} of drops
*/
public List<ItemStack> getDrops() {
return this.drops;
}
/**
* Get associated {@link EntityDeathEvent}
* Use this to modify event parameters.
*
* @return The associated {@link EntityDeathEvent}
*/
public EntityDeathEvent getDeathEvent() {
return this.deathEvent;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}
/**
* Internal bukkit.
*/
public static HandlerList getHandlerList() {
return HANDLERS;
}

View File

@@ -9,6 +9,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
@@ -16,14 +18,29 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
public class EntityDeathByEntityListeners extends PluginDependent implements Listener {
final Set<EntityDeathByEntityBuilder> events = new HashSet<>();
/**
* The events currently being built.
*/
private final Set<EntityDeathByEntityBuilder> events = new HashSet<>();
public EntityDeathByEntityListeners(AbstractEcoPlugin plugin) {
/**
* Create a listener associated with an {@link AbstractEcoPlugin}.
*
* @param plugin The plugin to associate with.
*/
@ApiStatus.Internal
public EntityDeathByEntityListeners(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
}
/**
* Called when an entity is damaged by another entity.
* Used to find the damager.
*
* @param event The event to listen for.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDamage(EntityDamageByEntityEvent event) {
public void onEntityDamage(@NotNull final EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof LivingEntity)) return;
LivingEntity victim = (LivingEntity) event.getEntity();
@@ -39,7 +56,7 @@ public class EntityDeathByEntityListeners extends PluginDependent implements Lis
}
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
public void onEntityDeath(@NotNull final EntityDeathEvent event) {
LivingEntity victim = event.getEntity();
List<ItemStack> drops = event.getDrops();

View File

@@ -1,15 +1,23 @@
package com.willfp.eco.util.injection;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import lombok.AccessLevel;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public abstract class PluginDependent {
/**
* The {@link AbstractEcoPlugin} that is stored.
*/
@Getter(AccessLevel.PROTECTED)
private final AbstractEcoPlugin plugin;
protected PluginDependent(AbstractEcoPlugin plugin) {
/**
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
*
* @param plugin The plugin to manage.
*/
protected PluginDependent(@NotNull final AbstractEcoPlugin plugin) {
this.plugin = plugin;
}
protected final AbstractEcoPlugin getPlugin() {
return this.plugin;
}
}

View File

@@ -55,7 +55,6 @@ import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@SuppressWarnings("DeprecatedIsStillUsed")
public abstract class AbstractEcoPlugin extends JavaPlugin {
protected static AbstractEcoPlugin instance;