From bc40f3b7515a60a534cc25099056deae899b0058 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 18 Jan 2012 06:01:50 -0600 Subject: [PATCH] Server admins can now promote or demote any member of any faction to/from faction leader or officer using the existing /f leader and /f officer commands, with two new permissions 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 leader promotion routine if faction was permanent with no current leader. New permissions: factions.leader.any - allows use of /f leader on any player in any faction factions officer.any - allows use of /f officer 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 | 9 ++++++ src/com/massivecraft/factions/Faction.java | 8 +++-- .../massivecraft/factions/cmd/CmdHome.java | 2 +- .../massivecraft/factions/cmd/CmdJoin.java | 2 +- .../massivecraft/factions/cmd/CmdLeader.java | 16 ++++++++-- .../massivecraft/factions/cmd/CmdOfficer.java | 32 +++++++++++++++---- .../factions/struct/Permission.java | 3 ++ .../factions/util/RelationUtil.java | 2 +- 8 files changed, 58 insertions(+), 16 deletions(-) diff --git a/plugin.yml b/plugin.yml index 987119a8..578238ac 100644 --- a/plugin.yml +++ b/plugin.yml @@ -25,6 +25,9 @@ permissions: children: factions.kit.halfmod: true factions.flag.set: true + factions.join.any: true + factions.leader.any: true + factions.officer.any: true factions.kit.halfmod: description: Can use adminmode and chat spy children: @@ -102,10 +105,14 @@ 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.leader: description: hand over leader rights + factions.leader.any: + description: give or revoke leader status for any player in any faction factions.leave: description: leave your faction factions.list: @@ -139,6 +146,8 @@ permissions: factions.money.withdraw: true factions.officer: description: give or revoke officer rights + factions.officer.any: + description: give or revoke officer rights for any player in any faction factions.open: description: switch if invitation is required to join factions.perm: diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 84c1cb4f..126439ef 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -443,7 +443,8 @@ public class Faction extends Entity implements EconomyParticipator { // faction leader is the only member; one-man faction if (this.getFlag(FFlag.PERMANENT)) { - oldLeader.setRole(Rel.MEMBER); + if (oldLeader != null) + oldLeader.setRole(Rel.MEMBER); return; } @@ -460,9 +461,10 @@ public class Faction extends Entity implements EconomyParticipator } else { // promote new faction leader - oldLeader.setRole(Rel.MEMBER); + if (oldLeader != null) + oldLeader.setRole(Rel.MEMBER); replacements.get(0).setRole(Rel.LEADER); - this.msg("Faction leader %s has been removed. %s has been promoted as the new faction leader.", oldLeader.getName(), replacements.get(0).getName()); + this.msg("Faction leader %s has been removed. %s has been promoted as the new faction leader.", oldLeader == null ? "" : oldLeader.getName(), replacements.get(0).getName()); P.p.log("Faction "+this.getTag()+" ("+this.getId()+") leader was removed. Replacement leader: "+replacements.get(0).getName()); } } diff --git a/src/com/massivecraft/factions/cmd/CmdHome.java b/src/com/massivecraft/factions/cmd/CmdHome.java index ef8c5eab..acd9f6a5 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 70eba562..32eecec7 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.hasAdminMode())) + if( ! (faction.getOpen() || faction.isInvited(fme) || fme.hasAdminMode() || 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/CmdLeader.java b/src/com/massivecraft/factions/cmd/CmdLeader.java index 7a801bef..e370fbf3 100644 --- a/src/com/massivecraft/factions/cmd/CmdLeader.java +++ b/src/com/massivecraft/factions/cmd/CmdLeader.java @@ -38,7 +38,7 @@ public class CmdLeader extends FCommand FPlayer targetFactionCurrentLeader = targetFaction.getFPlayerLeader(); // We now have fplayer and the target faction - if (this.senderIsConsole || fme.hasAdminMode()) + if (this.senderIsConsole || fme.hasAdminMode() || Permission.LEADER_ANY.has(sender, false)) { // Do whatever you wish } @@ -47,7 +47,7 @@ public class CmdLeader extends FCommand // Follow the standard rules if (fme.getRole() != Rel.LEADER) { - sender.sendMessage(p.txt.parse("Only faction admins can %s.", this.getHelpShort())); + sender.sendMessage(p.txt.parse("Only faction leaders can %s.", this.getHelpShort())); return; } @@ -64,6 +64,15 @@ public class CmdLeader extends FCommand } } + // if target player is currently leader, demote and replace him + if (targetFactionCurrentLeader == newLeader) + { + targetFaction.promoteNewLeader(); + msg("You have demoted %s from the position of faction leader.", newLeader.describeTo(fme, true)); + newLeader.msg("You have been demoted from the position of faction leader by %s.", senderIsConsole ? "a server admin" : fme.describeTo(newLeader, true)); + return; + } + // Perform the switching if (targetFactionCurrentLeader != null) { @@ -71,11 +80,12 @@ public class CmdLeader extends FCommand } newLeader.setFaction(targetFaction); newLeader.setRole(Rel.LEADER); + msg("You have promoted %s to the position of faction leader.", newLeader.describeTo(fme, true)); // Inform all players for (FPlayer fplayer : FPlayers.i.getOnline()) { - fplayer.msg("%s gave %s the leadership of %s", RelationUtil.describeThatToMe(fme, fplayer, true), newLeader.describeTo(fplayer), targetFaction.describeTo(fplayer)); + fplayer.msg("%s gave %s the leadership of %s.", senderIsConsole ? "A server admin" : RelationUtil.describeThatToMe(fme, fplayer, true), newLeader.describeTo(fplayer), targetFaction.describeTo(fplayer)); } } } diff --git a/src/com/massivecraft/factions/cmd/CmdOfficer.java b/src/com/massivecraft/factions/cmd/CmdOfficer.java index 8415f4da..ee67efbf 100644 --- a/src/com/massivecraft/factions/cmd/CmdOfficer.java +++ b/src/com/massivecraft/factions/cmd/CmdOfficer.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.Rel; @@ -18,10 +19,10 @@ public class CmdOfficer extends FCommand this.permission = Permission.OFFICER.node; this.disableOnLock = true; - senderMustBePlayer = true; + senderMustBePlayer = false; senderMustBeMember = false; senderMustBeOfficer = false; - senderMustBeLeader = true; + senderMustBeLeader = false; } @Override @@ -29,30 +30,47 @@ public class CmdOfficer extends FCommand { FPlayer you = this.argAsBestFPlayerMatch(0); if (you == null) return; - - if (you.getFaction() != myFaction) + + boolean permAny = Permission.OFFICER_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() != Rel.LEADER && !permAny) + { + msg("You are not the faction leader."); + return; + } + + if (you == fme && !permAny) { msg("The target player musn't be yourself."); return; } + if (you.getRole() == Rel.LEADER) + { + msg("The target player is a faction leader. Demote them first."); + return; + } + if (you.getRole() == Rel.OFFICER) { // Revoke you.setRole(Rel.MEMBER); - myFaction.msg("%s is no longer officer in your faction.", you.describeTo(myFaction, true)); + targetFaction.msg("%s is no longer officer in your faction.", you.describeTo(targetFaction, true)); + msg("You have removed officer status from %s.", you.describeTo(fme, true)); } else { // Give you.setRole(Rel.OFFICER); - myFaction.msg("%s was promoted to officer in your faction.", you.describeTo(myFaction, true)); + targetFaction.msg("%s was promoted to officer in your faction.", you.describeTo(targetFaction, true)); + msg("You have promoted %s to officer.", you.describeTo(fme, true)); } } diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index b977257b..0c4b289a 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -21,8 +21,10 @@ public enum Permission HOME("home"), INVITE("invite"), JOIN("join"), + JOIN_ANY("join.any"), KICK("kick"), LEADER("leader"), + LEADER_ANY("leader.any"), LEAVE("leave"), LIST("list"), LOCK("lock"), @@ -35,6 +37,7 @@ public enum Permission MONEY_P2F("money.p2f"), MONEY_WITHDRAW("money.withdraw"), OFFICER("officer"), + OFFICER_ANY("officer.any"), OPEN("open"), PERM("perm"), POWER("power"), diff --git a/src/com/massivecraft/factions/util/RelationUtil.java b/src/com/massivecraft/factions/util/RelationUtil.java index c9c0e1d1..daea2d85 100644 --- a/src/com/massivecraft/factions/util/RelationUtil.java +++ b/src/com/massivecraft/factions/util/RelationUtil.java @@ -25,7 +25,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 thatFaction.getTag(); // no relation, but can show basic name or tag if (that instanceof Faction) {