Reworked flag & perm cmd

Flag & Perm commands are now parent commands, and not so awkward.
This commit is contained in:
Magnus Ulf 2015-01-09 22:36:12 +01:00 committed by Olof Larsson
parent d6d5cb325d
commit afc45fea13
12 changed files with 691 additions and 325 deletions

View File

@ -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

View File

@ -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);
}
}

View File

@ -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("<b>The flag <h>%s <b>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("<h>%s <i>set a flag for <h>%s", msender.describeTo(msender, true), faction.describeTo(msender, true));
msg(stateInfo);
}
faction.msg("<h>%s <i>set a flag for <h>%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));
}
}

View File

@ -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<String> messages = new ArrayList<String>();
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));
}
}

View File

@ -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("<b>The flag <h>%s <b>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 <i>already has %s <i>set to %s<i>.", 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("<h>%s <i>set a flag for <h>%s<i>.", msender.describeTo(msender, true), faction.describeTo(msender, true));
sendMessage(stateInfo);
}
faction.msg("<h>%s <i>set a flag for <h>%s<i>.", msender.describeTo(faction, true), faction.describeTo(faction, true));
faction.sendMessage(stateInfo);
}
}

View File

@ -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<MFlag> flags = new ArrayList<MFlag>();
// 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<MFlag> mflags = this.arg(this.argConcatFrom(1), ARList.get(ARMFlag.get()));
if (mflags == null) return;
flags.addAll(mflags);
}
// Create messages
List<String> messages = new ArrayList<String>();
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);
}
}

View File

@ -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("<b>The perm <h>%s <b>is not editable.", mperm.getName());
return;
}
// Arg: Rel
Rel rel = this.arg(2, ARRel.get());
if (rel == null) return;
if ( ! this.argIsSet(3))
{
msg("<b>Should <h>%s <b>have the <h>%s <b>permission or not?\nYou must <h>add \"yes\" or \"no\" <b>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));
}
}

View File

@ -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<String> messages = new ArrayList<String>();
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));
}
}

View File

@ -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("<b>The perm <h>%s <b>is not editable.", perm.getName());
return;
}
// No change
if (faction.getPermitted(perm).contains(rel) == value)
{
msg("%s <i>already has %s <i>set to %s <i>for %s<i>.", faction.describeTo(msender), perm.getDesc(true, false), Txt.parse(value ? "<g>YES" : "<b>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<String> messages = new ArrayList<String>();
// 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<MPlayer> recipients = faction.getMPlayers();
recipients.remove(msender);
for (MPlayer recipient : recipients)
{
messages.add(0, Txt.parse("<h>%s <i>set a perm for <h>%s<i>.", msender.describeTo(recipient, true), faction.describeTo(recipient, true)));
recipient.sendMessage(messages);
}
}
}

View File

@ -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<MPerm> perms = new ArrayList<MPerm>();
// 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<MPerm> mperms = this.arg(this.argConcatFrom(1), ARList.get(ARMPerm.get()));
if (mperms == null) return;
perms.addAll(mperms);
}
// Create messages
List<String> messages = new ArrayList<String>();
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);
}
}

View File

@ -83,9 +83,9 @@ public class MFlag extends Entity<MFlag> 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); }

View File

@ -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<MPerm> implements Prioritized, Registerable
return ret;
}
public String getDesc(boolean withName, boolean withDesc)
{
List<String> parts = new ArrayList<String>();
if (withName)
{
String nameFormat;
if ( ! this.isVisible())
{
nameFormat = "<silver>%s";
}
else if (this.isEditable())
{
nameFormat = "<pink>%s";
}
else
{
nameFormat = "<aqua>%s";
}
String name = this.getName();
String nameDesc = Txt.parse(nameFormat, name);
parts.add(nameDesc);
}
if (withDesc)
{
String desc = this.getDesc();
String descDesc = Txt.parse("<i>%s", desc);
parts.add(descDesc);
}
return Txt.implode(parts, " ");
}
public boolean has(Faction faction, Faction hostFaction)
{
// Null Check