Fixed NPE when player clicks in air

This commit is contained in:
Eric 2016-08-06 13:32:37 +02:00
parent 417aaa36d3
commit bb54c7da67

View File

@ -62,39 +62,41 @@ public class ShopInteractListener implements Listener {
Player p = e.getPlayer(); Player p = e.getPlayer();
Block b = e.getClickedBlock(); Block b = e.getClickedBlock();
if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) {
if (ClickType.getPlayerClickType(p) != null) { if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) { if (ClickType.getPlayerClickType(p) != null) {
if (!shopUtils.isShop(b.getLocation())) { if (ClickType.getPlayerClickType(p).getClickType() == ClickType.EnumClickType.CREATE) {
if (e.isCancelled() && !perm.has(p, "shopchest.create.protected")) { if (!shopUtils.isShop(b.getLocation())) {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED)); if (e.isCancelled() && !perm.has(p, "shopchest.create.protected")) {
ClickType.removePlayerClickType(p); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NO_PERMISSION_CREATE_PROTECTED));
plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest"); ClickType.removePlayerClickType(p);
return; plugin.debug(p.getName() + " is not allowed to create a shop on the selected chest");
} return;
}
e.setCancelled(true); e.setCancelled(true);
if (b.getRelative(BlockFace.UP).getType() == Material.AIR) { if (b.getRelative(BlockFace.UP).getType() == Material.AIR) {
ClickType clickType = ClickType.getPlayerClickType(p); ClickType clickType = ClickType.getPlayerClickType(p);
ItemStack product = clickType.getProduct(); ItemStack product = clickType.getProduct();
double buyPrice = clickType.getBuyPrice(); double buyPrice = clickType.getBuyPrice();
double sellPrice = clickType.getSellPrice(); double sellPrice = clickType.getSellPrice();
ShopType shopType = clickType.getShopType(); ShopType shopType = clickType.getShopType();
create(p, b.getLocation(), product, buyPrice, sellPrice, shopType); create(p, b.getLocation(), product, buyPrice, sellPrice, shopType);
} else {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED));
plugin.debug("Chest is blocked");
}
} else { } else {
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_BLOCKED)); e.setCancelled(true);
plugin.debug("Chest is blocked"); p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP));
plugin.debug("Chest is already a shop");
} }
} else {
e.setCancelled(true);
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CHEST_ALREADY_SHOP));
plugin.debug("Chest is already a shop");
}
ClickType.removePlayerClickType(p); ClickType.removePlayerClickType(p);
}
} }
} }
} }