From 422c896631751e9ee56b11fb6d877cd322b33598 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 2 Oct 2014 14:02:07 +0200 Subject: [PATCH] Make the Faction Permissions more dynamic as well. --- .../java/com/massivecraft/factions/FPerm.java | 223 ------------ .../com/massivecraft/factions/Factions.java | 4 +- .../factions/adapter/FPermAdapter.java | 29 -- .../cmd/CmdFactionsAccessFaction.java | 6 +- .../factions/cmd/CmdFactionsAccessPlayer.java | 6 +- .../factions/cmd/CmdFactionsAutoClaim.java | 6 +- .../factions/cmd/CmdFactionsClaim.java | 6 +- .../factions/cmd/CmdFactionsDisband.java | 6 +- .../factions/cmd/CmdFactionsFlag.java | 4 +- .../factions/cmd/CmdFactionsHome.java | 4 +- .../factions/cmd/CmdFactionsInvite.java | 6 +- .../factions/cmd/CmdFactionsKick.java | 6 +- .../factions/cmd/CmdFactionsPerm.java | 54 +-- .../factions/cmd/CmdFactionsSethome.java | 6 +- .../factions/cmd/CmdFactionsUnclaimall.java | 6 +- .../factions/cmd/CmdFactionsUnsethome.java | 6 +- .../factions/cmd/arg/ARFPerm.java | 51 --- .../factions/cmd/arg/ARMPerm.java | 88 +++++ .../massivecraft/factions/entity/Faction.java | 128 ++++--- .../factions/entity/FactionColl.java | 31 +- .../massivecraft/factions/entity/MConf.java | 3 - .../massivecraft/factions/entity/MFlag.java | 2 +- .../massivecraft/factions/entity/MPerm.java | 325 ++++++++++++++++++ .../factions/entity/MPermColl.java | 51 +++ .../massivecraft/factions/entity/MPlayer.java | 5 +- .../factions/integration/Econ.java | 6 +- .../listeners/FactionsListenerMain.java | 22 +- .../massivecraft/factions/update/OldConf.java | 8 +- 28 files changed, 650 insertions(+), 448 deletions(-) delete mode 100644 src/main/java/com/massivecraft/factions/FPerm.java delete mode 100644 src/main/java/com/massivecraft/factions/adapter/FPermAdapter.java delete mode 100644 src/main/java/com/massivecraft/factions/cmd/arg/ARFPerm.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/arg/ARMPerm.java create mode 100644 src/main/java/com/massivecraft/factions/entity/MPerm.java create mode 100644 src/main/java/com/massivecraft/factions/entity/MPermColl.java diff --git a/src/main/java/com/massivecraft/factions/FPerm.java b/src/main/java/com/massivecraft/factions/FPerm.java deleted file mode 100644 index 32e412f9..00000000 --- a/src/main/java/com/massivecraft/factions/FPerm.java +++ /dev/null @@ -1,223 +0,0 @@ -package com.massivecraft.factions; - -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.Txt; - -/** - * Permissions that you (a player) may or may not have in the territory of a certain faction. - * Each faction have many Rel's assigned to each one of these Perms. - */ -public enum FPerm -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - BUILD(true, "build", "edit the terrain", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY), - PAINBUILD(true, "painbuild", "edit, take damage"), - DOOR(true, "door", "use doors", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), - BUTTON(true, "button", "use stone buttons", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), - LEVER(true, "lever", "use levers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY), - CONTAINER(true, "container", "use containers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER), - - INVITE(false, "invite", "invite players", Rel.LEADER, Rel.OFFICER), - KICK(false, "kick", "kick members", Rel.LEADER, Rel.OFFICER), - SETHOME(false, "sethome", "set the home", Rel.LEADER, Rel.OFFICER), - WITHDRAW(false, "withdraw", "withdraw money", Rel.LEADER, Rel.OFFICER), - TERRITORY(false, "territory", "claim or unclaim", Rel.LEADER, Rel.OFFICER), - ACCESS(false, "access", "grant territory", Rel.LEADER, Rel.OFFICER), - DISBAND(false, "disband", "disband the faction", Rel.LEADER), - PERMS(false, "perms", "manage permissions", Rel.LEADER), - FLAGS(false, "flags", "manage flags", Rel.LEADER), - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final boolean territoryPerm; - public boolean isTerritoryPerm() { return this.territoryPerm; } - - private final String nicename; - public String getNicename() { return this.nicename; } - - private final String desc; - public String getDescription() { return this.desc; } - - public final Set defaultDefault; - public Set getDefaultDefault() { return new LinkedHashSet(this.defaultDefault); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - private FPerm(boolean territoryPerm, final String nicename, final String desc, final Rel... rels) - { - this.territoryPerm = territoryPerm; - this.nicename = nicename; - this.desc = desc; - - Set defaultDefaultValue = new LinkedHashSet(); - defaultDefaultValue.addAll(Arrays.asList(rels)); - defaultDefaultValue = Collections.unmodifiableSet(defaultDefaultValue); - this.defaultDefault = defaultDefaultValue; - } - - // -------------------------------------------- // - // DEFAULTS - // -------------------------------------------- // - - public Set getDefault() - { - Set ret = MConf.get().defaultFactionPerms.get(this); - if (ret == null) return this.getDefaultDefault(); - ret = new LinkedHashSet(ret); - return ret; - } - - public static Map> getDefaultDefaults() - { - Map> ret = new LinkedHashMap>(); - for (FPerm fperm : values()) - { - ret.put(fperm, fperm.getDefaultDefault()); - } - return ret; - } - - // -------------------------------------------- // - // PARSE - // -------------------------------------------- // - - public static FPerm parse(String str) - { - str = str.toLowerCase(); - if (str.startsWith("a")) return ACCESS; - if (str.startsWith("bui")) return BUILD; - if (str.startsWith("pa")) return PAINBUILD; - if (str.startsWith("do")) return DOOR; - if (str.startsWith("but")) return BUTTON; - if (str.startsWith("l")) return LEVER; - if (str.startsWith("co")) return CONTAINER; - if (str.startsWith("i")) return INVITE; - if (str.startsWith("k")) return KICK; - if (str.startsWith("s")) return SETHOME; - if (str.startsWith("w")) return WITHDRAW; - if (str.startsWith("t")) return TERRITORY; - if (str.startsWith("di")) return DISBAND; - if (str.startsWith("pe")) return PERMS; - if (str.startsWith("f")) return FLAGS; - return null; - } - - // -------------------------------------------- // - // HAS? - // -------------------------------------------- // - - public String createDeniedMessage(MPlayer mplayer, Faction hostFaction) - { - String ret = Txt.parse("%s does not allow you to %s.", hostFaction.describeTo(mplayer, true), this.getDescription()); - if (Perm.ADMIN.has(mplayer.getPlayer())) - { - ret += Txt.parse("\nYou can bypass by using " + Factions.get().getOuterCmdFactions().cmdFactionsAdmin.getUseageTemplate(false)); - } - return ret; - } - - public boolean has(Faction faction, Faction hostFaction) - { - Rel rel = faction.getRelationTo(hostFaction); - return hostFaction.getPermittedRelations(this).contains(rel); - } - - public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose) - { - if (mplayer.isUsingAdminMode()) return true; - - Rel rel = mplayer.getRelationTo(hostFaction); - if (hostFaction.getPermittedRelations(this).contains(rel)) return true; - - if (verboose) mplayer.sendMessage(this.createDeniedMessage(mplayer, hostFaction)); - - return false; - } - - public boolean has(MPlayer mplayer, PS ps, boolean verboose) - { - if (mplayer.isUsingAdminMode()) return true; - - TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(ps); - Faction hostFaction = ta.getHostFaction(); - - if (this.isTerritoryPerm()) - { - Boolean hasTerritoryAccess = ta.hasTerritoryAccess(mplayer); - if (hasTerritoryAccess != null) - { - if (verboose && !hasTerritoryAccess) - { - mplayer.sendMessage(this.createDeniedMessage(mplayer, hostFaction)); - } - return hasTerritoryAccess; - } - } - - return this.has(mplayer, hostFaction, verboose); - } - - // -------------------------------------------- // - // UTIL: ASCII - // -------------------------------------------- // - - public static String getStateHeaders() - { - String ret = ""; - for (Rel rel : Rel.values()) - { - ret += rel.getColor().toString(); - ret += rel.toString().substring(0, 3); - ret += " "; - } - - 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 += " "; - } - - ret +=""+this.getNicename(); - if (withDesc) - { - ret += " " + this.getDescription(); - } - return ret; - } - -} diff --git a/src/main/java/com/massivecraft/factions/Factions.java b/src/main/java/com/massivecraft/factions/Factions.java index 9411e3b4..0d0cc15e 100644 --- a/src/main/java/com/massivecraft/factions/Factions.java +++ b/src/main/java/com/massivecraft/factions/Factions.java @@ -2,7 +2,6 @@ package com.massivecraft.factions; import com.massivecraft.factions.adapter.BoardAdapter; import com.massivecraft.factions.adapter.BoardMapAdapter; -import com.massivecraft.factions.adapter.FPermAdapter; import com.massivecraft.factions.adapter.FactionPreprocessAdapter; import com.massivecraft.factions.adapter.RelAdapter; import com.massivecraft.factions.adapter.TerritoryAccessAdapter; @@ -25,6 +24,7 @@ import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.MFlagColl; +import com.massivecraft.factions.entity.MPermColl; import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.entity.MConfColl; import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; @@ -120,6 +120,7 @@ public class Factions extends MassivePlugin // Initialize Database this.databaseInitialized = false; MFlagColl.get().init(); + MPermColl.get().init(); MConfColl.get().init(); UpdateUtil.update(); MPlayerColl.get().init(); @@ -184,7 +185,6 @@ public class Factions extends MassivePlugin .registerTypeAdapter(Board.class, BoardAdapter.get()) .registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get()) .registerTypeAdapter(Rel.class, RelAdapter.get()) - .registerTypeAdapter(FPerm.class, FPermAdapter.get()) ; } diff --git a/src/main/java/com/massivecraft/factions/adapter/FPermAdapter.java b/src/main/java/com/massivecraft/factions/adapter/FPermAdapter.java deleted file mode 100644 index d578710c..00000000 --- a/src/main/java/com/massivecraft/factions/adapter/FPermAdapter.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.massivecraft.factions.adapter; - -import java.lang.reflect.Type; - -import com.massivecraft.factions.FPerm; -import com.massivecraft.massivecore.xlib.gson.JsonDeserializationContext; -import com.massivecraft.massivecore.xlib.gson.JsonDeserializer; -import com.massivecraft.massivecore.xlib.gson.JsonElement; -import com.massivecraft.massivecore.xlib.gson.JsonParseException; - -public class FPermAdapter implements JsonDeserializer -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static FPermAdapter i = new FPermAdapter(); - public static FPermAdapter get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public FPerm deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException - { - return FPerm.parse(json.getAsString()); - } -} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessFaction.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessFaction.java index e6b57dc9..8c572a7c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessFaction.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessFaction.java @@ -1,10 +1,10 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; @@ -41,8 +41,8 @@ public class CmdFactionsAccessFaction extends CmdFactionsAccessAbstract Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isFactionIdGranted(faction.getId())); if (newValue == null) return; - // FPerm - if (!FPerm.ACCESS.has(msender, hostFaction, true)) return; + // MPerm + if (!MPerm.getAccess().has(msender, hostFaction, true)) return; // Apply ta = ta.withFactionId(faction.getId(), newValue); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessPlayer.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessPlayer.java index 4abf18ce..e26e25aa 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessPlayer.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessPlayer.java @@ -1,9 +1,9 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARMPlayer; import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; @@ -41,8 +41,8 @@ public class CmdFactionsAccessPlayer extends CmdFactionsAccessAbstract Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isPlayerIdGranted(mplayer.getId())); if (newValue == null) return; - // FPerm - if (!FPerm.ACCESS.has(msender, hostFaction, true)) return; + // MPerm + if (!MPerm.getAccess().has(msender, hostFaction, true)) return; // Apply ta = ta.withPlayerId(mplayer.getId(), newValue); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java index 9ae49dad..58de4c02 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java @@ -1,9 +1,9 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; import com.massivecraft.massivecore.ps.PS; @@ -44,8 +44,8 @@ public class CmdFactionsAutoClaim extends FactionsCommand return; } - // FPerm - if (forFaction.isNormal() && !FPerm.TERRITORY.has(msender, forFaction, true)) return; + // MPerm + if (forFaction.isNormal() && !MPerm.getTerritory().has(msender, forFaction, true)) return; msender.setAutoClaimFaction(forFaction); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java index ef1e4c49..d5981c45 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsClaim.java @@ -1,10 +1,10 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.task.SpiralTask; import com.massivecraft.massivecore.cmd.arg.ARInteger; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; @@ -46,8 +46,8 @@ public class CmdFactionsClaim extends FactionsCommand final Faction forFaction = this.arg(1, ARFaction.get(), msenderFaction); if (forFaction == null) return; - // FPerm - if (forFaction.isNormal() && !FPerm.TERRITORY.has(msender, forFaction, true)) return; + // MPerm + if (forFaction.isNormal() && !MPerm.getTerritory().has(msender, forFaction, true)) return; // Validate if (radius < 1) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java index 874e0732..ced7f837 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -3,13 +3,13 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.EventFactionsDisband; import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; @@ -45,8 +45,8 @@ public class CmdFactionsDisband extends FactionsCommand Faction faction = this.arg(0, ARFaction.get(), msenderFaction); if (faction == null) return; - // FPerm - if ( ! FPerm.DISBAND.has(msender, faction, true)) return; + // MPerm + if ( ! MPerm.getDisband().has(msender, faction, true)) return; // Verify if (faction.getFlag(MFlag.getPermanent())) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java index 11da036d..7736d1dc 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsFlag.java @@ -1,11 +1,11 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARMFlag; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.event.EventFactionsFlagChange; import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; @@ -67,7 +67,7 @@ public class CmdFactionsFlag extends FactionsCommand } // Do the sender have the right to change flags for this faction? - if ( ! FPerm.PERMS.has(msender, faction, true)) return; + if ( ! MPerm.getFlags().has(msender, faction, true)) return; // Is this flag editable? if (!msender.isUsingAdminMode() && !mflag.isEditable()) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java index 41557854..3a57b0e9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -4,7 +4,6 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; @@ -12,6 +11,7 @@ import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.event.EventFactionsHomeTeleport; @@ -68,7 +68,7 @@ public class CmdFactionsHome extends FactionsCommandHome { msender.msg("%s does not have a home.", faction.describeTo(msender, true)); - if (FPerm.SETHOME.has(msender, faction, false)) + if (MPerm.getSethome().has(msender, faction, false)) { msender.msg("You should:"); msender.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsSethome.getUseageTemplate()); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInvite.java index dc94dae8..9829b242 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInvite.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsInvite.java @@ -1,10 +1,10 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARMPlayer; import com.massivecraft.factions.cmd.req.ReqHasFaction; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.event.EventFactionsInvitedChange; import com.massivecraft.massivecore.cmd.arg.ARBoolean; @@ -54,8 +54,8 @@ public class CmdFactionsInvite extends FactionsCommand return; } - // FPerm - if ( ! FPerm.INVITE.has(msender, msenderFaction, true)) return; + // MPerm + if ( ! MPerm.getInvite().has(msender, msenderFaction, true)) return; // Event EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, newInvited); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsKick.java index ee52a4e8..74abb15d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -1,11 +1,11 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARMPlayer; import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; @@ -63,9 +63,9 @@ public class CmdFactionsKick extends FactionsCommand return; } - // FPerm + // MPerm Faction mplayerFaction = mplayer.getFaction(); - if (!FPerm.KICK.has(msender, mplayerFaction, true)) return; + if ( ! MPerm.getKick().has(msender, mplayerFaction, true)) return; // Event EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPerm.java index 228f5b15..c56e9a12 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPerm.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsPerm.java @@ -1,12 +1,12 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; -import com.massivecraft.factions.cmd.arg.ARFPerm; +import com.massivecraft.factions.cmd.arg.ARMPerm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARRel; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.util.Txt; @@ -40,60 +40,72 @@ public class CmdFactionsPerm extends FactionsCommand @Override public void perform() { + // Arg: Faction Faction faction = this.arg(0, ARFaction.get(), msenderFaction); if (faction == null) return; + // Case: Show All if ( ! this.argIsSet(1)) { msg(Txt.titleize("Perms for " + faction.describeTo(msender, true))); - msg(FPerm.getStateHeaders()); - for (FPerm perm : FPerm.values()) + msg(MPerm.getStateHeaders()); + for (MPerm perm : MPerm.getAll()) { msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); } return; } - FPerm perm = this.arg(1, ARFPerm.get()); - if (perm == null) return; - //System.out.println("perm = "+perm); + // Arg: MPerm + MPerm mperm = this.arg(1, ARMPerm.get()); + if (mperm == null) return; + // Case: Show One if ( ! this.argIsSet(2)) { msg(Txt.titleize("Perm for " + faction.describeTo(msender, true))); - msg(FPerm.getStateHeaders()); - msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); + msg(MPerm.getStateHeaders()); + msg(mperm.getStateInfo(faction.getPermittedRelations(mperm), true)); return; } // Do the sender have the right to change perms for this faction? - if ( ! FPerm.PERMS.has(msender, faction, true)) return; + if ( ! MPerm.getPerms().has(msender, faction, true)) return; + // Is this perm editable? + if (!msender.isUsingAdminMode() && !mperm.isEditable()) + { + msg("The perm %s is not editable.", mperm.getName()); + return; + } + + // Arg: Rel Rel rel = this.arg(2, ARRel.get()); if (rel == null) return; - if (!this.argIsSet(3)) + if ( ! this.argIsSet(3)) { - msg("Should %s have the %s permission or not?\nYou must add \"yes\" or \"no\" at the end.", Txt.getNicedEnum(rel), Txt.getNicedEnum(perm)); + msg("Should %s have the %s permission or not?\nYou must add \"yes\" or \"no\" at the end.", Txt.getNicedEnum(rel), Txt.upperCaseFirst(mperm.getName())); return; } - Boolean val = this.arg(3, ARBoolean.get(), null); - if (val == null) return; + // Arg: Target Value + Boolean targetValue = this.arg(3, ARBoolean.get(), null); + if (targetValue == null) return; - // Do the change - //System.out.println("setRelationPermitted perm "+perm+", rel "+rel+", val "+val); - faction.setRelationPermitted(perm, rel, val); + // Apply + faction.setRelationPermitted(mperm, rel, targetValue); // The following is to make sure the leader always has the right to change perms if that is our goal. - if (perm == FPerm.PERMS && FPerm.PERMS.getDefault().contains(Rel.LEADER)) + if (mperm == MPerm.getPerms() && MPerm.getPerms().getStandard().contains(Rel.LEADER)) { - faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true); + faction.setRelationPermitted(MPerm.getPerms(), Rel.LEADER, true); } + // Inform msg(Txt.titleize("Perm for " + faction.describeTo(msender, true))); - msg(FPerm.getStateHeaders()); - msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); + msg(MPerm.getStateHeaders()); + msg(mperm.getStateInfo(faction.getPermittedRelations(mperm), true)); } } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSethome.java index b76f8321..05531b72 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSethome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSethome.java @@ -1,10 +1,10 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.event.EventFactionsHomeChange; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; @@ -42,8 +42,8 @@ public class CmdFactionsSethome extends FactionsCommandHome PS newHome = PS.valueOf(me.getLocation()); - // FPerm - if ( ! FPerm.SETHOME.has(msender, faction, true)) return; + // MPerm + if ( ! MPerm.getSethome().has(msender, faction, true)) return; // Verify if (!msender.isUsingAdminMode() && !faction.isValidHome(newHome)) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index 6fbdf2b9..a3e37163 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -2,7 +2,6 @@ package com.massivecraft.factions.cmd; import java.util.Set; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; @@ -12,6 +11,7 @@ import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.event.EventFactionsChunkChange; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.ps.PS; @@ -44,8 +44,8 @@ public class CmdFactionsUnclaimall extends FactionsCommand Faction faction = msenderFaction; Faction newFaction = FactionColl.get().getNone(); - // FPerm - if (!FPerm.TERRITORY.has(msender, faction, true)) return; + // MPerm + if ( ! MPerm.getTerritory().has(msender, faction, true)) return; // Apply Set chunks = BoardColl.get().getChunks(faction); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java index c57cea24..336bf5d4 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsUnsethome.java @@ -1,9 +1,9 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.event.EventFactionsHomeChange; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; @@ -39,8 +39,8 @@ public class CmdFactionsUnsethome extends FactionsCommandHome // Other Perm if (faction != msenderFaction && !Perm.HOME_OTHER.has(sender, true)) return; - // FPerm - if ( ! FPerm.SETHOME.has(msender, faction, true)) return; + // MPerm + if ( ! MPerm.getSethome().has(msender, faction, true)) return; // NoChange if ( ! faction.hasHome()) diff --git a/src/main/java/com/massivecraft/factions/cmd/arg/ARFPerm.java b/src/main/java/com/massivecraft/factions/cmd/arg/ARFPerm.java deleted file mode 100644 index f8d6eb41..00000000 --- a/src/main/java/com/massivecraft/factions/cmd/arg/ARFPerm.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.massivecraft.factions.cmd.arg; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.bukkit.command.CommandSender; - -import com.massivecraft.factions.FPerm; -import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect; -import com.massivecraft.massivecore.util.Txt; - -public class ARFPerm extends ARAbstractSelect -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ARFPerm i = new ARFPerm(); - public static ARFPerm get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String typename() - { - return "faction permission"; - } - - @Override - public FPerm select(String str, CommandSender sender) - { - return FPerm.parse(str); - } - - @Override - public Collection altNames(CommandSender sender) - { - List ret = new ArrayList(); - - for (FPerm fperm : FPerm.values()) - { - ret.add(Txt.getNicedEnum(fperm)); - } - - return ret; - } - -} diff --git a/src/main/java/com/massivecraft/factions/cmd/arg/ARMPerm.java b/src/main/java/com/massivecraft/factions/cmd/arg/ARMPerm.java new file mode 100644 index 00000000..aa394ac7 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/arg/ARMPerm.java @@ -0,0 +1,88 @@ +package com.massivecraft.factions.cmd.arg; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect; +import com.massivecraft.massivecore.util.Txt; + +public class ARMPerm extends ARAbstractSelect +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ARMPerm i = new ARMPerm(); + public static ARMPerm get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String typename() + { + return "faction permission"; + } + + @Override + public MPerm select(String arg, CommandSender sender) + { + if (arg == null) return null; + arg = getComparable(arg); + + // Algorithmic General Detection + int startswithCount = 0; + MPerm startswith = null; + for (MPerm mperm : MPerm.getAll()) + { + String comparable = getComparable(mperm); + if (comparable.equals(arg)) return mperm; + if (comparable.startsWith(arg)) + { + startswith = mperm; + startswithCount++; + } + } + + if (startswithCount == 1) + { + return startswith; + } + + // Nothing found + return null; + } + + @Override + public Collection altNames(CommandSender sender) + { + List ret = new ArrayList(); + + for (MPerm mperm : MPerm.getAll()) + { + ret.add(Txt.upperCaseFirst(mperm.getName())); + } + + return ret; + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static String getComparable(String string) + { + return string.toLowerCase(); + } + + public static String getComparable(MPerm mperm) + { + return getComparable(mperm.getName()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/Faction.java b/src/main/java/com/massivecraft/factions/entity/Faction.java index 274351f4..dda96830 100644 --- a/src/main/java/com/massivecraft/factions/entity/Faction.java +++ b/src/main/java/com/massivecraft/factions/entity/Faction.java @@ -9,7 +9,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.massivecraft.factions.EconomyParticipator; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FactionEqualsPredictate; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Lang; @@ -50,7 +49,7 @@ public class Faction extends Entity implements EconomyParticipator this.setInvitedPlayerIds(that.invitedPlayerIds); this.setRelationWishes(that.relationWishes); this.setFlagIds(that.flags); - this.setPerms(that.perms); + this.setPermIds(that.perms); return this; } @@ -123,7 +122,7 @@ public class Faction extends Entity implements EconomyParticipator // The perm overrides are modifications to the default values. // Null means default. - private Map> perms = null; + private Map> perms = null; // -------------------------------------------- // // FIELD: id @@ -546,15 +545,24 @@ public class Faction extends Entity implements EconomyParticipator ret.put(mflag, mflag.isStandard()); } - // ... and if anything is explicitly set ... + // ... and if anything is explicitly set we use that info ... if (this.flags != null) { - // ... we we use that info. - for (Entry entry : this.flags.entrySet()) + Iterator> iter = this.flags.entrySet().iterator(); + while (iter.hasNext()) { - String id = entry.getKey(); - if (id == null) continue; + // ... 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 ... MFlag mflag = MFlag.get(id); if (mflag == null) continue; @@ -580,8 +588,18 @@ public class Faction extends Entity implements EconomyParticipator Iterator> iter = target.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; + } + + // ... remove if known and standard ... MFlag mflag = MFlag.get(id); if (mflag != null && mflag.isStandard() == entry.getValue()) { @@ -632,62 +650,76 @@ public class Faction extends Entity implements EconomyParticipator // RAW - public Map> getPerms() + public Map> getPerms() { - Map> ret = new LinkedHashMap>(); - - for (FPerm fperm : FPerm.values()) + // We start with default values ... + Map> ret = new LinkedHashMap>(); + for (MPerm mperm : MPerm.getAll()) { - ret.put(fperm, fperm.getDefault()); + ret.put(mperm, new LinkedHashSet(mperm.getStandard())); } + // ... and if anything is explicitly set we use that info ... if (this.perms != null) { - for (Entry> entry : this.perms.entrySet()) + Iterator>> iter = this.perms.entrySet().iterator(); + while (iter.hasNext()) { - ret.put(entry.getKey(), new LinkedHashSet(entry.getValue())); + // ... 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 LinkedHashSet(entry.getValue())); } } return ret; } - public void setPerms(Map> perms) + public void setPermIds(Map> perms) { // Clean input - Map> target; - if (perms == null) + Map> target = null; + if (perms != null) { - target = null; - } - else - { - target = new LinkedHashMap>(); - for (Entry> entry : perms.entrySet()) + // We start out with what was suggested + target = new LinkedHashMap>(); + for (Entry> entry : perms.entrySet()) { target.put(entry.getKey(), new LinkedHashSet(entry.getValue())); } + // However if the context is fully live we try to throw some default values away. if (this.attached() && Factions.get().isDatabaseInitialized()) { - Iterator>> iter = target.entrySet().iterator(); + Iterator>> iter = target.entrySet().iterator(); while (iter.hasNext()) { - Entry> entry = iter.next(); + // For each entry ... + Entry> entry = iter.next(); - FPerm key = entry.getKey(); - if (key == null) + // ... extract id and remove null values ... + String id = entry.getKey(); + if (id == null) { - // TODO: I have no idea why this key is null at times... Why? - System.out.println("key was null :/"); iter.remove(); continue; } - Set keyDefault = key.getDefault(); - Set value = entry.getValue(); - - if (keyDefault.equals(value)) + // ... remove if known and standard ... + MPerm mperm = MPerm.get(id); + if (mperm != null && mperm.getStandard().equals(entry.getValue())) { iter.remove(); } @@ -707,33 +739,40 @@ public class Faction extends Entity implements EconomyParticipator this.changed(); } + public void setPerms(Map> perms) + { + Map> permIds = new LinkedHashMap>(); + for (Entry> entry : perms.entrySet()) + { + permIds.put(entry.getKey().getId(), entry.getValue()); + } + setPermIds(permIds); + } + // FINER - public Set getPermittedRelations(FPerm perm) + public Set getPermittedRelations(MPerm perm) { return this.getPerms().get(perm); } - public void setPermittedRelations(FPerm perm, Set rels) + public void setPermittedRelations(MPerm perm, Set rels) { - Map> perms = this.getPerms(); + Map> perms = this.getPerms(); perms.put(perm, rels); this.setPerms(perms); } - public void setPermittedRelations(FPerm perm, Rel... rels) + public void setPermittedRelations(MPerm perm, Rel... rels) { Set temp = new HashSet(); temp.addAll(Arrays.asList(rels)); this.setPermittedRelations(perm, temp); } - public void setRelationPermitted(FPerm perm, Rel rel, boolean permitted) + public void setRelationPermitted(MPerm perm, Rel rel, boolean permitted) { - Map> perms = this.getPerms(); - - //System.out.println("setRelationPermitted before:"); - //System.out.println(Factions.get().gson.toJson(perms, new TypeToken>>(){}.getType())); + Map> perms = this.getPerms(); Set rels = perms.get(perm); @@ -746,9 +785,6 @@ public class Faction extends Entity implements EconomyParticipator rels.remove(rel); } - //System.out.println("setRelationPermitted after:"); - //System.out.println(Factions.get().gson.toJson(perms, new TypeToken>>(){}.getType())); - this.setPerms(perms); } diff --git a/src/main/java/com/massivecraft/factions/entity/FactionColl.java b/src/main/java/com/massivecraft/factions/entity/FactionColl.java index dc9ff4c4..314b9c46 100644 --- a/src/main/java/com/massivecraft/factions/entity/FactionColl.java +++ b/src/main/java/com/massivecraft/factions/entity/FactionColl.java @@ -8,7 +8,6 @@ import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.MStore; import com.massivecraft.massivecore.util.Txt; import com.massivecraft.factions.Const; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; import com.massivecraft.factions.integration.Econ; @@ -106,11 +105,11 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFirespread(), true); faction.setFlag(MFlag.getEndergrief(), true); - faction.setPermittedRelations(FPerm.BUILD, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getBuild(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); return faction; } @@ -139,11 +138,11 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFirespread(), false); faction.setFlag(MFlag.getEndergrief(), false); - faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.TERRITORY, Rel.LEADER, Rel.OFFICER, Rel.MEMBER); + faction.setPermittedRelations(MPerm.getDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER); return faction; } @@ -172,11 +171,11 @@ public class FactionColl extends Coll faction.setFlag(MFlag.getFirespread(), true); faction.setFlag(MFlag.getEndergrief(), true); - faction.setPermittedRelations(FPerm.DOOR, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.CONTAINER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.BUTTON, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.LEVER, Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); - faction.setPermittedRelations(FPerm.TERRITORY, Rel.LEADER, Rel.OFFICER, Rel.MEMBER); + faction.setPermittedRelations(MPerm.getDoor(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getContainer(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getButton(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY); + faction.setPermittedRelations(MPerm.getTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER); return faction; } diff --git a/src/main/java/com/massivecraft/factions/entity/MConf.java b/src/main/java/com/massivecraft/factions/entity/MConf.java index 5c2b45dd..e994b0d1 100644 --- a/src/main/java/com/massivecraft/factions/entity/MConf.java +++ b/src/main/java/com/massivecraft/factions/entity/MConf.java @@ -12,7 +12,6 @@ import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.event.EventPriority; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; import com.massivecraft.factions.WorldExceptionSet; @@ -103,8 +102,6 @@ public class MConf extends Entity public String defaultPlayerFactionId = Factions.ID_NONE; public Rel defaultPlayerRole = Rel.RECRUIT; public double defaultPlayerPower = 0.0; - - public Map> defaultFactionPerms = FPerm.getDefaultDefaults(); // -------------------------------------------- // // POWER diff --git a/src/main/java/com/massivecraft/factions/entity/MFlag.java b/src/main/java/com/massivecraft/factions/entity/MFlag.java index 1f2a97ac..116afada 100644 --- a/src/main/java/com/massivecraft/factions/entity/MFlag.java +++ b/src/main/java/com/massivecraft/factions/entity/MFlag.java @@ -152,7 +152,7 @@ public class MFlag extends Entity implements Prioritized, Registerable public boolean isStandard() { return this.standard; } public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; } - // If the flag is editable by the faction leader (or however the flag permission is configured) + // If it editable by the faction leader (or for who ever the permission is configured) // Example: true (if players want to turn mob spawning on I guess they should be able to) private boolean editable = false; public boolean isEditable() { return this.editable; } diff --git a/src/main/java/com/massivecraft/factions/entity/MPerm.java b/src/main/java/com/massivecraft/factions/entity/MPerm.java new file mode 100644 index 00000000..33a042d4 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MPerm.java @@ -0,0 +1,325 @@ +package com.massivecraft.factions.entity; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.massivecore.PredictateIsRegistered; +import com.massivecraft.massivecore.Prioritized; +import com.massivecraft.massivecore.Registerable; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.store.Entity; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; + +public class MPerm extends Entity implements Prioritized, Registerable +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public final static transient String ID_BUILD = "build"; + public final static transient String ID_PAINBUILD = "painbuild"; + public final static transient String ID_DOOR = "door"; + public final static transient String ID_BUTTON = "button"; + public final static transient String ID_LEVER = "lever"; + public final static transient String ID_CONTAINER = "container"; + public final static transient String ID_INVITE = "invite"; + public final static transient String ID_KICK = "kick"; + public final static transient String ID_SETHOME = "sethome"; + public final static transient String ID_WITHDRAW = "withdraw"; + public final static transient String ID_TERRITORY = "territory"; + public final static transient String ID_ACCESS = "access"; + public final static transient String ID_DISBAND = "disband"; + public final static transient String ID_FLAGS = "flags"; + public final static transient String ID_PERMS = "perms"; + + public final static transient int PRIORITY_BUILD = 1000; + public final static transient int PRIORITY_PAINBUILD = 2000; + public final static transient int PRIORITY_DOOR = 3000; + public final static transient int PRIORITY_BUTTON = 4000; + public final static transient int PRIORITY_LEVER = 5000; + public final static transient int PRIORITY_CONTAINER = 6000; + public final static transient int PRIORITY_INVITE = 7000; + public final static transient int PRIORITY_KICK = 8000; + public final static transient int PRIORITY_SETHOME = 9000; + public final static transient int PRIORITY_WITHDRAW = 10000; + public final static transient int PRIORITY_TERRITORY = 12000; + public final static transient int PRIORITY_ACCESS = 13000; + public final static transient int PRIORITY_DISBAND = 14000; + public final static transient int PRIORITY_FLAGS = 15000; + public final static transient int PRIORITY_PERMS = 16000; + + // -------------------------------------------- // + // META: CORE + // -------------------------------------------- // + + public static MPerm get(Object oid) + { + return MPermColl.get().get(oid); + } + + public static List getAll() + { + return MPermColl.get().getAll(PredictateIsRegistered.get()); + } + + public static void setupStandardPerms() + { + getBuild(); + getPainbuild(); + getDoor(); + getButton(); + getLever(); + getContainer(); + + getInvite(); + getKick(); + getSethome(); + getWithdraw(); + getTerritory(); + getAccess(); + getDisband(); + getFlags(); + getPerms(); + } + + public static MPerm getBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY), true, true, true); } + public static MPerm getPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", new LinkedHashSet(), true, true, true); } + public static MPerm getDoor() { 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 getButton() { 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 getLever() { 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 getContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", MUtil.set(Rel.LEADER, Rel.OFFICER, Rel.MEMBER), true, true, true); } + + public static MPerm getInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); } + public static MPerm getKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); } + public static MPerm getSethome() { return getCreative(PRIORITY_SETHOME, ID_SETHOME, ID_SETHOME, "set the home", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); } + public static MPerm getWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); } + public static MPerm getTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); } + public static MPerm getAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", MUtil.set(Rel.LEADER, Rel.OFFICER), false, true, true); } + public static MPerm getDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", MUtil.set(Rel.LEADER), false, true, true); } + public static MPerm getFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", MUtil.set(Rel.LEADER), false, true, true); } + public static MPerm getPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", MUtil.set(Rel.LEADER), false, true, true); } + + public static MPerm getCreative(int priority, String id, String name, String desc, Set standard, boolean territory, boolean editable, boolean visible) + { + MPerm ret = MPermColl.get().get(id, false); + if (ret != null) + { + ret.setRegistered(true); + return ret; + } + + ret = new MPerm(priority, name, desc, standard, territory, editable, visible); + MPermColl.get().attach(ret, id); + ret.setRegistered(true); + ret.sync(); + + return ret; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public MPerm load(MPerm that) + { + this.priority = that.priority; + this.name = that.name; + this.desc = that.desc; + this.standard = that.standard; + this.territory = that.territory; + this.editable = that.editable; + this.visible = that.visible; + + return this; + } + + // -------------------------------------------- // + // TRANSIENT FIELDS (Registered) + // -------------------------------------------- // + + private transient boolean registered = false; + public boolean isRegistered() { return this.registered; } + public void setRegistered(boolean registered) { this.registered = registered; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + // The sort order priority 1 is high up, 99999 is far down. + private int priority = 0; + @Override public int getPriority() { return this.priority; } + public MPerm setPriority(int priority) { this.priority = priority; this.changed(); return this; } + + // Nice name / Display name + // Example: "build" + private String name = "defaultName"; + public String getName() { return this.name; } + public MPerm setName(String name) { this.name = name; this.changed(); return this; } + + // Short description + // Example: "edit the terrain" + private String desc = "defaultDesc"; + public String getDesc() { return this.desc; } + public MPerm setDesc(String desc) { this.desc = desc; this.changed(); return this; } + + // Standard value + // Example: ... set of relations ... + private Set standard = new LinkedHashSet(); + public Set getStandard() { return this.standard; } + public MPerm setStandard(Set standard) { this.standard = standard; this.changed(); return this; } + + // Is this a territory permission? + private boolean territory = false; + public boolean isTerritory() { return this.territory; } + public MPerm setTerritory(boolean territory) { this.territory = territory; this.changed(); return this; } + + // If it editable by the faction leader (or for who ever the permission is configured) + // Example: true (all perms are editable by default) + private boolean editable = false; + public boolean isEditable() { return this.editable; } + public MPerm setEditable(boolean editable) { this.editable = editable; this.changed(); return this; } + + // If the flag is visible or hidden. + // Example: true (yeah we need to see this permission) + // Explanation: Some flags are rendered meaningless by other plugins. + private boolean visible = true; + public boolean isVisible() { return this.visible; } + public MPerm setVisible(boolean visible) { this.visible = visible; this.changed(); return this; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public MPerm() + { + // No argument constructor for GSON + } + + public MPerm(int priority, String name, String desc, Set standard, boolean territory, boolean editable, boolean visible) + { + this.priority = priority; + this.name = name; + this.desc = desc; + this.standard = standard; + this.territory = territory; + this.editable = editable; + this.visible = visible; + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public String createDeniedMessage(MPlayer mplayer, Faction hostFaction) + { + String ret = Txt.parse("%s does not allow you to %s.", hostFaction.describeTo(mplayer, true), this.getDesc()); + if (Perm.ADMIN.has(mplayer.getPlayer())) + { + ret += Txt.parse("\nYou can bypass by using " + Factions.get().getOuterCmdFactions().cmdFactionsAdmin.getUseageTemplate(false)); + } + return ret; + } + + public boolean has(Faction faction, Faction hostFaction) + { + Rel rel = faction.getRelationTo(hostFaction); + return hostFaction.getPermittedRelations(this).contains(rel); + } + + public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose) + { + if (mplayer.isUsingAdminMode()) return true; + + Rel rel = mplayer.getRelationTo(hostFaction); + if (hostFaction.getPermittedRelations(this).contains(rel)) return true; + + if (verboose) mplayer.sendMessage(this.createDeniedMessage(mplayer, hostFaction)); + + return false; + } + + public boolean has(MPlayer mplayer, PS ps, boolean verboose) + { + if (mplayer.isUsingAdminMode()) return true; + + TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(ps); + Faction hostFaction = ta.getHostFaction(); + + if (this.isTerritory()) + { + Boolean hasTerritoryAccess = ta.hasTerritoryAccess(mplayer); + if (hasTerritoryAccess != null) + { + if (verboose && !hasTerritoryAccess) + { + mplayer.sendMessage(this.createDeniedMessage(mplayer, hostFaction)); + } + return hasTerritoryAccess; + } + } + + return this.has(mplayer, hostFaction, verboose); + } + + // -------------------------------------------- // + // UTIL: ASCII + // -------------------------------------------- // + + public static String getStateHeaders() + { + String ret = ""; + for (Rel rel : Rel.values()) + { + ret += rel.getColor().toString(); + ret += rel.toString().substring(0, 3); + ret += " "; + } + + 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 ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MPermColl.java b/src/main/java/com/massivecraft/factions/entity/MPermColl.java new file mode 100644 index 00000000..4f8fe462 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/entity/MPermColl.java @@ -0,0 +1,51 @@ +package com.massivecraft.factions.entity; + +import java.util.ArrayList; +import java.util.List; + +import com.massivecraft.factions.Const; +import com.massivecraft.factions.Factions; +import com.massivecraft.massivecore.PriorityComparator; +import com.massivecraft.massivecore.store.Coll; +import com.massivecraft.massivecore.store.MStore; + +public class MPermColl extends Coll +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MPermColl i = new MPermColl(); + public static MPermColl get() { return i; } + private MPermColl() + { + super(Const.COLLECTION_MPERM, MPerm.class, MStore.getDb(), Factions.get(), false, false, true, null, PriorityComparator.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void init() + { + super.init(); + MPerm.setupStandardPerms(); + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public List getAll(boolean registered) + { + List ret = new ArrayList(); + for (MPerm mperm : this.getAll()) + { + if (mperm.isRegistered() != registered) continue; + ret.add(mperm); + } + return ret; + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MPlayer.java b/src/main/java/com/massivecraft/factions/entity/MPlayer.java index 109ffca3..fbf573f6 100644 --- a/src/main/java/com/massivecraft/factions/entity/MPlayer.java +++ b/src/main/java/com/massivecraft/factions/entity/MPlayer.java @@ -7,7 +7,6 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Player; import com.massivecraft.factions.EconomyParticipator; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Lang; import com.massivecraft.factions.Perm; @@ -711,7 +710,7 @@ public class MPlayer extends SenderEntity implements EconomyParticipato return false; } - if (!FPerm.TERRITORY.has(this, newFaction, true)) + if (!MPerm.getTerritory().has(this, newFaction, true)) { return false; } @@ -761,7 +760,7 @@ public class MPlayer extends SenderEntity implements EconomyParticipato if (oldFaction.isNormal()) { - if (!FPerm.TERRITORY.has(this, oldFaction, false)) + if (!MPerm.getTerritory().has(this, oldFaction, false)) { if (!mconf.claimingFromOthersAllowed) { diff --git a/src/main/java/com/massivecraft/factions/integration/Econ.java b/src/main/java/com/massivecraft/factions/integration/Econ.java index c67f4d6a..406a71fd 100644 --- a/src/main/java/com/massivecraft/factions/integration/Econ.java +++ b/src/main/java/com/massivecraft/factions/integration/Econ.java @@ -4,8 +4,8 @@ import java.util.HashSet; import java.util.Set; import com.massivecraft.factions.EconomyParticipator; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.util.RelationUtil; @@ -88,8 +88,8 @@ public class Econ // Factions can be controlled by those that have permissions if (you instanceof Faction) { - if (i instanceof Faction && FPerm.WITHDRAW.has((Faction)i, fYou)) return true; - if (i instanceof MPlayer && FPerm.WITHDRAW.has((MPlayer)i, fYou, false)) return true; + if (i instanceof Faction && MPerm.getWithdraw().has((Faction)i, fYou)) return true; + if (i instanceof MPlayer && MPerm.getWithdraw().has((MPlayer)i, fYou, false)) return true; } // Otherwise you may not! ;,,; diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java index 6b02add7..9af6ff69 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -54,12 +54,12 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.projectiles.ProjectileSource; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; @@ -717,7 +717,7 @@ public class FactionsListenerMain implements Listener if (mplayer.isUsingAdminMode()) return true; - if (!FPerm.BUILD.has(mplayer, ps, false) && FPerm.PAINBUILD.has(mplayer, ps, false)) + if (!MPerm.getBuild().has(mplayer, ps, false) && MPerm.getPainbuild().has(mplayer, ps, false)) { if (verboose) { @@ -732,7 +732,7 @@ public class FactionsListenerMain implements Listener return true; } - return FPerm.BUILD.has(mplayer, ps, verboose); + return MPerm.getBuild().has(mplayer, ps, verboose); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -822,7 +822,7 @@ public class FactionsListenerMain implements Listener if (targetFaction == pistonFaction) return; // if potentially pushing into air/water/lava in another territory, we need to check it out - if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && ! FPerm.BUILD.has(pistonFaction, targetFaction)) + if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && ! MPerm.getBuild().has(pistonFaction, targetFaction)) { event.setCancelled(true); } @@ -852,7 +852,7 @@ public class FactionsListenerMain implements Listener Faction targetFaction = BoardColl.get().getFactionAt(retractPs); if (targetFaction == pistonFaction) return; - if (!FPerm.BUILD.has(pistonFaction, targetFaction)) + if (!MPerm.getBuild().has(pistonFaction, targetFaction)) { event.setCancelled(true); } @@ -900,7 +900,7 @@ public class FactionsListenerMain implements Listener MPlayer mplayer = MPlayer.get(player); if (mplayer.isUsingAdminMode()) return true; - return FPerm.BUILD.has(mplayer, ps, !justCheck); + return MPerm.getBuild().has(mplayer, ps, !justCheck); } public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) @@ -914,11 +914,11 @@ public class FactionsListenerMain implements Listener PS ps = PS.valueOf(block); Material material = block.getType(); - if (MConf.get().materialsEditOnInteract.contains(material) && ! FPerm.BUILD.has(me, ps, ! justCheck)) return false; - if (MConf.get().materialsContainer.contains(material) && ! FPerm.CONTAINER.has(me, ps, ! justCheck)) return false; - if (MConf.get().materialsDoor.contains(material) && ! FPerm.DOOR.has(me, ps, ! justCheck)) return false; - if (material == Material.STONE_BUTTON && ! FPerm.BUTTON.has(me, ps, ! justCheck)) return false; - if (material == Material.LEVER && ! FPerm.LEVER.has(me, ps, ! justCheck)) return false; + if (MConf.get().materialsEditOnInteract.contains(material) && ! MPerm.getBuild().has(me, ps, ! justCheck)) return false; + if (MConf.get().materialsContainer.contains(material) && ! MPerm.getContainer().has(me, ps, ! justCheck)) return false; + if (MConf.get().materialsDoor.contains(material) && ! MPerm.getDoor().has(me, ps, ! justCheck)) return false; + if (material == Material.STONE_BUTTON && ! MPerm.getButton().has(me, ps, ! justCheck)) return false; + if (material == Material.LEVER && ! MPerm.getLever().has(me, ps, ! justCheck)) return false; return true; } diff --git a/src/main/java/com/massivecraft/factions/update/OldConf.java b/src/main/java/com/massivecraft/factions/update/OldConf.java index 6732fb8d..5d890980 100644 --- a/src/main/java/com/massivecraft/factions/update/OldConf.java +++ b/src/main/java/com/massivecraft/factions/update/OldConf.java @@ -2,11 +2,9 @@ package com.massivecraft.factions.update; import java.util.List; import java.util.Map; -import java.util.Set; import org.bukkit.event.EventPriority; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.event.EventFactionsChunkChangeType; @@ -29,7 +27,7 @@ public class OldConf extends Entity mconf.defaultPlayerPower = this.defaultPlayerPower; //mconf.defaultFactionOpen = this.defaultFactionOpen; //mconf.defaultFactionFlags = this.defaultFactionFlags; - mconf.defaultFactionPerms = this.defaultFactionPerms; + //mconf.defaultFactionPerms = this.defaultFactionPerms; mconf.powerMax = this.powerMax; mconf.powerMin = this.powerMin; mconf.powerPerHour = this.powerPerHour; @@ -106,9 +104,9 @@ public class OldConf extends Entity public Rel defaultPlayerRole = null; public double defaultPlayerPower = 0.0; - public boolean defaultFactionOpen = false; + //public boolean defaultFactionOpen = false; //public Map defaultFactionFlags = null; - public Map> defaultFactionPerms = null; + //public Map> defaultFactionPerms = null; // -------------------------------------------- // // MESSAGES