From 789b73d3b3fa6e6a8b8f47c286fc866a0cfde8c5 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 10 Jan 2020 16:08:21 -0800 Subject: [PATCH] Fixed bugs with adding entity perm limits. https://github.com/BentoBoxWorld/Limits/issues/47 --- .../bentobox/limits/commands/LimitPanel.java | 5 +- .../limits/listeners/EntityLimitListener.java | 50 ++++++++----------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/main/java/world/bentobox/limits/commands/LimitPanel.java b/src/main/java/world/bentobox/limits/commands/LimitPanel.java index 9b91949..f210db3 100644 --- a/src/main/java/world/bentobox/limits/commands/LimitPanel.java +++ b/src/main/java/world/bentobox/limits/commands/LimitPanel.java @@ -105,7 +105,10 @@ public class LimitPanel { pb.item(pib.build()); } // Entity limits - addon.getSettings().getLimits().forEach((k,v) -> { + Map map = addon.getSettings().getLimits(); + // Merge in any permission-based limits + ibc.getEntityLimits().forEach(map::put); + map.forEach((k,v) -> { PanelItemBuilder pib = new PanelItemBuilder(); pib.name(Util.prettifyText(k.toString())); Material m; diff --git a/src/main/java/world/bentobox/limits/listeners/EntityLimitListener.java b/src/main/java/world/bentobox/limits/listeners/EntityLimitListener.java index d4ae0da..40037b7 100644 --- a/src/main/java/world/bentobox/limits/listeners/EntityLimitListener.java +++ b/src/main/java/world/bentobox/limits/listeners/EntityLimitListener.java @@ -42,32 +42,30 @@ public class EntityLimitListener implements Listener { if (!addon.getPlugin().getIWM().inWorld(e.getVehicle().getWorld())) { return; } - if (addon.getSettings().getLimits().containsKey(e.getVehicle().getType())) { - // If someone in that area has the bypass permission, allow the spawning - for (Entity entity : Objects.requireNonNull(e.getVehicle().getLocation().getWorld()).getNearbyEntities(e.getVehicle().getLocation(), 5, 5, 5)) { - if (entity instanceof Player) { - Player player = (Player)entity; - boolean bypass = (player.isOp() || player.hasPermission(addon.getPlugin().getIWM().getPermissionPrefix(e.getVehicle().getWorld()) + MOD_BYPASS)); - // Check island - addon.getIslands().getProtectedIslandAt(e.getVehicle().getLocation()).ifPresent(island -> { - // Ignore spawn - if (island.isSpawn()) { - return; - } - // Check if the player is at the limit - if (!bypass && atLimit(island, e.getVehicle())) { - e.setCancelled(true); - for (Entity ent : e.getVehicle().getLocation().getWorld().getNearbyEntities(e.getVehicle().getLocation(), 5, 5, 5)) { - if (ent instanceof Player) { - ((Player) ent).updateInventory(); - User.getInstance(ent).sendMessage("entity-limits.hit-limit", "[entity]", - Util.prettifyText(e.getVehicle().getType().toString()) - , TextVariables.NUMBER, String.valueOf(addon.getSettings().getLimits().get(e.getVehicle().getType()))); - } + // If someone in that area has the bypass permission, allow the spawning + for (Entity entity : Objects.requireNonNull(e.getVehicle().getLocation().getWorld()).getNearbyEntities(e.getVehicle().getLocation(), 5, 5, 5)) { + if (entity instanceof Player) { + Player player = (Player)entity; + boolean bypass = (player.isOp() || player.hasPermission(addon.getPlugin().getIWM().getPermissionPrefix(e.getVehicle().getWorld()) + MOD_BYPASS)); + // Check island + addon.getIslands().getProtectedIslandAt(e.getVehicle().getLocation()).ifPresent(island -> { + // Ignore spawn + if (island.isSpawn()) { + return; + } + // Check if the player is at the limit + if (!bypass && atLimit(island, e.getVehicle())) { + e.setCancelled(true); + for (Entity ent : e.getVehicle().getLocation().getWorld().getNearbyEntities(e.getVehicle().getLocation(), 5, 5, 5)) { + if (ent instanceof Player) { + ((Player) ent).updateInventory(); + User.getInstance(ent).sendMessage("entity-limits.hit-limit", "[entity]", + Util.prettifyText(e.getVehicle().getType().toString()) + , TextVariables.NUMBER, String.valueOf(addon.getSettings().getLimits().get(e.getVehicle().getType()))); } } - }); - } + } + }); } } } @@ -78,10 +76,6 @@ public class EntityLimitListener implements Listener { if (!addon.getPlugin().getIWM().inWorld(e.getLocation())) { return; } - if (!addon.getSettings().getLimits().containsKey(e.getEntityType())) { - // Unknown entity limit or unlimited - return; - } boolean bypass = false; // Check why it was spawned switch (e.getSpawnReason()) {