From 0fc3e472890702a10428b29a681e5c66aff04758 Mon Sep 17 00:00:00 2001 From: Driftay Date: Tue, 11 Feb 2020 22:17:01 -0500 Subject: [PATCH] Fixed Spawner Mining Error --- .../listeners/FactionsBlockListener.java | 30 ++++++++++++++----- .../listeners/FactionsPlayerListener.java | 11 +++---- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index 15b6d8bc..ccf0d509 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -162,18 +162,20 @@ public class FactionsBlockListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { - Faction at = Board.getInstance().getFactionAt(new FLocation(event.getBlockPlaced())); if (!event.canBuild()) return; if (event.getBlockPlaced().getType() == Material.FIRE) return; - + boolean isSpawner = event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial()); if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) { event.setCancelled(true); return; } - if (event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial()) && Conf.spawnerLock) { - event.setCancelled(true); - event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString())); + + if (isSpawner) { + if (Conf.spawnerLock) { + event.setCancelled(true); + event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString())); + } } } @@ -494,12 +496,24 @@ public class FactionsBlockListener implements Listener { Block block = event.getBlock(); Faction at = Board.getInstance().getFactionAt(new FLocation(block)); - boolean isSpawner = event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial(); - if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), !isSpawner ? "destroy" : "mine spawners", false)) { + boolean isSpawner = event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial()); + + if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { event.setCancelled(true); return; } - if (block != null && isSpawner) { + + FPlayer fme = FPlayers.getInstance().getByPlayer(event.getPlayer()); + if (fme == null || !fme.hasFaction()) return; + + if (isSpawner) { + Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER); + if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners"); + } + } + + if (isSpawner && !fme.isAdminBypassing()) { ItemStack item = new ItemStack(block.getType(), 1, block.getData()); if (at != null && at.isNormal()) { FPlayer fplayer = FPlayers.getInstance().getByPlayer(event.getPlayer()); diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index e96a3f21..ae77aaa6 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -925,16 +925,17 @@ public class FactionsPlayerListener implements Listener { @EventHandler public void onLogoutMove(PlayerMoveEvent e) { LogoutHandler handler = LogoutHandler.getByName(e.getPlayer().getName()); + + if (Objects.requireNonNull(e.getTo()).getBlockX() == e.getFrom().getBlockX() && + e.getTo().getBlockY() == e.getFrom().getBlockY() && + e.getTo().getBlockZ() == e.getFrom().getBlockZ()) + return; + if (handler.isLogoutActive(e.getPlayer())) { handler.cancelLogout(e.getPlayer()); e.getPlayer().sendMessage(String.valueOf(TL.COMMAND_LOGOUT_MOVED)); } - if (e.getTo().getBlockX() == e.getFrom().getBlockX() && - e.getTo().getBlockY() == e.getFrom().getBlockY() && - e.getTo().getBlockZ() == e.getFrom().getBlockZ()) - return; - if (CmdWild.waitingTeleport.containsKey(e.getPlayer())) { CmdWild.waitingTeleport.remove(e.getPlayer()); FPlayers.getInstance().getByPlayer(e.getPlayer()).msg(TL.COMMAND_WILD_INTERUPTED);