diff --git a/plugin.yml b/plugin.yml index 57ae179a..c9223b04 100644 --- a/plugin.yml +++ b/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 diff --git a/src/com/massivecraft/factions/FactionsParticipator.java b/src/com/massivecraft/factions/FactionsParticipator.java index 90998e51..26e10a76 100644 --- a/src/com/massivecraft/factions/FactionsParticipator.java +++ b/src/com/massivecraft/factions/FactionsParticipator.java @@ -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 { } diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index aa764bc4..1d7ac232 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -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, diff --git a/src/com/massivecraft/factions/Rel.java b/src/com/massivecraft/factions/Rel.java index 965649d5..93d9e13d 100644 --- a/src/com/massivecraft/factions/Rel.java +++ b/src/com/massivecraft/factions/Rel.java @@ -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 // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/Selector.java b/src/com/massivecraft/factions/Selector.java new file mode 100644 index 00000000..8437f9f5 --- /dev/null +++ b/src/com/massivecraft/factions/Selector.java @@ -0,0 +1,8 @@ +package com.massivecraft.factions; + +public interface Selector +{ + String getId(); + + SelectorType getType(); +} diff --git a/src/com/massivecraft/factions/SelectorType.java b/src/com/massivecraft/factions/SelectorType.java new file mode 100644 index 00000000..b961eaf5 --- /dev/null +++ b/src/com/massivecraft/factions/SelectorType.java @@ -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; + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index 5f15f509..b2310263 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -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)); // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsBan.java b/src/com/massivecraft/factions/cmd/CmdFactionsBan.java new file mode 100644 index 00000000..5038ba2e --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsBan.java @@ -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(); + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsBanAdd.java b/src/com/massivecraft/factions/cmd/CmdFactionsBanAdd.java new file mode 100644 index 00000000..557821cd --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsBanAdd.java @@ -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("Reason: %s", reason); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsBanList.java b/src/com/massivecraft/factions/cmd/CmdFactionsBanList.java new file mode 100644 index 00000000..5e373c4f --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsBanList.java @@ -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 pager = new Pager<>(this, title, page, faction.getFactionBans().getAll(), new Msonifier() + { + @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(); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsBanRemove.java b/src/com/massivecraft/factions/cmd/CmdFactionsBanRemove.java new file mode 100644 index 00000000..ac2de432 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsBanRemove.java @@ -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)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java index 48eab376..1f1edf20 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java @@ -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(); + } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermAdd.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermAdd.java new file mode 100644 index 00000000..495602b8 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermAdd.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPermAdd extends CmdFactionsPermSet +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermAdd() + { + super(true); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermCopy.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermCopy.java new file mode 100644 index 00000000..7b2f5add --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermCopy.java @@ -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 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); + } + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermFor.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermFor.java new file mode 100644 index 00000000..c616c1e9 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermFor.java @@ -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 perms = new MassiveList<>(); + + // Fill + for (MPerm perm : faction.getPermittedFor(selector)) + { + // Create inner + Mson permDesc = mson(perm.getDesc(true, false)); + List tooltip = Mson.toPlain(faction.getPermittedShow(perm, msender), true); + + // Add + perms.add(permDesc.tooltip(tooltip)); + } + + // Inform + message(Mson.implodeCommaAndDot(perms)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java index cd2e3243..e31dd178 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermList.java @@ -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 PREDICATE_MPERM_VISIBLE = new Predicate() @@ -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 pager = new Pager<>(this, title, page, new Stringifier() + final Pager pager = new Pager<>(this, title, page, new Msonifier() { @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 predicate = msender.isOverriding() ? null : PREDICATE_MPERM_VISIBLE; - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), new Runnable() { @Override @@ -76,5 +78,5 @@ public class CmdFactionsPermList extends FactionsCommand } }); } - + } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermRemove.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermRemove.java new file mode 100644 index 00000000..772e5f7c --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermRemove.java @@ -0,0 +1,14 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsPermRemove extends CmdFactionsPermSet +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPermRemove() + { + super(false); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java index d97feaf4..152ab972 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermSet.java @@ -1,35 +1,44 @@ 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())); } - + // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @@ -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("The perm %s 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 already has %s set to %s for %s.", faction.describeTo(msender), perm.getDesc(true, false), Txt.parse(value ? "YES" : "NOO"), rel.getColor() + rel.getDescPlayerMany()); + String already = "already"; + if (!adding) already += " not"; + msg("%s is %s permitted for faction %s and perm %s.", 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("You are not allowed to remove the leader from the perm perms."); } - // Create messages - List 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 recipients = faction.getMPlayers(); - recipients.remove(msender); - - for (MPlayer recipient : recipients) - { - recipient.msg("%s set a perm for %s.", 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)); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java index 587ec9b9..c1ec6109 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPermShow.java @@ -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 mperms = this.readArg(MPerm.getAll()); - - // Create messages - List messages = new ArrayList<>(); - - 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))); - } + // Parameter + MPerm perm = this.readArg(); + Faction faction = msender.getUsedFaction(); - // Send messages - message(messages); + // Create + List message = faction.getPermittedShow(perm, msender); + + // Inform + message(message); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRank.java b/src/com/massivecraft/factions/cmd/CmdFactionsRank.java index 33fa267d..4e8c8c34 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRank.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRank.java @@ -84,7 +84,7 @@ public class CmdFactionsRank extends FactionsCommand this.ensureAllowed(); if (factionChange) - { + { this.changeFaction(); } @@ -109,7 +109,7 @@ public class CmdFactionsRank extends FactionsCommand if ( ! set) { - this.unregisterFields(); + this.unregisterFields(); } } @@ -264,7 +264,7 @@ public class CmdFactionsRank extends FactionsCommand // -------------------------------------------- // private void changeFaction() throws MassiveException - { + { // Don't change a leader to a new faction. if (targetRank == Rel.LEADER) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUsed.java b/src/com/massivecraft/factions/cmd/CmdFactionsUsed.java new file mode 100644 index 00000000..16609dbc --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUsed.java @@ -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("Your used faction is %s.", faction.describeTo(msender)); + } + + // Parameter + Faction faction = this.readArg(); + + // Apply + msender.setUsedFaction(faction); + + // Inform + String message = "Your used faction was %s."; + String result = faction == null ? "unset." : "set to " + faction.describeTo(msender, true); + msg(message, result); + } + +} diff --git a/src/com/massivecraft/factions/cmd/req/RequirementHasMPerm.java b/src/com/massivecraft/factions/cmd/req/RequirementHasMPerm.java new file mode 100644 index 00000000..4b579e24 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/req/RequirementHasMPerm.java @@ -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 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 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 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); + } + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeSelector.java b/src/com/massivecraft/factions/cmd/type/TypeSelector.java new file mode 100644 index 00000000..711b3dc1 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/type/TypeSelector.java @@ -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 +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private Type 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 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("%s did not match any selector.", arg); + } + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + // Create + Collection 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 type = this.fetchType(selectorType); + + // Get Visual + return type.getVisualMson(selector, sender); + } + + // -------------------------------------------- // + // Type Fetching + // -------------------------------------------- // + + @SuppressWarnings("unchecked") + private Type fetchType(SelectorType selectorType) + { + switch (selectorType) + { + case RANK: + return (Type) typeRank; + case RELATION: + return (Type) typeRel; + case PLAYER: + return (Type) typeMPlayer; + case FACTION: + return (Type) 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 readSafe(String arg, CommandSender sender, Type type) + { + try + { + return type.read(arg, sender); + } + catch (MassiveException e) + { + return null; + } + } + +} diff --git a/src/com/massivecraft/factions/engine/EngineChunkChange.java b/src/com/massivecraft/factions/engine/EngineChunkChange.java index 05283a4e..8e897768 100644 --- a/src/com/massivecraft/factions/engine/EngineChunkChange.java +++ b/src/com/massivecraft/factions/engine/EngineChunkChange.java @@ -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; } diff --git a/src/com/massivecraft/factions/engine/EngineMoveChunk.java b/src/com/massivecraft/factions/engine/EngineMoveChunk.java index ef87eb47..e411e73e 100644 --- a/src/com/massivecraft/factions/engine/EngineMoveChunk.java +++ b/src/com/massivecraft/factions/engine/EngineMoveChunk.java @@ -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; diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index dc01c1b1..4d69a0bc 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -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 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 implements FactionsParticipator // VERSION // -------------------------------------------- // - public int version = 1; + public int version = 2; // -------------------------------------------- // // FIELDS: RAW @@ -154,7 +163,10 @@ public class Faction extends Entity implements FactionsParticipator // The perm overrides are modifications to the default values. // Null means default. - private MassiveMapDef> perms = new MassiveMapDef<>(); + private MassiveMapDef> perms = new MassiveMapDef<>(); + + // The perm blacklist of which selectors are not allowed in any way. + private EntityInternalMap factionBans = new EntityInternalMap<>(this, FactionBan.class); // -------------------------------------------- // // FIELD: id @@ -459,12 +471,9 @@ public class Faction extends Entity implements FactionsParticipator // -------------------------------------------- // // RAW - - public EntityInternalMap getInvitations() { return this.invitations; } // FINER - public boolean isInvited(String playerId) { return this.getInvitations().containsKey(playerId); @@ -678,66 +687,26 @@ public class Faction extends Entity implements FactionsParticipator } // -------------------------------------------- // - // FIELD: permOverrides + // FIELD: perms // -------------------------------------------- // // RAW - - public Map> getPerms() + public MassiveMapDef> getPermIds() { - // We start with default values ... - Map> ret = new MassiveMap<>(); - for (MPerm mperm : MPerm.getAll()) - { - ret.put(mperm, new MassiveSet<>(mperm.getStandard())); - } - - // ... and if anything is explicitly set we use that info ... - Iterator>> iter = this.perms.entrySet().iterator(); - while (iter.hasNext()) - { - // ... for each entry ... - Entry> 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; + return this.perms; } - public void setPerms(Map> perms) - { - Map> permIds = new MassiveMap<>(); - for (Entry> entry : perms.entrySet()) - { - permIds.put(entry.getKey().getId(), entry.getValue()); - } - setPermIds(permIds); - } - - public void setPermIds(Map> perms) + public void setPermIds(MassiveMapDef> perms) { // Clean input - MassiveMapDef> target = new MassiveMapDef<>(); - for (Entry> entry : perms.entrySet()) + MassiveMapDef> target = new MassiveMapDef>(); + for (Entry> entry : perms.entrySet()) { String key = entry.getKey(); if (key == null) continue; key = key.toLowerCase(); // Lowercased Keys Version 2.6.0 --> 2.7.0 - Set value = entry.getValue(); + Set value = entry.getValue(); if (value == null) continue; target.put(key, value); @@ -753,105 +722,341 @@ public class Faction extends Entity implements FactionsParticipator this.changed(); } - // FINER - - public boolean isPermitted(String permId, Rel rel) + // Finer + public Map> getPerms() { - if (permId == null) throw new NullPointerException("permId"); + // We start with default values ... + Map> ret = new MassiveMap<>(); - Set rels = this.perms.get(permId); - if (rels != null) return rels.contains(rel); - - MPerm perm = MPerm.get(permId); - if (perm == null) throw new NullPointerException("perm"); - - return perm.getStandard().contains(rel); - } - - public boolean isPermitted(MPerm perm, Rel rel) - { - if (perm == null) throw new NullPointerException("perm"); - - String permId = perm.getId(); - if (permId == null) throw new NullPointerException("permId"); - - Set rels = this.perms.get(permId); - if (rels != null) return rels.contains(rel); - - return perm.getStandard().contains(rel); - } - - // --- - - public Set getPermitted(MPerm perm) - { - if (perm == null) throw new NullPointerException("perm"); - - String permId = perm.getId(); - if (permId == null) throw new NullPointerException("permId"); - - Set rels = this.perms.get(permId); - if (rels != null) return rels; - - return perm.getStandard(); - } - - public Set getPermitted(String permId) - { - if (permId == null) throw new NullPointerException("permId"); - - Set rels = this.perms.get(permId); - if (rels != null) return rels; - - MPerm perm = MPerm.get(permId); - if (perm == null) throw new NullPointerException("perm"); - - return perm.getStandard(); - } - - @Deprecated - // Use getPermitted instead. It's much quicker although not immutable. - public Set getPermittedRelations(MPerm perm) - { - return this.getPerms().get(perm); - } - - // --- - // TODO: Fix these below. They are reworking the whole map. - - public void setPermittedRelations(MPerm perm, Set rels) - { - Map> perms = this.getPerms(); - perms.put(perm, rels); - this.setPerms(perms); - } - - public void setPermittedRelations(MPerm perm, Rel... rels) - { - Set temp = new HashSet<>(); - temp.addAll(Arrays.asList(rels)); - this.setPermittedRelations(perm, temp); - } - - public void setRelationPermitted(MPerm perm, Rel rel, boolean permitted) - { - Map> perms = this.getPerms(); - - Set rels = perms.get(perm); - - boolean changed; - if (permitted) + // ... and if anything is explicitly set we use that info ... + for (Iterator>> it = this.getPermIds().entrySet().iterator(); it.hasNext(); ) { - changed = rels.add(rel); - } - else - { - changed = rels.remove(rel); + // ... for each entry ... + Entry> entry = it.next(); + + // ... extract id and remove null values ... + String id = entry.getKey(); + if (id == null) + { + it.remove(); + continue; + } + + // ... resolve object and skip unknowns ... + MPerm mperm = MPerm.get(id); + if (mperm == null) continue; + + ret.put(mperm, new MassiveSet<>(entry.getValue())); } - this.setPerms(perms); + for (MPerm mperm : MPerm.getAll()) + { + // Is already configured? + if (ret.containsKey(mperm)) continue; + + // Add + ret.put(mperm, mperm.getStandardIds()); + } - if (changed) this.changed(); + return ret; + } + + public void setPerms(Map> perms) + { + // Create + MassiveMapDef> permIds = new MassiveMapDef<>(); + + // Fill + for (Entry> 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 getPermittedIds(MPerm perm) + { + String permId = perm.getId(); + Set permitted = this.perms.get(permId); + return permitted != null ? permitted : perm.getStandardIds(); + } + + public Set getPermittedFor(Selector selector) + { + // Create + Set ret = new MassiveSet<>(); + + // 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"); + + // Get Ids + String idSelector = selector.getId(); + String idPerm = perm.getId(); + + // Get perms + Map> perms = this.getPermIds(); + Set selectors = perms.get(idPerm); + + // 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); + } + + perms.put(idPerm, selectors); + + // Changed + this.changed(); + } + + public void setPermitted(MPerm perm, Selector... selectors) + { + for (Selector selector : selectors) + { + this.setPermitted(perm, selector, true); + } + } + + 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; + + // 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"); + + // Is specifically granted? + Set selectors = this.getPermIds().get(perm.getId()); + if (selectors != null) return selectors.contains(selector.getId()); + + // Is standard? + return selector instanceof Rel && perm.getStandard().contains(selector); + } + + // -------------------------------------------- // + // PERMITTED > VISUAL + // -------------------------------------------- // + + public List getPermittedShow(MPerm perm, RelationParticipator relationParticipator) + { + // Resolve Permitted + Map> permitted = this.resolvePermitted(perm); + + // Return show + return this.getPermittedShow(perm, permitted, relationParticipator); + } + + public Mson getPermittedLine(MPerm perm, RelationParticipator relationParticipator) + { + // Create + Mson ret = Mson.EMPTY; + Map> permitted = this.resolvePermitted(perm); + + // Fill > Ranks + List 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); + } + + ret = ret.add(rankMson.color(ChatColor.DARK_GREEN)); + } + + // Fill > Relations + List relations = permitted.get(SelectorType.RELATION); + if (relations != null) + { + Mson relMson = Mson.EMPTY; + for (Selector selector : relations) + { + 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 factions = permitted.get(SelectorType.FACTION); + if (factions != null) ret = ret.add(Mson.mson("F").color(ChatColor.GREEN)); + + // Fill > Factions + List 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 showLines = Mson.toPlain(this.getPermittedShow(perm, permitted, relationParticipator), true); + showLines.add(ret.getTooltip()); + ret = ret.tooltip(showLines); + + // Return + return ret; + } + + private Map> resolvePermitted(MPerm perm) + { + // Create + Map> 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 selectors = ret.get(selectorType); + if (selectors == null) + { + selectors = new MassiveList<>(selector); + ret.put(selectorType, selectors); + } + else + { + selectors.add(selector); + } + } + + // Return + return ret; + } + + private List getPermittedShow(MPerm perm, Map> 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 Mson getResolveSection(String header, List resolve, Type type) + { + Mson heading = Mson.mson(header).color(ChatColor.YELLOW); + if (resolve == null) return heading; + + List 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 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; } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/FactionBan.java b/src/com/massivecraft/factions/entity/FactionBan.java new file mode 100644 index 00000000..16606649 --- /dev/null +++ b/src/com/massivecraft/factions/entity/FactionBan.java @@ -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 +{ + // -------------------------------------------- // + // 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; + } + +} diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index af50ae79..640761bf 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -84,12 +84,12 @@ public class FactionColl extends Coll 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.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.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; } diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index da60fbd0..1cda8c8a 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -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 implements Prioritized, Registerable, Named { // -------------------------------------------- // @@ -53,7 +57,7 @@ public class MPerm extends Entity implements Prioritized, Registerable, N public final static transient String ID_FLAGS = "flags"; public final static transient String ID_PERMS = "perms"; public final static transient String ID_STATUS = "status"; - + public final static transient int PRIORITY_BUILD = 1000; public final static transient int PRIORITY_PAINBUILD = 2000; public final static transient int PRIORITY_DOOR = 3000; @@ -80,6 +84,32 @@ public class MPerm extends Entity 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 STANDARD_BUILD = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER); + public final static transient Set STANDARD_PAINBUILD = new MassiveSet<>(); + public final static transient Set STANDARD_DOOR = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY); + public final static transient Set STANDARD_BUTTON = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY); + public final static transient Set STANDARD_LEVER = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY); + public final static transient Set STANDARD_CONTAINER = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER); + + public final static transient Set STANDARD_NAME = new MassiveSet<>(Rel.LEADER); + public final static transient Set STANDARD_DESC = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_MOTD = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_INVITE = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_KICK = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_TITLE = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_HOME = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT); + public final static transient Set STANDARD_SETHOME = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_DEPOSIT = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, TRUCE, Rel.NEUTRAL, Rel.ENEMY); + public final static transient Set STANDARD_WITHDRAW = new MassiveSet<>(Rel.LEADER); + public final static transient Set STANDARD_TERRITORY = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_ACCESS = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_CLAIMNEAR = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY); + public final static transient Set STANDARD_REL = new MassiveSet<>(Rel.LEADER, Rel.OFFICER); + public final static transient Set STANDARD_DISBAND = new MassiveSet<>(Rel.LEADER); + public final static transient Set STANDARD_FLAGS = new MassiveSet<>(Rel.LEADER); + public final static transient Set STANDARD_PERMS = new MassiveSet<>(Rel.LEADER); + public final static transient Set STANDARD_STATUS = new MassiveSet<>(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT); + // -------------------------------------------- // // META: CORE // -------------------------------------------- // @@ -131,31 +161,31 @@ public class MPerm extends Entity 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(), 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 standard, boolean territory, boolean editable, boolean visible) { @@ -232,7 +262,7 @@ public class MPerm extends Entity 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 standard = new LinkedHashSet<>(); + private Set standard = new MassiveSet<>(); public Set getStandard() { return this.standard; } public MPerm setStandard(Set standard) { this.standard = standard; this.changed(); return this; } @@ -284,24 +314,45 @@ public class MPerm extends Entity 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 does not allow you to %s.", 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("\nYou 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 implements Prioritized, Registerable, N return Txt.implode(parts, " "); } - public boolean has(Faction faction, Faction hostFaction) + // -------------------------------------------- // + // HAS + // -------------------------------------------- // + + public boolean has(Selector selector, Faction faction) { - // Null Check - if (faction == null) throw new NullPointerException("faction"); - if (hostFaction == null) throw new NullPointerException("hostFaction"); - - Rel rel = faction.getRelationTo(hostFaction); - return hostFaction.isPermitted(this, rel); + 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 implements Prioritized, Registerable, N { if (verboose && accessStatus == AccessStatus.DECREASED) { - mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); + this.sendDeniedMessage(mplayer, hostFaction); } return accessStatus.hasAccess(); @@ -392,58 +448,24 @@ public class MPerm extends Entity implements Prioritized, Registerable, N return this.has(mplayer, hostFaction, verboose); } - + // -------------------------------------------- // - // UTIL: ASCII + // CONVENIENCE // -------------------------------------------- // - public static String getStateHeaders() + // TODO: REl to id conversion + public Set getStandardIds() { - String ret = ""; - for (Rel rel : Rel.values()) + // Create + Set 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 value, boolean withDesc) - { - String ret = ""; - - for (Rel rel : Rel.values()) - { - if (value.contains(rel)) - { - ret += "YES"; - } - else - { - ret += "NOO"; - } - ret += " "; - } - - String color = ""; - if (!this.isVisible()) - { - color = ""; - } - else if (this.isEditable()) - { - color = ""; - } - - ret += color; - ret += this.getName(); - - ret = Txt.parse(ret); - - if (withDesc) ret += " " + this.getDesc(); - + // Return return ret; } diff --git a/src/com/massivecraft/factions/entity/MPlayer.java b/src/com/massivecraft/factions/entity/MPlayer.java index 94571614..29690e8c 100644 --- a/src/com/massivecraft/factions/entity/MPlayer.java +++ b/src/com/massivecraft/factions/entity/MPlayer.java @@ -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; @@ -166,6 +167,9 @@ public class MPlayer extends SenderEntity implements FactionsParticipat // Does this player use titles for territory info? // 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. @@ -577,7 +581,43 @@ public class MPlayer extends SenderEntity implements FactionsParticipat // Mark as changed 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 // -------------------------------------------- // @@ -635,6 +675,16 @@ public class MPlayer extends SenderEntity implements FactionsParticipat { return this.getNameAndTitle(this.getColorTo(mplayer).toString()); } + + // -------------------------------------------- // + // OVERRIDE: Selector + // -------------------------------------------- // + + @Override + public SelectorType getType() + { + return SelectorType.PLAYER; + } // -------------------------------------------- // // RELATION AND RELATION COLORS diff --git a/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Perms.java b/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Perms.java new file mode 100644 index 00000000..df5a8490 --- /dev/null +++ b/src/com/massivecraft/factions/entity/migrator/MigratorFaction002Perms.java @@ -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 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; + } + + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsPermChange.java b/src/com/massivecraft/factions/event/EventFactionsPermChange.java index d03d60c8..580ddd4f 100644 --- a/src/com/massivecraft/factions/event/EventFactionsPermChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsPermChange.java @@ -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; } diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index b388c6a6..693f8770 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -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;