Fixed Spawner Mining Error

This commit is contained in:
Driftay 2020-02-11 22:17:01 -05:00
parent bcc04e6174
commit 0fc3e47289
2 changed files with 28 additions and 13 deletions

View File

@ -162,20 +162,22 @@ public class FactionsBlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
Faction at = Board.getInstance().getFactionAt(new FLocation(event.getBlockPlaced()));
if (!event.canBuild()) return; if (!event.canBuild()) return;
if (event.getBlockPlaced().getType() == Material.FIRE) 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)) { if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial()) && Conf.spawnerLock) {
if (isSpawner) {
if (Conf.spawnerLock) {
event.setCancelled(true); event.setCancelled(true);
event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString())); event.getPlayer().sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_SPAWNER_LOCK_CANNOT_PLACE.toString()));
} }
} }
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent event) { public void onBlockFromTo(BlockFromToEvent event) {
@ -494,12 +496,24 @@ public class FactionsBlockListener implements Listener {
Block block = event.getBlock(); Block block = event.getBlock();
Faction at = Board.getInstance().getFactionAt(new FLocation(block)); Faction at = Board.getInstance().getFactionAt(new FLocation(block));
boolean isSpawner = event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial(); boolean isSpawner = event.getBlock().getType().equals(XMaterial.SPAWNER.parseMaterial());
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), !isSpawner ? "destroy" : "mine spawners", false)) {
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
event.setCancelled(true); event.setCancelled(true);
return; 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()); ItemStack item = new ItemStack(block.getType(), 1, block.getData());
if (at != null && at.isNormal()) { if (at != null && at.isNormal()) {
FPlayer fplayer = FPlayers.getInstance().getByPlayer(event.getPlayer()); FPlayer fplayer = FPlayers.getInstance().getByPlayer(event.getPlayer());

View File

@ -925,16 +925,17 @@ public class FactionsPlayerListener implements Listener {
@EventHandler @EventHandler
public void onLogoutMove(PlayerMoveEvent e) { public void onLogoutMove(PlayerMoveEvent e) {
LogoutHandler handler = LogoutHandler.getByName(e.getPlayer().getName()); 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())) { if (handler.isLogoutActive(e.getPlayer())) {
handler.cancelLogout(e.getPlayer()); handler.cancelLogout(e.getPlayer());
e.getPlayer().sendMessage(String.valueOf(TL.COMMAND_LOGOUT_MOVED)); 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())) { if (CmdWild.waitingTeleport.containsKey(e.getPlayer())) {
CmdWild.waitingTeleport.remove(e.getPlayer()); CmdWild.waitingTeleport.remove(e.getPlayer());
FPlayers.getInstance().getByPlayer(e.getPlayer()).msg(TL.COMMAND_WILD_INTERUPTED); FPlayers.getInstance().getByPlayer(e.getPlayer()).msg(TL.COMMAND_WILD_INTERUPTED);