NPE fix ;D!

This commit is contained in:
Steffion 2013-07-30 20:50:50 +02:00
parent cd68ccf261
commit a8a96b7822

View File

@ -7,6 +7,7 @@ import nl.Steffion.BlockHunt.Managers.PlayerM;
import nl.Steffion.BlockHunt.Managers.PlayerM.PermsC;
import nl.Steffion.BlockHunt.Serializables.LocationSerializable;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -29,47 +30,50 @@ public class PlayerListener implements Listener {
Player player = event.getPlayer();
if (PlayerM.hasPerm(player, PermsC.create, false)) {
ItemStack item = player.getItemInHand();
if (item.getItemMeta().hasDisplayName()) {
ItemMeta im = item.getItemMeta();
if (im.getDisplayName().equals(
MessageM.replaceAll((String) W.config
.get(ConfigC.wandName)))) {
Action action = event.getAction();
if (event.hasBlock()) {
LocationSerializable location = new LocationSerializable(
event.getClickedBlock().getLocation());
if (action.equals(Action.LEFT_CLICK_BLOCK)) {
event.setCancelled(true);
if (W.pos1.get(player) == null
|| !W.pos1.get(player).equals(location)) {
MessageM.sendFMessage(
player,
ConfigC.normal_setPosition,
true,
"number-1",
"pos-%N(%A" + location.getBlockX()
+ "%N, %A"
+ location.getBlockY()
+ "%N, %A"
+ location.getBlockZ() + "%N)");
W.pos1.put(player, location);
}
} else if (action.equals(Action.RIGHT_CLICK_BLOCK)) {
event.setCancelled(true);
if (W.pos2.get(player) == null
|| !W.pos2.get(player).equals(location)) {
MessageM.sendFMessage(
player,
ConfigC.normal_setPosition,
true,
"number-2",
"pos-%N(%A" + location.getBlockX()
+ "%N, %A"
+ location.getBlockY()
+ "%N, %A"
+ location.getBlockZ() + "%N)");
W.pos2.put(player, location);
if (item.getType() != Material.AIR) {
if (item.getItemMeta().hasDisplayName()) {
ItemMeta im = item.getItemMeta();
if (im.getDisplayName().equals(
MessageM.replaceAll((String) W.config
.get(ConfigC.wandName)))) {
Action action = event.getAction();
if (event.hasBlock()) {
LocationSerializable location = new LocationSerializable(
event.getClickedBlock().getLocation());
if (action.equals(Action.LEFT_CLICK_BLOCK)) {
event.setCancelled(true);
if (W.pos1.get(player) == null
|| !W.pos1.get(player).equals(location)) {
MessageM.sendFMessage(
player,
ConfigC.normal_setPosition,
true,
"number-1",
"pos-%N(%A" + location.getBlockX()
+ "%N, %A"
+ location.getBlockY()
+ "%N, %A"
+ location.getBlockZ()
+ "%N)");
W.pos1.put(player, location);
}
} else if (action.equals(Action.RIGHT_CLICK_BLOCK)) {
event.setCancelled(true);
if (W.pos2.get(player) == null
|| !W.pos2.get(player).equals(location)) {
MessageM.sendFMessage(
player,
ConfigC.normal_setPosition,
true,
"number-2",
"pos-%N(%A" + location.getBlockX()
+ "%N, %A"
+ location.getBlockY()
+ "%N, %A"
+ location.getBlockZ()
+ "%N)");
W.pos2.put(player, location);
}
}
}
}