From fb136999fb9445c148060661858d9042043a2d46 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Thu, 12 Dec 2024 15:27:28 +0100 Subject: [PATCH] Use MachineBlockBreakHandler --- .../items/cargo/AbstractFilterNode.java | 13 ++----------- .../items/cargo/ReactorAccessPort.java | 15 ++------------- .../items/electric/machines/FluidPump.java | 14 ++------------ .../accelerators/AbstractGrowthAccelerator.java | 13 ++----------- .../electric/machines/entities/AutoBreeder.java | 13 ++----------- .../machines/entities/ExpCollector.java | 13 ++----------- .../items/electric/reactors/Reactor.java | 15 +++------------ .../implementation/items/geo/GEOMiner.java | 13 +++---------- .../SlimefunItem/abstractItems/AContainer.java | 17 ++--------------- .../SlimefunItem/abstractItems/AGenerator.java | 16 ++-------------- 10 files changed, 22 insertions(+), 120 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractFilterNode.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractFilterNode.java index d3197270bf..2bb2e42ff7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractFilterNode.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractFilterNode.java @@ -4,6 +4,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -52,17 +53,7 @@ public boolean hasItemFilter() { @Nonnull private BlockBreakHandler onBreak() { - return new SimpleBlockBreakHandler() { - - @Override - public void onBlockBreak(@Nonnull Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), SLOTS); - } - } - }; + return new MachineBlockBreakHandler(SLOTS); } @Nonnull diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java index 241c1f00f7..28730a6960 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java @@ -4,6 +4,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -117,19 +118,7 @@ public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportF @Nonnull private BlockBreakHandler onBreak() { - return new SimpleBlockBreakHandler() { - - @Override - public void onBlockBreak(@Nonnull Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getFuelSlots()); - inv.dropItems(b.getLocation(), getCoolantSlots()); - inv.dropItems(b.getLocation(), getOutputSlots()); - } - } - }; + return new MachineBlockBreakHandler(getFuelSlots(), getCoolantSlots(), getOutputSlots()); } private void constructMenu(@Nonnull BlockMenuPreset preset) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java index 729fd2ff51..94492962eb 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java @@ -8,6 +8,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; @@ -70,18 +71,7 @@ public FluidPump(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeT @Nonnull private BlockBreakHandler onBreak() { - return new SimpleBlockBreakHandler() { - - @Override - public void onBlockBreak(Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getInputSlots()); - inv.dropItems(b.getLocation(), getOutputSlots()); - } - } - }; + return new MachineBlockBreakHandler(getOutputSlots(), getOutputSlots()); } private void constructMenu(@Nonnull BlockMenuPreset preset) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java index 7136101287..324df08387 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java @@ -3,6 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.inventory.ItemStack; @@ -39,17 +40,7 @@ protected AbstractGrowthAccelerator(ItemGroup itemGroup, SlimefunItemStack item, @Nonnull private BlockBreakHandler onBreak() { - return new SimpleBlockBreakHandler() { - - @Override - public void onBlockBreak(Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getInputSlots()); - } - } - }; + return new MachineBlockBreakHandler(getInputSlots()); } private void constructMenu(BlockMenuPreset preset) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java index e62fd7951d..98fa4c7835 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java @@ -3,6 +3,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.block.Block; @@ -50,17 +51,7 @@ public AutoBreeder(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recip @Nonnull private ItemHandler onBreak() { - return new SimpleBlockBreakHandler() { - - @Override - public void onBlockBreak(Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getInputSlots()); - } - } - }; + return new MachineBlockBreakHandler(getInputSlots()); } protected void constructMenu(BlockMenuPreset preset) { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java index 4697ec75fd..27435173a6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java @@ -5,6 +5,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -77,17 +78,7 @@ public void onPlayerPlace(@Nonnull BlockPlaceEvent e) { } private @Nonnull ItemHandler onBreak() { - return new SimpleBlockBreakHandler() { - - @Override - public void onBlockBreak(@Nonnull Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getOutputSlots()); - } - } - }; + return new MachineBlockBreakHandler(getOutputSlots()); } @Override 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 47b524616f..7d6b9a94b5 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 @@ -10,6 +10,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -122,19 +123,9 @@ public MachineProcessor getMachineProcessor() { @Nonnull private BlockBreakHandler onBreak() { - return new SimpleBlockBreakHandler() { - + return new MachineBlockBreakHandler(processor, getFuelSlots(), getCoolantSlots(), getOutputSlots()) { @Override - public void onBlockBreak(@Nonnull Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getFuelSlots()); - inv.dropItems(b.getLocation(), getCoolantSlots()); - inv.dropItems(b.getLocation(), getOutputSlots()); - } - - processor.endOperation(b); + public void afterBreak(@Nonnull Block b) { removeHologram(b); } }; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java index d21815533b..a789a424f5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java @@ -7,6 +7,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -197,18 +198,10 @@ public void onPlayerPlace(BlockPlaceEvent e) { @Nonnull private BlockBreakHandler onBlockBreak() { - return new SimpleBlockBreakHandler() { - + return new MachineBlockBreakHandler(OUTPUT_SLOTS) { @Override - public void onBlockBreak(@Nonnull Block b) { + protected void beforeBreak(@Nonnull Block b) { removeHologram(b); - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), OUTPUT_SLOTS); - } - - processor.endOperation(b); } }; } 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 04747b4f84..0dbb76e479 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 @@ -8,6 +8,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; @@ -67,21 +68,7 @@ protected AContainer(ItemGroup itemGroup, SlimefunItemStack item, RecipeType rec @Nonnull protected BlockBreakHandler onBlockBreak() { - return new SimpleBlockBreakHandler() { - - @Override - public void onBlockBreak(Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getInputSlots()); - inv.dropItems(b.getLocation(), getOutputSlots()); - } - - processor.endOperation(b); - } - - }; + return new MachineBlockBreakHandler(processor, getOutputSlots(), getInputSlots()); } @ParametersAreNonnullByDefault diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java index db5555f6c9..8776424373 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java @@ -7,6 +7,7 @@ import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler; import org.apache.commons.lang.Validate; import org.bukkit.Location; import org.bukkit.Material; @@ -89,20 +90,7 @@ public MachineProcessor getMachineProcessor() { @Nonnull protected BlockBreakHandler onBlockBreak() { - return new SimpleBlockBreakHandler() { - - @Override - public void onBlockBreak(Block b) { - BlockMenu inv = BlockStorage.getInventory(b); - - if (inv != null) { - inv.dropItems(b.getLocation(), getInputSlots()); - inv.dropItems(b.getLocation(), getOutputSlots()); - } - - processor.endOperation(b); - } - }; + return new MachineBlockBreakHandler(processor, getInputSlots(), getOutputSlots()); } private void constructMenu(BlockMenuPreset preset) {