Take offhand into account with TNT auto-ignite.
It turns out that the Inventory#removeItem(ItemStack) method doesn't actually work for items held in the offhand. This commit changes the behavior so it simply decrements the ItemStack amount for the item held during the block place. Note that going from 1 to 0 will result in an air stack, which will just disappear from the inventory. Fixes #429
This commit is contained in:
@@ -278,7 +278,12 @@ public class ArenaListener
|
||||
// If auto-igniting, set the planter of the primed TNT instead
|
||||
if (autoIgniteTNT) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().getInventory().removeItem(new ItemStack(Material.TNT, 1));
|
||||
ItemStack stack = event.getItemInHand();
|
||||
if (stack == null || stack.getType() != Material.TNT) {
|
||||
plugin.getLogger().warning("Player " + event.getPlayer().getDisplayName() + " just placed TNT without holding a TNT block");
|
||||
return;
|
||||
}
|
||||
stack.setAmount(stack.getAmount() - 1);
|
||||
TNTPrimed tnt = b.getWorld().spawn(b.getRelative(BlockFace.UP).getLocation(), TNTPrimed.class);
|
||||
setPlanter(tnt, event.getPlayer());
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user