Many F Fly bug fixes:

- Async get nearby entities
- Not respecting admin bypass
- Not respecting permissions for system claims
- Not respecting permissions for relations
- Sending fly disabled message when user is not flying
- Sending double messages when disabling
- Sometimes disabling fly while in creative and spectator game modes
This commit is contained in:
DroppingAnvil 2020-01-17 17:55:37 -06:00 committed by droppinganvil
parent f7619f0685
commit 6544513ca7
7 changed files with 72 additions and 70 deletions

View File

@ -31,6 +31,19 @@ public interface FPlayer extends EconomyParticipator {
boolean hasNotificationsEnabled();
/**
* Determine if a player has enemies nearby based on the enemy check task in CmdFly
* NOTE: THIS VALUE IS ONLY UPDATED WHEN A USER IS USING FLY
* @return enemiesNearby as a boolean
*/
boolean hasEnemiesNearby();
/**
* Set if this FPlayer has an enemy nearby
* @param b enemiesNearby
*/
void setEnemiesNearby(Boolean b);
/**
* Get if a player has setup their Discord before
* @return if the player setup Discord as a boolean

View File

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

View File

@ -9,6 +9,7 @@ import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -34,7 +35,7 @@ public class CmdFly extends FCommand {
this.aliases.addAll(Aliases.fly);
this.optionalArgs.put("on/off", "flip");
this.requirements = new CommandRequirements.Builder(Permission.FLY)
this.requirements = new CommandRequirements.Builder(Permission.FLY_FLY)
.playerOnly()
.memberOnly()
.build();
@ -78,19 +79,15 @@ public class CmdFly extends FCommand {
}
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()) {
if (!player.hasPermission("factions.fly.bypassnearbyenemycheck") && !fPlayer.isAdminBypassing()) {
if (fPlayer.hasEnemiesNearby()) disableFlightSync(fPlayer);
checkEnemiesSync(fPlayer);
continue;
}
FLocation myFloc = new FLocation(player.getLocation());
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);
if (!checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
disableFlightSync(fPlayer);
}
}
@ -100,36 +97,15 @@ public class CmdFly extends FCommand {
}, 20L, 20L);
}
public static boolean checkBypassPerms(FPlayer fme, Player me, Faction toFac) {
public static boolean checkFly(FPlayer fme, Player me, Faction toFac) {
if (Conf.denyFlightIfInNoClaimingWorld && !Conf.worldsNoClaiming.isEmpty() && Conf.worldsNoClaiming.stream().anyMatch(me.getWorld().getName()::equalsIgnoreCase))
return false;
if (toFac != fme.getFaction()) {
if (!me.hasPermission(Permission.FLY_WILD.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.node) && (access != Access.DENY || toFac.isSystemFaction());
}
return true;
if (toFac.getAccess(fme, PermissableAction.FLY) == Access.ALLOW) return true;
if (fme.getFaction().isWilderness()) return false;
if (toFac.isSystemFaction()) return me.hasPermission(Permission.valueOf("FLY_" + ChatColor.stripColor(toFac.getTag()).toUpperCase()).node);
Relation relationTo = toFac.getRelationTo(fme.getFaction());
if (!relationTo.isEnemy() && !relationTo.isMember()) return me.hasPermission(Permission.valueOf("FLY_" + relationTo.name()).node);
return false;
}
@ -145,34 +121,43 @@ public class CmdFly extends FCommand {
flyMap.remove(fme.getPlayer().getName());
}
private static void disableFlightSync(FPlayer fme) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fme.setFFlying(false, false));
flyMap.remove(fme.getName());
}
public boolean isInFlightChecker(Player player) {
return flyMap.containsKey(player.getName());
}
private static void checkEnemiesSync(FPlayer fp) {
Bukkit.getScheduler().runTask(FactionsPlugin.instance, fp::checkIfNearbyEnemies);
}
@Override
public void perform(CommandContext context) {
// Disabled by default.
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) {
context.fPlayer.msg(TL.COMMAND_FLY_DISABLED);
return;
}
if (!context.fPlayer.isAdminBypassing()) {
List<Entity> entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D);
FLocation myfloc = new FLocation(context.player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkBypassPerms(context.fPlayer, context.player, toFac)) return;
List<Entity> entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D);
for (int i = 0; i <= entities.size() - 1; ++i) {
if (entities.get(i) instanceof Player) {
Player eplayer = (Player) entities.get(i);
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
if (efplayer.getRelationTo(context.fPlayer) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
context.msg(TL.COMMAND_FLY_CHECK_ENEMY);
return;
for (int i = 0; i <= entities.size() - 1; ++i) {
if (entities.get(i) instanceof Player) {
Player eplayer = (Player) entities.get(i);
FPlayer efplayer = FPlayers.getInstance().getByPlayer(eplayer);
if (efplayer.getRelationTo(context.fPlayer) == Relation.ENEMY && !efplayer.isStealthEnabled()) {
context.msg(TL.COMMAND_FLY_CHECK_ENEMY);
return;
}
context.fPlayer.setEnemiesNearby(false);
}
}
}
FLocation myfloc = new FLocation(context.player.getLocation());
Faction toFac = Board.getInstance().getFactionAt(myfloc);
if (!checkFly(context.fPlayer, context.player, toFac)) {
context.fPlayer.sendMessage(TL.COMMAND_FLY_NO_ACCESS.format(toFac.getTag()));
return;
}
}
if (context.args.size() == 0) {
toggleFlight(context.fPlayer.isFlying(), context.fPlayer, context);
@ -188,8 +173,6 @@ public class CmdFly extends FCommand {
return;
}
if (fme.canFlyAtLocation()) {
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
fme.setFlying(true);
flyMap.put(fme.getPlayer().getName(), true);
@ -201,9 +184,6 @@ public class CmdFly extends FCommand {
startFlyCheck();
}
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-fly", 0));
} else {
fme.msg(TL.COMMAND_FLY_NO_ACCESS, Board.getInstance().getFactionAt(fme.getLastStoodAt()).getTag());
}
}
@Override

View File

@ -668,7 +668,7 @@ public class FactionsPlayerListener implements Listener {
if (!fPlayer.checkIfNearbyEnemies()) {
FLocation myFloc = new FLocation(player.getLocation());
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
if (!CmdFly.checkBypassPerms(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
if (!CmdFly.checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
fPlayer.setFFlying(false, false);
CmdFly.flyMap.remove(name);
}

View File

@ -44,8 +44,8 @@ public enum Permission {
DISBAND_ANY("disband.any"),
DISCORD("discord"),
DRAIN("drain"),
FLY("fly"),
FLY_WILD("fly.wilderness"),
FLY_FLY("fly"),
FLY_WILDERNESS("fly.wilderness"),
FLY_SAFEZONE("fly.safezone"),
FLY_WARZONE("fly.warzone"),
FLY_ENEMY("fly.enemy"),

View File

@ -10,7 +10,10 @@ import org.bukkit.Bukkit;
public class UtilFly {
/**
* UtilFly is being removed very soon as all of its functionality has been updated and moved to CmdFly
*/
@Deprecated
public static void run() {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
return;
@ -22,7 +25,7 @@ public class UtilFly {
}
}, 0, FactionsPlugin.getInstance().getConfig().getInt("fly-task-interval", 10));
}
@Deprecated
public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
return;
@ -42,7 +45,7 @@ public class UtilFly {
setFallDamage(fp, fly, damage);
}
@Deprecated
public static void checkFly(FPlayer me, Faction factionTo) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
return;

View File

@ -47,6 +47,7 @@ import java.util.*;
*/
public abstract class MemoryFPlayer implements FPlayer {
public boolean enemiesNearby = false;
public boolean inChest = false;
public boolean discordSetup = false;
public String discordUserID = "";
@ -221,6 +222,10 @@ public abstract class MemoryFPlayer implements FPlayer {
return this.notificationsEnabled;
}
public boolean hasEnemiesNearby() {return this.enemiesNearby;}
public void setEnemiesNearby(Boolean b) {this.enemiesNearby = b;}
public boolean discordSetup() {return this.discordSetup;}
public String discordUserID() {return this.discordUserID;}
@ -972,7 +977,7 @@ 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.checkBypassPerms(this, getPlayer(), faction);
if (faction.isSystemFaction()) return CmdFly.checkFly(this, getPlayer(), faction);
Access access = faction.getAccess(this, PermissableAction.FLY);
return access == null || access == Access.UNDEFINED || access == Access.ALLOW;
}
@ -1108,16 +1113,18 @@ public abstract class MemoryFPlayer implements FPlayer {
setFlying(false);
msg(TL.COMMAND_FLY_ENEMY_NEAR);
Bukkit.getServer().getPluginManager().callEvent(new FPlayerStoppedFlying(this));
this.enemiesNearby = true;
return true;
}
}
}
this.enemiesNearby = false;
return false;
}
@Override
public Boolean canflyinWilderness() {
return getPlayer().hasPermission(Permission.FLY_WILD.node);
return getPlayer().hasPermission(Permission.FLY_WILDERNESS.node);
}
@Override