Server admins can now promote or demote any member of any faction to/from faction admin or moderator using the existing /f admin and /f mod commands, which can now also be used from the server console. Two new permissions are added to allow that. A third permission is also added to allow server admins or moderators to join any faction without the need of /f bypass mode.

Also, a couple more minor bugfixes are included for /f home payment giving the wrong message, player/faction descriptions being wrong for console messages, and potential NPE in new faction admin promotion routine if faction was permanent with no current admin.

New permissions:
factions.admin.any - allows use of /f admin on any player in any faction
factions mod.any - allows use of /f mod on any player in any faction
factions.join.any - allows player to join any faction, bypassing invitation process for closed factions (the same as players with /f bypass enabled can do)
This commit is contained in:
Brettflan 2012-01-18 06:01:29 -06:00
parent a44336ff04
commit edcb681210
9 changed files with 84 additions and 25 deletions

View File

@ -30,6 +30,9 @@ permissions:
factions.setpeaceful: true factions.setpeaceful: true
factions.sethome.any: true factions.sethome.any: true
factions.money.*: true factions.money.*: true
factions.join.any: true
factions.admin.any: true
factions.mod.any: true
factions.kit.halfmod: factions.kit.halfmod:
description: Zones, bypassing, kicking, and chatspy description: Zones, bypassing, kicking, and chatspy
children: children:
@ -82,6 +85,8 @@ permissions:
factions.unclaimall: true factions.unclaimall: true
factions.admin: factions.admin:
description: hand over your admin rights description: hand over your admin rights
factions.admin.any:
description: give or revoke admin status for any player in any faction
factions.autoclaim: factions.autoclaim:
description: auto-claim land as you walk around description: auto-claim land as you walk around
factions.bypass: factions.bypass:
@ -103,7 +108,7 @@ permissions:
factions.disband: factions.disband:
description: disband a faction description: disband a faction
factions.disband.any: factions.disband.any:
description: disband an other faction description: disband another faction
factions.help: factions.help:
description: display a help page description: display a help page
factions.home: factions.home:
@ -112,6 +117,8 @@ permissions:
description: invite a player to your faction description: invite a player to your faction
factions.join: factions.join:
description: join a faction description: join a faction
factions.join.any:
description: join any faction, bypassing invitation process for closed factions
factions.kick: factions.kick:
description: kick a player from the faction description: kick a player from the faction
factions.kick.any: factions.kick.any:
@ -130,6 +137,8 @@ permissions:
description: show the territory map, and set optional auto update description: show the territory map, and set optional auto update
factions.mod: factions.mod:
description: give or revoke moderator rights description: give or revoke moderator rights
factions.mod.any:
description: give or revoke moderator rights for any player in any faction
factions.money.balance: factions.money.balance:
description: show your factions current money balance description: show your factions current money balance
factions.money.balance.any: factions.money.balance.any:

View File

@ -461,7 +461,8 @@ public class Faction extends Entity implements EconomyParticipator
{ // faction admin is the only member; one-man faction { // faction admin is the only member; one-man faction
if (this.isPermanent()) if (this.isPermanent())
{ {
oldLeader.setRole(Role.NORMAL); if (oldLeader != null)
oldLeader.setRole(Role.NORMAL);
return; return;
} }
@ -478,9 +479,10 @@ public class Faction extends Entity implements EconomyParticipator
} }
else else
{ // promote new faction admin { // promote new faction admin
oldLeader.setRole(Role.NORMAL); if (oldLeader != null)
oldLeader.setRole(Role.NORMAL);
replacements.get(0).setRole(Role.ADMIN); 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()); this.msg("<i>Faction admin <h>%s<i> has been removed. %s<i> has been promoted as the new faction admin.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName());
P.p.log("Faction "+this.getTag()+" ("+this.getId()+") admin was removed. Replacement admin: "+replacements.get(0).getName()); P.p.log("Faction "+this.getTag()+" ("+this.getId()+") admin was removed. Replacement admin: "+replacements.get(0).getName());
} }
} }

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
@ -18,10 +19,10 @@ public class CmdAdmin extends FCommand
this.permission = Permission.ADMIN.node; this.permission = Permission.ADMIN.node;
this.disableOnLock = true; this.disableOnLock = true;
senderMustBePlayer = true; senderMustBePlayer = false;
senderMustBeMember = false; senderMustBeMember = false;
senderMustBeModerator = false; senderMustBeModerator = false;
senderMustBeAdmin = true; senderMustBeAdmin = false;
} }
@Override @Override
@ -30,25 +31,48 @@ public class CmdAdmin extends FCommand
FPlayer fyou = this.argAsBestFPlayerMatch(0); FPlayer fyou = this.argAsBestFPlayerMatch(0);
if (fyou == null) return; if (fyou == null) return;
if (fyou.getFaction() != myFaction) boolean permAny = Permission.ADMIN_ANY.has(sender, false);
Faction targetFaction = fyou.getFaction();
if (targetFaction != myFaction && !permAny)
{ {
msg("%s<i> is not a member in your faction.", fyou.describeTo(fme, true)); msg("%s<i> is not a member in your faction.", fyou.describeTo(fme, true));
return; return;
} }
if (fyou == fme) if (fme != null && fme.getRole() != Role.ADMIN && !permAny)
{
msg("<b>You are not the faction admin.");
return;
}
if (fyou == fme && !permAny)
{ {
msg("<b>The target player musn't be yourself."); msg("<b>The target player musn't be yourself.");
return; return;
} }
fme.setRole(Role.MODERATOR); FPlayer admin = targetFaction.getFPlayerAdmin();
// if target player is currently admin, demote and replace him
if (fyou == admin)
{
targetFaction.promoteNewLeader();
msg("<i>You have demoted %s<i> from the position of faction admin.", fyou.describeTo(fme, true));
fyou.msg("<i>You have been demoted from the position of faction admin by %s<i>.", senderIsConsole ? "a server admin" : fme.describeTo(fyou, true));
return;
}
// promote target player, and demote existing admin if one exists
if (admin != null)
admin.setRole(Role.MODERATOR);
fyou.setRole(Role.ADMIN); fyou.setRole(Role.ADMIN);
msg("<i>You have promoted %s<i> to the position of faction admin.", fyou.describeTo(fme, true));
// Inform all players // Inform all players
for (FPlayer fplayer : FPlayers.i.getOnline()) for (FPlayer fplayer : FPlayers.i.getOnline())
{ {
fplayer.msg("%s<i> gave %s<i> the leadership of %s", fme.describeTo(fplayer, true), fyou.describeTo(fplayer), myFaction.describeTo(fplayer)); fplayer.msg("%s<i> gave %s<i> the leadership of %s<i>.", senderIsConsole ? "A server admin" : fme.describeTo(fplayer, true), fyou.describeTo(fplayer), targetFaction.describeTo(fplayer));
} }
} }

View File

@ -124,7 +124,7 @@ public class CmdHome extends FCommand
} }
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
if ( ! payForCommand(Conf.econCostHome, "to change faction home", "for changing faction home")) return; if ( ! payForCommand(Conf.econCostHome, "to teleport to your faction home", "for teleporting to your faction home")) return;
// Create a smoke effect // Create a smoke effect
if (Conf.homesTeleportCommandSmokeEffectEnabled) if (Conf.homesTeleportCommandSmokeEffectEnabled)

View File

@ -54,7 +54,7 @@ public class CmdJoin extends FCommand
return; return;
} }
if( ! (faction.getOpen() || faction.isInvited(fme) || fme.isAdminBypassing())) if( ! (faction.getOpen() || faction.isInvited(fme) || fme.isAdminBypassing() || Permission.JOIN_ANY.has(sender, false)))
{ {
msg("<i>This faction requires invitation."); msg("<i>This faction requires invitation.");
faction.msg("%s<i> tried to join your faction.", fme.describeTo(faction, true)); faction.msg("%s<i> tried to join your faction.", fme.describeTo(faction, true));

View File

@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
@ -18,10 +19,10 @@ public class CmdMod extends FCommand
this.permission = Permission.MOD.node; this.permission = Permission.MOD.node;
this.disableOnLock = true; this.disableOnLock = true;
senderMustBePlayer = true; senderMustBePlayer = false;
senderMustBeMember = false; senderMustBeMember = false;
senderMustBeModerator = false; senderMustBeModerator = false;
senderMustBeAdmin = true; senderMustBeAdmin = false;
} }
@Override @Override
@ -30,29 +31,46 @@ public class CmdMod extends FCommand
FPlayer you = this.argAsBestFPlayerMatch(0); FPlayer you = this.argAsBestFPlayerMatch(0);
if (you == null) return; if (you == null) return;
if (you.getFaction() != myFaction) boolean permAny = Permission.MOD_ANY.has(sender, false);
Faction targetFaction = you.getFaction();
if (targetFaction != myFaction && !permAny)
{ {
msg("%s<b> is not a member in your faction.", you.describeTo(fme, true)); msg("%s<b> is not a member in your faction.", you.describeTo(fme, true));
return; return;
} }
if (you == fme) if (fme != null && fme.getRole() != Role.ADMIN && !permAny)
{
msg("<b>You are not the faction admin.");
return;
}
if (you == fme && !permAny)
{ {
msg("<b>The target player musn't be yourself."); msg("<b>The target player musn't be yourself.");
return; return;
} }
if (you.getRole() == Role.ADMIN)
{
msg("<b>The target player is a faction admin. Demote them first.");
return;
}
if (you.getRole() == Role.MODERATOR) if (you.getRole() == Role.MODERATOR)
{ {
// Revoke // Revoke
you.setRole(Role.NORMAL); you.setRole(Role.NORMAL);
myFaction.msg("%s<i> is no longer moderator in your faction.", you.describeTo(myFaction, true)); targetFaction.msg("%s<i> is no longer moderator in your faction.", you.describeTo(targetFaction, true));
msg("<i>You have removed moderator status from %s<i>.", you.describeTo(fme, true));
} }
else else
{ {
// Give // Give
you.setRole(Role.MODERATOR); you.setRole(Role.MODERATOR);
myFaction.msg("%s<i> was promoted to moderator in your faction.", you.describeTo(myFaction, true)); targetFaction.msg("%s<i> was promoted to moderator in your faction.", you.describeTo(targetFaction, true));
msg("<i>You have promoted %s<i> to moderator.", you.describeTo(fme, true));
} }
} }

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
@ -43,6 +44,8 @@ public class CmdPermanent extends FCommand
faction.setPermanent(true); faction.setPermanent(true);
} }
P.p.log((fme == null ? "A server admin" : fme.getName())+"<i> has "+change+" the faction \"" + faction.getTag() + "\".");
// Inform all players // Inform all players
for (FPlayer fplayer : FPlayers.i.getOnline()) for (FPlayer fplayer : FPlayers.i.getOnline())
{ {

View File

@ -10,6 +10,7 @@ public enum Permission
MANAGE_WAR_ZONE("managewarzone"), MANAGE_WAR_ZONE("managewarzone"),
OWNERSHIP_BYPASS("ownershipbypass"), OWNERSHIP_BYPASS("ownershipbypass"),
ADMIN("admin"), ADMIN("admin"),
ADMIN_ANY("admin.any"),
AUTOCLAIM("autoclaim"), AUTOCLAIM("autoclaim"),
BYPASS("bypass"), BYPASS("bypass"),
CHAT("chat"), CHAT("chat"),
@ -25,6 +26,7 @@ public enum Permission
HOME("home"), HOME("home"),
INVITE("invite"), INVITE("invite"),
JOIN("join"), JOIN("join"),
JOIN_ANY("join.any"),
KICK("kick"), KICK("kick"),
KICK_ANY("kick.any"), KICK_ANY("kick.any"),
LEAVE("leave"), LEAVE("leave"),
@ -32,6 +34,7 @@ public enum Permission
LOCK("lock"), LOCK("lock"),
MAP("map"), MAP("map"),
MOD("mod"), MOD("mod"),
MOD_ANY("mod.any"),
MONEY_BALANCE("money.balance"), MONEY_BALANCE("money.balance"),
MONEY_BALANCE_ANY("money.balance.any"), MONEY_BALANCE_ANY("money.balance.any"),
MONEY_DEPOSIT("money.deposit"), MONEY_DEPOSIT("money.deposit"),

View File

@ -19,7 +19,7 @@ public class RelationUtil
if (thatFaction == null) return "ERROR"; // ERROR if (thatFaction == null) return "ERROR"; // ERROR
Faction myFaction = getFaction(me); Faction myFaction = getFaction(me);
if (myFaction == null) return thatFaction.getTag(); // no relation, but can show basic faction tag // if (myFaction == null) return that.describeTo(null); // no relation, but can show basic name or tag
if (that instanceof Faction) if (that instanceof Faction)
{ {