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

@@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.struct.Permission;
@@ -18,10 +19,10 @@ public class CmdAdmin extends FCommand
this.permission = Permission.ADMIN.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = true;
senderMustBeAdmin = false;
}
@Override
@@ -29,26 +30,49 @@ public class CmdAdmin extends FCommand
{
FPlayer fyou = this.argAsBestFPlayerMatch(0);
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));
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.");
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);
msg("<i>You have promoted %s<i> to the position of faction admin.", fyou.describeTo(fme, true));
// Inform all players
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 ( ! 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
if (Conf.homesTeleportCommandSmokeEffectEnabled)

View File

@@ -54,7 +54,7 @@ public class CmdJoin extends FCommand
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.");
faction.msg("%s<i> tried to join your faction.", fme.describeTo(faction, true));

View File

@@ -1,5 +1,6 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
@@ -18,10 +19,10 @@ public class CmdMod extends FCommand
this.permission = Permission.MOD.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = true;
senderMustBeAdmin = false;
}
@Override
@@ -29,30 +30,47 @@ public class CmdMod extends FCommand
{
FPlayer you = this.argAsBestFPlayerMatch(0);
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));
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.");
return;
}
if (you.getRole() == Role.ADMIN)
{
msg("<b>The target player is a faction admin. Demote them first.");
return;
}
if (you.getRole() == Role.MODERATOR)
{
// Revoke
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
{
// Give
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.Faction;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
@@ -42,6 +43,8 @@ public class CmdPermanent extends FCommand
change = "added permanent status to";
faction.setPermanent(true);
}
P.p.log((fme == null ? "A server admin" : fme.getName())+"<i> has "+change+" the faction \"" + faction.getTag() + "\".");
// Inform all players
for (FPlayer fplayer : FPlayers.i.getOnline())