Pass 1 at reworking the Territory Access system.
This commit is contained in:
@@ -1,111 +1,36 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.mcore.cmd.HelpCommand;
|
||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.mcore.ps.PS;
|
||||
import com.massivecraft.mcore.util.Txt;
|
||||
|
||||
|
||||
public class CmdFactionsAccess extends FCommand
|
||||
{
|
||||
public CmdFactionsAccessView cmdFactionsAccessView = new CmdFactionsAccessView();
|
||||
public CmdFactionsAccessPlayer cmdFactionsAccessPlayer = new CmdFactionsAccessPlayer();
|
||||
public CmdFactionsAccessFaction cmdFactionsAccessFaction = new CmdFactionsAccessFaction();
|
||||
|
||||
public CmdFactionsAccess()
|
||||
{
|
||||
this.addAliases("access");
|
||||
|
||||
this.addOptionalArg("view|p|player|f|faction", "view");
|
||||
this.addOptionalArg("name", "you");
|
||||
|
||||
this.setDesc("view or grant access for the claimed territory you are in");
|
||||
|
||||
// TODO: Missing permission node here!?
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ACCESS.node));
|
||||
|
||||
this.addSubCommand(this.cmdFactionsAccessView);
|
||||
this.addSubCommand(this.cmdFactionsAccessPlayer);
|
||||
this.addSubCommand(this.cmdFactionsAccessFaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
String type = this.arg(0);
|
||||
type = (type == null) ? "" : type.toLowerCase();
|
||||
PS chunk = PS.valueOf(me).getChunk(true);
|
||||
|
||||
TerritoryAccess territory = BoardColls.get().getTerritoryAccessAt(chunk);
|
||||
Faction locFaction = BoardColls.get().getFactionAt(chunk);
|
||||
boolean accessAny = Perm.ACCESS_ANY.has(sender, false);
|
||||
|
||||
if (type.isEmpty() || type.equals("view"))
|
||||
{
|
||||
if ( ! accessAny && ! Perm.ACCESS_VIEW.has(sender, true)) return;
|
||||
if ( ! accessAny && ! territory.doesHostFactionMatch(usender))
|
||||
{
|
||||
msg("<b>This territory isn't controlled by your faction, so you can't view the access list.");
|
||||
return;
|
||||
}
|
||||
showAccessList(territory, locFaction);
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! accessAny && ! Perm.ACCESS.has(sender, true)) return;
|
||||
if ( ! accessAny && ! FPerm.ACCESS.has(usender, locFaction, true)) return;
|
||||
|
||||
boolean doPlayer = true;
|
||||
if (type.equals("f") || type.equals("faction"))
|
||||
{
|
||||
doPlayer = false;
|
||||
}
|
||||
else if (!type.equals("p") && !type.equals("player"))
|
||||
{
|
||||
msg("<b>You must specify \"p\" or \"player\" to indicate a player or \"f\" or \"faction\" to indicate a faction.");
|
||||
msg("<b>ex. /f access p SomePlayer -or- /f access f SomeFaction");
|
||||
msg("<b>Alternately, you can use the command with nothing (or \"view\") specified to simply view the access list.");
|
||||
return;
|
||||
}
|
||||
|
||||
String target = "";
|
||||
boolean added;
|
||||
|
||||
if (doPlayer)
|
||||
{
|
||||
UPlayer targetPlayer = this.arg(1, ARUPlayer.getStartAny(usender), usender);
|
||||
if (targetPlayer == null) return;
|
||||
added = territory.toggleFPlayer(targetPlayer);
|
||||
target = "Player \""+targetPlayer.getName()+"\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
Faction targetFaction = this.arg(1, ARFaction.get(usenderFaction), usenderFaction);
|
||||
if (targetFaction == null) return;
|
||||
added = territory.toggleFaction(targetFaction);
|
||||
target = "Faction \""+targetFaction.getName()+"\"";
|
||||
}
|
||||
|
||||
msg("<i>%s has been %s<i> the access list for this territory.", target, Txt.parse(added ? "<lime>added to" : "<rose>removed from"));
|
||||
showAccessList(territory, locFaction);
|
||||
}
|
||||
|
||||
private void showAccessList(TerritoryAccess territory, Faction locFaction)
|
||||
{
|
||||
msg("<i>Host faction %s <i>has %s<i> in this territory.", locFaction.getName(), Txt.parse(territory.isHostFactionAllowed() ? "<lime>normal access" : "<rose>restricted access"));
|
||||
|
||||
String players = territory.fplayerList();
|
||||
String factions = territory.factionList(locFaction);
|
||||
|
||||
if (factions.isEmpty())
|
||||
msg("No factions have been explicitly granted access.");
|
||||
else
|
||||
msg("Factions with explicit access: " + factions);
|
||||
|
||||
if (players.isEmpty())
|
||||
msg("No players have been explicitly granted access.");
|
||||
else
|
||||
msg("Players with explicit access: " + players);
|
||||
this.getCommandChain().add(this);
|
||||
HelpCommand.getInstance().execute(this.sender, this.args, this.commandChain);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,61 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.mcore.ps.PS;
|
||||
import com.massivecraft.mcore.ps.PSFormatHumanSpace;
|
||||
import com.massivecraft.mcore.util.Txt;
|
||||
|
||||
|
||||
public abstract class CmdFactionsAccessAbstract extends FCommand
|
||||
{
|
||||
public PS chunk;
|
||||
public TerritoryAccess ta;
|
||||
public Faction hostFaction;
|
||||
|
||||
public CmdFactionsAccessAbstract()
|
||||
{
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqIsPlayer.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
chunk = PS.valueOf(me).getChunk(true);
|
||||
ta = BoardColls.get().getTerritoryAccessAt(chunk);
|
||||
hostFaction = ta.getHostFaction(usender);
|
||||
|
||||
this.innerPerform();
|
||||
}
|
||||
|
||||
public abstract void innerPerform();
|
||||
|
||||
public void sendAccessInfo()
|
||||
{
|
||||
sendMessage(Txt.titleize("Access at " + chunk.toString(PSFormatHumanSpace.get())));
|
||||
msg("<k>Host Faction: %s", hostFaction.describeTo(usender, true));
|
||||
msg("<k>Host Faction Allowed: %s", ta.isHostFactionAllowed() ? Txt.parse("<lime>TRUE") : Txt.parse("<rose>FALSE"));
|
||||
msg("<k>Granted Players: %s", describeRelationParticipators(ta.getGrantedUPlayers(usender), usender));
|
||||
msg("<k>Granted Factions: %s", describeRelationParticipators(ta.getGrantedFactions(usender), usender));
|
||||
}
|
||||
|
||||
public static String describeRelationParticipators(Collection<? extends RelationParticipator> relationParticipators, RelationParticipator observer)
|
||||
{
|
||||
if (relationParticipators.size() == 0) return Txt.parse("<silver><em>none");
|
||||
List<String> descriptions = new ArrayList<String>();
|
||||
for (RelationParticipator relationParticipator : relationParticipators)
|
||||
{
|
||||
descriptions.add(relationParticipator.describeTo(observer));
|
||||
}
|
||||
return Txt.implodeCommaAnd(descriptions, Txt.parse("<i>, "), Txt.parse(" <i>and "));
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.mcore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsAccessFaction extends CmdFactionsAccessAbstract
|
||||
{
|
||||
public CmdFactionsAccessFaction()
|
||||
{
|
||||
this.addAliases("f", "faction");
|
||||
|
||||
this.addRequiredArg("faction");
|
||||
this.addOptionalArg("yes/no", "toggle");
|
||||
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ACCESS_FACTION.node));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void innerPerform()
|
||||
{
|
||||
// Args
|
||||
Faction faction = this.arg(0, ARFaction.get(usender));
|
||||
if (faction == null) return;
|
||||
|
||||
Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isFactionIdGranted(faction.getId()));
|
||||
if (newValue == null) return;
|
||||
|
||||
// FPerm
|
||||
if (FPerm.ACCESS.has(usender, hostFaction, true)) return;
|
||||
|
||||
// Apply
|
||||
ta = ta.withFactionId(faction.getId(), newValue);
|
||||
BoardColls.get().setTerritoryAccessAt(chunk, ta);
|
||||
|
||||
// Inform
|
||||
this.sendAccessInfo();
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARUPlayer;
|
||||
import com.massivecraft.factions.entity.BoardColls;
|
||||
import com.massivecraft.factions.entity.UPlayer;
|
||||
import com.massivecraft.mcore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsAccessPlayer extends CmdFactionsAccessAbstract
|
||||
{
|
||||
public CmdFactionsAccessPlayer()
|
||||
{
|
||||
this.addAliases("p", "player");
|
||||
|
||||
this.addRequiredArg("player");
|
||||
this.addOptionalArg("yes/no", "toggle");
|
||||
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ACCESS_PLAYER.node));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void innerPerform()
|
||||
{
|
||||
// Args
|
||||
UPlayer uplayer = this.arg(0, ARUPlayer.getStartAny(usender));
|
||||
if (uplayer == null) return;
|
||||
|
||||
Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isPlayerIdGranted(uplayer.getId()));
|
||||
if (newValue == null) return;
|
||||
|
||||
// FPerm
|
||||
if (FPerm.ACCESS.has(usender, hostFaction, true)) return;
|
||||
|
||||
// Apply
|
||||
ta = ta.withPlayerId(uplayer.getId(), newValue);
|
||||
BoardColls.get().setTerritoryAccessAt(chunk, ta);
|
||||
|
||||
// Inform
|
||||
this.sendAccessInfo();
|
||||
}
|
||||
}
|
21
src/com/massivecraft/factions/cmd/CmdFactionsAccessView.java
Normal file
21
src/com/massivecraft/factions/cmd/CmdFactionsAccessView.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||
|
||||
|
||||
public class CmdFactionsAccessView extends CmdFactionsAccessAbstract
|
||||
{
|
||||
public CmdFactionsAccessView()
|
||||
{
|
||||
this.addAliases("v", "view");
|
||||
|
||||
this.addRequirements(ReqHasPerm.get(Perm.ACCESS_VIEW.node));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void innerPerform()
|
||||
{
|
||||
this.sendAccessInfo();
|
||||
}
|
||||
}
|
@@ -1,7 +1,10 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.mcore.cmd.HelpCommand;
|
||||
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
||||
|
||||
public class CmdFactionsMoney extends FCommand
|
||||
{
|
||||
@@ -16,10 +19,9 @@ public class CmdFactionsMoney extends FCommand
|
||||
{
|
||||
this.addAliases("money");
|
||||
|
||||
this.setDesc("faction money commands");
|
||||
this.setHelp("The faction money commands.");
|
||||
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY.node));
|
||||
|
||||
this.addSubCommand(this.cmdMoneyBalance);
|
||||
this.addSubCommand(this.cmdMoneyDeposit);
|
||||
|
@@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.req.ReqBankCommandsEnabled;
|
||||
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.integration.Econ;
|
||||
import com.massivecraft.factions.Perm;
|
||||
@@ -15,6 +16,7 @@ public class CmdFactionsMoneyBalance extends FCommand
|
||||
|
||||
this.addOptionalArg("faction", "you");
|
||||
|
||||
this.addRequirements(ReqFactionsEnabled.get());
|
||||
this.addRequirements(ReqHasPerm.get(Perm.MONEY_BALANCE.node));
|
||||
this.addRequirements(ReqBankCommandsEnabled.get());
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ public class ARFaction extends ArgReaderAbstract<Faction>
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static ARFaction get(Object o) { return new ARFaction(FactionColls.get().get(o)); }
|
||||
public static ARFaction get(Object universe) { return new ARFaction(FactionColls.get().get(universe)); }
|
||||
private ARFaction(FactionColl coll)
|
||||
{
|
||||
this.coll = coll;
|
||||
|
Reference in New Issue
Block a user