1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
TheBusyBiscuit 2021-02-24 15:57:21 +01:00
parent af2b60cdf4
commit c4be51f7bb
2 changed files with 22 additions and 8 deletions

View File

@ -44,6 +44,7 @@
* Fixed exceptions with inventories not being printed using the logger of the addon that caused it
* Fixed #2818
* Fixed a duplication glitch with the Woodcutter Android
* Fixed #2839
## Release Candidate 20 (30 Jan 2021)

View File

@ -11,6 +11,16 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
/**
* This {@link Listener} makes sure that an {@link AndroidMineEvent} gets properly propagated
* to the {@link BlockBreakHandler#onAndroidBreak(AndroidMineEvent)} method of a placed block.
* If that block is a {@link SlimefunItem} of course.
*
* @author TheBusyBiscuit
*
* @see BlockBreakHandler
*
*/
public class MiningAndroidListener implements Listener {
public MiningAndroidListener(@Nonnull SlimefunPlugin plugin) {
@ -19,14 +29,17 @@ public class MiningAndroidListener implements Listener {
@EventHandler(ignoreCancelled = true)
public void onAndroidMine(AndroidMineEvent e) {
SlimefunItem item = BlockStorage.check(e.getBlock());
SlimefunItem slimefunItem = BlockStorage.check(e.getBlock());
item.callItemHandler(BlockBreakHandler.class, handler -> {
if (handler.isAndroidAllowed(e.getBlock())) {
handler.onAndroidBreak(e);
} else {
e.setCancelled(true);
}
});
// Fixes #2839 - Can't believe we forgot a null check here
if (slimefunItem != null) {
slimefunItem.callItemHandler(BlockBreakHandler.class, handler -> {
if (handler.isAndroidAllowed(e.getBlock())) {
handler.onAndroidBreak(e);
} else {
e.setCancelled(true);
}
});
}
}
}