From efb5d335f6bd176a8b74c2d3404ffbc8fdbc4b6b Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Sun, 29 May 2016 17:33:46 -0700 Subject: [PATCH] Add ability to bypass auto leave for FPlayers. Implements #659. Permission is factions.bypassautoleave --- src/main/java/com/massivecraft/factions/FPlayer.java | 4 ++++ .../factions/listeners/FactionsPlayerListener.java | 3 +++ .../com/massivecraft/factions/struct/Permission.java | 1 + .../factions/util/AutoLeaveProcessTask.java | 8 ++++++++ .../factions/zcore/persist/MemoryFPlayer.java | 12 +++++++++++- src/main/resources/plugin.yml | 4 +++- 6 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/FPlayer.java b/src/main/java/com/massivecraft/factions/FPlayer.java index 3f2ddf5e..0c974bdf 100644 --- a/src/main/java/com/massivecraft/factions/FPlayer.java +++ b/src/main/java/com/massivecraft/factions/FPlayer.java @@ -37,6 +37,10 @@ public interface FPlayer extends EconomyParticipator { public void setFaction(Faction faction); + public boolean willAutoLeave(); + + public void setAutoLeave(boolean autoLeave); + public void setMonitorJoins(boolean monitor); public boolean isMonitoringJoins(); diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index d73fc85b..d601fd52 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -85,6 +85,9 @@ public class FactionsPlayerListener implements Listener { } } } + + // If they have the permission, don't let them autoleave. Bad inverted setter :\ + me.setAutoLeave(!player.hasPermission(Permission.AUTO_LEAVE_BYPASS.node)); } @EventHandler(priority = EventPriority.NORMAL) diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index 42718746..d090c08c 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -12,6 +12,7 @@ public enum Permission { AHOME("ahome"), ANNOUNCE("announce"), AUTOCLAIM("autoclaim"), + AUTO_LEAVE_BYPASS("autoleavebypass"), BYPASS("bypass"), CHAT("chat"), CHATSPY("chatspy"), diff --git a/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java b/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java index a3868b33..7e62fc8e 100644 --- a/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java +++ b/src/main/java/com/massivecraft/factions/util/AutoLeaveProcessTask.java @@ -6,6 +6,7 @@ import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; import java.util.ListIterator; +import java.util.logging.Level; public class AutoLeaveProcessTask extends BukkitRunnable { @@ -46,6 +47,13 @@ public class AutoLeaveProcessTask extends BukkitRunnable { } FPlayer fplayer = iterator.next(); + + // Check if they should be exempt from this. + if (!fplayer.willAutoLeave()) { + P.p.log(Level.INFO, fplayer.getName() + " was going to be auto-removed but was set not to."); + continue; + } + if (fplayer.isOffline() && now - fplayer.getLastLoginTime() > toleranceMillis) { if (Conf.logFactionLeave || Conf.logFactionKick) { P.p.log("Player " + fplayer.getName() + " was auto-removed due to inactivity."); diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index f76d870d..dea283ee 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -57,6 +57,7 @@ public abstract class MemoryFPlayer implements FPlayer { protected int warmupTask; protected boolean isAdminBypassing = false; protected int kills, deaths; + protected boolean willAutoLeave; protected transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked? protected transient boolean mapAutoUpdating; @@ -124,6 +125,15 @@ public abstract class MemoryFPlayer implements FPlayer { this.powerBoost = powerBoost; } + public boolean willAutoLeave() { + return this.willAutoLeave; + } + + public void setAutoLeave(boolean willLeave) { + this.willAutoLeave = willLeave; + P.p.debug(name + " set autoLeave to " + willLeave); + } + public Faction getAutoClaimFor() { return autoClaimFor; } @@ -790,7 +800,7 @@ public abstract class MemoryFPlayer implements FPlayer { } // Was an over claim - if(currentFaction.isNormal() && currentFaction.hasLandInflation()) { + if (currentFaction.isNormal() && currentFaction.hasLandInflation()) { // Give them money for over claiming. Econ.modifyMoney(payee, Conf.econOverclaimRewardMultiplier, TL.CLAIM_TOOVERCLAIM.toString(), TL.CLAIM_FOROVERCLAIM.toString()); } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6e6b43e2..38854c23 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -262,4 +262,6 @@ permissions: factions.dontlosepoweroffline: description: Don't lose power for being offline. factions.ahome: - description: Ability to send players to their faction home. \ No newline at end of file + description: Ability to send players to their faction home. + factions.autoleavebypass: + description: Bypass autoleave. \ No newline at end of file