mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-29 22:02:23 +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 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shop.getItem() != null) {
|
||||||
shop.getItem().resetForPlayer(p);
|
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,12 +297,16 @@ 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) {
|
||||||
|
if (shop.getHologram() != null) {
|
||||||
shop.getHologram().showPlayer(p);
|
shop.getHologram().showPlayer(p);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (p.getLocation().distanceSquared(location) <= config.maximal_item_distance) {
|
if (p.getLocation().distanceSquared(location) <= config.maximal_item_distance) {
|
||||||
|
if (shop.getItem() != null) {
|
||||||
shop.getItem().setVisible(p, true);
|
shop.getItem().setVisible(p, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +68,11 @@ 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()) {
|
||||||
|
if (shop.getItem() != null) {
|
||||||
shop.getItem().setVisible(e.getPlayer(), false);
|
shop.getItem().setVisible(e.getPlayer(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateShopItemVisibility(Player p, boolean hideIfAway, boolean reset) {
|
private void updateShopItemVisibility(Player p, boolean hideIfAway, boolean reset) {
|
||||||
updateShopItemVisibility(p, hideIfAway, reset, p.getLocation());
|
updateShopItemVisibility(p, hideIfAway, reset, p.getLocation());
|
||||||
@ -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