mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2852
This commit is contained in:
parent
51b56b1e0b
commit
8c1c67731b
@ -47,6 +47,7 @@
|
|||||||
* Fixed #2839
|
* Fixed #2839
|
||||||
* Fixed #2849
|
* Fixed #2849
|
||||||
* Fixed #2851
|
* Fixed #2851
|
||||||
|
* Fixed #2852
|
||||||
|
|
||||||
## Release Candidate 20 (30 Jan 2021)
|
## Release Candidate 20 (30 Jan 2021)
|
||||||
|
|
||||||
|
@ -13,8 +13,10 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.Nameable;
|
import org.bukkit.Nameable;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Dispenser;
|
import org.bukkit.block.Dispenser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -25,6 +27,7 @@ import io.github.thebusybiscuit.slimefun4.api.events.BlockPlacerPlaceEvent;
|
|||||||
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
|
||||||
import io.github.thebusybiscuit.slimefun4.api.items.settings.MaterialTagSetting;
|
import io.github.thebusybiscuit.slimefun4.api.items.settings.MaterialTagSetting;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
import io.github.thebusybiscuit.slimefun4.core.attributes.NotPlaceable;
|
||||||
|
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockDispenseHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
|
||||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||||
@ -57,7 +60,7 @@ public class BlockPlacer extends SlimefunItem {
|
|||||||
super(category, item, recipeType, recipe);
|
super(category, item, recipeType, recipe);
|
||||||
|
|
||||||
addItemSetting(unplaceableBlocks);
|
addItemSetting(unplaceableBlocks);
|
||||||
addItemHandler(onPlace(), onBlockDispense());
|
addItemHandler(onPlace(), onBlockBreak(), onBlockDispense());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -74,6 +77,32 @@ public class BlockPlacer extends SlimefunItem {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
private BlockBreakHandler onBlockBreak() {
|
||||||
|
/*
|
||||||
|
* Explosions don't need explicit handling here.
|
||||||
|
* The default of "destroy the dispenser and drop the contents" is
|
||||||
|
* fine for our purposes already.
|
||||||
|
*/
|
||||||
|
return new BlockBreakHandler(false, true) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPlayerBreak(BlockBreakEvent e, ItemStack item, List<ItemStack> drops) {
|
||||||
|
// Fixes #2852 - Manually drop inventory contents
|
||||||
|
Block b = e.getBlock();
|
||||||
|
BlockState state = PaperLib.getBlockState(b, false).getState();
|
||||||
|
|
||||||
|
if (state instanceof Dispenser) {
|
||||||
|
for (ItemStack stack : ((Dispenser) state).getInventory()) {
|
||||||
|
if (stack != null && !stack.getType().isAir()) {
|
||||||
|
drops.add(stack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private BlockDispenseHandler onBlockDispense() {
|
private BlockDispenseHandler onBlockDispense() {
|
||||||
return (e, dispenser, facedBlock, machine) -> {
|
return (e, dispenser, facedBlock, machine) -> {
|
||||||
|
Loading…
Reference in New Issue
Block a user