Reverted Back To Old Fly Mechanics
This commit is contained in:
parent
499d41dea0
commit
ae7bb670d7
@ -230,6 +230,10 @@ public class FactionsPlugin extends MPlugin {
|
||||
else faction.addFPlayer(fPlayer);
|
||||
}
|
||||
|
||||
if (getConfig().getBoolean("enable-faction-flight", true)) {
|
||||
UtilFly.run();
|
||||
}
|
||||
|
||||
|
||||
Board.getInstance().load();
|
||||
Board.getInstance().clean();
|
||||
|
@ -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 flyTask = null;
|
||||
public static boolean autoenable = FactionsPlugin.instance.getConfig().getBoolean("ffly.AutoEnable");
|
||||
@ -43,15 +43,17 @@ public class CmdFly extends FCommand {
|
||||
}
|
||||
|
||||
public static void startParticles() {
|
||||
|
||||
particleTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
|
||||
for (FPlayer fPlayer : flyMap.keySet()) {
|
||||
Player player = fPlayer.getPlayer();
|
||||
if (player == null || !player.isOnline() || !fPlayer.isFlying()) continue;
|
||||
for (String name : flyMap.keySet()) {
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player == null) continue;
|
||||
if (!player.isFlying()) continue;
|
||||
if (!FactionsPlugin.getInstance().mc17) {
|
||||
if (player.getGameMode() == GameMode.SPECTATOR) continue;
|
||||
}
|
||||
fPlayer.isVanished();
|
||||
|
||||
FPlayer fplayer = FPlayers.getInstance().getByPlayer(player);
|
||||
fplayer.isVanished();
|
||||
}
|
||||
if (flyMap.isEmpty()) {
|
||||
particleTask.cancel();
|
||||
@ -64,44 +66,72 @@ public class CmdFly extends FCommand {
|
||||
flyTask = Bukkit.getScheduler().runTaskTimerAsynchronously(FactionsPlugin.instance, () -> {
|
||||
checkTaskState();
|
||||
if (flyMap.keySet().size() != 0) {
|
||||
for (FPlayer fPlayer : flyMap.keySet()) {
|
||||
Player player = fPlayer.getPlayer();
|
||||
for (String name : flyMap.keySet()) {
|
||||
if (name == null) {
|
||||
continue;
|
||||
}
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player == null
|
||||
|| !fPlayer.isFlying()
|
||||
|| !player.isFlying()
|
||||
|| player.getGameMode() == GameMode.CREATIVE
|
||||
|| !FactionsPlugin.getInstance().mc17 && player.getGameMode() == GameMode.SPECTATOR) {
|
||||
continue;
|
||||
}
|
||||
if (fPlayer.isAdminBypassing()) continue;
|
||||
if (!player.hasPermission("factions.fly.bypassnearbyenemycheck")) {
|
||||
if (fPlayer.hasEnemiesNearby()) {
|
||||
disableFlightSync(fPlayer);
|
||||
continue;
|
||||
}
|
||||
checkEnemiesSync(fPlayer);
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
||||
Faction myFaction = fPlayer.getFaction();
|
||||
if (myFaction.isWilderness()) {
|
||||
fPlayer.setFlying(false);
|
||||
flyMap.remove(name);
|
||||
continue;
|
||||
}
|
||||
if (player.hasPermission("factions.fly.bypassnearbyenemycheck") || fPlayer.checkIfNearbyEnemies()) {
|
||||
continue;
|
||||
}
|
||||
FLocation myFloc = new FLocation(player.getLocation());
|
||||
if (!checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
|
||||
disableFlightSync(fPlayer);
|
||||
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
|
||||
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;
|
||||
if (toFac.getAccess(fme, PermissableAction.FLY) == Access.ALLOW) return true;
|
||||
if (fme.getFaction().isWilderness() || !Conf.useComplexFly) return false;
|
||||
if (toFac.isSystemFaction())
|
||||
return me.hasPermission(toFac.isWilderness() ? Permission.FLY_WILDERNESS.node : toFac.isSafeZone() ? Permission.FLY_SAFEZONE.node : Permission.FLY_WARZONE.node);
|
||||
Relation relationTo = toFac.getRelationTo(fme.getFaction());
|
||||
if (!relationTo.isEnemy() && !relationTo.isMember())
|
||||
return me.hasPermission(Permission.valueOf("FLY_" + relationTo.name()).node);
|
||||
return false;
|
||||
|
||||
if (toFac != fme.getFaction()) {
|
||||
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()) {
|
||||
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
|
||||
return false;
|
||||
}
|
||||
Access access = toFac.getAccess(fme, PermissableAction.FLY);
|
||||
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) {
|
||||
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) {
|
||||
return flyMap.containsKey(fPlayer);
|
||||
@ -147,7 +171,7 @@ public class CmdFly extends FCommand {
|
||||
|
||||
FLocation myfloc = new FLocation(context.player.getLocation());
|
||||
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()));
|
||||
return;
|
||||
}
|
||||
@ -163,20 +187,25 @@ public class CmdFly extends FCommand {
|
||||
private void toggleFlight(final boolean toggle, final FPlayer fme, CommandContext context) {
|
||||
if (toggle) {
|
||||
fme.setFlying(false);
|
||||
flyMap.remove(fme.getPlayer().getName());
|
||||
return;
|
||||
}
|
||||
|
||||
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
|
||||
fme.setFlying(true);
|
||||
flyMap.put(fme, true);
|
||||
if (particleTask == null) {
|
||||
startParticles();
|
||||
}
|
||||
if (fme.canFlyAtLocation()) {
|
||||
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
|
||||
fme.setFlying(true);
|
||||
flyMap.put(fme.getPlayer().getName(), true);
|
||||
if (particleTask == null) {
|
||||
startParticles();
|
||||
}
|
||||
|
||||
if (flyTask == null) {
|
||||
startFlyCheck();
|
||||
}
|
||||
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
|
||||
if (flyTask == null) {
|
||||
startFlyCheck();
|
||||
}
|
||||
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
|
||||
} else {
|
||||
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(fme.getLastStoodAt()).getTag());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -575,17 +575,18 @@ public class FactionsPlayerListener implements Listener {
|
||||
.replace("{leader}", faction.getFPlayerAdmin() + "");
|
||||
return string;
|
||||
}
|
||||
@Deprecated
|
||||
|
||||
public void checkCanFly(FPlayer me) {
|
||||
if (!CmdFly.fly || !CmdFly.autoenable)
|
||||
if (me.isFlying() && (!me.canFlyAtLocation() || me.checkIfNearbyEnemies())) {
|
||||
me.setFFlying(false, false);
|
||||
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
|
||||
@ -660,6 +661,32 @@ public class FactionsPlayerListener implements Listener {
|
||||
}
|
||||
refreshPosition(player, lastLocations.get(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);
|
||||
@ -724,11 +751,8 @@ public class FactionsPlayerListener implements Listener {
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
if (FCmdRoot.instance.fFlyEnabled && CmdFly.autoenable && CmdFly.checkFly(me, me.getPlayer(), factionTo)) {
|
||||
me.setFFlying(true, false);
|
||||
if (CmdFly.particleTask == null)
|
||||
CmdFly.startParticles();
|
||||
}
|
||||
|
||||
checkCanFly(me);
|
||||
|
||||
Faction at = Board.getInstance().getFactionAt(new FLocation(me.getPlayer().getLocation()));
|
||||
if (me.getAutoClaimFor() != null) {
|
||||
|
@ -964,7 +964,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public void setFFlying(boolean fly, boolean damage) {
|
||||
Player player = getPlayer();
|
||||
assert player != null;
|
||||
if (player == null) return;
|
||||
|
||||
player.setAllowFlight(fly);
|
||||
player.setFlying(fly);
|
||||
@ -973,9 +973,8 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled");
|
||||
if (!fly) {
|
||||
sendMessage(TL.COMMAND_FLY_COOLDOWN.toString().replace("{amount}", FactionsPlugin.getInstance().getConfig().getInt("fly-falldamage-cooldown", 3) + ""));
|
||||
} else {
|
||||
CmdFly.flyMap.put(this, true);
|
||||
}
|
||||
|
||||
} else {
|
||||
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 (!fly) {
|
||||
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.
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
isFlying = fly;
|
||||
}
|
||||
|
||||
@ -1018,8 +1018,14 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
|
||||
public boolean canFlyAtLocation(FLocation location) {
|
||||
Faction faction = Board.getInstance().getFactionAt(location);
|
||||
if ((faction == getFaction() && getRole() == Role.LEADER) || isAdminBypassing) return true;
|
||||
if (faction.isSystemFaction()) return CmdFly.checkFly(this, getPlayer(), faction);
|
||||
if ((faction == getFaction() && getRole() == Role.LEADER) || isAdminBypassing) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (faction.isSystemFaction()) {
|
||||
return CmdFly.checkBypassPerms(this, getPlayer(), faction);
|
||||
}
|
||||
|
||||
Access access = faction.getAccess(this, PermissableAction.FLY);
|
||||
return access == null || access == Access.UNDEFINED || access == Access.ALLOW;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user