Fixed NPE on PLAYER_INTERACT when player's hand is empty and still in spawn.

This commit is contained in:
taoneill 2012-01-18 17:48:41 -05:00
parent 1eed5ca366
commit 6ff3cbe0c3
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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);
}
}
}
}