Skip to content

Commit

Permalink
Use MachineBlockBreakHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Intybyte committed Dec 12, 2024
1 parent 584afa0 commit fb13699
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -122,19 +123,9 @@ public MachineProcessor<FuelOperation> 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);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -89,20 +90,7 @@ public MachineProcessor<FuelOperation> 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) {
Expand Down

0 comments on commit fb13699

Please sign in to comment.