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:
parent
f7619f0685
commit
6544513ca7
@ -31,6 +31,19 @@ public interface FPlayer extends EconomyParticipator {
|
|||||||
|
|
||||||
boolean hasNotificationsEnabled();
|
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
|
* Get if a player has setup their Discord before
|
||||||
* @return if the player setup Discord as a boolean
|
* @return if the player setup Discord as a boolean
|
||||||
|
@ -210,7 +210,6 @@ public class FactionsPlugin extends MPlugin {
|
|||||||
if (fPlayer.isAlt()) faction.addAltPlayer(fPlayer);
|
if (fPlayer.isAlt()) faction.addAltPlayer(fPlayer);
|
||||||
else faction.addFPlayer(fPlayer);
|
else faction.addFPlayer(fPlayer);
|
||||||
}
|
}
|
||||||
if (getConfig().getBoolean("enable-faction-flight", true)) UtilFly.run();
|
|
||||||
|
|
||||||
|
|
||||||
Board.getInstance().load();
|
Board.getInstance().load();
|
||||||
|
@ -9,6 +9,7 @@ import com.massivecraft.factions.zcore.fperms.Access;
|
|||||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -34,7 +35,7 @@ public class CmdFly extends FCommand {
|
|||||||
this.aliases.addAll(Aliases.fly);
|
this.aliases.addAll(Aliases.fly);
|
||||||
this.optionalArgs.put("on/off", "flip");
|
this.optionalArgs.put("on/off", "flip");
|
||||||
|
|
||||||
this.requirements = new CommandRequirements.Builder(Permission.FLY)
|
this.requirements = new CommandRequirements.Builder(Permission.FLY_FLY)
|
||||||
.playerOnly()
|
.playerOnly()
|
||||||
.memberOnly()
|
.memberOnly()
|
||||||
.build();
|
.build();
|
||||||
@ -78,19 +79,15 @@ public class CmdFly extends FCommand {
|
|||||||
}
|
}
|
||||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
||||||
Faction myFaction = fPlayer.getFaction();
|
Faction myFaction = fPlayer.getFaction();
|
||||||
if (myFaction.isWilderness()) {
|
if (!player.hasPermission("factions.fly.bypassnearbyenemycheck") && !fPlayer.isAdminBypassing()) {
|
||||||
fPlayer.setFlying(false);
|
if (fPlayer.hasEnemiesNearby()) disableFlightSync(fPlayer);
|
||||||
flyMap.remove(name);
|
checkEnemiesSync(fPlayer);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (player.hasPermission("factions.fly.bypassnearbyenemycheck") || fPlayer.checkIfNearbyEnemies()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
FLocation myFloc = new FLocation(player.getLocation());
|
FLocation myFloc = new FLocation(player.getLocation());
|
||||||
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
|
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
|
||||||
if (!checkBypassPerms(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
|
if (!checkFly(fPlayer, player, Board.getInstance().getFactionAt(myFloc))) {
|
||||||
Bukkit.getScheduler().runTask(FactionsPlugin.instance, () -> fPlayer.setFFlying(false, false));
|
disableFlightSync(fPlayer);
|
||||||
flyMap.remove(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,37 +97,16 @@ public class CmdFly extends FCommand {
|
|||||||
}, 20L, 20L);
|
}, 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))
|
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 != fme.getFaction()) {
|
if (fme.getFaction().isWilderness()) return false;
|
||||||
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()) {
|
if (toFac.isSystemFaction()) return me.hasPermission(Permission.valueOf("FLY_" + ChatColor.stripColor(toFac.getTag()).toUpperCase()).node);
|
||||||
fme.msg(TL.COMMAND_FLY_NO_ACCESS, toFac.getTag(fme));
|
Relation relationTo = toFac.getRelationTo(fme.getFaction());
|
||||||
|
if (!relationTo.isEnemy() && !relationTo.isMember()) return me.hasPermission(Permission.valueOf("FLY_" + relationTo.name()).node);
|
||||||
return false;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void checkTaskState() {
|
public static void checkTaskState() {
|
||||||
@ -145,21 +121,22 @@ public class CmdFly extends FCommand {
|
|||||||
flyMap.remove(fme.getPlayer().getName());
|
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) {
|
public boolean isInFlightChecker(Player player) {
|
||||||
return flyMap.containsKey(player.getName());
|
return flyMap.containsKey(player.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static void checkEnemiesSync(FPlayer fp) {
|
||||||
public void perform(CommandContext context) {
|
Bukkit.getScheduler().runTask(FactionsPlugin.instance, fp::checkIfNearbyEnemies);
|
||||||
// Disabled by default.
|
|
||||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight", false)) {
|
|
||||||
context.fPlayer.msg(TL.COMMAND_FLY_DISABLED);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FLocation myfloc = new FLocation(context.player.getLocation());
|
@Override
|
||||||
Faction toFac = Board.getInstance().getFactionAt(myfloc);
|
public void perform(CommandContext context) {
|
||||||
if (!checkBypassPerms(context.fPlayer, context.player, toFac)) return;
|
if (!context.fPlayer.isAdminBypassing()) {
|
||||||
List<Entity> entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D);
|
List<Entity> entities = context.player.getNearbyEntities(16.0D, 256.0D, 16.0D);
|
||||||
|
|
||||||
for (int i = 0; i <= entities.size() - 1; ++i) {
|
for (int i = 0; i <= entities.size() - 1; ++i) {
|
||||||
@ -170,9 +147,17 @@ public class CmdFly extends FCommand {
|
|||||||
context.msg(TL.COMMAND_FLY_CHECK_ENEMY);
|
context.msg(TL.COMMAND_FLY_CHECK_ENEMY);
|
||||||
return;
|
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) {
|
if (context.args.size() == 0) {
|
||||||
toggleFlight(context.fPlayer.isFlying(), context.fPlayer, context);
|
toggleFlight(context.fPlayer.isFlying(), context.fPlayer, context);
|
||||||
@ -188,8 +173,6 @@ public class CmdFly extends FCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (fme.canFlyAtLocation()) {
|
|
||||||
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
|
context.doWarmUp(WarmUpUtil.Warmup.FLIGHT, TL.WARMUPS_NOTIFY_FLIGHT, "Fly", () -> {
|
||||||
fme.setFlying(true);
|
fme.setFlying(true);
|
||||||
flyMap.put(fme.getPlayer().getName(), true);
|
flyMap.put(fme.getPlayer().getName(), true);
|
||||||
@ -201,9 +184,6 @@ public class CmdFly extends FCommand {
|
|||||||
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
|
||||||
|
@ -668,7 +668,7 @@ public class FactionsPlayerListener implements Listener {
|
|||||||
if (!fPlayer.checkIfNearbyEnemies()) {
|
if (!fPlayer.checkIfNearbyEnemies()) {
|
||||||
FLocation myFloc = new FLocation(player.getLocation());
|
FLocation myFloc = new FLocation(player.getLocation());
|
||||||
if (Board.getInstance().getFactionAt(myFloc) != myFaction) {
|
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);
|
fPlayer.setFFlying(false, false);
|
||||||
CmdFly.flyMap.remove(name);
|
CmdFly.flyMap.remove(name);
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,8 @@ public enum Permission {
|
|||||||
DISBAND_ANY("disband.any"),
|
DISBAND_ANY("disband.any"),
|
||||||
DISCORD("discord"),
|
DISCORD("discord"),
|
||||||
DRAIN("drain"),
|
DRAIN("drain"),
|
||||||
FLY("fly"),
|
FLY_FLY("fly"),
|
||||||
FLY_WILD("fly.wilderness"),
|
FLY_WILDERNESS("fly.wilderness"),
|
||||||
FLY_SAFEZONE("fly.safezone"),
|
FLY_SAFEZONE("fly.safezone"),
|
||||||
FLY_WARZONE("fly.warzone"),
|
FLY_WARZONE("fly.warzone"),
|
||||||
FLY_ENEMY("fly.enemy"),
|
FLY_ENEMY("fly.enemy"),
|
||||||
|
@ -10,7 +10,10 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
|
|
||||||
public class UtilFly {
|
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() {
|
public static void run() {
|
||||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
|
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
|
||||||
return;
|
return;
|
||||||
@ -22,7 +25,7 @@ public class UtilFly {
|
|||||||
}
|
}
|
||||||
}, 0, FactionsPlugin.getInstance().getConfig().getInt("fly-task-interval", 10));
|
}, 0, FactionsPlugin.getInstance().getConfig().getInt("fly-task-interval", 10));
|
||||||
}
|
}
|
||||||
|
@Deprecated
|
||||||
public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) {
|
public static void setFly(FPlayer fp, boolean fly, boolean silent, boolean damage) {
|
||||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
|
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
|
||||||
return;
|
return;
|
||||||
@ -42,7 +45,7 @@ public class UtilFly {
|
|||||||
|
|
||||||
setFallDamage(fp, fly, damage);
|
setFallDamage(fp, fly, damage);
|
||||||
}
|
}
|
||||||
|
@Deprecated
|
||||||
public static void checkFly(FPlayer me, Faction factionTo) {
|
public static void checkFly(FPlayer me, Faction factionTo) {
|
||||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
|
if (!FactionsPlugin.getInstance().getConfig().getBoolean("enable-faction-flight"))
|
||||||
return;
|
return;
|
||||||
|
@ -47,6 +47,7 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class MemoryFPlayer implements FPlayer {
|
public abstract class MemoryFPlayer implements FPlayer {
|
||||||
|
public boolean enemiesNearby = false;
|
||||||
public boolean inChest = false;
|
public boolean inChest = false;
|
||||||
public boolean discordSetup = false;
|
public boolean discordSetup = false;
|
||||||
public String discordUserID = "";
|
public String discordUserID = "";
|
||||||
@ -221,6 +222,10 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
return this.notificationsEnabled;
|
return this.notificationsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasEnemiesNearby() {return this.enemiesNearby;}
|
||||||
|
|
||||||
|
public void setEnemiesNearby(Boolean b) {this.enemiesNearby = b;}
|
||||||
|
|
||||||
public boolean discordSetup() {return this.discordSetup;}
|
public boolean discordSetup() {return this.discordSetup;}
|
||||||
|
|
||||||
public String discordUserID() {return this.discordUserID;}
|
public String discordUserID() {return this.discordUserID;}
|
||||||
@ -972,7 +977,7 @@ 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) 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);
|
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;
|
||||||
}
|
}
|
||||||
@ -1108,16 +1113,18 @@ public abstract class MemoryFPlayer implements FPlayer {
|
|||||||
setFlying(false);
|
setFlying(false);
|
||||||
msg(TL.COMMAND_FLY_ENEMY_NEAR);
|
msg(TL.COMMAND_FLY_ENEMY_NEAR);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new FPlayerStoppedFlying(this));
|
Bukkit.getServer().getPluginManager().callEvent(new FPlayerStoppedFlying(this));
|
||||||
|
this.enemiesNearby = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.enemiesNearby = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean canflyinWilderness() {
|
public Boolean canflyinWilderness() {
|
||||||
return getPlayer().hasPermission(Permission.FLY_WILD.node);
|
return getPlayer().hasPermission(Permission.FLY_WILDERNESS.node);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user