mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-10 04:31:06 +00:00
Fix NPEs caused by non-existent Shop Items
This commit is contained in:
parent
3f3ddfe66f
commit
8ecea0d938
@ -73,7 +73,10 @@ public class ChestProtectListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
shop.getItem().resetForPlayer(p);
|
if (shop.getItem() != null) {
|
||||||
|
shop.getItem().resetForPlayer(p);
|
||||||
|
}
|
||||||
|
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
e.getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CANNOT_BREAK_SHOP));
|
e.getPlayer().sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.CANNOT_BREAK_SHOP));
|
||||||
}
|
}
|
||||||
|
@ -297,10 +297,14 @@ public class ShopInteractListener implements Listener {
|
|||||||
|
|
||||||
for (Player p : location.getWorld().getPlayers()) {
|
for (Player p : location.getWorld().getPlayers()) {
|
||||||
if (p.getLocation().distanceSquared(location) <= config.maximal_distance) {
|
if (p.getLocation().distanceSquared(location) <= config.maximal_distance) {
|
||||||
shop.getHologram().showPlayer(p);
|
if (shop.getHologram() != null) {
|
||||||
|
shop.getHologram().showPlayer(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (p.getLocation().distanceSquared(location) <= config.maximal_item_distance) {
|
if (p.getLocation().distanceSquared(location) <= config.maximal_item_distance) {
|
||||||
shop.getItem().setVisible(p, true);
|
if (shop.getItem() != null) {
|
||||||
|
shop.getItem().setVisible(p, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,9 @@ public class ShopItemListener implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerLeave(PlayerQuitEvent e) {
|
public void onPlayerLeave(PlayerQuitEvent e) {
|
||||||
for (Shop shop : plugin.getShopUtils().getShops()) {
|
for (Shop shop : plugin.getShopUtils().getShops()) {
|
||||||
shop.getItem().setVisible(e.getPlayer(), false);
|
if (shop.getItem() != null) {
|
||||||
|
shop.getItem().setVisible(e.getPlayer(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +102,10 @@ public class ShopItemListener implements Listener {
|
|||||||
Block below = b.getRelative(BlockFace.DOWN);
|
Block below = b.getRelative(BlockFace.DOWN);
|
||||||
|
|
||||||
if (shopUtils.isShop(below.getLocation())) {
|
if (shopUtils.isShop(below.getLocation())) {
|
||||||
shopUtils.getShop(below.getLocation()).getItem().resetForPlayer(e.getPlayer());
|
Shop shop = shopUtils.getShop(below.getLocation());
|
||||||
|
if (shop.getItem() != null) {
|
||||||
|
shop.getItem().resetForPlayer(e.getPlayer());
|
||||||
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +116,10 @@ public class ShopItemListener implements Listener {
|
|||||||
Block below = blockState.getBlock().getRelative(BlockFace.DOWN);
|
Block below = blockState.getBlock().getRelative(BlockFace.DOWN);
|
||||||
|
|
||||||
if (shopUtils.isShop(below.getLocation())) {
|
if (shopUtils.isShop(below.getLocation())) {
|
||||||
shopUtils.getShop(below.getLocation()).getItem().resetForPlayer(e.getPlayer());
|
Shop shop = shopUtils.getShop(below.getLocation());
|
||||||
|
if (shop.getItem() != null) {
|
||||||
|
shop.getItem().resetForPlayer(e.getPlayer());
|
||||||
|
}
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,7 +150,10 @@ public class ShopItemListener implements Listener {
|
|||||||
if (shopUtils.isShop(belowNewBlock.getLocation())) {
|
if (shopUtils.isShop(belowNewBlock.getLocation())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
shopUtils.getShop(belowNewBlock.getLocation()).getItem().resetForPlayer(p);
|
Shop shop = shopUtils.getShop(belowNewBlock.getLocation());
|
||||||
|
if (shop.getItem() != null) {
|
||||||
|
shop.getItem().resetForPlayer(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,11 +174,17 @@ public class ShopItemListener implements Listener {
|
|||||||
|
|
||||||
if (shopUtils.isShop(clicked.getLocation())) {
|
if (shopUtils.isShop(clicked.getLocation())) {
|
||||||
if (e.getBucket() == Material.LAVA_BUCKET) {
|
if (e.getBucket() == Material.LAVA_BUCKET) {
|
||||||
shopUtils.getShop(clicked.getLocation()).getItem().resetForPlayer(e.getPlayer());
|
Shop shop = shopUtils.getShop(clicked.getLocation());
|
||||||
|
if (shop.getItem() != null) {
|
||||||
|
shop.getItem().resetForPlayer(e.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (shopUtils.isShop(underWater.getLocation())) {
|
} else if (shopUtils.isShop(underWater.getLocation())) {
|
||||||
if (e.getBucket() == Material.LAVA_BUCKET) {
|
if (e.getBucket() == Material.LAVA_BUCKET) {
|
||||||
shopUtils.getShop(underWater.getLocation()).getItem().resetForPlayer(e.getPlayer());
|
Shop shop = shopUtils.getShop(underWater.getLocation());
|
||||||
|
if (shop.getItem() != null) {
|
||||||
|
shop.getItem().resetForPlayer(e.getPlayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user