Reverted Back To Old Fly Mechanics

This commit is contained in:
Driftay 2020-05-05 07:20:06 -04:00
parent 499d41dea0
commit ae7bb670d7
4 changed files with 129 additions and 66 deletions

View File

@ -230,6 +230,10 @@ public class FactionsPlugin extends MPlugin {
else faction.addFPlayer(fPlayer); else faction.addFPlayer(fPlayer);
} }
if (getConfig().getBoolean("enable-faction-flight", true)) {
UtilFly.run();
}
Board.getInstance().load(); Board.getInstance().load();
Board.getInstance().clean(); Board.getInstance().clean();

View File

@ -24,7 +24,7 @@ public class CmdFly extends FCommand {
*/ */
public static ConcurrentHashMap<FPlayer, Boolean> flyMap = new ConcurrentHashMap<>(); public static ConcurrentHashMap<String, Boolean> flyMap = new ConcurrentHashMap<>();
public static BukkitTask particleTask = null; public static BukkitTask particleTask = null;
public static BukkitTask flyTask = null; public static BukkitTask flyTask = null;
public static boolean autoenable = FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable"); public static boolean autoenable = FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable");
@ -43,15 +43,17 @@ public class CmdFly extends FCommand {
} }
public static void startParticles() { public static void startParticles() {
particleTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> { particleTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
for (FPlayer fPlayer : flyMap.keySet()) { for (String name : flyMap.keySet()) {
Player player = fPlayer.getPlayer(); Player player = Bukkit.getPlayer(name);
if (player == null || !player.isOnline() || !fPlayer.isFlying()) continue; if (player == null) continue;
if (!player.isFlying()) continue;
if (!FactionsPlugin.getInstance().mc17) { if (!FactionsPlugin.getInstance().mc17) {
if (player.getGameMode() == GameMode.SPECTATOR) continue; if (player.getGameMode() == GameMode.SPECTATOR) continue;
} }
fPlayer.isVanished();
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
fplayer.isVanished();
} }
if (flyMap.isEmpty()) { if (flyMap.isEmpty()) {
particleTask.cancel(); particleTask.cancel();
@ -64,44 +66,72 @@ public class CmdFly extends FCommand {
flyTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> { flyTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
checkTaskState(); checkTaskState();
if (flyMap.keySet().size() != 0) { if (flyMap.keySet().size() != 0) {
for (FPlayer fPlayer : flyMap.keySet()) { for (String name : flyMap.keySet()) {
Player player = fPlayer.getPlayer(); if (name == null) {
continue;
}
Player player = Bukkit.getPlayer(name);
if (player == null if (player == null
|| !fPlayer.isFlying() || !player.isFlying()
|| player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.CREATIVE
|| !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) { || !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) {
continue; continue;
} }
if (fPlayer.isAdminBypassing()) continue; FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
if (!player.hasPermission("factions.fly.bypassnearbyenemycheck")) { Faction myFaction = fPlayer.getFaction();
if (fPlayer.hasEnemiesNearby()) { if (myFaction.isWilderness()) {
disableFlightSync(fPlayer); fPlayer.setFlying(false);
continue; flyMap.remove(name);
} continue;
checkEnemiesSync(fPlayer); }
if (player.hasPermission("factions.fly.bypassnearbyenemycheck") || fPlayer.checkIfNearbyEnemies()) {
continue;
} }
FLocation myFloc = new FLocation(player.getLocation()); FLocation myFloc = new FLocation(player.getLocation());
if (!checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) { if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
disableFlightSync(fPlayer); if (!checkBypassPerms(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fPlayer.setFFlying(false, false));
flyMap.remove(name);
}
} }
} }
} }
}, 20L, 15L); }, 20L, 20L);
} }
public static boolean checkFly(FPlayer fme, Player me, Faction toFac) {
if ((Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase)) || !me.hasPermission(Permission.FLY_FLY.node)) public static boolean checkBypassPerms(FPlayer fme, Player me, Faction toFac) {
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 (fme.getFaction().isWilderness() || !Conf.useComplexFly) return false; if (toFac != fme.getFaction()) {
if (toFac.isSystemFaction()) if (!me.hasPermission(Permission.FLY_WILDERNESS.node) && toFac.isWilderness() || !me.hasPermission(Permission.FLY_SAFEZONE.node) && toFac.isSafeZone() || !me.hasPermission(Permission.FLY_WARZONE.node) && toFac.isWarZone()) {
return me.hasPermission(toFac.isWilderness() ? Permission.FLY_WILDERNESS.node : toFac.isSafeZone() ? Permission.FLY_SAFEZONE.node : Permission.FLY_WARZONE.node); fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
Relation relationTo = toFac.getRelationTo(fme.getFaction()); return false;
if (!relationTo.isEnemy() && !relationTo.isMember()) }
return me.hasPermission(Permission.valueOf("FLY_" + relationTo.name()).node); Access access = toFac.getAccess(fme, PermissableAction.FLY);
return false; if ((!(me.hasPermission(Permission.FLY_ENEMY.node) || access == Access.ALLOW)) && toFac.getRelationTo(fme.getFaction()) == Relation.ENEMY) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
if (!(me.hasPermission(Permission.FLY_ALLY.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.ALLY) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
if (!(me.hasPermission(Permission.FLY_TRUCE.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.TRUCE) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
if (!(me.hasPermission(Permission.FLY_NEUTRAL.node) || access == Access.ALLOW) && toFac.getRelationTo(fme.getFaction()) == Relation.NEUTRAL && !toFac.isSystemFaction()) {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
return false;
}
return me.hasPermission(Permission.FLY_FLY.node) && (access != Access.DENY || toFac.isSystemFaction());
}
return true;
} }
@ -114,15 +144,9 @@ public class CmdFly extends FCommand {
public static void disableFlight(final FPlayer fme) { public static void disableFlight(final FPlayer fme) {
fme.setFlying(false); fme.setFlying(false);
flyMap.remove(fme.getPlayer().getName());
} }
private static void disableFlightSync(FPlayer fme) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fme.setFFlying(false, false));
}
private static void checkEnemiesSync(FPlayer fp) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, fp::checkIfNearbyEnemies);
}
public boolean isInFlightChecker(FPlayer fPlayer) { public boolean isInFlightChecker(FPlayer fPlayer) {
return flyMap.containsKey(fPlayer); return flyMap.containsKey(fPlayer);
@ -147,7 +171,7 @@ public class CmdFly extends FCommand {
FLocation myfloc = new FLocation(context.player.getLocation()); FLocation myfloc = new FLocation(context.player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc); Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkFly(context.fPlayer, context.player, toFac)) { if (!checkBypassPerms(context.fPlayer, context.player, toFac)) {
context.fPlayer.sendMessage(TL.COMMAND_FLY_NO_ACCESS.format(toFac.getTag())); context.fPlayer.sendMessage(TL.COMMAND_FLY_NO_ACCESS.format(toFac.getTag()));
return; return;
} }
@ -163,20 +187,25 @@ public class CmdFly extends FCommand {
private void toggleFlight(final boolean toggle, final FPlayer fme, CommandContext context) { private void toggleFlight(final boolean toggle, final FPlayer fme, CommandContext context) {
if (toggle) { if (toggle) {
fme.setFlying(false); fme.setFlying(false);
flyMap.remove(fme.getPlayer().getName());
return; return;
} }
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> { if (fme.canFlyAtLocation()) {
fme.setFlying(true); context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
flyMap.put(fme, true); fme.setFlying(true);
if (particleTask == null) { flyMap.put(fme.getPlayer().getName(), true);
startParticles(); if (particleTask == null) {
} startParticles();
}
if (flyTask == null) { if (flyTask == null) {
startFlyCheck(); startFlyCheck();
} }
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0)); }, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
} else {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(fme.getLastStoodAt()).getTag());
}
} }
@Override @Override

View File

@ -575,17 +575,18 @@ public class FactionsPlayerListener implements Listener {
.replace("{leader}", faction.getFPlayerAdmin() + ""); .replace("{leader}", faction.getFPlayerAdmin() + "");
return string; return string;
} }
@Deprecated
public void checkCanFly(FPlayer me) { public void checkCanFly(FPlayer me) {
if (!CmdFly.fly || !CmdFly.autoenable) if (me.isFlying() && (!me.canFlyAtLocation() || me.checkIfNearbyEnemies())) {
me.setFFlying(false, false);
return; return;
if (me.isFlying()) return;
if (me.getPlayer().hasPermission(Permission.FLY_FLY.node)) {
me.setFFlying(true, false);
CmdFly.flyMap.put(me, true);
if (CmdFly.particleTask == null)
CmdFly.startParticles();
} }
if (me.isFlying() || !FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable"))
return;
me.setFFlying(true, false);
CmdFly.flyMap.put(me.getName(), true);
if (CmdFly.particleTask == null)
CmdFly.startParticles();
} }
//inspect //inspect
@ -660,6 +661,32 @@ 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.checkBypassPerms(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
fPlayer.setFFlying(false, false);
CmdFly.flyMap.remove(name);
}
}
}
});
}
} }
} }
}, 5L, 10L); }, 5L, 10L);
@ -724,11 +751,8 @@ public class FactionsPlayerListener implements Listener {
}, 5); }, 5);
} }
} }
if (FCmdRoot.instance.fFlyEnabled && CmdFly.autoenable && CmdFly.checkFly(me, me.getPlayer(), factionTo)) {
me.setFFlying(true, false); checkCanFly(me);
if (CmdFly.particleTask == null)
CmdFly.startParticles();
}
Faction at = Board.getInstance().getFactionAt(new FLocation(me.getPlayer().getLocation())); Faction at = Board.getInstance().getFactionAt(new FLocation(me.getPlayer().getLocation()));
if (me.getAutoClaimFor() != null) { if (me.getAutoClaimFor() != null) {

View File

@ -964,7 +964,7 @@ public abstract class MemoryFPlayer implements FPlayer {
public void setFFlying(boolean fly, boolean damage) { public void setFFlying(boolean fly, boolean damage) {
Player player = getPlayer(); Player player = getPlayer();
assert player != null; if (player == null) return;
player.setAllowFlight(fly); player.setAllowFlight(fly);
player.setFlying(fly); player.setFlying(fly);
@ -973,9 +973,8 @@ public abstract class MemoryFPlayer implements FPlayer {
msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled"); msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled");
if (!fly) { if (!fly) {
sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + "")); sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + ""));
} else {
CmdFly.flyMap.put(this, true);
} }
} else { } else {
msg(TL.COMMAND_FLY_DAMAGE); msg(TL.COMMAND_FLY_DAMAGE);
} }
@ -983,7 +982,7 @@ public abstract class MemoryFPlayer implements FPlayer {
// If leaving fly mode, don't let them take fall damage for x seconds. // If leaving fly mode, don't let them take fall damage for x seconds.
if (!fly) { if (!fly) {
int cooldown = FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3); int cooldown = FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3);
CmdFly.flyMap.remove(this); CmdFly.flyMap.remove(player.getName());
// If the value is 0 or lower, make them take fall damage. // If the value is 0 or lower, make them take fall damage.
// Otherwise, start a timer and have this cancel after a few seconds. // Otherwise, start a timer and have this cancel after a few seconds.
@ -993,6 +992,7 @@ public abstract class MemoryFPlayer implements FPlayer {
Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> setTakeFallDamage(true), 20L * cooldown); Bukkit.getScheduler().runTaskLater(FactionsPlugin.getInstance(), () -> setTakeFallDamage(true), 20L * cooldown);
} }
} }
isFlying = fly; isFlying = fly;
} }
@ -1018,8 +1018,14 @@ public abstract class MemoryFPlayer implements FPlayer {
public boolean canFlyAtLocation(FLocation location) { public boolean canFlyAtLocation(FLocation location) {
Faction faction = Board.getInstance().getFactionAt(location); Faction faction = Board.getInstance().getFactionAt(location);
if ((faction == getFaction() && getRole() == Role.LEADER) || isAdminBypassing) return true; if ((faction == getFaction() && getRole() == Role.LEADER) || isAdminBypassing) {
if (faction.isSystemFaction()) return CmdFly.checkFly(this, getPlayer(), faction); return true;
}
if (faction.isSystemFaction()) {
return CmdFly.checkBypassPerms(this, getPlayer(), faction);
}
Access access = faction.getAccess(this, PermissableAction.FLY); Access access = faction.getAccess(this, PermissableAction.FLY);
return access == null || access == Access.UNDEFINED || access == Access.ALLOW; return access == null || access == Access.UNDEFINED || access == Access.ALLOW;
} }