From b98cdcf7d8a65508ab189044274ca0534b2310cf Mon Sep 17 00:00:00 2001 From: poma123 <25465545+poma123@users.noreply.github.com> Date: Sat, 19 Sep 2020 10:37:06 +0200 Subject: [PATCH] Added AsyncReactorProcessCompleteEvent --- .../AsyncReactorProcessCompleteEvent.java | 77 +++++++++++++++++++ .../items/electric/reactors/Reactor.java | 3 + 2 files changed, 80 insertions(+) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncReactorProcessCompleteEvent.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncReactorProcessCompleteEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncReactorProcessCompleteEvent.java new file mode 100644 index 000000000..3667f4392 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/AsyncReactorProcessCompleteEvent.java @@ -0,0 +1,77 @@ +package io.github.thebusybiscuit.slimefun4.api.events; + +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import org.bukkit.Location; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import io.github.thebusybiscuit.slimefun4.implementation.items.electric.reactors.Reactor; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineFuel; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; + +/** + * This {@link Event} is fired whenever a {@link Reactor} has completed its process. + * + * @author poma123 + * + */ +public class AsyncReactorProcessCompleteEvent extends Event { + + private static final HandlerList handlers = new HandlerList(); + + private final Location location; + private final Reactor reactor; + private final MachineFuel machineFuel; + + @ParametersAreNonnullByDefault + public AsyncReactorProcessCompleteEvent(Location l, Reactor reactor, MachineFuel machineFuel) { + super(true); + + this.location = l; + this.reactor = reactor; + this.machineFuel = machineFuel; + } + + /** + * This returns the {@link Location} of the reactor. + * + * @return The {@link Location} of the reactor + */ + @Nonnull + public Location getLocation() { + return location; + } + + /** + * The {@link SlimefunItem} instance of the reactor. + * + * @return The {@link SlimefunItem} instance of the reactor + */ + @Nonnull + public Reactor getReactor() { + return reactor; + } + + /** + * This returns the used {@link MachineFuel} in the process. + * + * @return The {@link MachineFuel} of the process + */ + @Nonnull + public MachineFuel getMachineFuel() { + return machineFuel; + } + + @Nonnull + public static HandlerList getHandlerList() { + return handlers; + } + + @Nonnull + @Override + public HandlerList getHandlers() { + return getHandlerList(); + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java index 8a5ba74bb..98bc100e4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java @@ -21,6 +21,7 @@ import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction; +import io.github.thebusybiscuit.slimefun4.api.events.AsyncReactorProcessCompleteEvent; import io.github.thebusybiscuit.slimefun4.api.events.ReactorExplodeEvent; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; @@ -376,6 +377,8 @@ public abstract class Reactor extends AbstractEnergyProvider { } } + Bukkit.getPluginManager().callEvent(new AsyncReactorProcessCompleteEvent(l, Reactor.this, getProcessing(l))); + progress.remove(l); processing.remove(l); }