From afc45fea13d5ed121779a380f41ee61edf2abadc Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Fri, 9 Jan 2015 22:36:12 +0100 Subject: [PATCH] Reworked flag & perm cmd Flag & Perm commands are now parent commands, and not so awkward. --- plugin.yml | 18 ++ src/com/massivecraft/factions/Perm.java | 222 +++++++++--------- .../factions/cmd/CmdFactionsFlag.java | 138 +++-------- .../factions/cmd/CmdFactionsFlagList.java | 54 +++++ .../factions/cmd/CmdFactionsFlagSet.java | 86 +++++++ .../factions/cmd/CmdFactionsFlagShow.java | 77 ++++++ .../factions/cmd/CmdFactionsPerm.java | 145 +++--------- .../factions/cmd/CmdFactionsPermList.java | 54 +++++ .../factions/cmd/CmdFactionsPermSet.java | 102 ++++++++ .../factions/cmd/CmdFactionsPermShow.java | 80 +++++++ .../massivecraft/factions/entity/MFlag.java | 4 +- .../massivecraft/factions/entity/MPerm.java | 36 +++ 12 files changed, 691 insertions(+), 325 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsPermList.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java diff --git a/plugin.yml b/plugin.yml index a47ae238..d60971cf 100644 --- a/plugin.yml +++ b/plugin.yml @@ -28,6 +28,9 @@ permissions: factions.expansions: {description: list expansions, default: false} factions.faction: {description: show faction information, default: false} factions.flag: {description: manage faction flags, default: false} + factions.flag.list: {description: list flags, default: false} + factions.flag.set: {description: set flags, default: false} + factions.flag.show: {description: show flags, default: false} factions.home: {description: teleport to faction home, default: false} factions.invite: {description: manage invites, default: false} factions.invite.list: {description: list invited players, default: false} @@ -52,6 +55,9 @@ permissions: factions.motd: {description: faction motd, default: false} factions.open: {description: set if invitation is required to join, default: false} factions.perm: {description: change faction permissions, default: false} + factions.perm.list: {description: list perms, default: false} + factions.perm.set: {description: set perms, default: false} + factions.perm.show: {description: show perms, default: false} factions.player: {description: show player information} factions.powerboost: {description: set powerboost, default: false} factions.rank: {description: manage/show ranks, default: false} @@ -98,6 +104,9 @@ permissions: factions.expansions: true factions.faction: true factions.flag: true + factions.flag.list: true + factions.flag.set: true + factions.flag.show: true factions.home: true factions.invite: true factions.invite.list: true @@ -126,6 +135,9 @@ permissions: factions.officer.any: true factions.open: true factions.perm: true + factions.perm.list: true + factions.perm.set: true + factions.perm.show: true factions.player: true factions.powerboost: true factions.promote: true @@ -195,6 +207,9 @@ permissions: factions.expansions: true factions.faction: true factions.flag: true + factions.flag.list: true + factions.flag.set: true + factions.flag.show: true factions.home: true factions.invite: true factions.invite.list: true @@ -218,6 +233,9 @@ permissions: factions.officer: true factions.open: true factions.perm: true + factions.perm.list: true + factions.perm.set: true + factions.perm.show: true factions.player: true factions.promote: true factions.rank: true diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index f23d92d4..6f89229f 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -1,110 +1,116 @@ -package com.massivecraft.factions; - -import org.bukkit.permissions.Permissible; - -import com.massivecraft.massivecore.util.PermUtil; - -public enum Perm -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - ACCESS("access"), - ACCESS_VIEW("access.view"), - ACCESS_PLAYER("access.player"), - ACCESS_FACTION("access.faction"), - ADMIN("admin"), - CLAIM("claim"), - CLAIM_ONE("claim.one"), - CLAIM_AUTO("claim.auto"), - CLAIM_FILL("claim.fill"), - CLAIM_SQUARE("claim.square"), - CLAIM_CIRCLE("claim.circle"), - CLAIM_ALL("claim.all"), - CREATE("create"), - DESCRIPTION("description"), - DISBAND("disband"), - EXPANSIONS("expansions"), - FACTION("faction"), - FLAG("flag"), - HOME("home"), - INVITE("invite"), - INVITE_LIST("invite.list"), - INVITE_LIST_OTHER("invite.list.other"), - INVITE_ADD("invite.add"), - INVITE_REMOVE("invite.remove"), - JOIN("join"), - JOIN_ANY("join.any"), - JOIN_OTHERS("join.others"), - KICK("kick"), - LEAVE("leave"), - LIST("list"), - MAP("map"), - MONEY("money"), - MONEY_BALANCE("money.balance"), - MONEY_BALANCE_ANY("money.balance.any"), - MONEY_DEPOSIT("money.deposit"), - MONEY_F2F("money.f2f"), - MONEY_F2P("money.f2p"), - MONEY_P2F("money.p2f"), - MONEY_WITHDRAW("money.withdraw"), - MOTD("motd"), - OPEN("open"), - PERM("perm"), - PLAYER("player"), - POWERBOOST("powerboost"), - RANK("rank"), - RANK_SHOW("rank.show"), - RANK_ACTION("rank.action"), - RELATION("relation"), - SEECHUNK("seechunk"), - SEECHUNKOLD("seechunkold"), +package com.massivecraft.factions; + +import org.bukkit.permissions.Permissible; + +import com.massivecraft.massivecore.util.PermUtil; + +public enum Perm +{ + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + ACCESS("access"), + ACCESS_VIEW("access.view"), + ACCESS_PLAYER("access.player"), + ACCESS_FACTION("access.faction"), + ADMIN("admin"), + CLAIM("claim"), + CLAIM_ONE("claim.one"), + CLAIM_AUTO("claim.auto"), + CLAIM_FILL("claim.fill"), + CLAIM_SQUARE("claim.square"), + CLAIM_CIRCLE("claim.circle"), + CLAIM_ALL("claim.all"), + CREATE("create"), + DESCRIPTION("description"), + DISBAND("disband"), + EXPANSIONS("expansions"), + FACTION("faction"), + FLAG("flag"), + FLAG_LIST("flag.list"), + FLAG_SET("flag.set"), + FLAG_SHOW("flag.show"), + HOME("home"), + INVITE("invite"), + INVITE_LIST("invite.list"), + INVITE_LIST_OTHER("invite.list.other"), + INVITE_ADD("invite.add"), + INVITE_REMOVE("invite.remove"), + JOIN("join"), + JOIN_ANY("join.any"), + JOIN_OTHERS("join.others"), + KICK("kick"), + LEAVE("leave"), + LIST("list"), + MAP("map"), + MONEY("money"), + MONEY_BALANCE("money.balance"), + MONEY_BALANCE_ANY("money.balance.any"), + MONEY_DEPOSIT("money.deposit"), + MONEY_F2F("money.f2f"), + MONEY_F2P("money.f2p"), + MONEY_P2F("money.p2f"), + MONEY_WITHDRAW("money.withdraw"), + MOTD("motd"), + OPEN("open"), + PERM("perm"), + PERM_LIST("perm.list"), + PERM_SET("perm.set"), + PERM_SHOW("perm.show"), + PLAYER("player"), + POWERBOOST("powerboost"), + RANK("rank"), + RANK_SHOW("rank.show"), + RANK_ACTION("rank.action"), + RELATION("relation"), + SEECHUNK("seechunk"), + SEECHUNKOLD("seechunkold"), SETHOME("sethome"), - SETPOWER("setpower"), - NAME("name"), - TITLE("title"), - TITLE_COLOR("title.color"), - UNCLAIM("unclaim"), - UNCLAIM_ONE("unclaim.one"), - UNCLAIM_AUTO("unclaim.auto"), - UNCLAIM_FILL("unclaim.fill"), - UNCLAIM_SQUARE("unclaim.square"), - UNCLAIM_CIRCLE("unclaim.circle"), - UNCLAIM_ALL("unclaim.all"), - UNSETHOME("unsethome"), - VERSION("version"), - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public final String node; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - Perm(final String node) - { - this.node = "factions."+node; - } - - // -------------------------------------------- // - // HAS - // -------------------------------------------- // - - public boolean has(Permissible permissible, boolean informSenderIfNot) - { - return PermUtil.has(permissible, this.node, informSenderIfNot); - } - - public boolean has(Permissible permissible) - { - return has(permissible, false); - } - + SETPOWER("setpower"), + NAME("name"), + TITLE("title"), + TITLE_COLOR("title.color"), + UNCLAIM("unclaim"), + UNCLAIM_ONE("unclaim.one"), + UNCLAIM_AUTO("unclaim.auto"), + UNCLAIM_FILL("unclaim.fill"), + UNCLAIM_SQUARE("unclaim.square"), + UNCLAIM_CIRCLE("unclaim.circle"), + UNCLAIM_ALL("unclaim.all"), + UNSETHOME("unsethome"), + VERSION("version"), + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public final String node; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + Perm(final String node) + { + this.node = "factions."+node; + } + + // -------------------------------------------- // + // HAS + // -------------------------------------------- // + + public boolean has(Permissible permissible, boolean informSenderIfNot) + { + return PermUtil.has(permissible, this.node, informSenderIfNot); + } + + public boolean has(Permissible permissible) + { + return has(permissible, false); + } + } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java index 2aad078b..b4bb6130 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java @@ -1,104 +1,34 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.arg.ARMFlag; -import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.event.EventFactionsFlagChange; -import com.massivecraft.massivecore.cmd.arg.ARBoolean; -import com.massivecraft.massivecore.cmd.req.ReqHasPerm; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsFlag extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsFlag() - { - // Aliases - this.addAliases("flag"); - - // Args - this.addOptionalArg("faction", "you"); - this.addOptionalArg("flag", "all"); - this.addOptionalArg("yes/no", "read"); - - // Requirements - this.addRequirements(ReqHasPerm.get(Perm.FLAG.node)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - // Arg: Faction - Faction faction = this.arg(0, ARFaction.get(), msenderFaction); - if (faction == null) return; - - // Case: Show All - if ( ! this.argIsSet(1)) - { - msg(Txt.titleize("Flags for " + faction.describeTo(msender, true))); - for (MFlag mflag : MFlag.getAll()) - { - if (!mflag.isVisible() && !msender.isUsingAdminMode()) continue; - msg(mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, false)); - } - return; - } - - // Arg: MFlag - MFlag mflag = this.arg(1, ARMFlag.get()); - if (mflag == null) return; - - // Case: Show One - if ( ! this.argIsSet(2)) - { - msg(Txt.titleize("Flag for " + faction.describeTo(msender, true))); - msg(mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, false)); - return; - } - - // Do the sender have the right to change flags for this faction? - if ( ! MPerm.getPermFlags().has(msender, faction, true)) return; - - // Is this flag editable? - if (!msender.isUsingAdminMode() && !mflag.isEditable()) - { - msg("The flag %s is not editable.", mflag.getName()); - return; - } - - // Arg: Target Value - Boolean targetValue = this.arg(2, ARBoolean.get()); - if (targetValue == null) return; - - // Event - EventFactionsFlagChange event = new EventFactionsFlagChange(sender, faction, mflag, targetValue); - event.run(); - if (event.isCancelled()) return; - targetValue = event.isNewValue(); - - // Apply - faction.setFlag(mflag, targetValue); - - // Inform - String stateInfo = mflag.getStateDesc(faction.getFlag(mflag), true, false, true, true, true); - if (msender.getFaction() != faction) - { - // Send message to sender - msg("%s set a flag for %s", msender.describeTo(msender, true), faction.describeTo(msender, true)); - msg(stateInfo); - } - faction.msg("%s set a flag for %s", msender.describeTo(faction, true), faction.describeTo(faction, true)); - faction.msg(stateInfo); - } - -} +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; + +public class CmdFactionsFlag extends FactionsCommand +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + CmdFactionsFlagList cmdFactionsFlagList = new CmdFactionsFlagList(); + CmdFactionsFlagShow cmdFactionsFlagShow = new CmdFactionsFlagShow(); + CmdFactionsFlagSet cmdFactionsFlagSet = new CmdFactionsFlagSet(); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFlag() + { + // Aliases + this.addAliases("flag"); + + // Subcommands + this.addSubCommand(this.cmdFactionsFlagList); + this.addSubCommand(this.cmdFactionsFlagShow); + this.addSubCommand(this.cmdFactionsFlagSet); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.FLAG.node)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java new file mode 100644 index 00000000..f67d580f --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlagList.java @@ -0,0 +1,54 @@ +package com.massivecraft.factions.cmd; + +import java.util.ArrayList; +import java.util.List; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.massivecore.cmd.arg.ARInteger; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsFlagList extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFlagList() + { + // Aliases + this.addAliases("l", "list"); + + // Args + this.addOptionalArg("page", "1"); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.FLAG_LIST.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // Args + Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); + if (pageHumanBased == null) return; + + //Create messages + List messages = new ArrayList(); + + for (MFlag flag : MFlag.getAll()) + { + if ( ! flag.isVisible() && ! msender.isUsingAdminMode()) continue; + messages.add(flag.getStateDesc(false, false, true, true, true, false)); + } + + //Send messages + sendMessage(Txt.getPage(messages, pageHumanBased, "Available Faction Flags", sender)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java new file mode 100644 index 00000000..33b35b71 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlagSet.java @@ -0,0 +1,86 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.cmd.arg.ARMFlag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.event.EventFactionsFlagChange; +import com.massivecraft.massivecore.cmd.arg.ARBoolean; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; + +public class CmdFactionsFlagSet extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFlagSet() + { + // Aliases + this.addAliases("set"); + + // Args + this.addRequiredArg("flag"); + this.addRequiredArg("yes/no"); + this.addOptionalArg("faction", "you"); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.FLAG_SET.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // Args + MFlag flag = this.arg(0, ARMFlag.get()); + if (flag == null) return; + Boolean value = this.arg(1, ARBoolean.get()); + if (value == null) return; + Faction faction = this.arg(2, ARFaction.get(), msenderFaction); + if (faction == null) return; + + // Do the sender have the right to change flags for this faction? + if ( ! MPerm.getPermFlags().has(msender, faction, true)) return; + + // Is this flag editable? + if (!msender.isUsingAdminMode() && ! flag.isEditable()) + { + msg("The flag %s is not editable.", flag.getName()); + return; + } + + // Event + EventFactionsFlagChange event = new EventFactionsFlagChange(sender, faction, flag, value); + event.run(); + if (event.isCancelled()) return; + value = event.isNewValue(); + + // No change + if (faction.getFlag(flag) == value) + { + msg("%s already has %s set to %s.", faction.describeTo(msender), flag.getStateDesc(value, false, true, true, false, true), flag.getStateDesc(value, true, true, false, false, false)); + return; + } + + // Apply + faction.setFlag(flag, value); + + // Inform + String stateInfo = flag.getStateDesc(faction.getFlag(flag), true, false, true, true, true); + if (msender.getFaction() != faction) + { + // Send message to sender + msg("%s set a flag for %s.", msender.describeTo(msender, true), faction.describeTo(msender, true)); + sendMessage(stateInfo); + } + faction.msg("%s set a flag for %s.", msender.describeTo(faction, true), faction.describeTo(faction, true)); + faction.sendMessage(stateInfo); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java new file mode 100644 index 00000000..13456023 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlagShow.java @@ -0,0 +1,77 @@ +package com.massivecraft.factions.cmd; + +import java.util.ArrayList; +import java.util.List; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.cmd.arg.ARMFlag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.massivecore.cmd.arg.ARList; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsFlagShow extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsFlagShow() + { + // Aliases + this.addAliases("s", "show"); + + // Args + this.addOptionalArg("faction", "you"); + this.addOptionalArg("flags", "all"); + this.setErrorOnToManyArgs(false); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.FLAG_SHOW.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // Arg: Faction + Faction faction = this.arg(0, ARFaction.get(), msenderFaction); + if (faction == null) return; + + List flags = new ArrayList(); + + // Case: Show All + if ( ! this.argIsSet(1) || "all".equalsIgnoreCase(this.arg(1))) + { + for (MFlag mflag : MFlag.getAll()) + { + if (!mflag.isVisible() && ! msender.isUsingAdminMode()) continue; + flags.add(mflag); + } + } + else + { + // Arg: MFlag. Maybe we should use ARSet but that is currently buggy. + List mflags = this.arg(this.argConcatFrom(1), ARList.get(ARMFlag.get())); + if (mflags == null) return; + flags.addAll(mflags); + } + + // Create messages + List messages = new ArrayList(); + messages.add(Txt.titleize("Flag for " + faction.describeTo(msender, true))); + for (MFlag mflag : flags) + { + messages.add(mflag.getStateDesc(faction.getFlag(mflag), true, true, true, true, true)); + } + + // Send messages + sendMessage(messages); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java index 2d7d67c4..bbc3825e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java @@ -1,111 +1,34 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.arg.ARMPerm; -import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.cmd.arg.ARRel; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.cmd.arg.ARBoolean; -import com.massivecraft.massivecore.cmd.req.ReqHasPerm; -import com.massivecraft.massivecore.util.Txt; - -public class CmdFactionsPerm extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPerm() - { - // Aliases - this.addAliases("perm"); - - // Args - this.addOptionalArg("faction", "you"); - this.addOptionalArg("perm", "all"); - this.addOptionalArg("relation", "read"); - this.addOptionalArg("yes/no", "read"); - this.setErrorOnToManyArgs(false); - - // Requirements - this.addRequirements(ReqHasPerm.get(Perm.PERM.node)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() - { - // Arg: Faction - Faction faction = this.arg(0, ARFaction.get(), msenderFaction); - if (faction == null) return; - - // Case: Show All - if ( ! this.argIsSet(1)) - { - msg(Txt.titleize("Perms for " + faction.describeTo(msender, true))); - msg(MPerm.getStateHeaders()); - for (MPerm perm : MPerm.getAll()) - { - msg(perm.getStateInfo(faction.getPermitted(perm), true)); - } - return; - } - - // Arg: MPerm - MPerm mperm = this.arg(1, ARMPerm.get()); - if (mperm == null) return; - - // Case: Show One - if ( ! this.argIsSet(2)) - { - msg(Txt.titleize("Perm for " + faction.describeTo(msender, true))); - msg(MPerm.getStateHeaders()); - msg(mperm.getStateInfo(faction.getPermitted(mperm), true)); - return; - } - - // Do the sender have the right to change perms for this faction? - if ( ! MPerm.getPermPerms().has(msender, faction, true)) return; - - // Is this perm editable? - if (!msender.isUsingAdminMode() && !mperm.isEditable()) - { - msg("The perm %s is not editable.", mperm.getName()); - return; - } - - // Arg: Rel - Rel rel = this.arg(2, ARRel.get()); - if (rel == null) return; - - if ( ! this.argIsSet(3)) - { - msg("Should %s have the %s permission or not?\nYou must add \"yes\" or \"no\" at the end.", Txt.getNicedEnum(rel), Txt.upperCaseFirst(mperm.getName())); - return; - } - - // Arg: Target Value - Boolean targetValue = this.arg(3, ARBoolean.get(), null); - if (targetValue == null) return; - - // Apply - faction.setRelationPermitted(mperm, rel, targetValue); - - // The following is to make sure the leader always has the right to change perms if that is our goal. - if (mperm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains(Rel.LEADER)) - { - faction.setRelationPermitted(MPerm.getPermPerms(), Rel.LEADER, true); - } - - // Inform - msg(Txt.titleize("Perm for " + faction.describeTo(msender, true))); - msg(MPerm.getStateHeaders()); - msg(mperm.getStateInfo(faction.getPermitted(mperm), true)); - } - -} +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; + +public class CmdFactionsPerm extends FactionsCommand +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + CmdFactionsPermList cmdFactionsPermList = new CmdFactionsPermList(); + CmdFactionsPermShow cmdFactionsPermShow = new CmdFactionsPermShow(); + CmdFactionsPermSet cmdFactionsPermSet = new CmdFactionsPermSet(); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPerm() + { + // Aliases + this.addAliases("perm"); + + // Subcommands + this.addSubCommand(this.cmdFactionsPermList); + this.addSubCommand(this.cmdFactionsPermShow); + this.addSubCommand(this.cmdFactionsPermSet); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.PERM.node)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java new file mode 100644 index 00000000..8e467378 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java @@ -0,0 +1,54 @@ +package com.massivecraft.factions.cmd; + +import java.util.ArrayList; +import java.util.List; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.cmd.arg.ARInteger; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsPermList extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermList() + { + // Aliases + this.addAliases("l", "list"); + + // Args + this.addOptionalArg("page", "1"); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.PERM_LIST.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // Args + Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); + if (pageHumanBased == null) return; + + // Create messages + List messages = new ArrayList(); + + for (MPerm perm : MPerm.getAll()) + { + if ( ! perm.isVisible() && ! msender.isUsingAdminMode()) continue; + messages.add(perm.getDesc(true, true)); + } + + // Send messages + sendMessage(Txt.getPage(messages, pageHumanBased, "Available Faction Perms", sender)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java new file mode 100644 index 00000000..08ce3bec --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java @@ -0,0 +1,102 @@ +package com.massivecraft.factions.cmd; + +import java.util.ArrayList; +import java.util.List; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.cmd.arg.ARMPerm; +import com.massivecraft.factions.cmd.arg.ARRel; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.cmd.arg.ARBoolean; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsPermSet extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermSet() + { + // Aliases + this.addAliases("set"); + + // Args + this.addRequiredArg("perm"); + this.addRequiredArg("relation"); + this.addRequiredArg("yes/no"); + this.addOptionalArg("faction", "you"); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.PERM_SET.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // Args + MPerm perm = this.arg(0, ARMPerm.get()); + if (perm == null) return; + Rel rel = this.arg(1, ARRel.get()); + if (rel == null) return; + Boolean value = this.arg(2, ARBoolean.get()); + if (value == null) return; + Faction faction = this.arg(3, ARFaction.get(), msenderFaction); + if (faction == null) return; + + // Do the sender have the right to change perms for this faction? + if ( ! MPerm.getPermPerms().has(msender, faction, true)) return; + + // Is this perm editable? + if ( ! msender.isUsingAdminMode() && ! perm.isEditable()) + { + msg("The perm %s is not editable.", perm.getName()); + return; + } + + // No change + if (faction.getPermitted(perm).contains(rel) == value) + { + msg("%s already has %s set to %s for %s.", faction.describeTo(msender), perm.getDesc(true, false), Txt.parse(value ? "YES" : "NOO"), rel.getColor() + rel.getDescPlayerMany()); + return; + } + + // Apply + faction.setRelationPermitted(perm, rel, value); + + // The following is to make sure the leader always has the right to change perms if that is our goal. + if (perm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains(Rel.LEADER)) + { + faction.setRelationPermitted(MPerm.getPermPerms(), Rel.LEADER, true); + } + + // Create messages + List messages = new ArrayList(); + + // Inform sender + messages.add(Txt.titleize("Perm for " + faction.describeTo(msender, true))); + messages.add(MPerm.getStateHeaders()); + messages.add(Txt.parse(perm.getStateInfo(faction.getPermitted(perm), true))); + sendMessage(messages); + + // Inform faction (their message is slighly different) + List recipients = faction.getMPlayers(); + recipients.remove(msender); + + for (MPlayer recipient : recipients) + { + messages.add(0, Txt.parse("%s set a perm for %s.", msender.describeTo(recipient, true), faction.describeTo(recipient, true))); + recipient.sendMessage(messages); + } + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java new file mode 100644 index 00000000..daa59634 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java @@ -0,0 +1,80 @@ +package com.massivecraft.factions.cmd; + +import java.util.ArrayList; +import java.util.List; + +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; +import com.massivecraft.factions.cmd.arg.ARMPerm; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.cmd.arg.ARList; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsPermShow extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermShow() + { + // Aliases + this.addAliases("s", "show"); + + // Args + this.addOptionalArg("faction", "you"); + this.addOptionalArg("perms", "all"); + this.setErrorOnToManyArgs(false); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.PERM_SHOW.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // Arg: Faction + Faction faction = this.arg(0, ARFaction.get(), msenderFaction); + if (faction == null) return; + + List perms = new ArrayList(); + + // Case: Show All + if ( ! this.argIsSet(1) || "all".equalsIgnoreCase(this.arg(1))) + { + for (MPerm mperm : MPerm.getAll()) + { + if ( ! mperm.isVisible() && ! msender.isUsingAdminMode()) continue; + perms.add(mperm); + } + } + // Case: Show Some + else + { + // Arg perm. Maybe we should use ARSet but that is currently buggy. + List mperms = this.arg(this.argConcatFrom(1), ARList.get(ARMPerm.get())); + if (mperms == null) return; + perms.addAll(mperms); + } + + // Create messages + List messages = new ArrayList(); + + messages.add(Txt.titleize("Perm for " + faction.describeTo(msender, true))); + messages.add(MPerm.getStateHeaders()); + for (MPerm mperm : perms) + { + messages.add(Txt.parse(mperm.getStateInfo(faction.getPermitted(mperm), true))); + } + + // Send messages + sendMessage(messages); + } + +} diff --git a/src/com/massivecraft/factions/entity/MFlag.java b/src/com/massivecraft/factions/entity/MFlag.java index 2a36b8b2..59cc1bf4 100644 --- a/src/com/massivecraft/factions/entity/MFlag.java +++ b/src/com/massivecraft/factions/entity/MFlag.java @@ -83,9 +83,9 @@ public class MFlag extends Entity implements Prioritized, Registerable public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); } public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); } public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); } - public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friends can hurt eachother in this territory.", "Friends can NOT hurt eachother in this territory.", false, false, true); } + public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); } public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); } - public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions can occur if faction is offline.", "Explosions can NOT occur if faction is offline.", false, false, true); } + public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions if faction is offline.", "No explosions if faction is offline.", false, false, true); } public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); } public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory", "Endermen can NOT grief in this territory.", false, false, true); } public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); } diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index ec4aa373..59e13108 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -1,5 +1,6 @@ package com.massivecraft.factions.entity; +import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -297,6 +298,41 @@ public class MPerm extends Entity implements Prioritized, Registerable return ret; } + public String getDesc(boolean withName, boolean withDesc) + { + List parts = new ArrayList(); + + if (withName) + { + String nameFormat; + if ( ! this.isVisible()) + { + nameFormat = "%s"; + } + else if (this.isEditable()) + { + nameFormat = "%s"; + } + else + { + nameFormat = "%s"; + } + String name = this.getName(); + String nameDesc = Txt.parse(nameFormat, name); + parts.add(nameDesc); + } + + if (withDesc) + { + String desc = this.getDesc(); + + String descDesc = Txt.parse("%s", desc); + parts.add(descDesc); + } + + return Txt.implode(parts, " "); + } + public boolean has(Faction faction, Faction hostFaction) { // Null Check