From e628ad26854813e90dd84897a6509e6f6aae9185 Mon Sep 17 00:00:00 2001 From: poma123 <25465545+poma123@users.noreply.github.com> Date: Wed, 9 Sep 2020 14:25:20 +0200 Subject: [PATCH 1/6] Added MachineProcessCompleteEvent --- .../events/MachineProcessCompleteEvent.java | 54 +++++++++++++++++++ .../abstractItems/AContainer.java | 4 ++ 2 files changed, 58 insertions(+) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java new file mode 100644 index 000000000..97632e2fe --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java @@ -0,0 +1,54 @@ +package io.github.thebusybiscuit.slimefun4.api.events; + +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer; +import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe; +import org.bukkit.block.Block; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * This {@link Event} is fired whenever an {@link AContainer} has completed its process. + * + * @author poma123 + * + */ +public class MachineProcessCompleteEvent extends Event { + + private static final HandlerList handlerList = new HandlerList(); + + private final Block block; + private final MachineRecipe machineRecipe; + + @ParametersAreNonnullByDefault + public MachineProcessCompleteEvent(Block block, MachineRecipe machineRecipe) { + this.block = block; + this.machineRecipe = machineRecipe; + } + + /** This method returns the {@link Block} of the machine. + * + * @return the {@link Block} of the machine + */ + public Block getMachine() { + return block; + } + + /** This returns the used {@link MachineRecipe} in the process. + * + * @return the {@link MachineRecipe} of the process. + */ + public MachineRecipe getMachineRecipe() { + return machineRecipe; + } + + @Override + public HandlerList getHandlers() { + return handlerList; + } + + public static HandlerList getHandlerList() { + return handlerList; + } +} \ No newline at end of file diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java index 2a61919ec..3851ac0d4 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java @@ -5,6 +5,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import io.github.thebusybiscuit.slimefun4.api.events.MachineProcessCompleteEvent; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -254,6 +256,8 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock, inv.pushItem(output.clone(), getOutputSlots()); } + Bukkit.getPluginManager().callEvent(new MachineProcessCompleteEvent(b, getProcessing(b))); + progress.remove(b); processing.remove(b); } From 274c5ada2f6289e2a58838a06b4d78d12116aa3f Mon Sep 17 00:00:00 2001 From: poma123 <25465545+poma123@users.noreply.github.com> Date: Wed, 9 Sep 2020 14:25:47 +0200 Subject: [PATCH 2/6] Minor improvement --- .../Objects/SlimefunItem/abstractItems/AContainer.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java index 3851ac0d4..83f78ee83 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java @@ -243,11 +243,8 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock, } removeCharge(b.getLocation(), getEnergyConsumption()); - progress.put(b, timeleft - 1); - } - else { - progress.put(b, timeleft - 1); } + progress.put(b, timeleft - 1); } else { inv.replaceExistingItem(22, new CustomItem(Material.BLACK_STAINED_GLASS_PANE, " ")); From 25bd60fd0e902aecf7f39fccb954cc59a05abc9a Mon Sep 17 00:00:00 2001 From: poma123 <25465545+poma123@users.noreply.github.com> Date: Wed, 9 Sep 2020 14:26:01 +0200 Subject: [PATCH 3/6] Fixed a typo --- .../slimefun4/api/events/GEOResourceGenerationEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/GEOResourceGenerationEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/GEOResourceGenerationEvent.java index 9bcae84dc..cc659b773 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/GEOResourceGenerationEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/GEOResourceGenerationEvent.java @@ -17,7 +17,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOScanner; /** * This {@link Event} is fired whenever a {@link GEOResource} is being freshly generated. - * This only ocurs when a {@link GEOScanner} queries the {@link Chunk} for a {@link GEOResource} + * This only occurs when a {@link GEOScanner} queries the {@link Chunk} for a {@link GEOResource} * but cannot find it. * * You can modify this {@link Event} by listening to it. From a4eb852b195b04c4eb59cae04ee4a682a26298f3 Mon Sep 17 00:00:00 2001 From: poma123 <25465545+poma123@users.noreply.github.com> Date: Wed, 9 Sep 2020 14:34:01 +0200 Subject: [PATCH 4/6] Added annotations --- .../api/events/MachineProcessCompleteEvent.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java index 97632e2fe..542844574 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java @@ -6,6 +6,7 @@ import org.bukkit.block.Block; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; /** @@ -22,7 +23,7 @@ public class MachineProcessCompleteEvent extends Event { private final MachineRecipe machineRecipe; @ParametersAreNonnullByDefault - public MachineProcessCompleteEvent(Block block, MachineRecipe machineRecipe) { + public MachineProcessCompleteEvent(@Nonnull Block block, @Nonnull MachineRecipe machineRecipe) { this.block = block; this.machineRecipe = machineRecipe; } @@ -31,6 +32,7 @@ public class MachineProcessCompleteEvent extends Event { * * @return the {@link Block} of the machine */ + @Nonnull public Block getMachine() { return block; } @@ -39,16 +41,19 @@ public class MachineProcessCompleteEvent extends Event { * * @return the {@link MachineRecipe} of the process. */ + @Nonnull public MachineRecipe getMachineRecipe() { return machineRecipe; } + @Nonnull + public static HandlerList getHandlerList() { + return handlerList; + } + + @Nonnull @Override public HandlerList getHandlers() { return handlerList; } - - public static HandlerList getHandlerList() { - return handlerList; - } } \ No newline at end of file From 87543ccb83ec85eacbf57e4b0c320b469273c59e Mon Sep 17 00:00:00 2001 From: poma123 <25465545+poma123@users.noreply.github.com> Date: Wed, 9 Sep 2020 14:35:17 +0200 Subject: [PATCH 5/6] Fixed javadocs --- .../slimefun4/api/events/MachineProcessCompleteEvent.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java index 542844574..cfb6cadfc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java @@ -28,7 +28,8 @@ public class MachineProcessCompleteEvent extends Event { this.machineRecipe = machineRecipe; } - /** This method returns the {@link Block} of the machine. + /** + * This method returns the {@link Block} of the machine. * * @return the {@link Block} of the machine */ @@ -37,7 +38,8 @@ public class MachineProcessCompleteEvent extends Event { return block; } - /** This returns the used {@link MachineRecipe} in the process. + /** + * This returns the used {@link MachineRecipe} in the process. * * @return the {@link MachineRecipe} of the process. */ From 8f34365aaac2fb94508a39ae69bc2426a25b36e8 Mon Sep 17 00:00:00 2001 From: poma123 <25465545+poma123@users.noreply.github.com> Date: Wed, 9 Sep 2020 14:51:21 +0200 Subject: [PATCH 6/6] Removed redundant annotations --- .../slimefun4/api/events/MachineProcessCompleteEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java index cfb6cadfc..9e18ff7cf 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/events/MachineProcessCompleteEvent.java @@ -23,7 +23,7 @@ public class MachineProcessCompleteEvent extends Event { private final MachineRecipe machineRecipe; @ParametersAreNonnullByDefault - public MachineProcessCompleteEvent(@Nonnull Block block, @Nonnull MachineRecipe machineRecipe) { + public MachineProcessCompleteEvent(Block block, MachineRecipe machineRecipe) { this.block = block; this.machineRecipe = machineRecipe; }