mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-09-27 13:32:38 +02:00
Add new Perm system.
This commit is contained in:
parent
fa4b850b01
commit
4d5152d207
21
plugin.yml
21
plugin.yml
@ -14,6 +14,10 @@ permissions:
|
||||
factions.access.faction: {description: grant faction access, with the proper fperm, default: false}
|
||||
factions.access.player: {description: grant player access, with the proper fperm, default: false}
|
||||
factions.access.view: {description: view access, default: false}
|
||||
factions.ban: {description: manage faction bans, default: false}
|
||||
factions.ban.add: {description: add faction bans, default: false}
|
||||
factions.ban.list: {description: list faction bans, default: false}
|
||||
factions.ban.remove: {description: remove faction bans, default: false}
|
||||
factions.override: {description: enable override mode, default: false}
|
||||
factions.basecommand: {description: use factions base command, default: false}
|
||||
factions.claim: {description: claim faction territory, default: false}
|
||||
@ -55,9 +59,12 @@ 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.add: {description: add perm to selector, default: false}
|
||||
factions.perm.copy: {description: copy perms, default: false}
|
||||
factions.perm.for: {description: list perms for a selector, 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.perm.remove: {description: remove perm from a selector, default: false}
|
||||
factions.perm.show: {description: show a perm, default: false}
|
||||
factions.player: {description: show player information}
|
||||
factions.powerboost: {description: manage powerboost, default: false}
|
||||
factions.powerboost.faction: {description: show faction powerboost, default: false}
|
||||
@ -88,6 +95,7 @@ permissions:
|
||||
factions.unclaim.all: {description: unclaim all faction land, default: false}
|
||||
factions.unsethome: {description: unset faction home, default: false}
|
||||
factions.unstuck: {description: teleport to nearest wilderness, default: false}
|
||||
factions.used: {description: set used faction, default: false}
|
||||
factions.config: {description: edit the factions config, default: false}
|
||||
factions.clean: {description: clean the factions database, default: false}
|
||||
factions.version: {description: see plugin version, default: false}
|
||||
@ -217,6 +225,10 @@ permissions:
|
||||
factions.access.player: true
|
||||
factions.access.view: true
|
||||
factions.basecommand: true
|
||||
factions.ban: true
|
||||
factions.ban.add: true
|
||||
factions.ban.list: true
|
||||
factions.ban.remove: true
|
||||
factions.claim: true
|
||||
factions.claim.one: true
|
||||
factions.claim.auto: true
|
||||
@ -257,8 +269,11 @@ permissions:
|
||||
factions.officer: true
|
||||
factions.open: true
|
||||
factions.perm: true
|
||||
factions.perm.add: true
|
||||
factions.perm.copy: true
|
||||
factions.perm.for: true
|
||||
factions.perm.list: true
|
||||
factions.perm.set: true
|
||||
factions.perm.remove: true
|
||||
factions.perm.show: true
|
||||
factions.player: true
|
||||
factions.promote: true
|
||||
|
@ -2,6 +2,6 @@ package com.massivecraft.factions;
|
||||
|
||||
import com.massivecraft.massivecore.Named;
|
||||
|
||||
public interface FactionsParticipator extends Named, EconomyParticipator, PowerBoosted
|
||||
public interface FactionsParticipator extends Named, EconomyParticipator, PowerBoosted, Selector
|
||||
{
|
||||
}
|
||||
|
@ -14,6 +14,10 @@ public enum Perm implements Identified
|
||||
ACCESS_VIEW,
|
||||
ACCESS_PLAYER,
|
||||
ACCESS_FACTION,
|
||||
BAN,
|
||||
BAN_ADD,
|
||||
BAN_LIST,
|
||||
BAN_REMOVE,
|
||||
OVERRIDE,
|
||||
BASECOMMAND,
|
||||
CLAIM,
|
||||
@ -55,8 +59,11 @@ public enum Perm implements Identified
|
||||
MOTD,
|
||||
OPEN,
|
||||
PERM,
|
||||
PERM_ADD,
|
||||
PERM_COPY,
|
||||
PERM_FOR,
|
||||
PERM_LIST,
|
||||
PERM_SET,
|
||||
PERM_REMOVE,
|
||||
PERM_SHOW,
|
||||
PLAYER,
|
||||
POWERBOOST,
|
||||
@ -88,6 +95,7 @@ public enum Perm implements Identified
|
||||
UNCLAIM_ALL,
|
||||
UNSETHOME,
|
||||
UNSTUCK,
|
||||
USED,
|
||||
CONFIG,
|
||||
CLEAN,
|
||||
VERSION,
|
||||
|
@ -9,7 +9,7 @@ import org.bukkit.ChatColor;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
public enum Rel implements Colorized, Named
|
||||
public enum Rel implements Colorized, Named, Selector
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ENUM
|
||||
@ -103,6 +103,18 @@ public enum Rel implements Colorized, Named
|
||||
return MConf.get().colorMember;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SelectorType getType()
|
||||
{
|
||||
return isRank() ? SelectorType.RANK : SelectorType.RELATION;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
8
src/com/massivecraft/factions/Selector.java
Normal file
8
src/com/massivecraft/factions/Selector.java
Normal file
@ -0,0 +1,8 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
public interface Selector
|
||||
{
|
||||
String getId();
|
||||
|
||||
SelectorType getType();
|
||||
}
|
46
src/com/massivecraft/factions/SelectorType.java
Normal file
46
src/com/massivecraft/factions/SelectorType.java
Normal file
@ -0,0 +1,46 @@
|
||||
package com.massivecraft.factions;
|
||||
|
||||
public enum SelectorType
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// ENUM
|
||||
// -------------------------------------------- //
|
||||
|
||||
PLAYER("p"),
|
||||
FACTION("f"),
|
||||
RANK("ra"),
|
||||
RELATION("re"),
|
||||
|
||||
// END OF LIST
|
||||
;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final String prefix;
|
||||
public String getPrefix() { return this.prefix; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
SelectorType(String prefix)
|
||||
{
|
||||
this.prefix = prefix + ":";
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONVENIENCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static SelectorType getFromPrefix(String arg)
|
||||
{
|
||||
for (SelectorType type : values())
|
||||
{
|
||||
if (arg.startsWith(type.getPrefix())) return type;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -59,6 +59,7 @@ public class CmdFactions extends FactionsCommand
|
||||
public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral");
|
||||
public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy");
|
||||
public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm();
|
||||
public CmdFactionsBan cmdFactionsBan = new CmdFactionsBan();
|
||||
public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag();
|
||||
public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck();
|
||||
public CmdFactionsExpansions cmdFactionsExpansions = new CmdFactionsExpansions();
|
||||
@ -70,6 +71,7 @@ public class CmdFactions extends FactionsCommand
|
||||
public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower();
|
||||
public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig();
|
||||
public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean();
|
||||
public CmdFactionsUsed cmdFactionsUsed = new CmdFactionsUsed();
|
||||
public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()).setAliases("v", "version").addRequirements(RequirementHasPerm.get(Perm.VERSION));
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
13
src/com/massivecraft/factions/cmd/CmdFactionsBan.java
Normal file
13
src/com/massivecraft/factions/cmd/CmdFactionsBan.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
public class CmdFactionsBan extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsBanList cmdFactionsBanList = new CmdFactionsBanList();
|
||||
public CmdFactionsBanAdd cmdFactionsBanAdd = new CmdFactionsBanAdd();
|
||||
public CmdFactionsBanRemove cmdFactionsBanRemove = new CmdFactionsBanRemove();
|
||||
|
||||
}
|
51
src/com/massivecraft/factions/cmd/CmdFactionsBanAdd.java
Normal file
51
src/com/massivecraft/factions/cmd/CmdFactionsBanAdd.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.cmd.req.RequirementHasMPerm;
|
||||
import com.massivecraft.factions.cmd.type.TypeSelector;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionBan;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.TypeNullable;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class CmdFactionsBanAdd extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsBanAdd()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeSelector.get(), "selector");
|
||||
this.addParameter(TypeNullable.get(TypeString.get()), "reason");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(RequirementHasMPerm.get(MPerm.getPermPerms()));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
Selector selector = this.readArg();
|
||||
String reason = this.readArg();
|
||||
Faction faction = msender.getUsedFaction();
|
||||
|
||||
// Add
|
||||
FactionBan factionBan = new FactionBan(selector, msender, reason);
|
||||
faction.getFactionBans().attach(factionBan, selector.getId());
|
||||
|
||||
// Inform
|
||||
message(mson(TypeSelector.get().getVisualMson(selector), " was banned.").color(ChatColor.YELLOW));
|
||||
if (reason != null) msg("<i>Reason: %s", reason);
|
||||
}
|
||||
|
||||
}
|
63
src/com/massivecraft/factions/cmd/CmdFactionsBanList.java
Normal file
63
src/com/massivecraft/factions/cmd/CmdFactionsBanList.java
Normal file
@ -0,0 +1,63 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.entity.FactionBan;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.cmd.type.TypeSelector;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.Parameter;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.pager.Msonifier;
|
||||
import com.massivecraft.massivecore.pager.Pager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class CmdFactionsBanList extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsBanList()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(Parameter.getPage());
|
||||
this.addParameter(TypeFaction.get(), "faction", "your");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameter
|
||||
final int page = this.readArg();
|
||||
final Faction faction = this.readArg(msenderFaction);
|
||||
final MPlayer mplayer = msender;
|
||||
final CommandSender sendee = sender;
|
||||
final TypeSelector type = TypeSelector.get();
|
||||
|
||||
// Pager create
|
||||
String title = "Faction Bans for " + faction.describeTo(mplayer);
|
||||
final Pager<FactionBan> pager = new Pager<>(this, title, page, faction.getFactionBans().getAll(), new Msonifier<FactionBan>()
|
||||
{
|
||||
@Override
|
||||
public Mson toMson(FactionBan factionBan, int index)
|
||||
{
|
||||
Mson visualSelector = type.getVisualMson(factionBan.getSelector(), sendee);
|
||||
Mson visualExecutor = TypeMPlayer.get().getVisualMson(factionBan.getExecutor(), sendee);
|
||||
Mson visualReason = TypeString.get().getVisualMson(factionBan.getReason(), sendee);
|
||||
return mson(visualSelector, " was banned by ", visualExecutor, ". Reason: ", visualReason).color(ChatColor.YELLOW);
|
||||
}
|
||||
});
|
||||
|
||||
// Pager message
|
||||
pager.messageAsync();
|
||||
}
|
||||
|
||||
}
|
47
src/com/massivecraft/factions/cmd/CmdFactionsBanRemove.java
Normal file
47
src/com/massivecraft/factions/cmd/CmdFactionsBanRemove.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.cmd.req.RequirementHasMPerm;
|
||||
import com.massivecraft.factions.cmd.type.TypeSelector;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class CmdFactionsBanRemove extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsBanRemove()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeSelector.get(), "selector");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(RequirementHasMPerm.get(MPerm.getPermPerms()));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameters
|
||||
Selector selector = this.readArg();
|
||||
Faction faction = msender.getUsedFaction();
|
||||
|
||||
// Remove
|
||||
faction.getFactionBans().detachId(selector.getId());
|
||||
|
||||
// Inform
|
||||
Mson visualSelector = TypeSelector.get().getVisualMson(selector);
|
||||
visualSelector = visualSelector.uppercaseFirst();
|
||||
message(mson(visualSelector, " was un-banned.").color(ChatColor.YELLOW));
|
||||
}
|
||||
|
||||
}
|
@ -6,8 +6,11 @@ public class CmdFactionsPerm extends FactionsCommand
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
CmdFactionsPermList cmdFactionsPermList = new CmdFactionsPermList();
|
||||
CmdFactionsPermShow cmdFactionsPermShow = new CmdFactionsPermShow();
|
||||
CmdFactionsPermSet cmdFactionsPermSet = new CmdFactionsPermSet();
|
||||
public CmdFactionsPermList cmdFactionsPermList = new CmdFactionsPermList();
|
||||
public CmdFactionsPermShow cmdFactionsPermShow = new CmdFactionsPermShow();
|
||||
public CmdFactionsPermAdd cmdFactionsPermAdd = new CmdFactionsPermAdd();
|
||||
public CmdFactionsPermRemove cmdFactionsPermRemove = new CmdFactionsPermRemove();
|
||||
public CmdFactionsPermFor cmdFactionsPermFor = new CmdFactionsPermFor();
|
||||
public CmdFactionsPermCopy cmdFactionsPermCopy = new CmdFactionsPermCopy();
|
||||
|
||||
}
|
||||
|
14
src/com/massivecraft/factions/cmd/CmdFactionsPermAdd.java
Normal file
14
src/com/massivecraft/factions/cmd/CmdFactionsPermAdd.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
public class CmdFactionsPermAdd extends CmdFactionsPermSet
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPermAdd()
|
||||
{
|
||||
super(true);
|
||||
}
|
||||
|
||||
}
|
70
src/com/massivecraft/factions/cmd/CmdFactionsPermCopy.java
Normal file
70
src/com/massivecraft/factions/cmd/CmdFactionsPermCopy.java
Normal file
@ -0,0 +1,70 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPerm;
|
||||
import com.massivecraft.factions.cmd.type.TypeSelector;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPermColl;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.TypeNullable;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class CmdFactionsPermCopy extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPermCopy()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeSelector.get(), "selectorFrom");
|
||||
this.addParameter(TypeSelector.get(), "selectorTo");
|
||||
this.addParameter(TypeNullable.get(TypeMPerm.get()), "permission", "all");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameter
|
||||
Selector selectorFrom = this.readArg();
|
||||
Selector selectorTo = this.readArg();
|
||||
MPerm mperm = this.readArg();
|
||||
|
||||
// Copy
|
||||
copyPerms(mperm, selectorFrom, selectorTo);
|
||||
|
||||
// Inform
|
||||
TypeSelector type = TypeSelector.get();
|
||||
message(mson(
|
||||
"All perms have been copied from ",
|
||||
type.getVisualMson(selectorFrom),
|
||||
" to ",
|
||||
type.getVisualMson(selectorTo),
|
||||
Mson.DOT
|
||||
).color(ChatColor.GREEN));
|
||||
}
|
||||
|
||||
private void copyPerms(MPerm mperm, Selector selectorFrom, Selector selectorTo)
|
||||
{
|
||||
Faction faction = msender.getUsedFaction();
|
||||
Collection<MPerm> perms = mperm != null ? Collections.singleton(mperm) : MPermColl.get().getAll();
|
||||
|
||||
boolean permitted;
|
||||
for (MPerm perm : perms)
|
||||
{
|
||||
permitted = faction.isPermitted(perm, selectorFrom);
|
||||
faction.setPermitted(perm, selectorTo, permitted);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
54
src/com/massivecraft/factions/cmd/CmdFactionsPermFor.java
Normal file
54
src/com/massivecraft/factions/cmd/CmdFactionsPermFor.java
Normal file
@ -0,0 +1,54 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.cmd.type.TypeSelector;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CmdFactionsPermFor extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPermFor()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeSelector.get(), "selector");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Parameter
|
||||
Selector selector = this.readArg();
|
||||
Faction faction = msender.getUsedFaction();
|
||||
|
||||
// Create
|
||||
List<Mson> perms = new MassiveList<>();
|
||||
|
||||
// Fill
|
||||
for (MPerm perm : faction.getPermittedFor(selector))
|
||||
{
|
||||
// Create inner
|
||||
Mson permDesc = mson(perm.getDesc(true, false));
|
||||
List<String> tooltip = Mson.toPlain(faction.getPermittedShow(perm, msender), true);
|
||||
|
||||
// Add
|
||||
perms.add(permDesc.tooltip(tooltip));
|
||||
}
|
||||
|
||||
// Inform
|
||||
message(Mson.implodeCommaAndDot(perms));
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPermColl;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.Parameter;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.pager.Msonifier;
|
||||
import com.massivecraft.massivecore.pager.Pager;
|
||||
import com.massivecraft.massivecore.pager.Stringifier;
|
||||
import com.massivecraft.massivecore.predicate.Predicate;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@ -15,7 +17,7 @@ import java.util.List;
|
||||
public class CmdFactionsPermList extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// REUSABLE PREDICATE
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final Predicate<MPerm> PREDICATE_MPERM_VISIBLE = new Predicate<MPerm>()
|
||||
@ -46,20 +48,20 @@ public class CmdFactionsPermList extends FactionsCommand
|
||||
{
|
||||
// Parameter
|
||||
int page = this.readArg();
|
||||
final Faction faction = msender.getUsedFaction();
|
||||
|
||||
// Pager create
|
||||
String title = String.format("Perms for %s", msenderFaction.describeTo(msender));
|
||||
final Pager<MPerm> pager = new Pager<>(this, title, page, new Stringifier<MPerm>()
|
||||
final Pager<MPerm> pager = new Pager<>(this, title, page, new Msonifier<MPerm>()
|
||||
{
|
||||
@Override
|
||||
public String toString(MPerm mperm, int index)
|
||||
public Mson toMson(MPerm mperm, int index)
|
||||
{
|
||||
return mperm.getDesc(true, true);
|
||||
return faction.getPermittedLine(mperm, msender);
|
||||
}
|
||||
});
|
||||
|
||||
final Predicate<MPerm> predicate = msender.isOverriding() ? null : PREDICATE_MPERM_VISIBLE;
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
|
14
src/com/massivecraft/factions/cmd/CmdFactionsPermRemove.java
Normal file
14
src/com/massivecraft/factions/cmd/CmdFactionsPermRemove.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
public class CmdFactionsPermRemove extends CmdFactionsPermSet
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPermRemove()
|
||||
{
|
||||
super(false);
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +1,42 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.cmd.req.RequirementHasMPerm;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPerm;
|
||||
import com.massivecraft.factions.cmd.type.TypeRel;
|
||||
import com.massivecraft.factions.cmd.type.TypeSelector;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsPermChange;
|
||||
import com.massivecraft.massivecore.Button;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CmdFactionsPermSet extends FactionsCommand
|
||||
public abstract class CmdFactionsPermSet extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private boolean add;
|
||||
public boolean isAdd() { return this.add; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsPermSet()
|
||||
public CmdFactionsPermSet(boolean add)
|
||||
{
|
||||
// Add/Remove
|
||||
this.add = add;
|
||||
|
||||
// Parameters
|
||||
this.addParameter(TypeMPerm.get(), "perm");
|
||||
this.addParameter(TypeRel.get(), "relation");
|
||||
this.addParameter(TypeBooleanYes.get(), "yes/no");
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
this.addParameter(TypeMPerm.get(), "permission");
|
||||
this.addParameter(TypeSelector.get(), "selector");
|
||||
|
||||
// Requirements
|
||||
this.addRequirements(RequirementHasMPerm.get(MPerm.getPermPerms()));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -37,62 +46,56 @@ public class CmdFactionsPermSet extends FactionsCommand
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Args
|
||||
// Parameter
|
||||
MPerm perm = this.readArg();
|
||||
Rel rel = this.readArg();
|
||||
Boolean value = this.readArg();
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
|
||||
// Do the sender have the right to change perms for this faction?
|
||||
if ( ! MPerm.getPermPerms().has(msender, faction, true)) return;
|
||||
Selector selector = this.readArg();
|
||||
Faction faction = msender.getUsedFaction();
|
||||
boolean adding = this.isAdd();
|
||||
|
||||
// Is this perm editable?
|
||||
if ( ! msender.isOverriding() && ! perm.isEditable())
|
||||
if (!msender.isOverriding() && !perm.isEditable())
|
||||
{
|
||||
msg("<b>The perm <h>%s <b>is not editable.", perm.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
// Event
|
||||
EventFactionsPermChange event = new EventFactionsPermChange(sender, faction, perm, rel, value);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
value = event.getNewValue();
|
||||
// Visuals
|
||||
String visualSelector = TypeSelector.get().getVisual(selector);
|
||||
String visualFaction = faction.describeTo(msender);
|
||||
String visualPerm = perm.getDesc(true, false);
|
||||
|
||||
// No change
|
||||
if (faction.getPermitted(perm).contains(rel) == value)
|
||||
if (faction.isPermitted(perm, selector) == adding)
|
||||
{
|
||||
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());
|
||||
String already = "already";
|
||||
if (!adding) already += " not";
|
||||
msg("%s <i>is %s permitted for faction %s<i> and perm %s<i>.", visualSelector, already, visualFaction, visualPerm);
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply
|
||||
faction.setRelationPermitted(perm, rel, value);
|
||||
// Event
|
||||
EventFactionsPermChange event = new EventFactionsPermChange(sender, faction, perm, selector, adding);
|
||||
event.run();
|
||||
if (event.isCancelled()) return;
|
||||
adding = event.getNewValue();
|
||||
|
||||
// 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))
|
||||
if (perm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains(Rel.LEADER) && !adding)
|
||||
{
|
||||
faction.setRelationPermitted(MPerm.getPermPerms(), Rel.LEADER, true);
|
||||
throw new MassiveException().setMsg("<b>You are not allowed to remove the leader from the perm <h>perms<b>.");
|
||||
}
|
||||
|
||||
// Create messages
|
||||
List<Object> messages = new ArrayList<>();
|
||||
// Apply
|
||||
faction.setPermitted(perm, selector, adding);
|
||||
|
||||
// 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)));
|
||||
message(messages);
|
||||
|
||||
// Inform faction (their message is slighly different)
|
||||
List<MPlayer> recipients = faction.getMPlayers();
|
||||
recipients.remove(msender);
|
||||
|
||||
for (MPlayer recipient : recipients)
|
||||
{
|
||||
recipient.msg("<h>%s <i>set a perm for <h>%s<i>.", msender.describeTo(recipient, true), faction.describeTo(recipient, true));
|
||||
recipient.message(messages);
|
||||
}
|
||||
// Inform
|
||||
String addRemove = adding ? "added" : "removed";
|
||||
Mson button = new Button()
|
||||
.setName("Show")
|
||||
.setCommand(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermShow)
|
||||
.setArgs(perm.getId())
|
||||
.render();
|
||||
faction.sendMessage(mson(visualSelector, " was ", addRemove, " to the perm ", visualPerm, ". ", button).color(ChatColor.YELLOW));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPerm;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.container.TypeSet;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CmdFactionsPermShow extends FactionsCommand
|
||||
@ -21,8 +17,7 @@ public class CmdFactionsPermShow extends FactionsCommand
|
||||
public CmdFactionsPermShow()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeFaction.get(), "faction", "you");
|
||||
this.addParameter(TypeSet.get(TypeMPerm.get()), "perms", "all", true);
|
||||
this.addParameter(TypeMPerm.get(), "perm");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -32,22 +27,15 @@ public class CmdFactionsPermShow extends FactionsCommand
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Arg: Faction
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
Collection<MPerm> mperms = this.readArg(MPerm.getAll());
|
||||
// Parameter
|
||||
MPerm perm = this.readArg();
|
||||
Faction faction = msender.getUsedFaction();
|
||||
|
||||
// Create messages
|
||||
List<Object> messages = new ArrayList<>();
|
||||
// Create
|
||||
List<Mson> message = faction.getPermittedShow(perm, msender);
|
||||
|
||||
messages.add(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
|
||||
messages.add(MPerm.getStateHeaders());
|
||||
for (MPerm mperm : mperms)
|
||||
{
|
||||
messages.add(Txt.parse(mperm.getStateInfo(faction.getPermitted(mperm), true)));
|
||||
}
|
||||
|
||||
// Send messages
|
||||
message(messages);
|
||||
// Inform
|
||||
message(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
50
src/com/massivecraft/factions/cmd/CmdFactionsUsed.java
Normal file
50
src/com/massivecraft/factions/cmd/CmdFactionsUsed.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.Visibility;
|
||||
import com.massivecraft.massivecore.command.type.TypeNullable;
|
||||
|
||||
public class CmdFactionsUsed extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public CmdFactionsUsed()
|
||||
{
|
||||
// Parameters
|
||||
this.addParameter(TypeNullable.get(TypeFaction.get()), "faction", "show");
|
||||
|
||||
// Visibility
|
||||
this.setVisibility(Visibility.SECRET);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
// Is show?
|
||||
if (!this.argIsSet(0))
|
||||
{
|
||||
Faction faction = msender.getUsedFaction();
|
||||
msg("<i>Your used faction is %s.", faction.describeTo(msender));
|
||||
}
|
||||
|
||||
// Parameter
|
||||
Faction faction = this.readArg();
|
||||
|
||||
// Apply
|
||||
msender.setUsedFaction(faction);
|
||||
|
||||
// Inform
|
||||
String message = "<g>Your used faction was <h>%s<g>.";
|
||||
String result = faction == null ? "unset." : "set to " + faction.describeTo(msender, true);
|
||||
msg(message, result);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.massivecraft.factions.cmd.req;
|
||||
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.Triple;
|
||||
import com.massivecraft.massivecore.command.MassiveCommand;
|
||||
import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class RequirementHasMPerm extends RequirementAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// SERIALIZABLE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static RequirementHasMPerm get(MPerm perm) { return new RequirementHasMPerm(perm); }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private RequirementHasMPerm(MPerm perm)
|
||||
{
|
||||
this.mpermId = perm.getId();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final String mpermId;
|
||||
public String getMPermId() { return this.mpermId; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public boolean apply(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
// Resolve
|
||||
Triple<MPlayer, Faction, MPerm> tripple = this.resolve(sender);
|
||||
if (tripple == null) return false;
|
||||
|
||||
MPlayer mplayer = tripple.getFirst();
|
||||
Faction faction = tripple.getSecond();
|
||||
MPerm mperm = tripple.getThird();
|
||||
|
||||
// Override
|
||||
if (mplayer.isOverriding()) return true;
|
||||
|
||||
// Has
|
||||
return mperm.has(mplayer, faction, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String createErrorMessage(CommandSender sender, MassiveCommand command)
|
||||
{
|
||||
// Resolve
|
||||
Triple<MPlayer, Faction, MPerm> tripple = this.resolve(sender);
|
||||
if (tripple == null) return null;
|
||||
|
||||
MPlayer mplayer = tripple.getFirst();
|
||||
Faction faction = tripple.getSecond();
|
||||
MPerm mperm = tripple.getThird();
|
||||
|
||||
// Create Message
|
||||
return mperm.getDeniedMessage(mplayer, faction).toPlain(true);
|
||||
}
|
||||
|
||||
private Triple<MPlayer, Faction, MPerm> resolve(CommandSender sender)
|
||||
{
|
||||
// Get the MPlayer
|
||||
MPlayer mplayer = MPlayer.get(sender);
|
||||
if (mplayer == null) return null;
|
||||
|
||||
// Get the Faction
|
||||
Faction faction = mplayer.getFaction();
|
||||
if (faction == null) return null;
|
||||
|
||||
// Get MPerm
|
||||
MPerm mperm = MPerm.get(this.getMPermId());
|
||||
if (mperm == null) return null;
|
||||
|
||||
// Return
|
||||
return new Triple<>(mplayer, faction, mperm);
|
||||
}
|
||||
|
||||
}
|
158
src/com/massivecraft/factions/cmd/type/TypeSelector.java
Normal file
158
src/com/massivecraft/factions/cmd/type/TypeSelector.java
Normal file
@ -0,0 +1,158 @@
|
||||
package com.massivecraft.factions.cmd.type;
|
||||
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.SelectorType;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.command.type.Type;
|
||||
import com.massivecraft.massivecore.command.type.TypeAbstract;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class TypeSelector extends TypeAbstract<Selector>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private Type<MPlayer> typeMPlayer = TypeMPlayer.get();
|
||||
private TypeRank typeRank = TypeRank.get();
|
||||
private TypeRel typeRel = TypeRel.get();
|
||||
private TypeFaction typeFaction = TypeFaction.get();
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TypeSelector i = new TypeSelector();
|
||||
public static TypeSelector get() { return i; }
|
||||
private TypeSelector()
|
||||
{
|
||||
super(Selector.class);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public Selector read(String arg, CommandSender sender) throws MassiveException
|
||||
{
|
||||
if (arg == null) throw new MassiveException().setMsg("Selector can't be null.");
|
||||
if (arg.length() < 2) throw new MassiveException().setMsg("Selector must be longer than two characters.");
|
||||
|
||||
// Get Prefix
|
||||
SelectorType prefix = SelectorType.getFromPrefix(arg);
|
||||
return prefix != null ? this.readPrefixed(arg, sender, prefix) : this.readPrioritized(arg, sender);
|
||||
}
|
||||
|
||||
private Selector readPrefixed(String arg, CommandSender sender, SelectorType prefix) throws MassiveException
|
||||
{
|
||||
// Cut off prefix length
|
||||
int length = prefix.getPrefix().length();
|
||||
arg = arg.substring(length);
|
||||
|
||||
// Use correct type to read the selector
|
||||
Type<Selector> type = this.fetchType(prefix);
|
||||
return type.read(arg, sender);
|
||||
}
|
||||
|
||||
private Selector readPrioritized(String arg, CommandSender sender) throws MassiveException
|
||||
{
|
||||
Selector ret;
|
||||
|
||||
// Try Relation
|
||||
ret = readSafe(arg, sender, this.typeRel);
|
||||
if (ret != null) return ret;
|
||||
|
||||
// Try Player
|
||||
// NOTE: Player before Faction, otherwise players get interpreted as a faction
|
||||
ret = readSafe(arg, sender, this.typeMPlayer);
|
||||
if (ret != null) return ret;
|
||||
|
||||
// Try Faction
|
||||
ret = readSafe(arg, sender, this.typeFaction);
|
||||
if (ret != null) return ret;
|
||||
|
||||
// Try Rank
|
||||
ret = readSafe(arg, sender, this.typeRank);
|
||||
if (ret != null) return ret;
|
||||
|
||||
// Error
|
||||
throw new MassiveException().setMsg("<h>%s<b> did not match any selector.", arg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getTabList(CommandSender sender, String arg)
|
||||
{
|
||||
// Create
|
||||
Collection<String> ret = new MassiveList<>();
|
||||
|
||||
// Choose specific if possible
|
||||
SelectorType prefix = SelectorType.getFromPrefix(arg);
|
||||
if (prefix != null) return this.fetchType(prefix).getTabList(sender, arg);
|
||||
|
||||
// Fill All
|
||||
ret.addAll(this.typeFaction.getTabList(sender, arg));
|
||||
ret.addAll(this.typeMPlayer.getTabList(sender, arg));
|
||||
// TODO: ret.addAll(this.typeRank.getTabList(sender, arg));
|
||||
ret.addAll(this.typeRel.getTabList(sender, arg));
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mson getVisualMsonInner(Selector selector, CommandSender sender)
|
||||
{
|
||||
// Get Type
|
||||
SelectorType selectorType = selector.getType();
|
||||
Type<Selector> type = this.fetchType(selectorType);
|
||||
|
||||
// Get Visual
|
||||
return type.getVisualMson(selector, sender);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Type Fetching
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <E> Type<E> fetchType(SelectorType selectorType)
|
||||
{
|
||||
switch (selectorType)
|
||||
{
|
||||
case RANK:
|
||||
return (Type<E>) typeRank;
|
||||
case RELATION:
|
||||
return (Type<E>) typeRel;
|
||||
case PLAYER:
|
||||
return (Type<E>) typeMPlayer;
|
||||
case FACTION:
|
||||
return (Type<E>) typeFaction;
|
||||
default:
|
||||
throw new IllegalStateException("SelectorType " + selectorType + " was not matchable.");
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SAFE READING
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Selector readSafe(String arg, CommandSender sender) { return readSafe(arg, sender, this); }
|
||||
private static <T> T readSafe(String arg, CommandSender sender, Type<T> type)
|
||||
{
|
||||
try
|
||||
{
|
||||
return type.read(arg, sender);
|
||||
}
|
||||
catch (MassiveException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -171,7 +171,7 @@ public class EngineChunkChange extends Engine
|
||||
for (Faction nearbyFaction : nearbyFactions)
|
||||
{
|
||||
if (claimnear.has(newFaction, nearbyFaction)) continue;
|
||||
mplayer.message(claimnear.createDeniedMessage(mplayer, nearbyFaction));
|
||||
claimnear.sendDeniedMessage(mplayer, nearbyFaction);
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.massivecraft.factions.engine;
|
||||
|
||||
import com.massivecraft.factions.AccessStatus;
|
||||
import com.massivecraft.factions.Const;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
@ -9,7 +8,6 @@ import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.util.AsciiMap;
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||
import com.massivecraft.massivecore.mixin.MixinTitle;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
@ -5,6 +5,13 @@ import com.massivecraft.factions.FactionsIndex;
|
||||
import com.massivecraft.factions.FactionsParticipator;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.SelectorType;
|
||||
import com.massivecraft.factions.cmd.CmdFactions;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.cmd.type.TypeRel;
|
||||
import com.massivecraft.factions.cmd.type.TypeSelector;
|
||||
import com.massivecraft.factions.predicate.PredicateCommandSenderFaction;
|
||||
import com.massivecraft.factions.predicate.PredicateMPlayerRole;
|
||||
import com.massivecraft.factions.util.MiscUtil;
|
||||
@ -13,8 +20,11 @@ import com.massivecraft.massivecore.collections.MassiveList;
|
||||
import com.massivecraft.massivecore.collections.MassiveMap;
|
||||
import com.massivecraft.massivecore.collections.MassiveMapDef;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.collections.MassiveSetDef;
|
||||
import com.massivecraft.massivecore.command.type.Type;
|
||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||
import com.massivecraft.massivecore.money.Money;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.predicate.Predicate;
|
||||
import com.massivecraft.massivecore.predicate.PredicateAnd;
|
||||
import com.massivecraft.massivecore.predicate.PredicateVisibleTo;
|
||||
@ -29,10 +39,8 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -74,6 +82,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
this.setRelationWishes(that.relationWishes);
|
||||
this.setFlagIds(that.flags);
|
||||
this.setPermIds(that.perms);
|
||||
this.factionBans.load(that.factionBans);
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -96,7 +105,7 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
// VERSION
|
||||
// -------------------------------------------- //
|
||||
|
||||
public int version = 1;
|
||||
public int version = 2;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS: RAW
|
||||
@ -154,7 +163,10 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
|
||||
// The perm overrides are modifications to the default values.
|
||||
// Null means default.
|
||||
private MassiveMapDef<String, Set<Rel>> perms = new MassiveMapDef<>();
|
||||
private MassiveMapDef<String, Set<String>> perms = new MassiveMapDef<>();
|
||||
|
||||
// The perm blacklist of which selectors are not allowed in any way.
|
||||
private EntityInternalMap<FactionBan> factionBans = new EntityInternalMap<>(this, FactionBan.class);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: id
|
||||
@ -459,12 +471,9 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
// -------------------------------------------- //
|
||||
|
||||
// RAW
|
||||
|
||||
|
||||
public EntityInternalMap<Invitation> getInvitations() { return this.invitations; }
|
||||
|
||||
// FINER
|
||||
|
||||
public boolean isInvited(String playerId)
|
||||
{
|
||||
return this.getInvitations().containsKey(playerId);
|
||||
@ -678,66 +687,26 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: permOverrides
|
||||
// FIELD: perms
|
||||
// -------------------------------------------- //
|
||||
|
||||
// RAW
|
||||
|
||||
public Map<MPerm, Set<Rel>> getPerms()
|
||||
public MassiveMapDef<String, Set<String>> getPermIds()
|
||||
{
|
||||
// We start with default values ...
|
||||
Map<MPerm, Set<Rel>> ret = new MassiveMap<>();
|
||||
for (MPerm mperm : MPerm.getAll())
|
||||
{
|
||||
ret.put(mperm, new MassiveSet<>(mperm.getStandard()));
|
||||
return this.perms;
|
||||
}
|
||||
|
||||
// ... and if anything is explicitly set we use that info ...
|
||||
Iterator<Entry<String, Set<Rel>>> iter = this.perms.entrySet().iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
// ... for each entry ...
|
||||
Entry<String, Set<Rel>> entry = iter.next();
|
||||
|
||||
// ... extract id and remove null values ...
|
||||
String id = entry.getKey();
|
||||
if (id == null)
|
||||
{
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
// ... resolve object and skip unknowns ...
|
||||
MPerm mperm = MPerm.get(id);
|
||||
if (mperm == null) continue;
|
||||
|
||||
ret.put(mperm, new MassiveSet<>(entry.getValue()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPerms(Map<MPerm, Set<Rel>> perms)
|
||||
{
|
||||
Map<String, Set<Rel>> permIds = new MassiveMap<>();
|
||||
for (Entry<MPerm, Set<Rel>> entry : perms.entrySet())
|
||||
{
|
||||
permIds.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
setPermIds(permIds);
|
||||
}
|
||||
|
||||
public void setPermIds(Map<String, Set<Rel>> perms)
|
||||
public void setPermIds(MassiveMapDef<String, Set<String>> perms)
|
||||
{
|
||||
// Clean input
|
||||
MassiveMapDef<String, Set<Rel>> target = new MassiveMapDef<>();
|
||||
for (Entry<String, Set<Rel>> entry : perms.entrySet())
|
||||
MassiveMapDef<String, Set<String>> target = new MassiveMapDef<String, Set<String>>();
|
||||
for (Entry<String, Set<String>> entry : perms.entrySet())
|
||||
{
|
||||
String key = entry.getKey();
|
||||
if (key == null) continue;
|
||||
key = key.toLowerCase(); // Lowercased Keys Version 2.6.0 --> 2.7.0
|
||||
|
||||
Set<Rel> value = entry.getValue();
|
||||
Set<String> value = entry.getValue();
|
||||
if (value == null) continue;
|
||||
|
||||
target.put(key, value);
|
||||
@ -753,105 +722,341 @@ public class Faction extends Entity<Faction> implements FactionsParticipator
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// FINER
|
||||
|
||||
public boolean isPermitted(String permId, Rel rel)
|
||||
// Finer
|
||||
public Map<MPerm, Set<String>> getPerms()
|
||||
{
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
// We start with default values ...
|
||||
Map<MPerm, Set<String>> ret = new MassiveMap<>();
|
||||
|
||||
Set<Rel> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels.contains(rel);
|
||||
// ... and if anything is explicitly set we use that info ...
|
||||
for (Iterator<Entry<String, Set<String>>> it = this.getPermIds().entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
// ... for each entry ...
|
||||
Entry<String, Set<String>> entry = it.next();
|
||||
|
||||
MPerm perm = MPerm.get(permId);
|
||||
if (perm == null) throw new NullPointerException("perm");
|
||||
|
||||
return perm.getStandard().contains(rel);
|
||||
// ... extract id and remove null values ...
|
||||
String id = entry.getKey();
|
||||
if (id == null)
|
||||
{
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
public boolean isPermitted(MPerm perm, Rel rel)
|
||||
{
|
||||
if (perm == null) throw new NullPointerException("perm");
|
||||
// ... resolve object and skip unknowns ...
|
||||
MPerm mperm = MPerm.get(id);
|
||||
if (mperm == null) continue;
|
||||
|
||||
ret.put(mperm, new MassiveSet<>(entry.getValue()));
|
||||
}
|
||||
|
||||
for (MPerm mperm : MPerm.getAll())
|
||||
{
|
||||
// Is already configured?
|
||||
if (ret.containsKey(mperm)) continue;
|
||||
|
||||
// Add
|
||||
ret.put(mperm, mperm.getStandardIds());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPerms(Map<MPerm, Set<String>> perms)
|
||||
{
|
||||
// Create
|
||||
MassiveMapDef<String, Set<String>> permIds = new MassiveMapDef<>();
|
||||
|
||||
// Fill
|
||||
for (Entry<MPerm, Set<String>> entry : perms.entrySet())
|
||||
{
|
||||
permIds.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
|
||||
// Set
|
||||
this.setPermIds(permIds);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// PERMITTED
|
||||
// -------------------------------------------- //
|
||||
// Being permitted for a perm can have many reasons:
|
||||
// For Players, either their Relation, Faction, Rank or themselves can have been permitted.
|
||||
// For Factions, this can be their relation or themselves being permitted.
|
||||
//
|
||||
// For each selector we need to check if any of the sub-selectors are permitted.
|
||||
|
||||
private Set<String> getPermittedIds(MPerm perm)
|
||||
{
|
||||
String permId = perm.getId();
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
|
||||
Set<Rel> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels.contains(rel);
|
||||
|
||||
return perm.getStandard().contains(rel);
|
||||
Set<String> permitted = this.perms.get(permId);
|
||||
return permitted != null ? permitted : perm.getStandardIds();
|
||||
}
|
||||
|
||||
// ---
|
||||
public Set<MPerm> getPermittedFor(Selector selector)
|
||||
{
|
||||
// Create
|
||||
Set<MPerm> ret = new MassiveSet<>();
|
||||
|
||||
public Set<Rel> getPermitted(MPerm perm)
|
||||
// Fill
|
||||
for (MPerm perm : MPermColl.get().getAll())
|
||||
{
|
||||
if (this.isPermitted(perm, selector)) ret.add(perm);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setPermitted(MPerm perm, Selector selector, boolean add)
|
||||
{
|
||||
if (perm == null) throw new NullPointerException("perm");
|
||||
if (selector == null) throw new NullPointerException("selector");
|
||||
|
||||
String permId = perm.getId();
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
// Get Ids
|
||||
String idSelector = selector.getId();
|
||||
String idPerm = perm.getId();
|
||||
|
||||
Set<Rel> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels;
|
||||
// Get perms
|
||||
Map<String, Set<String>> perms = this.getPermIds();
|
||||
Set<String> selectors = perms.get(idPerm);
|
||||
|
||||
return perm.getStandard();
|
||||
// If new, assign standard ids on first change.
|
||||
if (add && selectors == null) selectors = new MassiveSetDef<>(perm.getStandardIds());
|
||||
|
||||
// Add || Remove
|
||||
if (add)
|
||||
{
|
||||
selectors.add(idSelector);
|
||||
}
|
||||
else if (selectors != null)
|
||||
{
|
||||
selectors.remove(idSelector);
|
||||
}
|
||||
|
||||
public Set<Rel> getPermitted(String permId)
|
||||
perms.put(idPerm, selectors);
|
||||
|
||||
// Changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
public void setPermitted(MPerm perm, Selector... selectors)
|
||||
{
|
||||
if (permId == null) throw new NullPointerException("permId");
|
||||
for (Selector selector : selectors)
|
||||
{
|
||||
this.setPermitted(perm, selector, true);
|
||||
}
|
||||
}
|
||||
|
||||
Set<Rel> rels = this.perms.get(permId);
|
||||
if (rels != null) return rels;
|
||||
public boolean isPermittedAny(MPerm perm, Selector selector)
|
||||
{
|
||||
// Special
|
||||
if (selector instanceof MPlayer && this.isPermittedPlayer(perm, (MPlayer)selector)) return true;
|
||||
if (selector instanceof Faction && this.isPermittedFaction(perm, (Faction)selector)) return true;
|
||||
|
||||
MPerm perm = MPerm.get(permId);
|
||||
// Default
|
||||
return this.isPermitted(perm, selector);
|
||||
}
|
||||
|
||||
private boolean isPermittedFaction(MPerm perm, Faction faction)
|
||||
{
|
||||
return this.isPermittedAny(perm, faction, faction.getRelationTo(this));
|
||||
}
|
||||
|
||||
private boolean isPermittedPlayer(MPerm perm, MPlayer mplayer)
|
||||
{
|
||||
// TODO: Add Rank in the future
|
||||
return this.isPermittedAny(perm, mplayer, mplayer.getFaction(), mplayer.getRelationTo(this));
|
||||
}
|
||||
|
||||
private boolean isPermittedAny(MPerm perm, Selector... selectors)
|
||||
{
|
||||
for (Selector selector : selectors)
|
||||
{
|
||||
if (this.isPermitted(perm, selector)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPermitted(MPerm perm, Selector selector)
|
||||
{
|
||||
if (perm == null) throw new NullPointerException("perm");
|
||||
if (selector == null) throw new NullPointerException("selector");
|
||||
|
||||
return perm.getStandard();
|
||||
// Is specifically granted?
|
||||
Set<String> selectors = this.getPermIds().get(perm.getId());
|
||||
if (selectors != null) return selectors.contains(selector.getId());
|
||||
|
||||
// Is standard?
|
||||
return selector instanceof Rel && perm.getStandard().contains(selector);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
// Use getPermitted instead. It's much quicker although not immutable.
|
||||
public Set<Rel> getPermittedRelations(MPerm perm)
|
||||
// -------------------------------------------- //
|
||||
// PERMITTED > VISUAL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public List<Mson> getPermittedShow(MPerm perm, RelationParticipator relationParticipator)
|
||||
{
|
||||
return this.getPerms().get(perm);
|
||||
// Resolve Permitted
|
||||
Map<SelectorType, List<Selector>> permitted = this.resolvePermitted(perm);
|
||||
|
||||
// Return show
|
||||
return this.getPermittedShow(perm, permitted, relationParticipator);
|
||||
}
|
||||
|
||||
// ---
|
||||
// TODO: Fix these below. They are reworking the whole map.
|
||||
|
||||
public void setPermittedRelations(MPerm perm, Set<Rel> rels)
|
||||
public Mson getPermittedLine(MPerm perm, RelationParticipator relationParticipator)
|
||||
{
|
||||
Map<MPerm, Set<Rel>> perms = this.getPerms();
|
||||
perms.put(perm, rels);
|
||||
this.setPerms(perms);
|
||||
// Create
|
||||
Mson ret = Mson.EMPTY;
|
||||
Map<SelectorType, List<Selector>> permitted = this.resolvePermitted(perm);
|
||||
|
||||
// Fill > Ranks
|
||||
List<Selector> ranks = permitted.get(SelectorType.RANK);
|
||||
if (ranks != null)
|
||||
{
|
||||
Mson rankMson = Mson.EMPTY;
|
||||
for (Selector selector : ranks)
|
||||
{
|
||||
Rel rank = (Rel) selector;
|
||||
// TODO: Change this to number after ranks are creatable
|
||||
Mson mson = Mson.mson(String.valueOf(rank.getName().charAt(0)));
|
||||
rankMson = rankMson.add(mson);
|
||||
}
|
||||
|
||||
public void setPermittedRelations(MPerm perm, Rel... rels)
|
||||
{
|
||||
Set<Rel> temp = new HashSet<>();
|
||||
temp.addAll(Arrays.asList(rels));
|
||||
this.setPermittedRelations(perm, temp);
|
||||
ret = ret.add(rankMson.color(ChatColor.DARK_GREEN));
|
||||
}
|
||||
|
||||
public void setRelationPermitted(MPerm perm, Rel rel, boolean permitted)
|
||||
// Fill > Relations
|
||||
List<Selector> relations = permitted.get(SelectorType.RELATION);
|
||||
if (relations != null)
|
||||
{
|
||||
Map<MPerm, Set<Rel>> perms = this.getPerms();
|
||||
|
||||
Set<Rel> rels = perms.get(perm);
|
||||
|
||||
boolean changed;
|
||||
if (permitted)
|
||||
Mson relMson = Mson.EMPTY;
|
||||
for (Selector selector : relations)
|
||||
{
|
||||
changed = rels.add(rel);
|
||||
Rel rel = (Rel) selector;
|
||||
Mson mson = Mson.mson(String.valueOf(rel.getName().charAt(0)));
|
||||
relMson = relMson.add(mson);
|
||||
}
|
||||
|
||||
ret = ret.add(relMson.color(ChatColor.LIGHT_PURPLE));
|
||||
}
|
||||
|
||||
// Fill > Factions
|
||||
List<Selector> factions = permitted.get(SelectorType.FACTION);
|
||||
if (factions != null) ret = ret.add(Mson.mson("F").color(ChatColor.GREEN));
|
||||
|
||||
// Fill > Factions
|
||||
List<Selector> players = permitted.get(SelectorType.PLAYER);
|
||||
if (players != null) ret = ret.add(Mson.mson("P").color(ChatColor.WHITE));
|
||||
|
||||
// Fill > Name
|
||||
ret = ret.add(Mson.SPACE).add(Mson.mson(perm.getName()).uppercaseFirst().color(ChatColor.YELLOW));
|
||||
|
||||
// Fill > Show
|
||||
ret = ret.command(CmdFactions.get().cmdFactionsPerm.cmdFactionsPermShow, perm.getId());
|
||||
List<String> showLines = Mson.toPlain(this.getPermittedShow(perm, permitted, relationParticipator), true);
|
||||
showLines.add(ret.getTooltip());
|
||||
ret = ret.tooltip(showLines);
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
private Map<SelectorType, List<Selector>> resolvePermitted(MPerm perm)
|
||||
{
|
||||
// Create
|
||||
Map<SelectorType, List<Selector>> ret = new MassiveMap<>();
|
||||
|
||||
// Fill
|
||||
TypeSelector type = TypeSelector.get();
|
||||
for (String id : this.getPermittedIds(perm))
|
||||
{
|
||||
Selector selector = type.readSafe(id, null);
|
||||
if (selector == null) throw new IllegalStateException("Selector id " + id + "wasn't resolvable.");
|
||||
|
||||
SelectorType selectorType = selector.getType();
|
||||
List<Selector> selectors = ret.get(selectorType);
|
||||
if (selectors == null)
|
||||
{
|
||||
selectors = new MassiveList<>(selector);
|
||||
ret.put(selectorType, selectors);
|
||||
}
|
||||
else
|
||||
{
|
||||
changed = rels.remove(rel);
|
||||
selectors.add(selector);
|
||||
}
|
||||
}
|
||||
|
||||
this.setPerms(perms);
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (changed) this.changed();
|
||||
private List<Mson> getPermittedShow(MPerm perm, Map<SelectorType, List<Selector>> permitted, RelationParticipator relationParticipator)
|
||||
{
|
||||
String factionName = this.describeTo(relationParticipator, true);
|
||||
Mson header = Txt.titleize(factionName + " " + perm.getDesc(true, true));
|
||||
Mson ranks = getResolveSection("Ranks: ", permitted.get(SelectorType.RANK), TypeRel.get());
|
||||
Mson relations = getResolveSection("Relations: ", permitted.get(SelectorType.RELATION), TypeRel.get());
|
||||
Mson factions = getResolveSection("Factions: ", permitted.get(SelectorType.FACTION), TypeFaction.get());
|
||||
Mson players = getResolveSection("Players: ", permitted.get(SelectorType.PLAYER), TypeMPlayer.get());
|
||||
|
||||
return new MassiveList<>(header, ranks, relations, factions, players);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <E> Mson getResolveSection(String header, List<Selector> resolve, Type<E> type)
|
||||
{
|
||||
Mson heading = Mson.mson(header).color(ChatColor.YELLOW);
|
||||
if (resolve == null) return heading;
|
||||
|
||||
List<Mson> ret = new MassiveList<>();
|
||||
for (Selector selector : resolve)
|
||||
{
|
||||
E element = (E) selector;
|
||||
ret.add(type.getVisualMson(element));
|
||||
}
|
||||
|
||||
return heading.add(Mson.implode(ret, Mson.mson(", ")));
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: factionBans
|
||||
// -------------------------------------------- //
|
||||
|
||||
// Raw
|
||||
public EntityInternalMap<FactionBan> getFactionBans()
|
||||
{
|
||||
return factionBans;
|
||||
}
|
||||
|
||||
// Finer
|
||||
public boolean isFactionBannedInherited(Selector selector)
|
||||
{
|
||||
if (selector instanceof Faction)
|
||||
{
|
||||
if (this.isFactionBanned(((Faction) selector).getRelationTo(this))) return true;
|
||||
}
|
||||
else if (selector instanceof MPlayer)
|
||||
{
|
||||
MPlayer mplayer = (MPlayer) selector;
|
||||
if (this.isFactionBanned(mplayer.getRelationTo(this)) || this.isFactionBanned(mplayer.getFaction())) return true;
|
||||
}
|
||||
|
||||
return this.isFactionBanned(selector);
|
||||
}
|
||||
|
||||
private boolean isFactionBanned(Selector selector)
|
||||
{
|
||||
return this.factionBans.containsKey(selector.getId());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: Selector
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public SelectorType getType()
|
||||
{
|
||||
return SelectorType.FACTION;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
|
100
src/com/massivecraft/factions/entity/FactionBan.java
Normal file
100
src/com/massivecraft/factions/entity/FactionBan.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.massivecraft.factions.entity;
|
||||
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.cmd.type.TypeMPlayer;
|
||||
import com.massivecraft.factions.cmd.type.TypeSelector;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.store.EntityInternal;
|
||||
|
||||
public class FactionBan extends EntityInternal<FactionBan>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: ENTITY
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public FactionBan load(FactionBan that)
|
||||
{
|
||||
this.selectorId = that.selectorId;
|
||||
this.executorId = that.executorId;
|
||||
this.reason = that.reason;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
// This is the id of the selector which is banned for that faction.
|
||||
private String selectorId = null;
|
||||
public String getSelectorId() { return this.selectorId; }
|
||||
public void setSelectorId(String selectorId) { this.selectorId = selectorId; }
|
||||
|
||||
// The id of the mplayer who banned the selector.
|
||||
private String executorId = null;
|
||||
public String getExecutorId() { return this.executorId; }
|
||||
public void setExecutorId(String executorId) { this.executorId = executorId; }
|
||||
|
||||
// The reason given upon banning the selector.
|
||||
private String reason = null;
|
||||
public String getReason() { return this.reason; }
|
||||
public void setReason(String reason) { this.reason = reason; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public FactionBan()
|
||||
{
|
||||
this(null, null, null);
|
||||
}
|
||||
|
||||
public FactionBan(Selector selector, MPlayer executor, String reason)
|
||||
{
|
||||
this.selector = selector;
|
||||
this.executor = executor;
|
||||
this.selectorId = selector == null ? null : selector.getId();
|
||||
this.executorId = executor == null ? null : executor.getId();
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// LAZY RESOLVING
|
||||
// -------------------------------------------- //
|
||||
|
||||
private transient Selector selector = null;
|
||||
private transient MPlayer executor = null;
|
||||
|
||||
public Selector getSelector()
|
||||
{
|
||||
// Already stored?
|
||||
if (this.selector != null) return this.selector;
|
||||
|
||||
// Resolve
|
||||
this.selector = TypeSelector.get().readSafe(this.getSelectorId(), null);
|
||||
|
||||
// Return
|
||||
return this.selector;
|
||||
}
|
||||
|
||||
public MPlayer getExecutor()
|
||||
{
|
||||
// Already stored?
|
||||
if (this.executor != null) return this.executor;
|
||||
|
||||
// Resolve
|
||||
try
|
||||
{
|
||||
this.executor = TypeMPlayer.get().read(this.getExecutorId());
|
||||
}
|
||||
catch (MassiveException e)
|
||||
{
|
||||
throw new IllegalStateException("Executor couldn't be resolved: " + this.getExecutorId(), e);
|
||||
}
|
||||
|
||||
// Return
|
||||
return this.executor;
|
||||
}
|
||||
|
||||
}
|
@ -84,12 +84,12 @@ public class FactionColl extends Coll<Faction>
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), true);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), true);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermBuild(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermDeposit(), Rel.LEADER, Rel.OFFICER); // Wilderness deposit should be limited as an anti spam meassure.
|
||||
faction.setPermitted(MPerm.getPermBuild(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermDeposit(), Rel.LEADER, Rel.OFFICER); // Wilderness deposit should be limited as an anti spam meassure.
|
||||
|
||||
return faction;
|
||||
}
|
||||
@ -120,11 +120,11 @@ public class FactionColl extends Coll<Faction>
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), false);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), false);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
|
||||
faction.setPermitted(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
|
||||
|
||||
return faction;
|
||||
}
|
||||
@ -155,11 +155,11 @@ public class FactionColl extends Coll<Faction>
|
||||
faction.setFlag(MFlag.getFlagEndergrief(), true);
|
||||
faction.setFlag(MFlag.getFlagZombiegrief(), true);
|
||||
|
||||
faction.setPermittedRelations(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermittedRelations(MPerm.getPermTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
|
||||
faction.setPermitted(MPerm.getPermDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
faction.setPermitted(MPerm.getPermTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
|
||||
|
||||
return faction;
|
||||
}
|
||||
|
@ -3,25 +3,29 @@ package com.massivecraft.factions.entity;
|
||||
import com.massivecraft.factions.AccessStatus;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.TerritoryAccess;
|
||||
import com.massivecraft.factions.cmd.CmdFactions;
|
||||
import com.massivecraft.factions.event.EventFactionsCreatePerms;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.Prioritized;
|
||||
import com.massivecraft.massivecore.Registerable;
|
||||
import com.massivecraft.massivecore.collections.MassiveSet;
|
||||
import com.massivecraft.massivecore.comparator.ComparatorSmart;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.predicate.PredicateIsRegistered;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.massivecraft.factions.Rel.TRUCE;
|
||||
|
||||
public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -80,6 +84,32 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
public final static transient int PRIORITY_PERMS = 23000;
|
||||
public final static transient int PRIORITY_STATUS = 24000;
|
||||
|
||||
public final static transient Set<Rel> STANDARD_BUILD = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
|
||||
public final static transient Set<Rel> STANDARD_PAINBUILD = new MassiveSet<>();
|
||||
public final static transient Set<Rel> STANDARD_DOOR = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY);
|
||||
public final static transient Set<Rel> STANDARD_BUTTON = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY);
|
||||
public final static transient Set<Rel> STANDARD_LEVER = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY);
|
||||
public final static transient Set<Rel> STANDARD_CONTAINER = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
|
||||
|
||||
public final static transient Set<Rel> STANDARD_NAME = new MassiveSet<>(Rel.LEADER);
|
||||
public final static transient Set<Rel> STANDARD_DESC = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_MOTD = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_INVITE = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_KICK = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_TITLE = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_HOME = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT);
|
||||
public final static transient Set<Rel> STANDARD_SETHOME = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_DEPOSIT = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, TRUCE, Rel.NEUTRAL, Rel.ENEMY);
|
||||
public final static transient Set<Rel> STANDARD_WITHDRAW = new MassiveSet<>(Rel.LEADER);
|
||||
public final static transient Set<Rel> STANDARD_TERRITORY = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_ACCESS = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_CLAIMNEAR = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY);
|
||||
public final static transient Set<Rel> STANDARD_REL = new MassiveSet<>(Rel.LEADER, Rel.OFFICER);
|
||||
public final static transient Set<Rel> STANDARD_DISBAND = new MassiveSet<>(Rel.LEADER);
|
||||
public final static transient Set<Rel> STANDARD_FLAGS = new MassiveSet<>(Rel.LEADER);
|
||||
public final static transient Set<Rel> STANDARD_PERMS = new MassiveSet<>(Rel.LEADER);
|
||||
public final static transient Set<Rel> STANDARD_STATUS = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT);
|
||||
|
||||
// -------------------------------------------- //
|
||||
// META: CORE
|
||||
// -------------------------------------------- //
|
||||
@ -131,31 +161,31 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
getPermPerms();
|
||||
}
|
||||
|
||||
public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER), true, true, true); }
|
||||
public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", new LinkedHashSet<Rel>(), true, true, true); }
|
||||
public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), true, true, true); }
|
||||
public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), true, true, true); }
|
||||
public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), true, true, true); }
|
||||
public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER), true, true, true); }
|
||||
public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", STANDARD_BUILD, true, true, true); }
|
||||
public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", STANDARD_PAINBUILD, true, true, true); }
|
||||
public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", STANDARD_DOOR, true, true, true); }
|
||||
public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", STANDARD_BUTTON, true, true, true); }
|
||||
public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", STANDARD_LEVER, true, true, true); }
|
||||
public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", STANDARD_CONTAINER, true, true, true); }
|
||||
|
||||
public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermStatus() { return getCreative(PRIORITY_STATUS, ID_STATUS, ID_STATUS, "show status", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermHome() { return getCreative(PRIORITY_HOME, ID_HOME, ID_HOME, "teleport home", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), false, true, true); }
|
||||
public static MPerm getPermSethome() { return getCreative(PRIORITY_SETHOME, ID_SETHOME, ID_SETHOME, "set the home", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY), false, false, false); } // non editable, non visible.
|
||||
public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), false, false, false); } // non editable, non visible.
|
||||
public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); }
|
||||
public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", MUtil.set(Rel.LEADER), false, true, true); }
|
||||
public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", STANDARD_NAME, false, true, true); }
|
||||
public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", STANDARD_DESC, false, true, true); }
|
||||
public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", STANDARD_MOTD, false, true, true); }
|
||||
public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", STANDARD_INVITE, false, true, true); }
|
||||
public static MPerm getPermStatus() { return getCreative(PRIORITY_STATUS, ID_STATUS, ID_STATUS, "show status", STANDARD_STATUS, false, true, true); }
|
||||
public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", STANDARD_KICK, false, true, true); }
|
||||
public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", STANDARD_TITLE, false, true, true); }
|
||||
public static MPerm getPermHome() { return getCreative(PRIORITY_HOME, ID_HOME, ID_HOME, "teleport home", STANDARD_HOME, false, true, true); }
|
||||
public static MPerm getPermSethome() { return getCreative(PRIORITY_SETHOME, ID_SETHOME, ID_SETHOME, "set the home", STANDARD_SETHOME, false, true, true); }
|
||||
public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", STANDARD_DEPOSIT, false, false, false); } // non editable, non visible.
|
||||
public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", STANDARD_WITHDRAW, false, true, true); }
|
||||
public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", STANDARD_TERRITORY, false, true, true); }
|
||||
public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", STANDARD_ACCESS, false, true, true); }
|
||||
public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", STANDARD_CLAIMNEAR, false, false, false); } // non editable, non visible.
|
||||
public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", STANDARD_REL, false, true, true); }
|
||||
public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", STANDARD_DISBAND, false, true, true); }
|
||||
public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", STANDARD_FLAGS, false, true, true); }
|
||||
public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", STANDARD_PERMS, false, true, true); }
|
||||
|
||||
public static MPerm getCreative(int priority, String id, String name, String desc, Set<Rel> standard, boolean territory, boolean editable, boolean visible)
|
||||
{
|
||||
@ -232,7 +262,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
// What is the standard (aka default) perm value?
|
||||
// This value will be set for factions from the beginning.
|
||||
// Example: ... set of relations ...
|
||||
private Set<Rel> standard = new LinkedHashSet<>();
|
||||
private Set<Rel> standard = new MassiveSet<>();
|
||||
public Set<Rel> getStandard() { return this.standard; }
|
||||
public MPerm setStandard(Set<Rel> standard) { this.standard = standard; this.changed(); return this; }
|
||||
|
||||
@ -284,24 +314,45 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// EXTRAS
|
||||
// MESSAGES
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String createDeniedMessage(MPlayer mplayer, Faction hostFaction)
|
||||
public Mson getDeniedMessage(MPlayer mplayer, Faction faction)
|
||||
{
|
||||
// Null Check
|
||||
if (mplayer == null) throw new NullPointerException("mplayer");
|
||||
if (hostFaction == null) throw new NullPointerException("hostFaction");
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
String ret = Txt.parse("%s<b> does not allow you to %s<b>.", hostFaction.describeTo(mplayer, true), this.getDesc());
|
||||
CommandSender sender = mplayer.getSender();
|
||||
|
||||
Player player = mplayer.getPlayer();
|
||||
if (player != null && Perm.OVERRIDE.has(player))
|
||||
// Create not allowed message
|
||||
Mson message = Mson.mson(
|
||||
Mson.fromParsedMessage(faction.describeTo(mplayer, true)),
|
||||
Mson.mson(" does not allow you to "),
|
||||
this.getDesc(),
|
||||
"."
|
||||
).color(ChatColor.RED);
|
||||
|
||||
// Add bypass notice
|
||||
if (sender != null && Perm.OVERRIDE.has(sender))
|
||||
{
|
||||
ret += Txt.parse("\n<i>You can bypass by using " + CmdFactions.get().cmdFactionsOverride.getTemplate(false).toPlain(true));
|
||||
message = message.add(
|
||||
"\nYou can bypass by using ",
|
||||
CmdFactions.get().cmdFactionsOverride.getTemplate()
|
||||
).color(ChatColor.YELLOW);
|
||||
}
|
||||
|
||||
return ret;
|
||||
// Return
|
||||
return message;
|
||||
}
|
||||
|
||||
public void sendDeniedMessage(Selector selector, Faction faction)
|
||||
{
|
||||
if (selector == null) throw new NullPointerException("selector");
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
if (!(selector instanceof MPlayer)) return;
|
||||
|
||||
MPlayer mplayer = (MPlayer) selector;
|
||||
mplayer.message(this.getDeniedMessage(mplayer, faction));
|
||||
}
|
||||
|
||||
public String getDesc(boolean withName, boolean withDesc)
|
||||
@ -339,29 +390,34 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
return Txt.implode(parts, " ");
|
||||
}
|
||||
|
||||
public boolean has(Faction faction, Faction hostFaction)
|
||||
{
|
||||
// Null Check
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
if (hostFaction == null) throw new NullPointerException("hostFaction");
|
||||
// -------------------------------------------- //
|
||||
// HAS
|
||||
// -------------------------------------------- //
|
||||
|
||||
Rel rel = faction.getRelationTo(hostFaction);
|
||||
return hostFaction.isPermitted(this, rel);
|
||||
public boolean has(Selector selector, Faction faction)
|
||||
{
|
||||
return this.has(selector, faction, false);
|
||||
}
|
||||
|
||||
public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose)
|
||||
public boolean has(Selector selector, Faction faction, boolean verboose)
|
||||
{
|
||||
// Null Check
|
||||
if (mplayer == null) throw new NullPointerException("mplayer");
|
||||
if (hostFaction == null) throw new NullPointerException("hostFaction");
|
||||
if (selector == null) throw new NullPointerException("selector");
|
||||
if (faction == null) throw new NullPointerException("faction");
|
||||
|
||||
if (mplayer.isOverriding()) return true;
|
||||
// Is overriding?
|
||||
if (selector instanceof MPlayer && ((MPlayer) selector).isOverriding()) return true;
|
||||
|
||||
Rel rel = mplayer.getRelationTo(hostFaction);
|
||||
if (hostFaction.isPermitted(this, rel)) return true;
|
||||
// Is this participator blacklisted?
|
||||
if (!faction.isFactionBannedInherited(selector))
|
||||
{
|
||||
// Is he permitted?
|
||||
if (faction.isPermittedAny(this, selector)) return true;
|
||||
}
|
||||
|
||||
if (verboose) mplayer.message(this.createDeniedMessage(mplayer, hostFaction));
|
||||
// Inform
|
||||
if (verboose) this.sendDeniedMessage(selector, faction);
|
||||
|
||||
// Otherwise, he doesn't have this perm.
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -383,7 +439,7 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
{
|
||||
if (verboose && accessStatus == AccessStatus.DECREASED)
|
||||
{
|
||||
mplayer.message(this.createDeniedMessage(mplayer, hostFaction));
|
||||
this.sendDeniedMessage(mplayer, hostFaction);
|
||||
}
|
||||
|
||||
return accessStatus.hasAccess();
|
||||
@ -394,56 +450,22 @@ public class MPerm extends Entity<MPerm> implements Prioritized, Registerable, N
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL: ASCII
|
||||
// CONVENIENCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String getStateHeaders()
|
||||
// TODO: REl to id conversion
|
||||
public Set<String> getStandardIds()
|
||||
{
|
||||
String ret = "";
|
||||
for (Rel rel : Rel.values())
|
||||
// Create
|
||||
Set<String> ret = new MassiveSet<>();
|
||||
|
||||
// Fill
|
||||
for (Rel rel : this.getStandard())
|
||||
{
|
||||
ret += rel.getColor().toString();
|
||||
ret += rel.toString().substring(0, 3);
|
||||
ret += " ";
|
||||
ret.add(rel.getId());
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public String getStateInfo(Set<Rel> value, boolean withDesc)
|
||||
{
|
||||
String ret = "";
|
||||
|
||||
for (Rel rel : Rel.values())
|
||||
{
|
||||
if (value.contains(rel))
|
||||
{
|
||||
ret += "<g>YES";
|
||||
}
|
||||
else
|
||||
{
|
||||
ret += "<b>NOO";
|
||||
}
|
||||
ret += " ";
|
||||
}
|
||||
|
||||
String color = "<aqua>";
|
||||
if (!this.isVisible())
|
||||
{
|
||||
color = "<silver>";
|
||||
}
|
||||
else if (this.isEditable())
|
||||
{
|
||||
color = "<pink>";
|
||||
}
|
||||
|
||||
ret += color;
|
||||
ret += this.getName();
|
||||
|
||||
ret = Txt.parse(ret);
|
||||
|
||||
if (withDesc) ret += " <i>" + this.getDesc();
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import com.massivecraft.factions.FactionsParticipator;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.RelationParticipator;
|
||||
import com.massivecraft.factions.SelectorType;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
|
||||
import com.massivecraft.factions.event.EventFactionsChunksChange;
|
||||
import com.massivecraft.factions.event.EventFactionsDisband;
|
||||
@ -167,6 +168,9 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
// Null means default specified in MConf.
|
||||
private Boolean territoryInfoTitles = null;
|
||||
|
||||
private String usedFactionId = null;
|
||||
private transient Faction usedFaction = null;
|
||||
|
||||
// The Faction this player is currently autoclaiming for.
|
||||
// Null means the player isn't auto claiming.
|
||||
// NOTE: This field will not be saved to the database ever.
|
||||
@ -578,6 +582,42 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
this.changed();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELD: usedFactionId
|
||||
// -------------------------------------------- //
|
||||
|
||||
public String getUsedFactionId()
|
||||
{
|
||||
return usedFactionId;
|
||||
}
|
||||
|
||||
public void setUsedFactionId(String usedFactionId)
|
||||
{
|
||||
// Detect Nochange
|
||||
if (MUtil.equals(this.usedFactionId, usedFactionId)) return;
|
||||
|
||||
// Apply
|
||||
this.usedFactionId = usedFactionId;
|
||||
|
||||
// Mark as changed
|
||||
this.changed();
|
||||
}
|
||||
|
||||
public Faction getUsedFaction()
|
||||
{
|
||||
if (this.usedFaction != null) return this.usedFaction;
|
||||
if (this.usedFactionId == null) return this.getFaction();
|
||||
|
||||
this.usedFaction = Faction.get(this.getUsedFactionId());
|
||||
return usedFaction;
|
||||
}
|
||||
|
||||
public void setUsedFaction(Faction usedFaction)
|
||||
{
|
||||
this.usedFaction = usedFaction;
|
||||
if (usedFaction != null) this.setUsedFactionId(usedFaction.getId());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// TITLE, NAME, FACTION NAME AND CHAT
|
||||
// -------------------------------------------- //
|
||||
@ -636,6 +676,16 @@ public class MPlayer extends SenderEntity<MPlayer> implements FactionsParticipat
|
||||
return this.getNameAndTitle(this.getColorTo(mplayer).toString());
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: Selector
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public SelectorType getType()
|
||||
{
|
||||
return SelectorType.PLAYER;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// RELATION AND RELATION COLORS
|
||||
// -------------------------------------------- //
|
||||
|
@ -0,0 +1,85 @@
|
||||
package com.massivecraft.factions.entity.migrator;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.store.migrator.MigratorFieldConvert;
|
||||
import com.massivecraft.massivecore.store.migrator.MigratorRoot;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonArray;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class MigratorFaction002Perms extends MigratorRoot
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static MigratorFaction002Perms i = new MigratorFaction002Perms();
|
||||
public static MigratorFaction002Perms get() { return i; }
|
||||
private MigratorFaction002Perms()
|
||||
{
|
||||
super(Faction.class);
|
||||
this.addInnerMigrator(new MigratorFaction002PermsField());
|
||||
}
|
||||
|
||||
public class MigratorFaction002PermsField extends MigratorFieldConvert
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private MigratorFaction002PermsField()
|
||||
{
|
||||
super("perms");
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public Object migrateInner(JsonElement perms)
|
||||
{
|
||||
JsonObject ret = new JsonObject();
|
||||
|
||||
// If non-null ...
|
||||
if (!perms.isJsonNull())
|
||||
{
|
||||
// ... and proper type ...
|
||||
if (!perms.isJsonObject()) throw new IllegalArgumentException(perms.toString());
|
||||
|
||||
JsonArray arrayRel;
|
||||
JsonArray arrayString;
|
||||
Rel rel;
|
||||
|
||||
// ... go through all perms ...
|
||||
for (Entry<String, JsonElement> entry: perms.getAsJsonObject().entrySet())
|
||||
{
|
||||
String id = entry.getKey();
|
||||
JsonElement value = entry.getValue();
|
||||
|
||||
if (!value.isJsonArray()) throw new IllegalArgumentException("Inner element was no array:" + value.toString());
|
||||
arrayRel = value.getAsJsonArray();
|
||||
arrayString = new JsonArray();
|
||||
|
||||
// ... change from Rel to string-Id ...
|
||||
for (JsonElement jsonElement : arrayRel)
|
||||
{
|
||||
if (jsonElement.isJsonNull()) continue;
|
||||
rel = MassiveCore.gson.fromJson(jsonElement, Rel.class);
|
||||
arrayString.add(rel.getId());
|
||||
}
|
||||
|
||||
// ... and attach back to object.
|
||||
ret.add(id, arrayString);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.massivecraft.factions.event;
|
||||
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -26,8 +26,8 @@ public class EventFactionsPermChange extends EventFactionsAbstractSender
|
||||
private final MPerm perm;
|
||||
public MPerm getPerm() { return this.perm; }
|
||||
|
||||
private final Rel rel;
|
||||
public Rel getRel() { return this.rel; }
|
||||
private final Selector selector;
|
||||
public Selector getSelector() { return this.selector; }
|
||||
|
||||
private boolean newValue;
|
||||
public boolean getNewValue() { return this.newValue; }
|
||||
@ -37,12 +37,12 @@ public class EventFactionsPermChange extends EventFactionsAbstractSender
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public EventFactionsPermChange(CommandSender sender, Faction faction, MPerm perm, Rel rel, boolean newValue)
|
||||
public EventFactionsPermChange(CommandSender sender, Faction faction, MPerm perm, Selector selector, boolean newValue)
|
||||
{
|
||||
super(sender);
|
||||
this.faction = faction;
|
||||
this.perm = perm;
|
||||
this.rel = rel;
|
||||
this.selector = selector;
|
||||
this.newValue = newValue;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.massivecraft.factions.integration;
|
||||
|
||||
import com.massivecraft.factions.EconomyParticipator;
|
||||
import com.massivecraft.factions.Selector;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
@ -86,11 +87,7 @@ public class Econ
|
||||
if (me == fMe && fMe == fYou) return true;
|
||||
|
||||
// Factions can be controlled by those that have permissions
|
||||
if (you instanceof Faction)
|
||||
{
|
||||
if (me instanceof Faction && mperm.has((Faction)me, fYou)) return true;
|
||||
if (me instanceof MPlayer && mperm.has((MPlayer)me, fYou, false)) return true;
|
||||
}
|
||||
if (you instanceof Faction && me instanceof Selector && mperm.has((Selector) me, fYou)) return true;
|
||||
|
||||
// Otherwise you may not! ;,,;
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user