Skip to content

Commit fb13699

Browse files
committed
Use MachineBlockBreakHandler
1 parent 584afa0 commit fb13699

File tree

10 files changed

+22
-120
lines changed

10 files changed

+22
-120
lines changed

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/AbstractFilterNode.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import javax.annotation.Nullable;
55
import javax.annotation.ParametersAreNonnullByDefault;
66

7+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
78
import org.bukkit.Location;
89
import org.bukkit.Material;
910
import org.bukkit.block.Block;
@@ -52,17 +53,7 @@ public boolean hasItemFilter() {
5253

5354
@Nonnull
5455
private BlockBreakHandler onBreak() {
55-
return new SimpleBlockBreakHandler() {
56-
57-
@Override
58-
public void onBlockBreak(@Nonnull Block b) {
59-
BlockMenu inv = BlockStorage.getInventory(b);
60-
61-
if (inv != null) {
62-
inv.dropItems(b.getLocation(), SLOTS);
63-
}
64-
}
65-
};
56+
return new MachineBlockBreakHandler(SLOTS);
6657
}
6758

6859
@Nonnull

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/cargo/ReactorAccessPort.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import javax.annotation.Nullable;
55
import javax.annotation.ParametersAreNonnullByDefault;
66

7+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
78
import org.bukkit.Location;
89
import org.bukkit.Material;
910
import org.bukkit.block.Block;
@@ -117,19 +118,7 @@ public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportF
117118

118119
@Nonnull
119120
private BlockBreakHandler onBreak() {
120-
return new SimpleBlockBreakHandler() {
121-
122-
@Override
123-
public void onBlockBreak(@Nonnull Block b) {
124-
BlockMenu inv = BlockStorage.getInventory(b);
125-
126-
if (inv != null) {
127-
inv.dropItems(b.getLocation(), getFuelSlots());
128-
inv.dropItems(b.getLocation(), getCoolantSlots());
129-
inv.dropItems(b.getLocation(), getOutputSlots());
130-
}
131-
}
132-
};
121+
return new MachineBlockBreakHandler(getFuelSlots(), getCoolantSlots(), getOutputSlots());
133122
}
134123

135124
private void constructMenu(@Nonnull BlockMenuPreset preset) {

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FluidPump.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.annotation.ParametersAreNonnullByDefault;
99

1010
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
11+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
1112
import org.bukkit.Material;
1213
import org.bukkit.World;
1314
import org.bukkit.block.Block;
@@ -70,18 +71,7 @@ public FluidPump(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeT
7071

7172
@Nonnull
7273
private BlockBreakHandler onBreak() {
73-
return new SimpleBlockBreakHandler() {
74-
75-
@Override
76-
public void onBlockBreak(Block b) {
77-
BlockMenu inv = BlockStorage.getInventory(b);
78-
79-
if (inv != null) {
80-
inv.dropItems(b.getLocation(), getInputSlots());
81-
inv.dropItems(b.getLocation(), getOutputSlots());
82-
}
83-
}
84-
};
74+
return new MachineBlockBreakHandler(getOutputSlots(), getOutputSlots());
8575
}
8676

8777
private void constructMenu(@Nonnull BlockMenuPreset preset) {

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/accelerators/AbstractGrowthAccelerator.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import javax.annotation.Nonnull;
44
import javax.annotation.ParametersAreNonnullByDefault;
55

6+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
67
import org.bukkit.Material;
78
import org.bukkit.block.Block;
89
import org.bukkit.inventory.ItemStack;
@@ -39,17 +40,7 @@ protected AbstractGrowthAccelerator(ItemGroup itemGroup, SlimefunItemStack item,
3940

4041
@Nonnull
4142
private BlockBreakHandler onBreak() {
42-
return new SimpleBlockBreakHandler() {
43-
44-
@Override
45-
public void onBlockBreak(Block b) {
46-
BlockMenu inv = BlockStorage.getInventory(b);
47-
48-
if (inv != null) {
49-
inv.dropItems(b.getLocation(), getInputSlots());
50-
}
51-
}
52-
};
43+
return new MachineBlockBreakHandler(getInputSlots());
5344
}
5445

5546
private void constructMenu(BlockMenuPreset preset) {

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/AutoBreeder.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import javax.annotation.Nonnull;
44
import javax.annotation.ParametersAreNonnullByDefault;
55

6+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
67
import org.bukkit.Material;
78
import org.bukkit.Particle;
89
import org.bukkit.block.Block;
@@ -50,17 +51,7 @@ public AutoBreeder(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recip
5051

5152
@Nonnull
5253
private ItemHandler onBreak() {
53-
return new SimpleBlockBreakHandler() {
54-
55-
@Override
56-
public void onBlockBreak(Block b) {
57-
BlockMenu inv = BlockStorage.getInventory(b);
58-
59-
if (inv != null) {
60-
inv.dropItems(b.getLocation(), getInputSlots());
61-
}
62-
}
63-
};
54+
return new MachineBlockBreakHandler(getInputSlots());
6455
}
6556

6657
protected void constructMenu(BlockMenuPreset preset) {

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/entities/ExpCollector.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import javax.annotation.Nonnull;
66
import javax.annotation.ParametersAreNonnullByDefault;
77

8+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
89
import org.bukkit.Location;
910
import org.bukkit.Material;
1011
import org.bukkit.block.Block;
@@ -77,17 +78,7 @@ public void onPlayerPlace(@Nonnull BlockPlaceEvent e) {
7778
}
7879

7980
private @Nonnull ItemHandler onBreak() {
80-
return new SimpleBlockBreakHandler() {
81-
82-
@Override
83-
public void onBlockBreak(@Nonnull Block b) {
84-
BlockMenu inv = BlockStorage.getInventory(b);
85-
86-
if (inv != null) {
87-
inv.dropItems(b.getLocation(), getOutputSlots());
88-
}
89-
}
90-
};
81+
return new MachineBlockBreakHandler(getOutputSlots());
9182
}
9283

9384
@Override

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/reactors/Reactor.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javax.annotation.Nullable;
1111
import javax.annotation.ParametersAreNonnullByDefault;
1212

13+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
1314
import org.bukkit.Bukkit;
1415
import org.bukkit.Location;
1516
import org.bukkit.Material;
@@ -122,19 +123,9 @@ public MachineProcessor<FuelOperation> getMachineProcessor() {
122123

123124
@Nonnull
124125
private BlockBreakHandler onBreak() {
125-
return new SimpleBlockBreakHandler() {
126-
126+
return new MachineBlockBreakHandler(processor, getFuelSlots(), getCoolantSlots(), getOutputSlots()) {
127127
@Override
128-
public void onBlockBreak(@Nonnull Block b) {
129-
BlockMenu inv = BlockStorage.getInventory(b);
130-
131-
if (inv != null) {
132-
inv.dropItems(b.getLocation(), getFuelSlots());
133-
inv.dropItems(b.getLocation(), getCoolantSlots());
134-
inv.dropItems(b.getLocation(), getOutputSlots());
135-
}
136-
137-
processor.endOperation(b);
128+
public void afterBreak(@Nonnull Block b) {
138129
removeHologram(b);
139130
}
140131
};

src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.annotation.Nonnull;
88
import javax.annotation.ParametersAreNonnullByDefault;
99

10+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
1011
import org.apache.commons.lang.Validate;
1112
import org.bukkit.ChatColor;
1213
import org.bukkit.Material;
@@ -197,18 +198,10 @@ public void onPlayerPlace(BlockPlaceEvent e) {
197198

198199
@Nonnull
199200
private BlockBreakHandler onBlockBreak() {
200-
return new SimpleBlockBreakHandler() {
201-
201+
return new MachineBlockBreakHandler(OUTPUT_SLOTS) {
202202
@Override
203-
public void onBlockBreak(@Nonnull Block b) {
203+
protected void beforeBreak(@Nonnull Block b) {
204204
removeHologram(b);
205-
BlockMenu inv = BlockStorage.getInventory(b);
206-
207-
if (inv != null) {
208-
inv.dropItems(b.getLocation(), OUTPUT_SLOTS);
209-
}
210-
211-
processor.endOperation(b);
212205
}
213206
};
214207
}

src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import javax.annotation.Nonnull;
99
import javax.annotation.ParametersAreNonnullByDefault;
1010

11+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
1112
import org.apache.commons.lang.Validate;
1213
import org.bukkit.Location;
1314
import org.bukkit.Material;
@@ -67,21 +68,7 @@ protected AContainer(ItemGroup itemGroup, SlimefunItemStack item, RecipeType rec
6768

6869
@Nonnull
6970
protected BlockBreakHandler onBlockBreak() {
70-
return new SimpleBlockBreakHandler() {
71-
72-
@Override
73-
public void onBlockBreak(Block b) {
74-
BlockMenu inv = BlockStorage.getInventory(b);
75-
76-
if (inv != null) {
77-
inv.dropItems(b.getLocation(), getInputSlots());
78-
inv.dropItems(b.getLocation(), getOutputSlots());
79-
}
80-
81-
processor.endOperation(b);
82-
}
83-
84-
};
71+
return new MachineBlockBreakHandler(processor, getOutputSlots(), getInputSlots());
8572
}
8673

8774
@ParametersAreNonnullByDefault

src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.annotation.Nullable;
88
import javax.annotation.ParametersAreNonnullByDefault;
99

10+
import io.github.thebusybiscuit.slimefun4.implementation.handlers.MachineBlockBreakHandler;
1011
import org.apache.commons.lang.Validate;
1112
import org.bukkit.Location;
1213
import org.bukkit.Material;
@@ -89,20 +90,7 @@ public MachineProcessor<FuelOperation> getMachineProcessor() {
8990

9091
@Nonnull
9192
protected BlockBreakHandler onBlockBreak() {
92-
return new SimpleBlockBreakHandler() {
93-
94-
@Override
95-
public void onBlockBreak(Block b) {
96-
BlockMenu inv = BlockStorage.getInventory(b);
97-
98-
if (inv != null) {
99-
inv.dropItems(b.getLocation(), getInputSlots());
100-
inv.dropItems(b.getLocation(), getOutputSlots());
101-
}
102-
103-
processor.endOperation(b);
104-
}
105-
};
93+
return new MachineBlockBreakHandler(processor, getInputSlots(), getOutputSlots());
10694
}
10795

10896
private void constructMenu(BlockMenuPreset preset) {

0 commit comments

Comments
 (0)