Fly improved

This commit is contained in:
DroppingAnvil 2020-04-04 18:41:13 -05:00 committed by droppinganvil
parent 44cac68a15
commit 5cf21d479e
3 changed files with 11 additions and 40 deletions

View File

@ -77,18 +77,18 @@ public class CmdFly extends FCommand {
continue; continue;
} }
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
Faction myFaction = fPlayer.getFaction(); if (fPlayer.isAdminBypassing()) continue;
if (!player.hasPermission("factions.fly.bypassnearbyenemycheck") && !fPlayer.isAdminBypassing()) { if (!player.hasPermission("factions.fly.bypassnearbyenemycheck")) {
if (fPlayer.hasEnemiesNearby()) disableFlightSync(fPlayer);
checkEnemiesSync(fPlayer); checkEnemiesSync(fPlayer);
continue; if (fPlayer.hasEnemiesNearby()) {
disableFlightSync(fPlayer);
continue;
}
} }
FLocation myFloc = new FLocation(player.getLocation()); FLocation myFloc = new FLocation(player.getLocation());
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
if (!checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) { if (!checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
disableFlightSync(fPlayer); disableFlightSync(fPlayer);
} }
}
} }
} }
@ -97,6 +97,7 @@ public class CmdFly extends FCommand {
} }
public static boolean checkFly(FPlayer fme, Player me, Faction toFac) { public static boolean checkFly(FPlayer fme, Player me, Faction toFac) {
System.out.print("Checking user " + me.getName());
if (Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase)) if (Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase))
return false; return false;
if (toFac.getAccess(fme, PermissableAction.FLY) == Access.ALLOW) return true; if (toFac.getAccess(fme, PermissableAction.FLY) == Access.ALLOW) return true;

View File

@ -403,6 +403,8 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false) && !fFlyEnabled) { if (FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false) && !fFlyEnabled) {
this.addSubCommand(this.cmdFly); this.addSubCommand(this.cmdFly);
fFlyEnabled = true; fFlyEnabled = true;
CmdFly.startFlyCheck();
CmdFly.startParticles();
} }
} }

View File

@ -571,13 +571,8 @@ public class FactionsPlayerListener implements Listener {
} }
public void checkCanFly(FPlayer me) { public void checkCanFly(FPlayer me) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight")) return; if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight") || !FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable")) return;
if (me.isFlying() && !me.isVanished() && (!me.canFlyAtLocation() || me.checkIfNearbyEnemies())) { if (me.isFlying()) return;
me.setFFlying(false, false);
me.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(me.getLastStoodAt()).getTag());
return;
}
if (me.isFlying() || !FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable")) return;
me.setFFlying(true, false); me.setFFlying(true, false);
CmdFly.flyMap.put(me.getName(), true); CmdFly.flyMap.put(me.getName(), true);
if (CmdFly.particleTask == null) if (CmdFly.particleTask == null)
@ -656,33 +651,6 @@ public class FactionsPlayerListener implements Listener {
} }
refreshPosition(player, lastLocations.get(player.getUniqueId()), player.getLocation()); refreshPosition(player, lastLocations.get(player.getUniqueId()), player.getLocation());
lastLocations.put(player.getUniqueId(), player.getLocation()); lastLocations.put(player.getUniqueId(), player.getLocation());
if (CmdFly.flyMap.containsKey(player.getName())) {
String name = player.getName();
if (!player.isFlying()
|| player.getGameMode() == GameMode.CREATIVE
|| !FactionsPlugin.instance.mc17 && player.getGameMode() == GameMode.SPECTATOR) {
continue;
}
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
Faction myFaction = fPlayer.getFaction();
if (myFaction.isWilderness()) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fPlayer.setFlying(false));
CmdFly.flyMap.remove(player.getName());
continue;
}
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> {
if (!fPlayer.checkIfNearbyEnemies()) {
FLocation myFloc = new FLocation(player.getLocation());
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
if (!CmdFly.checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
fPlayer.setFFlying(false, false);
CmdFly.flyMap.remove(name);
}
}
}
});
}
} }
} }
}, 5L, 10L); }, 5L, 10L);