From 68fe1f2d2862d8b022789047978616a3eb490e66 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Sun, 28 Dec 2014 17:22:53 +0100 Subject: [PATCH] Rank cmd rework --- .../java/com/massivecraft/factions/Perm.java | 9 +- .../factions/cmd/CmdFactions.java | 18 +- .../factions/cmd/CmdFactionsDemote.java | 75 ----- .../factions/cmd/CmdFactionsLeader.java | 109 ------- .../factions/cmd/CmdFactionsOfficer.java | 81 ----- .../factions/cmd/CmdFactionsPromote.java | 76 ----- .../factions/cmd/CmdFactionsRank.java | 304 ++++++++++++++++++ .../factions/cmd/CmdFactionsRankOld.java | 41 +++ .../massivecraft/factions/cmd/arg/ARRank.java | 153 +++++++++ src/main/resources/plugin.yml | 14 +- 10 files changed, 518 insertions(+), 362 deletions(-) delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsDemote.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsLeader.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsOfficer.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsPromote.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsRank.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankOld.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/arg/ARRank.java diff --git a/src/main/java/com/massivecraft/factions/Perm.java b/src/main/java/com/massivecraft/factions/Perm.java index 55403d8c..d32bce41 100644 --- a/src/main/java/com/massivecraft/factions/Perm.java +++ b/src/main/java/com/massivecraft/factions/Perm.java @@ -23,7 +23,6 @@ public enum Perm CLAIM_CIRCLE("claim.circle"), CLAIM_ALL("claim.all"), CREATE("create"), - DEMOTE("demote"), DESCRIPTION("description"), DISBAND("disband"), EXPANSIONS("expansions"), @@ -35,8 +34,6 @@ public enum Perm JOIN_ANY("join.any"), JOIN_OTHERS("join.others"), KICK("kick"), - LEADER("leader"), - LEADER_ANY("leader.any"), LEAVE("leave"), LIST("list"), MAP("map"), @@ -49,13 +46,13 @@ public enum Perm MONEY_P2F("money.p2f"), MONEY_WITHDRAW("money.withdraw"), MOTD("motd"), - OFFICER("officer"), - OFFICER_ANY("officer.any"), OPEN("open"), PERM("perm"), PLAYER("player"), POWERBOOST("powerboost"), - PROMOTE("promote"), + RANK("rank"), + RANK_SHOW("rank.show"), + RANK_ACTION("rank.action"), RELATION("relation"), SEECHUNK("seechunk"), SEECHUNKOLD("seechunkold"), diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java index 25a54989..de6e7291 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java @@ -30,10 +30,11 @@ public class CmdFactions extends FactionsCommand public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite(); public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick(); public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle(); - public CmdFactionsPromote cmdFactionsPromote = new CmdFactionsPromote(); - public CmdFactionsDemote cmdFactionsDemote = new CmdFactionsDemote(); - public CmdFactionsOfficer cmdFactionsOfficer = new CmdFactionsOfficer(); - public CmdFactionsLeader cmdFactionsLeader = new CmdFactionsLeader(); + public CmdFactionsRank cmdFactionsRank = new CmdFactionsRank(); + public CmdFactionsRankOld cmdFactionsRankOldLeader = new CmdFactionsRankOld("leader"); + public CmdFactionsRankOld cmdFactionsRankOldOfficer = new CmdFactionsRankOld("officer"); + public CmdFactionsRankOld cmdFactionsRankOldPromote = new CmdFactionsRankOld("promote"); + public CmdFactionsRankOld cmdFactionsRankOldDemote = new CmdFactionsRankOld("demote"); public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); @@ -78,10 +79,11 @@ public class CmdFactions extends FactionsCommand this.addSubCommand(this.cmdFactionsInvite); this.addSubCommand(this.cmdFactionsKick); this.addSubCommand(this.cmdFactionsTitle); - this.addSubCommand(this.cmdFactionsPromote); - this.addSubCommand(this.cmdFactionsDemote); - this.addSubCommand(this.cmdFactionsOfficer); - this.addSubCommand(this.cmdFactionsLeader); + this.addSubCommand(this.cmdFactionsRank); + this.addSubCommand(this.cmdFactionsRankOldLeader); + this.addSubCommand(this.cmdFactionsRankOldOfficer); + this.addSubCommand(this.cmdFactionsRankOldPromote); + this.addSubCommand(this.cmdFactionsRankOldDemote); this.addSubCommand(this.cmdFactionsMoney); this.addSubCommand(this.cmdFactionsSeeChunk); this.addSubCommand(this.cmdFactionsSeeChunkOld); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDemote.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDemote.java deleted file mode 100644 index e8cda4e9..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDemote.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.arg.ARMPlayer; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.cmd.req.ReqHasPerm; - -public class CmdFactionsDemote extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsDemote() - { - // Aliases - this.addAliases("demote"); - - // Args - this.addRequiredArg("player"); - - // Requirements - this.addRequirements(ReqHasPerm.get(Perm.DEMOTE.node)); - - //To demote someone from member -> recruit you must be an officer. - //To demote someone from officer -> member you must be a leader. - //We'll handle this internally - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - MPlayer you = this.arg(0, ARMPlayer.getAny()); - if (you == null) return; - - if (you.getFaction() != msenderFaction) - { - msg("%s is not a member in your faction.", you.describeTo(msender, true)); - return; - } - - if (you == msender) - { - msg("The target player mustn't be yourself."); - return; - } - - if (you.getRole() == Rel.MEMBER) - { - if (!msender.getRole().isAtLeast(Rel.OFFICER)) - { - msg("You must be an officer to demote a member to recruit."); - return; - } - you.setRole(Rel.RECRUIT); - msenderFaction.msg("%s was demoted to being a recruit in your faction.", you.describeTo(msenderFaction, true)); - } - else if (you.getRole() == Rel.OFFICER) - { - if (!msender.getRole().isAtLeast(Rel.LEADER)) - { - msg("You must be the leader to demote an officer to member."); - return; - } - you.setRole(Rel.MEMBER); - msenderFaction.msg("%s was demoted to being a member in your faction.", you.describeTo(msenderFaction, true)); - } - } - -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsLeader.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsLeader.java deleted file mode 100644 index 661ae1c4..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsLeader.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.arg.ARMPlayer; -import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.factions.util.RelationUtil; -import com.massivecraft.massivecore.cmd.req.ReqHasPerm; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsLeader extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - public CmdFactionsLeader() - { - // Aliases - this.addAliases("leader"); - - // Args - this.addRequiredArg("player"); - this.addOptionalArg("faction", "you"); - - // Requirements - this.addRequirements(ReqHasPerm.get(Perm.LEADER.node)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - MPlayer newLeader = this.arg(0, ARMPlayer.getAny()); - if (newLeader == null) return; - - Faction targetFaction = this.arg(1, ARFaction.get(), msenderFaction); - if (targetFaction == null) return; - - MPlayer targetFactionCurrentLeader = targetFaction.getLeader(); - - // We now have mplayer and the target faction - if (this.senderIsConsole || msender.isUsingAdminMode() || Perm.LEADER_ANY.has(sender, false)) - { - // Do whatever you wish - } - else - { - // Follow the standard rules - if (msender.getRole() != Rel.LEADER || targetFaction != msenderFaction) - { - sender.sendMessage(Txt.parse("You must be leader of the faction to %s.", this.getDesc())); - return; - } - - if (newLeader.getFaction() != msenderFaction) - { - msg("%s is not a member in the faction.", newLeader.describeTo(msender, true)); - return; - } - - if (newLeader == msender) - { - msg("The target player musn't be yourself."); - return; - } - } - - // only run event when newLeader isn't actually in the faction - if (newLeader.getFaction() != targetFaction) - { - EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, newLeader, targetFaction, MembershipChangeReason.LEADER); - event.run(); - if (event.isCancelled()) return; - } - - // 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(msender, true)); - newLeader.msg("You have been demoted from the position of faction leader by %s.", msender.describeTo(newLeader, true)); - return; - } - - // Perform the switching - if (targetFactionCurrentLeader != null) - { - targetFactionCurrentLeader.setRole(Rel.OFFICER); - } - newLeader.setFaction(targetFaction); - newLeader.setRole(Rel.LEADER); - msg("You have promoted %s to the position of faction leader.", newLeader.describeTo(msender, true)); - - // Inform all players - for (MPlayer mplayer : MPlayerColl.get().getAllOnline()) - { - mplayer.msg("%s gave %s the leadership of %s.", senderIsConsole ? "A server admin" : RelationUtil.describeThatToMe(msender, mplayer, true), newLeader.describeTo(mplayer), targetFaction.describeTo(mplayer)); - } - } - -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsOfficer.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsOfficer.java deleted file mode 100644 index 157355e0..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsOfficer.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.arg.ARMPlayer; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.cmd.req.ReqHasPerm; - -public class CmdFactionsOfficer extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsOfficer() - { - // Aliases - this.addAliases("officer"); - - // Args - this.addRequiredArg("player"); - - // Requirements - this.addRequirements(ReqHasPerm.get(Perm.OFFICER.node)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - MPlayer you = this.arg(0, ARMPlayer.getAny()); - if (you == null) return; - - boolean permAny = Perm.OFFICER_ANY.has(sender, false); - Faction targetFaction = you.getFaction(); - - if (targetFaction != msenderFaction && !permAny) - { - msg("%s is not a member in your faction.", you.describeTo(msender, true)); - return; - } - - if (msender != null && msender.getRole() != Rel.LEADER && !permAny) - { - msg("You are not the faction leader."); - return; - } - - if (you == msender && !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); - targetFaction.msg("%s is no longer officer in your faction.", you.describeTo(targetFaction, true)); - msg("You have removed officer status from %s.", you.describeTo(msender, true)); - } - else - { - // Give - you.setRole(Rel.OFFICER); - targetFaction.msg("%s was promoted to officer in your faction.", you.describeTo(targetFaction, true)); - msg("You have promoted %s to officer.", you.describeTo(msender, true)); - } - } - -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPromote.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPromote.java deleted file mode 100644 index 100615d3..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPromote.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.arg.ARMPlayer; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.cmd.req.ReqHasPerm; - -public class CmdFactionsPromote extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPromote() - { - // Aliases - this.addAliases("promote"); - - // Args - this.addRequiredArg("player"); - - // Requirements - this.addRequirements(ReqHasPerm.get(Perm.PROMOTE.node)); - - //To promote someone from recruit -> member you must be an officer. - //To promote someone from member -> officer you must be a leader. - //We'll handle this internally - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - MPlayer you = this.arg(0, ARMPlayer.getAny()); - if (you == null) return; - - if (you.getFaction() != msenderFaction) - { - msg("%s is not a member in your faction.", you.describeTo(msender, true)); - return; - } - - if (you == msender) - { - msg("The target player mustn't be yourself."); - return; - } - - if (you.getRole() == Rel.RECRUIT) - { - if (!msender.getRole().isAtLeast(Rel.OFFICER)) - { - msg("You must be an officer to promote someone to member."); - return; - } - you.setRole(Rel.MEMBER); - msenderFaction.msg("%s was promoted to being a member of your faction.", you.describeTo(msenderFaction, true)); - } - else if (you.getRole() == Rel.MEMBER) - { - if (!msender.getRole().isAtLeast(Rel.LEADER)) - { - msg("You must be the leader to promote someone to officer."); - return; - } - // Give - you.setRole(Rel.OFFICER); - msenderFaction.msg("%s was promoted to being a officer in your faction.", you.describeTo(msenderFaction, true)); - } - } - -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRank.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRank.java new file mode 100644 index 00000000..ee7a4398 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRank.java @@ -0,0 +1,304 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.arg.ARMPlayer; +import com.massivecraft.factions.cmd.arg.ARRank; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.factions.util.RelationUtil; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsRank extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + // The rank required to do any rank changes + final static Rel rankReq = Rel.OFFICER; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + //These fields are set upon perform() and unset afterwards + + //Target + private Faction targetFaction = null; + private MPlayer target = null; + + //Roles + private Rel senderRole = null; + private Rel targetRole = null; + private Rel rank = null; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRank() + { + // Aliases + this.addAliases("r","rank"); + + // Args + this.addOptionalArg("player","you"); + this.addOptionalArg("action", "show"); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.RANK.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // This sets target and much other. Returns false if not succeeded + if(!registerFields()) + { + return; + } + + // Sometimes we just want to show the rank + if(!this.argIsSet(1)) + { + if(!Perm.RANK_SHOW.has(sender, true)) + { + return; + } + showRank(); + return; + } + + // Permission check + if(!Perm.RANK_ACTION.has(sender, true)) + { + return; + } + + // Is the player allowed or not. Method can be found later down + if(!isPlayerAllowed()) + { + return; + } + + // Does the change make sense. + if(!this.isChangeRequired()) + { + return; + } + + // Should we fire an event when rank is changed? + // Currently we don't + + // Change the rank + changeRank(); + } + + // This is always run after performing a MassiveCommand + // It might be a bit hacky, but is easier than adding a line of code at every return statement + // Sometimes it is nice to know the exact mechanics of MassiveCore + @Override + public void unsetSenderVars() + { + super.unsetSenderVars(); + this.unregisterFields(); + } + + // -------------------------------------------- // + // PRIVATE + // -------------------------------------------- // + + private boolean registerFields() + { + // Getting the target and faction + target = this.arg(0, ARMPlayer.getAny(), msender); + if (null == target) return false; + targetFaction = target.getFaction(); + + // Rank if any passed. + if (this.argIsSet(1)) + { + rank = this.arg(1, ARRank.get(target.getRole())); + if(null == rank) return false; + } + + //Roles/ranks + senderRole = msender.getRole(); + targetRole = target.getRole(); + + return true; + } + + private void unregisterFields() + { + targetFaction = null; + target = null; + + senderRole = null; + targetRole = null; + rank = null; + } + + private void showRank() + { + String name = target.describeTo(msender) + (target == msender ? "r" : "'s"); + msg(Txt.parse("%s rank is %s", name, target.getColorTo(msender)+Txt.getNicedEnum(target.getRole()))); + } + + private boolean isPlayerAllowed() + { + // People with permission don't follow the normal rules + if (msender.isUsingAdminMode()) + { + return true; + } + + // If somone gets the leadership of wilderness (Which has happened before) + // We can at least try to limit their powers + if (targetFaction.isNone()) + { + msg( "Wilderness doesn't use ranks sorry :(" ); + return false; + } + + if (targetFaction != msenderFaction) + { + //Don't change ranks outside of your faction + msg(Txt.parse( "%s is not in the same faction as you" ,target.describeTo(msender))); + return false; + } + + if (target == msender) + { + // Don't change your own rank + msg("The target player mustn't be yourself."); + return false; + } + + + if (senderRole.isLessThan(rankReq)) + { + // You need a specific rank to change ranks + msg(Txt.parse("You must be %s or higher to change ranks",Txt.getNicedEnum(rankReq).toLowerCase())); + return false; + } + + // The following two if statements could be merged. + // But isn't for the sake of nicer error messages. + if (senderRole == targetRole) + { + // You can't change someones rank if it is equal to yours + msg(Txt.parse("%s can't manage eachother",Txt.getNicedEnum(rankReq)+"s")); + return false; + } + + if (senderRole.isLessThan(targetRole)) + { + // You can't change someones rank if it is higher than yours + msg(Txt.parse("You can't manage people higher ranked than you")); + return false; + } + + if (senderRole.isAtMost(rank) && senderRole != Rel.LEADER) + { + // You can't set ranks equal to or higer than your own. Unless you are the leader + msg("You can't set ranks higher than or equal to your own"); + return false; + } + + // If it wasn't cancelled above, player is allowe + return true; + } + + private boolean isChangeRequired() + { + // Just a nice msg. It would however be caught by an if statement below + if (target.getRole() == Rel.RECRUIT && arg(1).equalsIgnoreCase("demote")) + { + msg("You can't demote a recruit"); + return false; + } + + // Just a nice msg. It would however be caught by an if statement below + if (target.getRole() == Rel.LEADER && arg(1).equalsIgnoreCase("promote")) + { + msg("You can't promote the leader"); + return false; + } + + // There must be a change, else it is all waste of time + if (target.getRole() == rank) + { + msg("Player already has that rank"); + return false; + } + return true; + } + + private void changeRank() + { + // In case of leadership change, we do special things not done in other rank changes + if (rank == Rel.LEADER) + { + changeRankLeader(); + } + else + { + changeRankOther(); + } + + } + + private void changeRankLeader() + { + // If there is a current leader. Demote & inform them + MPlayer targetFactionCurrentLeader = targetFaction.getLeader(); + if (targetFactionCurrentLeader != null) + { + // Inform & demote the old leader + targetFactionCurrentLeader.setRole(Rel.OFFICER); + if (targetFactionCurrentLeader != msender) //They kinda know if they fired the command themself + targetFactionCurrentLeader.msg("You have been demoted from the position of faction leader by %s.", msender.describeTo(targetFactionCurrentLeader, true)); + } + + // Inform & promote the new leader + target.setRole(Rel.LEADER); + if (target != msender) //They kinda know if they fired the command themself + target.msg("You have been promoted to the position of faction leader by %s.", msender.describeTo(target, true)); + + // Inform the msg sender + msg("You have promoted %s to the position of faction leader.", target.describeTo(msender, true)); + + // Inform everyone + for (MPlayer mplayer : MPlayerColl.get().getAllOnline()) + { + String changerName = senderIsConsole ? "A server admin" : RelationUtil.describeThatToMe(msender, mplayer, true); + mplayer.msg("%s gave %s the leadership of %s.", changerName, target.describeTo(mplayer), targetFaction.describeTo(mplayer)); + } + } + + private void changeRankOther() + { + // If the target is currently the leader and faction isn't permanent... + if(targetRole == Rel.LEADER && (!MConf.get().permanentFactionsDisableLeaderPromotion + || !targetFaction.getFlag(MFlag.ID_PERMANENT))) + { + // ...we must promote a new one + targetFaction.promoteNewLeader(); + } + // Were they demoted or promoted? + String change = (rank.isLessThan(targetRole) ? "demoted" : "promoted"); + // The rank will be set before the msg, so they have the appropriate prefix + target.setRole(rank); + String rankName = Txt.getNicedEnum(rank).toLowerCase(); + msenderFaction.msg("%s was %s to being %s %s in your faction.", target.describeTo(msenderFaction, true), change, Txt.aan(rankName), rankName); + } +} \ No newline at end of file diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankOld.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankOld.java new file mode 100644 index 00000000..dd70a641 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsRankOld.java @@ -0,0 +1,41 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.massivecore.cmd.VisibilityMode; +import com.massivecraft.massivecore.util.MUtil; + +public class CmdFactionsRankOld extends FactionsCommand +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + final String rankName; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsRankOld(String rank) + { + this.rankName = rank.toLowerCase(); + + // Aliases + this.addAliases(rankName); + + // Args + this.addRequiredArg("player"); + + this.setVisibilityMode(VisibilityMode.INVISIBLE); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + Factions.get().getOuterCmdFactions().cmdFactionsRank.execute(sender, MUtil.list(arg(0),rankName)); + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/arg/ARRank.java b/src/main/java/com/massivecraft/factions/cmd/arg/ARRank.java new file mode 100644 index 00000000..d589eac4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/arg/ARRank.java @@ -0,0 +1,153 @@ +package com.massivecraft.factions.cmd.arg; + +import java.util.Collection; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.factions.Rel; +import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect; +import com.massivecraft.massivecore.mixin.Mixin; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; + +public class ARRank extends ARAbstractSelect +{ + //----------------------------------------------// + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + //Default constructor. Can't use promote and demote. + private static ARRank i = new ARRank(); + public static ARRank get() { return i; } + + public ARRank() + { + this.startRank = null; + } + + //Fancy constructor. Can use promote and demote + public static ARRank get(Rel rank) { return new ARRank(rank); } + + public ARRank(Rel rank) + { + this.startRank = rank; + } + + //----------------------------------------------// + // FIELDS + // -------------------------------------------- // + + final Rel startRank; + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String typename() + { + return "rank"; + } + + @Override + public Rel select(String arg, CommandSender sender) + { + //Default it is nothing + Rel ret = null; + + // This is especially useful when one rank can have aliases. + // In the case of promote/demote, + // that would require 10 lines of code repeated for each alias. + arg = this.prepareArg(arg); + + switch(arg) + { + // All the normal ranks + case "leader": ret = Rel.LEADER; break; + case "officer": ret = Rel.OFFICER; break; + case "member": ret = Rel.MEMBER; break; + case "recruit": ret = Rel.RECRUIT; break; + + // Promote + case "promote": + switch(startRank) + { + case LEADER : ret = Rel.LEADER; break; + case OFFICER : ret = Rel.LEADER; break; + case MEMBER : ret = Rel.OFFICER; break; + case RECRUIT : ret = Rel.MEMBER; break; + // This should not happen + default: + //This might happen of the default constrcutor is used + Mixin.msgOne(sender, Txt.parse("You can't use promote & demote")); + ret = null; break; + + } break; + + // Demote + case "demote": + switch(startRank) + { + case LEADER : ret = Rel.OFFICER; break; + case OFFICER : ret = Rel.MEMBER; break; + case MEMBER : ret = Rel.RECRUIT; break; + case RECRUIT : ret = Rel.RECRUIT; break; + // This should not happen + default: + //This might happen of the default constrcutor is used + Mixin.msgOne(sender, Txt.parse("You can't use promote & demote")); + ret = null; break; + } break; + } + + return ret; + } + + @Override + public Collection altNames(CommandSender sender) + { + return MUtil.list( + Txt.getNicedEnum(Rel.LEADER), + Txt.getNicedEnum(Rel.OFFICER), + Txt.getNicedEnum(Rel.MEMBER), + Txt.getNicedEnum(Rel.RECRUIT), + "Promote", + "Demote"); + } + + // -------------------------------------------- // + // PRIVATE + // -------------------------------------------- // + + private String prepareArg(String str) + { + String ret = str; + + if (str.startsWith("admin") || str.startsWith("lea")) + { + ret = "leader"; + } + else if (str.startsWith("mod") || str.startsWith("off")) + { + ret = "officer"; + } + else if (str.startsWith("mem")) + { + ret = "member"; + } + else if (str.startsWith("rec")) + { + ret = "recruit"; + } + else if (str.startsWith("+") || str.startsWith("plus")) + { + ret = "promote"; + } + else if (str.startsWith("-") || str.startsWith("minus")) + { + ret = "demote"; + } + + return ret; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index beb7b114..d660755d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -23,7 +23,6 @@ permissions: factions.claim.circle: {description: claim by circle and radius, default: false} factions.claim.all: {description: claim all faction land, default: false} factions.create: {description: create new faction, default: false} - factions.demote: {description: demote lesser members in your faction, default: false} factions.description: {description: change faction description, default: false} factions.disband: {description: disband faction, default: false} factions.expansions: {description: list expansions, default: false} @@ -35,8 +34,6 @@ permissions: factions.join.any: {description: join closed faction, default: false} factions.join.others: {description: have another player join faction, default: false} factions.kick: {description: kick player from faction, default: false} - factions.leader: {description: set leader for faction, default: false} - factions.leader.any: {description: set leader for another faction, default: false} factions.leave: {description: leave your faction, default: false} factions.list: {description: list all factions, default: false} factions.map: {description: show territory map, default: false} @@ -49,13 +46,13 @@ permissions: factions.money.p2f: {description: transfer p --> f, default: false} factions.money.withdraw: {description: withdraw from faction, default: false} factions.motd: {description: faction motd, default: false} - factions.officer: {description: make player officer, default: false} - factions.officer.any: {description: set officers for another faction, default: false} factions.open: {description: set if invitation is required to join, default: false} factions.perm: {description: change faction permissions, default: false} factions.player: {description: show player information} factions.powerboost: {description: set powerboost, default: false} - factions.promote: {description: promote lesser members in your faction, default: false} + factions.rank: {description: manage/show ranks, default: false} + factions.rank.show: {description: show rank, default: false} + factions.rank.action: {description: change rank, default: false} factions.relation: {description: set relation wish to another faction, default: false} factions.seechunk: {description: see the chunk you stand in, default: false} factions.seechunkold: {description: see the chunk you stand in, default: false} @@ -208,6 +205,9 @@ permissions: factions.perm: true factions.player: true factions.promote: true + factions.rank: true + factions.rank.show: true + factions.rank.action: true factions.relation: true factions.seechunk: true factions.seechunkold: true @@ -227,4 +227,4 @@ permissions: factions.kit.default: default: true children: - factions.kit.rank0: true \ No newline at end of file + factions.kit.rank0: true