Browse Source

Automatically remove inactive party members after 7 days (default)

Inactive meaning, the player has offline for atleast 7 days. This will
prevent the parties.yml file from getting unnecessarily large.
TfT_02 12 years ago
parent
commit
e5e19f77b9

+ 2 - 0
src/main/java/com/gmail/nossr50/config/Config.java

@@ -78,6 +78,8 @@ public class Config extends ConfigLoader {
     public boolean getBlockModsEnabled() { return config.getBoolean("Mods.Block_Mods_Enabled", false); }
 
     /* PARTY SETTINGS */
+    public int getAutoPartyKickInterval() { return config.getInt("Party.AutoKick_Interval", 12); }
+    public int getAutoPartyKickTime() { return config.getInt("Party.Old_Party_Member_Cutoff", 7); }
     public boolean getExpShareEnabled() { return config.getBoolean("Party.Sharing.ExpShare_enabled", true); }
     public double getPartyShareBonusBase() { return config.getDouble("Party.Sharing.ExpShare_bonus_base", 1.1); }
     public double getPartyShareBonusIncrease() { return config.getDouble("Party.Sharing.ExpShare_bonus_increase", 0.05); }

+ 11 - 0
src/main/java/com/gmail/nossr50/mcMMO.java

@@ -59,6 +59,7 @@ import com.gmail.nossr50.skills.repair.RepairManagerFactory;
 import com.gmail.nossr50.skills.repair.Repairable;
 import com.gmail.nossr50.skills.repair.config.RepairConfigManager;
 import com.gmail.nossr50.skills.runnables.BleedTimer;
+import com.gmail.nossr50.skills.runnables.PartyAutoKick;
 import com.gmail.nossr50.skills.runnables.SkillMonitor;
 import com.gmail.nossr50.spout.SpoutConfig;
 import com.gmail.nossr50.spout.SpoutTools;
@@ -204,6 +205,16 @@ public class mcMMO extends JavaPlugin {
             scheduler.scheduleSyncRepeatingTask(this, new UserPurgeTask(), 0, purgeInterval * 60L * 60L * 20L);
         }
 
+        // Automatically remove old members from parties
+        long kickInterval = Config.getInstance().getAutoPartyKickInterval();
+
+        if (kickInterval == 0) {
+            scheduler.scheduleSyncDelayedTask(this, new PartyAutoKick(), 40); // Start 2 seconds after startup.
+        }
+        else if (kickInterval > 0) {
+            scheduler.scheduleSyncRepeatingTask(this, new PartyAutoKick(), 0, kickInterval * 60L * 60L * 20L);
+        }
+
         registerCommands();
 
         if (configInstance.getStatsTrackingEnabled()) {

+ 35 - 0
src/main/java/com/gmail/nossr50/skills/runnables/PartyAutoKick.java

@@ -0,0 +1,35 @@
+package com.gmail.nossr50.skills.runnables;
+
+import java.util.ArrayList;
+
+import com.gmail.nossr50.mcMMO;
+import com.gmail.nossr50.config.Config;
+import com.gmail.nossr50.party.Party;
+import com.gmail.nossr50.party.PartyManager;
+
+public class PartyAutoKick implements Runnable {
+
+    @Override
+    public void run() {
+        updatePartyMembers();
+    }
+
+    private void updatePartyMembers() {
+        long currentTime = System.currentTimeMillis();
+        long kickTime = 24L * 60L * 60L * 1000L * Config.getInstance().getAutoPartyKickTime();
+
+        ArrayList<Party> parties = new ArrayList<Party>(PartyManager.getParties());
+
+        for (Party party : parties) {
+            ArrayList<String> members = new ArrayList<String>(party.getMembers());
+            for (String member : members) {
+                long lastPlayed = mcMMO.p.getServer().getOfflinePlayer(member).getLastPlayed();
+
+                if (currentTime - lastPlayed > kickTime) {
+                    System.out.println("Removing " + member + " from " + party.getName()); // Debug, remove this later
+                    PartyManager.removeFromParty(member, party);
+                }
+            }
+        }
+    }
+}

+ 6 - 0
src/main/resources/config.yml

@@ -60,6 +60,12 @@ Mods:
 #  Settings for Parties
 ###
 Party:
+    #Amount of time (in hours) to wait between automatically kicking old party members
+    #To only run at server start, set to 0
+    #To never kick old users, set to -1
+    AutoKick_Interval: 12
+    #Any user who hasn't connected in this many days will get kicked from their party
+    Old_Party_Member_Cutoff: 7
     Sharing:
         ExpShare_enabled: true
         ExpShare_bonus_base: 1.1