Compare commits

...

6 Commits

Author SHA1 Message Date
DroppingAnvil
90d39a3974 Version change
1.6.9.5-2.2.5-RC -> 1.6.9.5-2.2.6-RC
2020-01-17 18:24:53 -06:00
DroppingAnvil
6544513ca7 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
2020-01-17 17:55:37 -06:00
DroppingAnvil
f7619f0685 Fixed a few issues with CmdAdmin now being Async 2020-01-15 16:01:32 -06:00
droppinganvil
a20c2ec2eb Tiny bug fix. 2020-01-15 15:21:02 -06:00
DroppingAnvil
028734a42c Shutdown JDA on disable. 2020-01-14 12:57:09 -06:00
DroppingAnvil
29b9eadd57 Fix mistype made in Aliases. 2020-01-10 20:41:12 -06:00
12 changed files with 93 additions and 77 deletions

View File

@@ -4,7 +4,7 @@
<groupId>com.massivecraft</groupId> <groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId> <artifactId>Factions</artifactId>
<version>1.6.9.5-2.2.5-RC</version> <version>1.6.9.5-2.2.6-RC</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>SaberFactions</name> <name>SaberFactions</name>

View File

@@ -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

View File

@@ -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();
@@ -437,6 +436,9 @@ public class FactionsPlugin extends MPlugin {
AutoLeaveTask = null; AutoLeaveTask = null;
} }
DiscordListener.saveGuilds(); DiscordListener.saveGuilds();
if (Discord.jda != null) {
Discord.jda.shutdownNow();
}
super.onDisable(); super.onDisable();
try { try {
fLogManager.saveLogs(); fLogManager.saveLogs();

View File

@@ -46,7 +46,7 @@ public class Aliases {
public static ArrayList<String> relation_truce = new ArrayList<>(Collections.singletonList("truce")); public static ArrayList<String> relation_truce = new ArrayList<>(Collections.singletonList("truce"));
public static ArrayList<String> reserve = new ArrayList<>(Collections.singletonList("reserve")); public static ArrayList<String> reserve = new ArrayList<>(Collections.singletonList("reserve"));
public static ArrayList<String> roles_demote = new ArrayList<>(Collections.singletonList("demote")); public static ArrayList<String> roles_demote = new ArrayList<>(Collections.singletonList("demote"));
public static ArrayList<String> roles_promote = new ArrayList<>(Collections.singletonList("ally")); public static ArrayList<String> roles_promote = new ArrayList<>(Collections.singletonList("promote"));
public static ArrayList<String> tnt_tnt = new ArrayList<>(Collections.singletonList("tnt")); public static ArrayList<String> tnt_tnt = new ArrayList<>(Collections.singletonList("tnt"));
public static ArrayList<String> tnt_tntfill = new ArrayList<>(Collections.singletonList("tntfill")); public static ArrayList<String> tnt_tntfill = new ArrayList<>(Collections.singletonList("tntfill"));
public static ArrayList<String> wild = new ArrayList<>(Collections.singletonList("wild")); public static ArrayList<String> wild = new ArrayList<>(Collections.singletonList("wild"));

View File

@@ -70,7 +70,7 @@ public class CmdAdmin extends FCommand {
// if target player is currently admin, demote and replace him // if target player is currently admin, demote and replace him
if (fyou == admin) { if (fyou == admin) {
targetFaction.promoteNewLeader(); promoteNewLeader(targetFaction);
context.msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(context.fPlayer, true)); context.msg(TL.COMMAND_ADMIN_DEMOTES, fyou.describeTo(context.fPlayer, true));
fyou.msg(TL.COMMAND_ADMIN_DEMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fyou, true)); fyou.msg(TL.COMMAND_ADMIN_DEMOTED, context.player == null ? TL.GENERIC_SERVERADMIN.toString() : context.fPlayer.describeTo(fyou, true));
return; return;
@@ -78,9 +78,9 @@ public class CmdAdmin extends FCommand {
// promote target player, and demote existing admin if one exists // promote target player, and demote existing admin if one exists
if (admin != null) { if (admin != null) {
admin.setRole(Role.COLEADER); setRole(admin, Role.COLEADER);
} }
fyou.setRole(Role.LEADER); setRole(fyou, Role.LEADER);
context.msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(context.fPlayer, true)); context.msg(TL.COMMAND_ADMIN_PROMOTES, fyou.describeTo(context.fPlayer, true));
FactionsPlugin.instance.getFlogManager().log(targetFaction, FLogType.RANK_EDIT, context.fPlayer.getName(), fyou.getName(), ChatColor.RED + "Admin"); FactionsPlugin.instance.getFlogManager().log(targetFaction, FLogType.RANK_EDIT, context.fPlayer.getName(), fyou.getName(), ChatColor.RED + "Admin");
@@ -94,6 +94,18 @@ public class CmdAdmin extends FCommand {
}); });
} }
private void setRole(FPlayer fp, Role r) {
FactionsPlugin.getInstance().getServer().getScheduler().runTask(FactionsPlugin.instance, () -> {
fp.setRole(r);
});
}
private void promoteNewLeader(Faction f) {
FactionsPlugin.getInstance().getServer().getScheduler().runTask(FactionsPlugin.instance, () -> {
f.promoteNewLeader();
});
}
public TL getUsageTranslation() { public TL getUsageTranslation() {
return TL.COMMAND_ADMIN_DESCRIPTION; return TL.COMMAND_ADMIN_DESCRIPTION;
} }

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.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

View File

@@ -268,7 +268,6 @@ public class FCmdRoot extends FCommand implements CommandExecutor {
this.addSubCommand(this.cmdPromote); this.addSubCommand(this.cmdPromote);
this.addSubCommand(this.cmdDebug); this.addSubCommand(this.cmdDebug);
this.addSubCommand(this.cmdDemote); this.addSubCommand(this.cmdDemote);
this.addSubCommand(this.cmdDiscord);
this.addSubCommand(this.cmdSetDefaultRole); this.addSubCommand(this.cmdSetDefaultRole);
this.addSubCommand(this.cmdMapHeight); this.addSubCommand(this.cmdMapHeight);
this.addSubCommand(this.cmdClaimAt); this.addSubCommand(this.cmdClaimAt);

View File

@@ -32,7 +32,7 @@ public class FPlayerRoleChangeEvent extends FactionPlayerEvent implements Cancel
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return false; return cancelled;
} }
@Override @Override

View File

@@ -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);
} }

View File

@@ -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"),

View File

@@ -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;

View File

@@ -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