F perm viewall
This command allows someone to see all the perms held by a rank/rel/player/faction
This commit is contained in:
parent
1dd2356c0f
commit
96989ee653
@ -64,6 +64,7 @@ permissions:
|
||||
factions.perm.set: {description: set perms, default: false}
|
||||
factions.perm.show: {description: show who has perm, default: false}
|
||||
factions.perm.view: {description: view perms given to, default: false}
|
||||
factions.perm.viewall: {description: view all perms held by, default: false}
|
||||
factions.player: {description: show player information}
|
||||
factions.powerboost: {description: manage powerboost, default: false}
|
||||
factions.powerboost.faction: {description: show faction powerboost, default: false}
|
||||
@ -163,6 +164,7 @@ permissions:
|
||||
factions.perm.set: true
|
||||
factions.perm.show: true
|
||||
factions.perm.view: true
|
||||
factions.perm.viewall: true
|
||||
factions.player: true
|
||||
factions.powerboost: true
|
||||
factions.powerboost.faction: true
|
||||
@ -285,6 +287,7 @@ permissions:
|
||||
factions.perm.set: true
|
||||
factions.perm.show: true
|
||||
factions.perm.view: true
|
||||
factions.perm.viewall: true
|
||||
factions.player: true
|
||||
factions.promote: true
|
||||
factions.powerboost: true
|
||||
|
@ -59,6 +59,7 @@ public enum Perm implements Identified
|
||||
PERM_SET,
|
||||
PERM_SHOW,
|
||||
PERM_VIEW,
|
||||
PERM_VIEWALL,
|
||||
PLAYER,
|
||||
POWERBOOST,
|
||||
POWERBOOST_PLAYER,
|
||||
|
@ -9,6 +9,7 @@ public class CmdFactionsPerm extends FactionsCommand
|
||||
CmdFactionsPermList cmdFactionsPermList = new CmdFactionsPermList();
|
||||
CmdFactionsPermShow cmdFactionsPermShow = new CmdFactionsPermShow();
|
||||
CmdFactionsPermView cmdFactionsPermView = new CmdFactionsPermView();
|
||||
CmdFactionsPermViewall cmdFactionsPermViewall = new CmdFactionsPermViewall();
|
||||
CmdFactionsPermSet cmdFactionsPermSet = new CmdFactionsPermSet();
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class CmdFactionsPermSet extends FactionsCommand
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeMPerm.get(), "perm");
|
||||
this.addParameter(TypeMPermable.get(), "relation");
|
||||
this.addParameter(TypeMPermable.get(), "rank/rel/player/faction");
|
||||
this.addParameter(TypeBooleanYes.get(), "yes/no");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
}
|
||||
|
103
src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java
Normal file
103
src/com/massivecraft/factions/cmd/CmdFactionsPermViewall.java
Normal file
@ -0,0 +1,103 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPermable;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPerm.MPermable;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CmdFactionsPermViewall extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPermViewall()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeMPermable.get(), "rank/rel/player/faction");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Arg: Faction
|
||||
Faction faction = this.readArgAt(1, msenderFaction);
|
||||
var permableType = TypeMPermable.get(faction);
|
||||
MPerm.MPermable permable = permableType.read(this.argAt(0), sender);
|
||||
|
||||
// Self check
|
||||
if (permable == faction)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>A faction can't have perms for itself.");
|
||||
}
|
||||
|
||||
// Create list of all applicable permables
|
||||
var permables = new MassiveList<MPermable>();
|
||||
permables.add(permable);
|
||||
|
||||
if (permable instanceof MPlayer)
|
||||
{
|
||||
MPlayer mplayer = (MPlayer) permable;
|
||||
permables.add(mplayer.getFaction());
|
||||
permables.add(mplayer.getRank());
|
||||
permables.add(faction.getRelationTo(mplayer));
|
||||
}
|
||||
if (permable instanceof Faction)
|
||||
{
|
||||
Faction faction1 = (Faction) permable;
|
||||
permables.add(faction.getRelationTo(faction1));
|
||||
}
|
||||
if (permable instanceof Rank && !faction.hasRank((Rank) permable))
|
||||
{
|
||||
Rank rank = (Rank) permable;
|
||||
Faction faction1 = rank.getFaction();
|
||||
permables.add(faction1);
|
||||
permables.add(faction.getRelationTo(faction1));
|
||||
}
|
||||
|
||||
// Find the perms they have
|
||||
var perms = new MassiveList<MPerm>();
|
||||
|
||||
perm:
|
||||
for (var mperm : MPerm.getAll())
|
||||
{
|
||||
String mpermId = mperm.getId();
|
||||
permable:
|
||||
for (var mpa : permables)
|
||||
{
|
||||
if (!faction.isPermitted(mpa.getId(), mperm.getId())) continue permable;
|
||||
perms.add(mperm);
|
||||
continue perm;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (perms.isEmpty())
|
||||
{
|
||||
msg("<i>In <reset>%s <reset>%s <i>has <b>no permissions<i>.", faction.describeTo(msender), permable.getDisplayName(sender));
|
||||
}
|
||||
else
|
||||
{
|
||||
var permNames = perms.stream().map(perm -> Txt.parse("<h>") + perm.getName()).collect(Collectors.toList());
|
||||
String names = Txt.implodeCommaAnd(permNames, Txt.parse("<i>"));
|
||||
|
||||
// Create messages
|
||||
var permissionSingularPlural = permNames.size() == 1 ? "permission" : "permissions";
|
||||
msg("<i>In <reset>%s <reset>%s <i>has the %s: <reset>%s<i> either specifically granted to them or through rank, relation or faction membership.", faction.describeTo(msender), permable.getDisplayName(sender), permissionSingularPlural, names);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user