mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
correctly handle sensitive blocks above blocks broken with explosive tool
This commit is contained in:
parent
dc22e66589
commit
4398098dec
@ -25,6 +25,7 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import io.github.bakedlibs.dough.protection.Interaction;
|
import io.github.bakedlibs.dough.protection.Interaction;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.api.events.ExplosiveToolBreakBlocksEvent;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockBreakEvent;
|
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockBreakEvent;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockPlaceEvent;
|
import io.github.thebusybiscuit.slimefun4.api.events.SlimefunBlockPlaceEvent;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
|
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
|
||||||
@ -141,7 +142,7 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!e.isCancelled()) {
|
if (!e.isCancelled()) {
|
||||||
checkForSensitiveBlockAbove(e, item);
|
checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock(), item);
|
||||||
|
|
||||||
int fortune = getBonusDropsWithFortune(item, e.getBlock());
|
int fortune = getBonusDropsWithFortune(item, e.getBlock());
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>();
|
||||||
@ -155,6 +156,13 @@ public class BlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onExplosiveToolBlockBreak(ExplosiveToolBreakBlocksEvent e) {
|
||||||
|
for (Block block : e.getAdditionalBlocks()) {
|
||||||
|
checkForSensitiveBlockAbove(e.getPlayer(), block, e.getItemInHand());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
private void callToolHandler(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
|
private void callToolHandler(BlockBreakEvent e, ItemStack item, int fortune, List<ItemStack> drops) {
|
||||||
SlimefunItem tool = SlimefunItem.getByItem(item);
|
SlimefunItem tool = SlimefunItem.getByItem(item);
|
||||||
@ -219,14 +227,16 @@ public class BlockListener implements Listener {
|
|||||||
* Sensitive {@link Block Blocks} are pressure plates or saplings, which should be broken
|
* Sensitive {@link Block Blocks} are pressure plates or saplings, which should be broken
|
||||||
* when the block beneath is broken as well.
|
* when the block beneath is broken as well.
|
||||||
*
|
*
|
||||||
* @param p
|
* @param player
|
||||||
* The {@link Player} who broke this {@link Block}
|
* The {@link Player} who broke this {@link Block}
|
||||||
* @param b
|
* @param block
|
||||||
* The {@link Block} that was broken
|
* The {@link Block} that was broken
|
||||||
|
* @param item
|
||||||
|
* The {@link ItemStack} that was used to break the {@link Block}
|
||||||
*/
|
*/
|
||||||
@ParametersAreNonnullByDefault
|
@ParametersAreNonnullByDefault
|
||||||
private void checkForSensitiveBlockAbove(BlockBreakEvent e, ItemStack item) {
|
private void checkForSensitiveBlockAbove(Player player, Block block, ItemStack item) {
|
||||||
Block blockAbove = e.getBlock().getRelative(BlockFace.UP);
|
Block blockAbove = block.getRelative(BlockFace.UP);
|
||||||
|
|
||||||
if (SlimefunTag.SENSITIVE_MATERIALS.isTagged(blockAbove.getType())) {
|
if (SlimefunTag.SENSITIVE_MATERIALS.isTagged(blockAbove.getType())) {
|
||||||
SlimefunItem sfItem = BlockStorage.check(blockAbove);
|
SlimefunItem sfItem = BlockStorage.check(blockAbove);
|
||||||
@ -236,9 +246,8 @@ public class BlockListener implements Listener {
|
|||||||
* We create a dummy here to pass onto the BlockBreakHandler.
|
* We create a dummy here to pass onto the BlockBreakHandler.
|
||||||
* This will set the correct block context.
|
* This will set the correct block context.
|
||||||
*/
|
*/
|
||||||
BlockBreakEvent dummyEvent = new BlockBreakEvent(blockAbove, e.getPlayer());
|
BlockBreakEvent dummyEvent = new BlockBreakEvent(blockAbove, player);
|
||||||
List<ItemStack> drops = new ArrayList<>();
|
List<ItemStack> drops = new ArrayList<>(sfItem.getDrops(player));
|
||||||
drops.addAll(sfItem.getDrops(e.getPlayer()));
|
|
||||||
|
|
||||||
sfItem.callItemHandler(BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops));
|
sfItem.callItemHandler(BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops));
|
||||||
blockAbove.setType(Material.AIR);
|
blockAbove.setType(Material.AIR);
|
||||||
|
Loading…
Reference in New Issue
Block a user