From 70f40fc6bca7e9504ac491991932e17fb80236f3 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 23 Dec 2020 14:18:29 +0000 Subject: [PATCH] Documented and lomboked events --- .../EntityDeathByEntityBuilder.java | 2 +- .../EntityDeathByEntityListeners.java | 6 ++ .../NaturalExpGainBuilder.java | 76 +++++++++++-------- .../NaturalExpGainEvent.java | 47 ++++++------ .../NaturalExpGainListeners.java | 6 +- 5 files changed, 81 insertions(+), 56 deletions(-) diff --git a/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityBuilder.java b/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityBuilder.java index 69cdb5c5..d55eacaa 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityBuilder.java +++ b/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityBuilder.java @@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack; import java.util.List; -public class EntityDeathByEntityBuilder { +class EntityDeathByEntityBuilder { /** * The killed {@link LivingEntity}. */ diff --git a/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityListeners.java b/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityListeners.java index 87311577..ff0b8d7c 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityListeners.java +++ b/eco-util/src/main/java/com/willfp/eco/util/events/entitydeathbyentity/EntityDeathByEntityListeners.java @@ -55,6 +55,12 @@ public class EntityDeathByEntityListeners extends PluginDependent implements Lis this.getPlugin().getScheduler().runLater(() -> events.remove(builtEvent), 1); } + /** + * Called when an entity is killed. + * Used to find the killer and associate the event. + * + * @param event The event to listen for. + */ @EventHandler public void onEntityDeath(@NotNull final EntityDeathEvent event) { LivingEntity victim = event.getEntity(); diff --git a/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainBuilder.java b/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainBuilder.java index 344602c3..e7b62d26 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainBuilder.java +++ b/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainBuilder.java @@ -1,48 +1,57 @@ package com.willfp.eco.util.events.naturalexpgainevent; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.entity.LivingEntity; import org.bukkit.event.player.PlayerExpChangeEvent; +import org.jetbrains.annotations.NotNull; class NaturalExpGainBuilder { - private final LivingEntity victim = null; + /** + * If the event has been cancelled and no experience should be given. + */ + @Getter + @Setter private boolean cancelled = false; + + /** + * The linked {@link PlayerExpChangeEvent}. + */ + @Getter + @Setter private PlayerExpChangeEvent event; - private Location loc; + + /** + * The location of the event. + */ + @Getter + @Setter + private Location location; + + /** + * The reason why the event was built. + */ + @Getter + @Setter private BuildReason reason; - public NaturalExpGainBuilder(BuildReason reason) { + /** + * Build a new {@link NaturalExpGainEvent} given a specific reason. + */ + NaturalExpGainBuilder(@NotNull final BuildReason reason) { this.reason = reason; } - public LivingEntity getVictim() { - return this.victim; - } - - public void setEvent(PlayerExpChangeEvent event) { - this.event = event; - } - - public void setCancelled(boolean cancel) { - this.cancelled = cancel; - } - - public void setLoc(Location location) { - this.loc = location; - } - - public Location getLoc() { - return this.loc; - } - - public BuildReason getReason() { - return reason; - } - + /** + * Call the event on the server. + */ public void push() { - if (this.event == null) return; - if (this.cancelled) return; + Validate.notNull(event); + if (this.cancelled) { + return; + } NaturalExpGainEvent naturalExpGainEvent = new NaturalExpGainEvent(event); @@ -50,7 +59,14 @@ class NaturalExpGainBuilder { } public enum BuildReason { + /** + * If the event was triggered by an experience bottle. + */ BOTTLE, + + /** + * If the event was triggered by a natural experience change. + */ PLAYER } } diff --git a/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainEvent.java b/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainEvent.java index f2e62905..8c772f12 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainEvent.java +++ b/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainEvent.java @@ -1,45 +1,48 @@ package com.willfp.eco.util.events.naturalexpgainevent; +import lombok.Getter; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.event.player.PlayerExpChangeEvent; import org.jetbrains.annotations.NotNull; -/** - * Event triggered when player receives experience not from bottle - */ public class NaturalExpGainEvent extends Event { + /** + * Internal bukkit. + */ private static final HandlerList HANDLERS = new HandlerList(); /** - * The associated {@link PlayerExpChangeEvent} - */ - private final PlayerExpChangeEvent event; - - /** - * Create event based off parameters - * - * @param event The associate PlayerExpChangeEvent - */ - public NaturalExpGainEvent(@NotNull PlayerExpChangeEvent event) { - this.event = event; - } - - /** - * Get associated {@link PlayerExpChangeEvent} + * The associated {@link PlayerExpChangeEvent}. * Use this to modify event parameters. - * - * @return The associated {@link PlayerExpChangeEvent} */ - public PlayerExpChangeEvent getExpChangeEvent() { - return this.event; + @Getter + private final PlayerExpChangeEvent expChangeEvent; + + /** + * Create event based off parameters. + * + * @param event The associated PlayerExpChangeEvent. + */ + public NaturalExpGainEvent(@NotNull final PlayerExpChangeEvent event) { + this.expChangeEvent = event; } + /** + * Internal bukkit. + * + * @return The handlers. + */ @Override public @NotNull HandlerList getHandlers() { return HANDLERS; } + /** + * Internal bukkit. + * + * @return The handlers. + */ public static HandlerList getHandlerList() { return HANDLERS; } diff --git a/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainListeners.java b/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainListeners.java index f4ac582d..8b5d5108 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainListeners.java +++ b/eco-util/src/main/java/com/willfp/eco/util/events/naturalexpgainevent/NaturalExpGainListeners.java @@ -18,8 +18,8 @@ public class NaturalExpGainListeners implements Listener { NaturalExpGainBuilder toRemove = null; for (NaturalExpGainBuilder searchBuilder : events) { - if(!searchBuilder.getLoc().getWorld().equals(event.getPlayer().getLocation().getWorld())) continue; - if(searchBuilder.getReason().equals(NaturalExpGainBuilder.BuildReason.BOTTLE) && searchBuilder.getLoc().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; } @@ -37,7 +37,7 @@ public class NaturalExpGainListeners implements Listener { @EventHandler public void onExpBottle(ExpBottleEvent event) { NaturalExpGainBuilder builtEvent = new NaturalExpGainBuilder(NaturalExpGainBuilder.BuildReason.BOTTLE); - builtEvent.setLoc(event.getEntity().getLocation()); + builtEvent.setLocation(event.getEntity().getLocation()); events.add(builtEvent); }