When a faction admin is kicked from his faction for whatever reason (not logging in for too long, a server admin running the /f kick command on him, the player being banned from server), another player will now be promoted to faction admin in his place. If the faction has at least one moderator, one of them will be chosen. Otherwise, a normal member will be promoted. If the faction admin was the last/only member, the faction will of course be disbanded.

This commit is contained in:
Brettflan 2011-12-18 07:47:15 -06:00
parent e32660c188
commit 281021ce46
5 changed files with 70 additions and 21 deletions

View File

@ -575,6 +575,13 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
public void leave(boolean makePay) public void leave(boolean makePay)
{ {
Faction myFaction = this.getFaction(); Faction myFaction = this.getFaction();
if (myFaction == null)
{
resetFactionData();
return;
}
boolean perm = myFaction.isPermanent(); boolean perm = myFaction.isPermanent();
if (!perm && this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1) if (!perm && this.getRole() == Role.ADMIN && myFaction.getFPlayers().size() > 1)

View File

@ -7,6 +7,7 @@ import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.persist.PlayerEntityCollection; import com.massivecraft.factions.zcore.persist.PlayerEntityCollection;
public class FPlayers extends PlayerEntityCollection<FPlayer> public class FPlayers extends PlayerEntityCollection<FPlayer>
@ -61,6 +62,13 @@ public class FPlayers extends PlayerEntityCollection<FPlayer>
{ {
if (now - fplayer.getLastLoginTime() > toleranceMillis) if (now - fplayer.getLastLoginTime() > toleranceMillis)
{ {
if (Conf.logFactionLeave || Conf.logFactionKick)
P.p.log("Player "+fplayer.getName()+" was auto-removed due to inactivity.");
// if player is faction admin, sort out the faction since he's going away
if (fplayer.getRole() == Role.ADMIN)
fplayer.getFaction().promoteNewLeader();
fplayer.leave(false); fplayer.leave(false);
fplayer.markForDeletion(true); fplayer.markForDeletion(true);
} }

View File

@ -56,7 +56,7 @@ public class Faction extends Entity implements EconomyParticipator
// FIELD: permanent // FIELD: permanent
// "permanent" status can only be set by server admins/moderators/ops, and allows the faction to remain even with 0 members // "permanent" status can only be set by server admins/moderators/ops, and allows the faction to remain even with 0 members
private boolean permanent; private boolean permanent;
public boolean isPermanent() { return permanent; } public boolean isPermanent() { return permanent || !this.isNormal(); }
public void setPermanent(boolean isPermanent) { permanent = isPermanent; } public void setPermanent(boolean isPermanent) { permanent = isPermanent; }
// FIELD: tag // FIELD: tag
@ -432,9 +432,48 @@ public class Faction extends Entity implements EconomyParticipator
lastPlayerLoggedOffTime = System.currentTimeMillis(); lastPlayerLoggedOffTime = System.currentTimeMillis();
} }
} }
// used when current leader is about to be removed from the faction; promotes new leader, or disbands faction if no other members left
public void promoteNewLeader()
{
if (! this.isNormal()) return;
FPlayer oldLeader = this.getFPlayerAdmin();
// get list of moderators, or list of normal members if there are no moderators
ArrayList<FPlayer> replacements = this.getFPlayersWhereRole(Role.MODERATOR);
if (replacements == null || replacements.isEmpty())
replacements = this.getFPlayersWhereRole(Role.NORMAL);
if (replacements == null || replacements.isEmpty())
{ // faction admin is the only member; one-man faction
if (this.isPermanent())
{
oldLeader.setRole(Role.NORMAL);
return;
}
// no members left and faction isn't permanent, so disband it
if (Conf.logFactionDisband)
P.p.log("The faction "+this.getTag()+" ("+this.getId()+") has been disbanded since it has no members left.");
for (FPlayer fplayer : FPlayers.i.getOnline())
{
fplayer.msg("The faction %s<i> was disbanded.", this.getTag(fplayer));
}
this.detach();
}
else
{ // promote new faction admin
oldLeader.setRole(Role.NORMAL);
replacements.get(0).setRole(Role.ADMIN);
this.msg("<i>Faction admin <h>%s<i> has been removed. %s<i> has been promoted as the new faction admin.", oldLeader.getName(), replacements.get(0).getName());
P.p.log("Faction "+this.getTag()+" ("+this.getId()+") admin was removed. Replacement admin: "+replacements.get(0).getName());
}
}
//----------------------------------------------// //----------------------------------------------//
// Messages // Messages
//----------------------------------------------// //----------------------------------------------//

View File

@ -6,6 +6,7 @@ import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdKick extends FCommand public class CmdKick extends FCommand
{ {
@ -75,24 +76,14 @@ public class CmdKick extends FCommand
fme.msg("<i>You kicked %s<i> from the faction %s<i>!", you.describeTo(fme), yourFaction.describeTo(fme)); fme.msg("<i>You kicked %s<i> from the faction %s<i>!", you.describeTo(fme), yourFaction.describeTo(fme));
} }
if (Conf.logFactionKick)
P.p.log((senderIsConsole ? "A console command" : fme.getName())+" kicked "+you.getName()+" from the faction: "+yourFaction.getTag());
if (you.getRole() == Role.ADMIN)
yourFaction.promoteNewLeader();
yourFaction.deinvite(you); yourFaction.deinvite(you);
you.resetFactionData(); you.resetFactionData();
if (Conf.logFactionKick)
P.p.log(fme.getName()+" kicked "+you.getName()+" from the faction: "+yourFaction.getTag());
if (yourFaction.getFPlayers().isEmpty() && !yourFaction.isPermanent())
{
// Remove this faction
for (FPlayer fplayer : FPlayers.i.getOnline())
{
fplayer.msg("The faction %s<i> was disbanded.", yourFaction.getTag(fplayer));
}
yourFaction.detach();
if (Conf.logFactionDisband)
P.p.log("The faction "+yourFaction.getTag()+" ("+yourFaction.getId()+") was disbanded since the last player was kicked by "+(senderIsConsole ? "console command" : fme.getName())+".");
}
} }
} }

View File

@ -33,6 +33,7 @@ import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TextUtil; import com.massivecraft.factions.zcore.util.TextUtil;
import java.util.logging.Level; import java.util.logging.Level;
@ -620,6 +621,9 @@ public class FactionsPlayerListener extends PlayerListener
// if player was banned (not just kicked), get rid of their stored info // if player was banned (not just kicked), get rid of their stored info
if (Conf.removePlayerDataWhenBanned && event.getReason().equals("Banned by admin.")) if (Conf.removePlayerDataWhenBanned && event.getReason().equals("Banned by admin."))
{ {
if (badGuy.getRole() == Role.ADMIN)
badGuy.getFaction().promoteNewLeader();
badGuy.leave(false); badGuy.leave(false);
badGuy.markForDeletion(true); badGuy.markForDeletion(true);
} }