From edcb6812108fa448acdb06a363cfb9c21f95264c Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 18 Jan 2012 06:01:29 -0600 Subject: [PATCH] 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) --- plugin.yml | 11 ++++- src/com/massivecraft/factions/Faction.java | 8 ++-- .../massivecraft/factions/cmd/CmdAdmin.java | 44 ++++++++++++++----- .../massivecraft/factions/cmd/CmdHome.java | 2 +- .../massivecraft/factions/cmd/CmdJoin.java | 2 +- src/com/massivecraft/factions/cmd/CmdMod.java | 34 ++++++++++---- .../factions/cmd/CmdPermanent.java | 3 ++ .../factions/struct/Permission.java | 3 ++ .../factions/util/RelationUtil.java | 2 +- 9 files changed, 84 insertions(+), 25 deletions(-) diff --git a/plugin.yml b/plugin.yml index 15cabee4..67a60462 100644 --- a/plugin.yml +++ b/plugin.yml @@ -30,6 +30,9 @@ permissions: factions.setpeaceful: true factions.sethome.any: true factions.money.*: true + factions.join.any: true + factions.admin.any: true + factions.mod.any: true factions.kit.halfmod: description: Zones, bypassing, kicking, and chatspy children: @@ -82,6 +85,8 @@ permissions: factions.unclaimall: true factions.admin: description: hand over your admin rights + factions.admin.any: + description: give or revoke admin status for any player in any faction factions.autoclaim: description: auto-claim land as you walk around factions.bypass: @@ -103,7 +108,7 @@ permissions: factions.disband: description: disband a faction factions.disband.any: - description: disband an other faction + description: disband another faction factions.help: description: display a help page factions.home: @@ -112,6 +117,8 @@ permissions: description: invite a player to your faction factions.join: description: join a faction + factions.join.any: + description: join any faction, bypassing invitation process for closed factions factions.kick: description: kick a player from the faction factions.kick.any: @@ -130,6 +137,8 @@ permissions: description: show the territory map, and set optional auto update factions.mod: description: give or revoke moderator rights + factions.mod.any: + description: give or revoke moderator rights for any player in any faction factions.money.balance: description: show your factions current money balance factions.money.balance.any: diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 8e49da21..204148bc 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -461,7 +461,8 @@ public class Faction extends Entity implements EconomyParticipator { // faction admin is the only member; one-man faction if (this.isPermanent()) { - oldLeader.setRole(Role.NORMAL); + if (oldLeader != null) + oldLeader.setRole(Role.NORMAL); return; } @@ -478,9 +479,10 @@ public class Faction extends Entity implements EconomyParticipator } else { // promote new faction admin - oldLeader.setRole(Role.NORMAL); + if (oldLeader != null) + oldLeader.setRole(Role.NORMAL); replacements.get(0).setRole(Role.ADMIN); - this.msg("Faction admin %s has been removed. %s has been promoted as the new faction admin.", oldLeader.getName(), replacements.get(0).getName()); + this.msg("Faction admin %s has been removed. %s 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()); } } diff --git a/src/com/massivecraft/factions/cmd/CmdAdmin.java b/src/com/massivecraft/factions/cmd/CmdAdmin.java index 2431ef35..69d6bd97 100644 --- a/src/com/massivecraft/factions/cmd/CmdAdmin.java +++ b/src/com/massivecraft/factions/cmd/CmdAdmin.java @@ -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 is not a member in your faction.", fyou.describeTo(fme, true)); return; } - - if (fyou == fme) + + if (fme != null && fme.getRole() != Role.ADMIN && !permAny) + { + msg("You are not the faction admin."); + return; + } + + if (fyou == fme && !permAny) { msg("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("You have demoted %s from the position of faction admin.", fyou.describeTo(fme, true)); + fyou.msg("You have been demoted from the position of faction admin by %s.", 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("You have promoted %s to the position of faction admin.", fyou.describeTo(fme, true)); + // Inform all players for (FPlayer fplayer : FPlayers.i.getOnline()) { - fplayer.msg("%s gave %s the leadership of %s", fme.describeTo(fplayer, true), fyou.describeTo(fplayer), myFaction.describeTo(fplayer)); + fplayer.msg("%s gave %s the leadership of %s.", senderIsConsole ? "A server admin" : fme.describeTo(fplayer, true), fyou.describeTo(fplayer), targetFaction.describeTo(fplayer)); } } diff --git a/src/com/massivecraft/factions/cmd/CmdHome.java b/src/com/massivecraft/factions/cmd/CmdHome.java index 6f6034cf..4ee4909f 100644 --- a/src/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/com/massivecraft/factions/cmd/CmdHome.java @@ -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) diff --git a/src/com/massivecraft/factions/cmd/CmdJoin.java b/src/com/massivecraft/factions/cmd/CmdJoin.java index 8560eb5c..938623ce 100644 --- a/src/com/massivecraft/factions/cmd/CmdJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdJoin.java @@ -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("This faction requires invitation."); faction.msg("%s tried to join your faction.", fme.describeTo(faction, true)); diff --git a/src/com/massivecraft/factions/cmd/CmdMod.java b/src/com/massivecraft/factions/cmd/CmdMod.java index 77d1dba0..48f08c38 100644 --- a/src/com/massivecraft/factions/cmd/CmdMod.java +++ b/src/com/massivecraft/factions/cmd/CmdMod.java @@ -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 is not a member in your faction.", you.describeTo(fme, true)); return; } - - if (you == fme) + + if (fme != null && fme.getRole() != Role.ADMIN && !permAny) + { + msg("You are not the faction admin."); + return; + } + + if (you == fme && !permAny) { msg("The target player musn't be yourself."); return; } + if (you.getRole() == Role.ADMIN) + { + msg("The target player is a faction admin. Demote them first."); + return; + } + if (you.getRole() == Role.MODERATOR) { // Revoke you.setRole(Role.NORMAL); - myFaction.msg("%s is no longer moderator in your faction.", you.describeTo(myFaction, true)); + targetFaction.msg("%s is no longer moderator in your faction.", you.describeTo(targetFaction, true)); + msg("You have removed moderator status from %s.", you.describeTo(fme, true)); } else { // Give you.setRole(Role.MODERATOR); - myFaction.msg("%s was promoted to moderator in your faction.", you.describeTo(myFaction, true)); + targetFaction.msg("%s was promoted to moderator in your faction.", you.describeTo(targetFaction, true)); + msg("You have promoted %s to moderator.", you.describeTo(fme, true)); } } diff --git a/src/com/massivecraft/factions/cmd/CmdPermanent.java b/src/com/massivecraft/factions/cmd/CmdPermanent.java index 3061253d..36c23bc3 100644 --- a/src/com/massivecraft/factions/cmd/CmdPermanent.java +++ b/src/com/massivecraft/factions/cmd/CmdPermanent.java @@ -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())+" has "+change+" the faction \"" + faction.getTag() + "\"."); // Inform all players for (FPlayer fplayer : FPlayers.i.getOnline()) diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index 19da93c7..ea0a3f6c 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -10,6 +10,7 @@ public enum Permission MANAGE_WAR_ZONE("managewarzone"), OWNERSHIP_BYPASS("ownershipbypass"), ADMIN("admin"), + ADMIN_ANY("admin.any"), AUTOCLAIM("autoclaim"), BYPASS("bypass"), CHAT("chat"), @@ -25,6 +26,7 @@ public enum Permission HOME("home"), INVITE("invite"), JOIN("join"), + JOIN_ANY("join.any"), KICK("kick"), KICK_ANY("kick.any"), LEAVE("leave"), @@ -32,6 +34,7 @@ public enum Permission LOCK("lock"), MAP("map"), MOD("mod"), + MOD_ANY("mod.any"), MONEY_BALANCE("money.balance"), MONEY_BALANCE_ANY("money.balance.any"), MONEY_DEPOSIT("money.deposit"), diff --git a/src/com/massivecraft/factions/util/RelationUtil.java b/src/com/massivecraft/factions/util/RelationUtil.java index 721e4b18..05862cf4 100644 --- a/src/com/massivecraft/factions/util/RelationUtil.java +++ b/src/com/massivecraft/factions/util/RelationUtil.java @@ -19,7 +19,7 @@ public class RelationUtil if (thatFaction == null) return "ERROR"; // ERROR 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) {