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.expansions: {description: list expansions, default: false}
factions.faction: {description: show faction information, default: false} factions.faction: {description: show faction information, default: false}
factions.flag: {description: manage faction flags, 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.home: {description: teleport to faction home, default: false}
factions.invite: {description: manage invites, default: false} factions.invite: {description: manage invites, default: false}
factions.invite.list: {description: list invited players, default: false} factions.invite.list: {description: list invited players, default: false}
@ -52,6 +55,9 @@ permissions:
factions.motd: {description: faction motd, default: false} factions.motd: {description: faction motd, default: false}
factions.open: {description: set if invitation is required to join, default: false} factions.open: {description: set if invitation is required to join, default: false}
factions.perm: {description: change faction permissions, 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.player: {description: show player information}
factions.powerboost: {description: set powerboost, default: false} factions.powerboost: {description: set powerboost, default: false}
factions.rank: {description: manage/show ranks, default: false} factions.rank: {description: manage/show ranks, default: false}
@ -98,6 +104,9 @@ permissions:
factions.expansions: true factions.expansions: true
factions.faction: true factions.faction: true
factions.flag: true factions.flag: true
factions.flag.list: true
factions.flag.set: true
factions.flag.show: true
factions.home: true factions.home: true
factions.invite: true factions.invite: true
factions.invite.list: true factions.invite.list: true
@ -126,6 +135,9 @@ permissions:
factions.officer.any: true factions.officer.any: true
factions.open: true factions.open: true
factions.perm: true factions.perm: true
factions.perm.list: true
factions.perm.set: true
factions.perm.show: true
factions.player: true factions.player: true
factions.powerboost: true factions.powerboost: true
factions.promote: true factions.promote: true
@ -195,6 +207,9 @@ permissions:
factions.expansions: true factions.expansions: true
factions.faction: true factions.faction: true
factions.flag: true factions.flag: true
factions.flag.list: true
factions.flag.set: true
factions.flag.show: true
factions.home: true factions.home: true
factions.invite: true factions.invite: true
factions.invite.list: true factions.invite.list: true
@ -218,6 +233,9 @@ permissions:
factions.officer: true factions.officer: true
factions.open: true factions.open: true
factions.perm: true factions.perm: true
factions.perm.list: true
factions.perm.set: true
factions.perm.show: true
factions.player: true factions.player: true
factions.promote: true factions.promote: true
factions.rank: true factions.rank: true

View File

@ -1,110 +1,116 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
import com.massivecraft.massivecore.util.PermUtil; import com.massivecraft.massivecore.util.PermUtil;
public enum Perm public enum Perm
{ {
// -------------------------------------------- // // -------------------------------------------- //
// ENUM // ENUM
// -------------------------------------------- // // -------------------------------------------- //
ACCESS("access"), ACCESS("access"),
ACCESS_VIEW("access.view"), ACCESS_VIEW("access.view"),
ACCESS_PLAYER("access.player"), ACCESS_PLAYER("access.player"),
ACCESS_FACTION("access.faction"), ACCESS_FACTION("access.faction"),
ADMIN("admin"), ADMIN("admin"),
CLAIM("claim"), CLAIM("claim"),
CLAIM_ONE("claim.one"), CLAIM_ONE("claim.one"),
CLAIM_AUTO("claim.auto"), CLAIM_AUTO("claim.auto"),
CLAIM_FILL("claim.fill"), CLAIM_FILL("claim.fill"),
CLAIM_SQUARE("claim.square"), CLAIM_SQUARE("claim.square"),
CLAIM_CIRCLE("claim.circle"), CLAIM_CIRCLE("claim.circle"),
CLAIM_ALL("claim.all"), CLAIM_ALL("claim.all"),
CREATE("create"), CREATE("create"),
DESCRIPTION("description"), DESCRIPTION("description"),
DISBAND("disband"), DISBAND("disband"),
EXPANSIONS("expansions"), EXPANSIONS("expansions"),
FACTION("faction"), FACTION("faction"),
FLAG("flag"), FLAG("flag"),
HOME("home"), FLAG_LIST("flag.list"),
INVITE("invite"), FLAG_SET("flag.set"),
INVITE_LIST("invite.list"), FLAG_SHOW("flag.show"),
INVITE_LIST_OTHER("invite.list.other"), HOME("home"),
INVITE_ADD("invite.add"), INVITE("invite"),
INVITE_REMOVE("invite.remove"), INVITE_LIST("invite.list"),
JOIN("join"), INVITE_LIST_OTHER("invite.list.other"),
JOIN_ANY("join.any"), INVITE_ADD("invite.add"),
JOIN_OTHERS("join.others"), INVITE_REMOVE("invite.remove"),
KICK("kick"), JOIN("join"),
LEAVE("leave"), JOIN_ANY("join.any"),
LIST("list"), JOIN_OTHERS("join.others"),
MAP("map"), KICK("kick"),
MONEY("money"), LEAVE("leave"),
MONEY_BALANCE("money.balance"), LIST("list"),
MONEY_BALANCE_ANY("money.balance.any"), MAP("map"),
MONEY_DEPOSIT("money.deposit"), MONEY("money"),
MONEY_F2F("money.f2f"), MONEY_BALANCE("money.balance"),
MONEY_F2P("money.f2p"), MONEY_BALANCE_ANY("money.balance.any"),
MONEY_P2F("money.p2f"), MONEY_DEPOSIT("money.deposit"),
MONEY_WITHDRAW("money.withdraw"), MONEY_F2F("money.f2f"),
MOTD("motd"), MONEY_F2P("money.f2p"),
OPEN("open"), MONEY_P2F("money.p2f"),
PERM("perm"), MONEY_WITHDRAW("money.withdraw"),
PLAYER("player"), MOTD("motd"),
POWERBOOST("powerboost"), OPEN("open"),
RANK("rank"), PERM("perm"),
RANK_SHOW("rank.show"), PERM_LIST("perm.list"),
RANK_ACTION("rank.action"), PERM_SET("perm.set"),
RELATION("relation"), PERM_SHOW("perm.show"),
SEECHUNK("seechunk"), PLAYER("player"),
SEECHUNKOLD("seechunkold"), POWERBOOST("powerboost"),
RANK("rank"),
RANK_SHOW("rank.show"),
RANK_ACTION("rank.action"),
RELATION("relation"),
SEECHUNK("seechunk"),
SEECHUNKOLD("seechunkold"),
SETHOME("sethome"), SETHOME("sethome"),
SETPOWER("setpower"), SETPOWER("setpower"),
NAME("name"), NAME("name"),
TITLE("title"), TITLE("title"),
TITLE_COLOR("title.color"), TITLE_COLOR("title.color"),
UNCLAIM("unclaim"), UNCLAIM("unclaim"),
UNCLAIM_ONE("unclaim.one"), UNCLAIM_ONE("unclaim.one"),
UNCLAIM_AUTO("unclaim.auto"), UNCLAIM_AUTO("unclaim.auto"),
UNCLAIM_FILL("unclaim.fill"), UNCLAIM_FILL("unclaim.fill"),
UNCLAIM_SQUARE("unclaim.square"), UNCLAIM_SQUARE("unclaim.square"),
UNCLAIM_CIRCLE("unclaim.circle"), UNCLAIM_CIRCLE("unclaim.circle"),
UNCLAIM_ALL("unclaim.all"), UNCLAIM_ALL("unclaim.all"),
UNSETHOME("unsethome"), UNSETHOME("unsethome"),
VERSION("version"), VERSION("version"),
// END OF LIST // END OF LIST
; ;
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
public final String node; public final String node;
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
Perm(final String node) Perm(final String node)
{ {
this.node = "factions."+node; this.node = "factions."+node;
} }
// -------------------------------------------- // // -------------------------------------------- //
// HAS // HAS
// -------------------------------------------- // // -------------------------------------------- //
public boolean has(Permissible permissible, boolean informSenderIfNot) public boolean has(Permissible permissible, boolean informSenderIfNot)
{ {
return PermUtil.has(permissible, this.node, informSenderIfNot); return PermUtil.has(permissible, this.node, informSenderIfNot);
} }
public boolean has(Permissible permissible) public boolean has(Permissible permissible)
{ {
return has(permissible, false); return has(permissible, false);
} }
} }

View File

@ -1,104 +1,34 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARMFlag; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction; public class CmdFactionsFlag extends FactionsCommand
import com.massivecraft.factions.entity.MFlag; {
import com.massivecraft.factions.entity.MPerm; // -------------------------------------------- //
import com.massivecraft.factions.event.EventFactionsFlagChange; // FIELDS
import com.massivecraft.massivecore.cmd.arg.ARBoolean; // -------------------------------------------- //
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.util.Txt; CmdFactionsFlagList cmdFactionsFlagList = new CmdFactionsFlagList();
CmdFactionsFlagShow cmdFactionsFlagShow = new CmdFactionsFlagShow();
public class CmdFactionsFlag extends FactionsCommand CmdFactionsFlagSet cmdFactionsFlagSet = new CmdFactionsFlagSet();
{
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CmdFactionsFlag() public CmdFactionsFlag()
{ {
// Aliases // Aliases
this.addAliases("flag"); this.addAliases("flag");
// Args // Subcommands
this.addOptionalArg("faction", "you"); this.addSubCommand(this.cmdFactionsFlagList);
this.addOptionalArg("flag", "all"); this.addSubCommand(this.cmdFactionsFlagShow);
this.addOptionalArg("yes/no", "read"); this.addSubCommand(this.cmdFactionsFlagSet);
// Requirements // Requirements
this.addRequirements(ReqHasPerm.get(Perm.FLAG.node)); 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);
}
}

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; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.factions.cmd.arg.ARMPerm;
import com.massivecraft.factions.cmd.arg.ARFaction; public class CmdFactionsPerm extends FactionsCommand
import com.massivecraft.factions.cmd.arg.ARRel; {
import com.massivecraft.factions.entity.Faction; // -------------------------------------------- //
import com.massivecraft.factions.entity.MPerm; // FIELDS
import com.massivecraft.massivecore.cmd.arg.ARBoolean; // -------------------------------------------- //
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.util.Txt; CmdFactionsPermList cmdFactionsPermList = new CmdFactionsPermList();
CmdFactionsPermShow cmdFactionsPermShow = new CmdFactionsPermShow();
public class CmdFactionsPerm extends FactionsCommand CmdFactionsPermSet cmdFactionsPermSet = new CmdFactionsPermSet();
{
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CmdFactionsPerm() public CmdFactionsPerm()
{ {
// Aliases // Aliases
this.addAliases("perm"); this.addAliases("perm");
// Args // Subcommands
this.addOptionalArg("faction", "you"); this.addSubCommand(this.cmdFactionsPermList);
this.addOptionalArg("perm", "all"); this.addSubCommand(this.cmdFactionsPermShow);
this.addOptionalArg("relation", "read"); this.addSubCommand(this.cmdFactionsPermSet);
this.addOptionalArg("yes/no", "read");
this.setErrorOnToManyArgs(false); // Requirements
this.addRequirements(ReqHasPerm.get(Perm.PERM.node));
// 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));
}
}

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 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 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 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 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 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 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); } 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; package com.massivecraft.factions.entity;
import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -297,6 +298,41 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable
return ret; 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) public boolean has(Faction faction, Faction hostFaction)
{ {
// Null Check // Null Check