New auto leave on anactivity feature.
This commit is contained in:
parent
27d414ffc4
commit
39a02f0fd4
@ -53,6 +53,8 @@ public class Conf {
|
||||
|
||||
public static boolean allowNoSlashCommand = true;
|
||||
|
||||
public static double autoLeaveFactionAfterDaysOfInactivity = 14;
|
||||
|
||||
static {
|
||||
territoryProtectedMaterials.add(Material.WOODEN_DOOR);
|
||||
territoryProtectedMaterials.add(Material.DISPENSER);
|
||||
|
@ -43,6 +43,7 @@ public class FPlayer {
|
||||
private String title;
|
||||
private double power;
|
||||
private long lastPowerUpdateTime;
|
||||
private long lastLoginTime;
|
||||
private transient boolean mapAutoUpdating;
|
||||
private boolean factionChatting;
|
||||
|
||||
@ -55,6 +56,7 @@ public class FPlayer {
|
||||
this.resetFactionData();
|
||||
this.power = this.getPowerMax();
|
||||
this.lastPowerUpdateTime = System.currentTimeMillis();
|
||||
this.lastLoginTime = System.currentTimeMillis();
|
||||
this.mapAutoUpdating = false;
|
||||
}
|
||||
|
||||
@ -126,6 +128,14 @@ public class FPlayer {
|
||||
this.factionChatting = factionChatting;
|
||||
}
|
||||
|
||||
public long getLastLoginTime() {
|
||||
return lastLoginTime;
|
||||
}
|
||||
|
||||
public void setLastLoginTime(long lastLoginTime) {
|
||||
this.lastLoginTime = lastLoginTime;
|
||||
}
|
||||
|
||||
public boolean isMapAutoUpdating() {
|
||||
return mapAutoUpdating;
|
||||
}
|
||||
@ -354,6 +364,32 @@ public class FPlayer {
|
||||
this.sendMessage(msg);
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Actions
|
||||
// -------------------------------
|
||||
|
||||
public void leave() {
|
||||
Faction myFaction = this.getFaction();
|
||||
|
||||
if (this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1) {
|
||||
sendMessage("You must give the admin role to someone else first.");
|
||||
return;
|
||||
}
|
||||
|
||||
myFaction.sendMessage(this.getNameAndRelevant(myFaction) + Conf.colorSystem + " left your faction.");
|
||||
this.resetFactionData();
|
||||
|
||||
if (myFaction.getFPlayers().size() == 0) {
|
||||
// Remove this faction
|
||||
for (FPlayer fplayer : FPlayer.getAllOnline()) {
|
||||
fplayer.sendMessage("The faction "+myFaction.getTag(fplayer)+Conf.colorSystem+" was disbanded.");
|
||||
}
|
||||
Faction.delete(myFaction.getId());
|
||||
}
|
||||
FPlayer.save();
|
||||
FPlayer.save();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Messages
|
||||
// -------------------------------------------- //
|
||||
@ -478,4 +514,15 @@ public class FPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void autoLeaveOnInactivityRoutine() {
|
||||
long now = System.currentTimeMillis();
|
||||
double toleranceMillis = Conf.autoLeaveFactionAfterDaysOfInactivity * 24 * 60 * 60 * 1000;
|
||||
|
||||
for (FPlayer fplayer : FPlayer.getAll()) {
|
||||
if (now - fplayer.getLastLoginTime() > toleranceMillis) {
|
||||
fplayer.leave();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -77,6 +77,13 @@ public class Factions extends JavaPlugin {
|
||||
|
||||
public Factions() {
|
||||
Factions.instance = this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log("=== INIT START ===");
|
||||
long timeInitStart = System.currentTimeMillis();
|
||||
|
||||
// Add the commands
|
||||
commands.add(new FCommandHelp());
|
||||
@ -102,24 +109,18 @@ public class Factions extends JavaPlugin {
|
||||
commands.add(new FCommandTitle());
|
||||
commands.add(new FCommandUnclaim());
|
||||
commands.add(new FCommandVersion());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
log("=== INIT START ===");
|
||||
long timeInitStart = System.currentTimeMillis();
|
||||
|
||||
setupHelp();
|
||||
setupPermissions();
|
||||
|
||||
// Ensure basefolder exists!
|
||||
this.getDataFolder().mkdirs();
|
||||
|
||||
Conf.load();
|
||||
FPlayer.load();
|
||||
Faction.load();
|
||||
Board.load();
|
||||
|
||||
setupHelp();
|
||||
setupPermissions();
|
||||
|
||||
// Register events
|
||||
PluginManager pm = this.getServer().getPluginManager();
|
||||
pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest, this);
|
||||
|
@ -2,11 +2,6 @@ package com.bukkit.mcteam.factions.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.bukkit.mcteam.factions.Conf;
|
||||
import com.bukkit.mcteam.factions.FPlayer;
|
||||
import com.bukkit.mcteam.factions.Faction;
|
||||
import com.bukkit.mcteam.factions.struct.Role;
|
||||
|
||||
public class FCommandLeave extends FBaseCommand {
|
||||
|
||||
public FCommandLeave() {
|
||||
@ -28,24 +23,7 @@ public class FCommandLeave extends FBaseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
Faction faction = me.getFaction();
|
||||
|
||||
if (me.getRole() == Role.ADMIN && faction.getFPlayers().size() > 1) {
|
||||
sendMessage("You must give the admin role to someone else first.");
|
||||
return;
|
||||
}
|
||||
|
||||
faction.sendMessage(me.getNameAndRelevant(faction) + Conf.colorSystem + " left your faction.");
|
||||
me.resetFactionData();
|
||||
FPlayer.save();
|
||||
|
||||
if (faction.getFPlayers().size() == 0) {
|
||||
// Remove this faction
|
||||
for (FPlayer fplayer : FPlayer.getAllOnline()) {
|
||||
fplayer.sendMessage("The faction "+faction.getTag(fplayer)+Conf.colorSystem+" was disbanded.");
|
||||
}
|
||||
Faction.delete(faction.getId());
|
||||
}
|
||||
me.leave();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -91,9 +91,17 @@ public class FactionsPlayerListener extends PlayerListener{
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerEvent event) {
|
||||
// Make sure that all online players do have a fplayer.
|
||||
FPlayer.get(event.getPlayer());
|
||||
FPlayer me = FPlayer.get(event.getPlayer());
|
||||
|
||||
// Update the lastLoginTime for this fplayer
|
||||
me.setLastLoginTime(System.currentTimeMillis());
|
||||
|
||||
// Run the member auto kick routine. Twice to getToTheAdmins...
|
||||
FPlayer.autoLeaveOnInactivityRoutine();
|
||||
FPlayer.autoLeaveOnInactivityRoutine();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerEvent event) {
|
||||
// Save all players on player quit.
|
||||
|
Loading…
Reference in New Issue
Block a user