mirror of
https://github.com/taoneill/war.git
synced 2024-11-23 10:45:52 +01:00
Fixed NPE on PLAYER_INTERACT when player's hand is empty and still in spawn.
This commit is contained in:
parent
1eed5ca366
commit
6ff3cbe0c3
@ -158,7 +158,9 @@ public class WarBlockListener extends BlockListener {
|
||||
private void cancelAndKeepItem(BlockPlaceEvent event) {
|
||||
event.setCancelled(true);
|
||||
ItemStack inHand = event.getItemInHand();
|
||||
event.getPlayer().setItemInHand(new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData()));
|
||||
ItemStack newItemInHand = new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData());
|
||||
newItemInHand.setDurability(inHand.getDurability());
|
||||
event.getPlayer().setItemInHand(newItemInHand);
|
||||
}
|
||||
|
||||
// Do not allow moving of block into or from important zones
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@ -249,7 +250,16 @@ public class WarPlayerListener extends PlayerListener {
|
||||
&& zone.getLoadoutSelections().get(player.getName()).isStillInSpawn()) {
|
||||
event.setUseItemInHand(Result.DENY);
|
||||
War.war.badMsg(player, "Can't use items while still in spawn.");
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack inHand = event.getItem();
|
||||
|
||||
if (inHand != null) {
|
||||
ItemStack newItemInHand = new ItemStack(inHand.getType(), inHand.getAmount(), inHand.getDurability(), inHand.getData().getData());
|
||||
newItemInHand.setDurability(inHand.getDurability());
|
||||
event.getPlayer().setItemInHand(newItemInHand);
|
||||
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user