Make the Faction Permissions more dynamic as well.

This commit is contained in:
Olof Larsson 2014-10-02 14:02:07 +02:00
parent 670d8e4a5f
commit 422c896631
28 changed files with 650 additions and 448 deletions

View File

@ -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<Rel> defaultDefault;
public Set<Rel> getDefaultDefault() { return new LinkedHashSet<Rel>(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<Rel> defaultDefaultValue = new LinkedHashSet<Rel>();
defaultDefaultValue.addAll(Arrays.asList(rels));
defaultDefaultValue = Collections.unmodifiableSet(defaultDefaultValue);
this.defaultDefault = defaultDefaultValue;
}
// -------------------------------------------- //
// DEFAULTS
// -------------------------------------------- //
public Set<Rel> getDefault()
{
Set<Rel> ret = MConf.get().defaultFactionPerms.get(this);
if (ret == null) return this.getDefaultDefault();
ret = new LinkedHashSet<Rel>(ret);
return ret;
}
public static Map<FPerm, Set<Rel>> getDefaultDefaults()
{
Map<FPerm, Set<Rel>> ret = new LinkedHashMap<FPerm, Set<Rel>>();
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<b> does not allow you to %s<b>.", hostFaction.describeTo(mplayer, true), this.getDescription());
if (Perm.ADMIN.has(mplayer.getPlayer()))
{
ret += Txt.parse("\n<i>You 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<Rel> value, boolean withDesc)
{
String ret = "";
for (Rel rel : Rel.values())
{
if (value.contains(rel))
{
ret += "<g>YES";
}
else
{
ret += "<b>NOO";
}
ret += " ";
}
ret +="<c>"+this.getNicename();
if (withDesc)
{
ret += " <i>" + this.getDescription();
}
return ret;
}
}

View File

@ -2,7 +2,6 @@ package com.massivecraft.factions;
import com.massivecraft.factions.adapter.BoardAdapter; import com.massivecraft.factions.adapter.BoardAdapter;
import com.massivecraft.factions.adapter.BoardMapAdapter; import com.massivecraft.factions.adapter.BoardMapAdapter;
import com.massivecraft.factions.adapter.FPermAdapter;
import com.massivecraft.factions.adapter.FactionPreprocessAdapter; import com.massivecraft.factions.adapter.FactionPreprocessAdapter;
import com.massivecraft.factions.adapter.RelAdapter; import com.massivecraft.factions.adapter.RelAdapter;
import com.massivecraft.factions.adapter.TerritoryAccessAdapter; 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.Faction;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MFlagColl; import com.massivecraft.factions.entity.MFlagColl;
import com.massivecraft.factions.entity.MPermColl;
import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.factions.entity.MConfColl; import com.massivecraft.factions.entity.MConfColl;
import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; import com.massivecraft.factions.integration.dynmap.IntegrationDynmap;
@ -120,6 +120,7 @@ public class Factions extends MassivePlugin
// Initialize Database // Initialize Database
this.databaseInitialized = false; this.databaseInitialized = false;
MFlagColl.get().init(); MFlagColl.get().init();
MPermColl.get().init();
MConfColl.get().init(); MConfColl.get().init();
UpdateUtil.update(); UpdateUtil.update();
MPlayerColl.get().init(); MPlayerColl.get().init();
@ -184,7 +185,6 @@ public class Factions extends MassivePlugin
.registerTypeAdapter(Board.class, BoardAdapter.get()) .registerTypeAdapter(Board.class, BoardAdapter.get())
.registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get()) .registerTypeAdapter(Board.MAP_TYPE, BoardMapAdapter.get())
.registerTypeAdapter(Rel.class, RelAdapter.get()) .registerTypeAdapter(Rel.class, RelAdapter.get())
.registerTypeAdapter(FPerm.class, FPermAdapter.get())
; ;
} }

View File

@ -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<FPerm>
{
// -------------------------------------------- //
// 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());
}
}

View File

@ -1,10 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; 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())); Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isFactionIdGranted(faction.getId()));
if (newValue == null) return; if (newValue == null) return;
// FPerm // MPerm
if (!FPerm.ACCESS.has(msender, hostFaction, true)) return; if (!MPerm.getAccess().has(msender, hostFaction, true)) return;
// Apply // Apply
ta = ta.withFactionId(faction.getId(), newValue); ta = ta.withFactionId(faction.getId(), newValue);

View File

@ -1,9 +1,9 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARMPlayer; import com.massivecraft.factions.cmd.arg.ARMPlayer;
import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; 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())); Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isPlayerIdGranted(mplayer.getId()));
if (newValue == null) return; if (newValue == null) return;
// FPerm // MPerm
if (!FPerm.ACCESS.has(msender, hostFaction, true)) return; if (!MPerm.getAccess().has(msender, hostFaction, true)) return;
// Apply // Apply
ta = ta.withPlayerId(mplayer.getId(), newValue); ta = ta.withPlayerId(mplayer.getId(), newValue);

View File

@ -1,9 +1,9 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction; 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.ReqHasPerm;
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
@ -44,8 +44,8 @@ public class CmdFactionsAutoClaim extends FactionsCommand
return; return;
} }
// FPerm // MPerm
if (forFaction.isNormal() && !FPerm.TERRITORY.has(msender, forFaction, true)) return; if (forFaction.isNormal() && !MPerm.getTerritory().has(msender, forFaction, true)) return;
msender.setAutoClaimFaction(forFaction); msender.setAutoClaimFaction(forFaction);

View File

@ -1,10 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.task.SpiralTask; import com.massivecraft.factions.task.SpiralTask;
import com.massivecraft.massivecore.cmd.arg.ARInteger; import com.massivecraft.massivecore.cmd.arg.ARInteger;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; 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); final Faction forFaction = this.arg(1, ARFaction.get(), msenderFaction);
if (forFaction == null) return; if (forFaction == null) return;
// FPerm // MPerm
if (forFaction.isNormal() && !FPerm.TERRITORY.has(msender, forFaction, true)) return; if (forFaction.isNormal() && !MPerm.getTerritory().has(msender, forFaction, true)) return;
// Validate // Validate
if (radius < 1) if (radius < 1)

View File

@ -3,13 +3,13 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.event.EventFactionsDisband; import com.massivecraft.factions.event.EventFactionsDisband;
import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
@ -45,8 +45,8 @@ public class CmdFactionsDisband extends FactionsCommand
Faction faction = this.arg(0, ARFaction.get(), msenderFaction); Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
if (faction == null) return; if (faction == null) return;
// FPerm // MPerm
if ( ! FPerm.DISBAND.has(msender, faction, true)) return; if ( ! MPerm.getDisband().has(msender, faction, true)) return;
// Verify // Verify
if (faction.getFlag(MFlag.getPermanent())) if (faction.getFlag(MFlag.getPermanent()))

View File

@ -1,11 +1,11 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARMFlag; import com.massivecraft.factions.cmd.arg.ARMFlag;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.event.EventFactionsFlagChange; import com.massivecraft.factions.event.EventFactionsFlagChange;
import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; 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? // 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? // Is this flag editable?
if (!msender.isUsingAdminMode() && !mflag.isEditable()) if (!msender.isUsingAdminMode() && !mflag.isEditable())

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; 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.BoardColl;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.event.EventFactionsHomeTeleport; import com.massivecraft.factions.event.EventFactionsHomeTeleport;
@ -68,7 +68,7 @@ public class CmdFactionsHome extends FactionsCommandHome
{ {
msender.msg("<b>%s <b>does not have a home.", faction.describeTo(msender, true)); msender.msg("<b>%s <b>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("<i>You should:"); msender.msg("<i>You should:");
msender.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsSethome.getUseageTemplate()); msender.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsSethome.getUseageTemplate());

View File

@ -1,10 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARMPlayer; import com.massivecraft.factions.cmd.arg.ARMPlayer;
import com.massivecraft.factions.cmd.req.ReqHasFaction; import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.event.EventFactionsInvitedChange; import com.massivecraft.factions.event.EventFactionsInvitedChange;
import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.arg.ARBoolean;
@ -54,8 +54,8 @@ public class CmdFactionsInvite extends FactionsCommand
return; return;
} }
// FPerm // MPerm
if ( ! FPerm.INVITE.has(msender, msenderFaction, true)) return; if ( ! MPerm.getInvite().has(msender, msenderFaction, true)) return;
// Event // Event
EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, newInvited); EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, newInvited);

View File

@ -1,11 +1,11 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARMPlayer; import com.massivecraft.factions.cmd.arg.ARMPlayer;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
@ -63,9 +63,9 @@ public class CmdFactionsKick extends FactionsCommand
return; return;
} }
// FPerm // MPerm
Faction mplayerFaction = mplayer.getFaction(); Faction mplayerFaction = mplayer.getFaction();
if (!FPerm.KICK.has(msender, mplayerFaction, true)) return; if ( ! MPerm.getKick().has(msender, mplayerFaction, true)) return;
// Event // Event
EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK); EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK);

View File

@ -1,12 +1,12 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; 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.ARFaction;
import com.massivecraft.factions.cmd.arg.ARRel; import com.massivecraft.factions.cmd.arg.ARRel;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.massivecore.cmd.arg.ARBoolean; import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -40,60 +40,72 @@ public class CmdFactionsPerm extends FactionsCommand
@Override @Override
public void perform() public void perform()
{ {
// Arg: Faction
Faction faction = this.arg(0, ARFaction.get(), msenderFaction); Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
if (faction == null) return; if (faction == null) return;
// Case: Show All
if ( ! this.argIsSet(1)) if ( ! this.argIsSet(1))
{ {
msg(Txt.titleize("Perms for " + faction.describeTo(msender, true))); msg(Txt.titleize("Perms for " + faction.describeTo(msender, true)));
msg(FPerm.getStateHeaders()); msg(MPerm.getStateHeaders());
for (FPerm perm : FPerm.values()) for (MPerm perm : MPerm.getAll())
{ {
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
} }
return; return;
} }
FPerm perm = this.arg(1, ARFPerm.get()); // Arg: MPerm
if (perm == null) return; MPerm mperm = this.arg(1, ARMPerm.get());
//System.out.println("perm = "+perm); if (mperm == null) return;
// Case: Show One
if ( ! this.argIsSet(2)) if ( ! this.argIsSet(2))
{ {
msg(Txt.titleize("Perm for " + faction.describeTo(msender, true))); msg(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
msg(FPerm.getStateHeaders()); msg(MPerm.getStateHeaders());
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(mperm.getStateInfo(faction.getPermittedRelations(mperm), true));
return; return;
} }
// Do the sender have the right to change perms for this faction? // 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("<b>The perm <h>%s <b>is not editable.", mperm.getName());
return;
}
// Arg: Rel
Rel rel = this.arg(2, ARRel.get()); Rel rel = this.arg(2, ARRel.get());
if (rel == null) return; if (rel == null) return;
if (!this.argIsSet(3)) if ( ! this.argIsSet(3))
{ {
msg("<b>Should <h>%s <b>have the <h>%s <b>permission or not?\nYou must <h>add \"yes\" or \"no\" <b>at the end.", Txt.getNicedEnum(rel), Txt.getNicedEnum(perm)); msg("<b>Should <h>%s <b>have the <h>%s <b>permission or not?\nYou must <h>add \"yes\" or \"no\" <b>at the end.", Txt.getNicedEnum(rel), Txt.upperCaseFirst(mperm.getName()));
return; return;
} }
Boolean val = this.arg(3, ARBoolean.get(), null); // Arg: Target Value
if (val == null) return; Boolean targetValue = this.arg(3, ARBoolean.get(), null);
if (targetValue == null) return;
// Do the change // Apply
//System.out.println("setRelationPermitted perm "+perm+", rel "+rel+", val "+val); faction.setRelationPermitted(mperm, rel, targetValue);
faction.setRelationPermitted(perm, rel, val);
// The following is to make sure the leader always has the right to change perms if that is our goal. // 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(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
msg(FPerm.getStateHeaders()); msg(MPerm.getStateHeaders());
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(mperm.getStateInfo(faction.getPermittedRelations(mperm), true));
} }
} }

View File

@ -1,10 +1,10 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.event.EventFactionsHomeChange; import com.massivecraft.factions.event.EventFactionsHomeChange;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
@ -42,8 +42,8 @@ public class CmdFactionsSethome extends FactionsCommandHome
PS newHome = PS.valueOf(me.getLocation()); PS newHome = PS.valueOf(me.getLocation());
// FPerm // MPerm
if ( ! FPerm.SETHOME.has(msender, faction, true)) return; if ( ! MPerm.getSethome().has(msender, faction, true)) return;
// Verify // Verify
if (!msender.isUsingAdminMode() && !faction.isValidHome(newHome)) if (!msender.isUsingAdminMode() && !faction.isValidHome(newHome))

View File

@ -2,7 +2,6 @@ package com.massivecraft.factions.cmd;
import java.util.Set; import java.util.Set;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; 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.Faction;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.event.EventFactionsChunkChange; import com.massivecraft.factions.event.EventFactionsChunkChange;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
@ -44,8 +44,8 @@ public class CmdFactionsUnclaimall extends FactionsCommand
Faction faction = msenderFaction; Faction faction = msenderFaction;
Faction newFaction = FactionColl.get().getNone(); Faction newFaction = FactionColl.get().getNone();
// FPerm // MPerm
if (!FPerm.TERRITORY.has(msender, faction, true)) return; if ( ! MPerm.getTerritory().has(msender, faction, true)) return;
// Apply // Apply
Set<PS> chunks = BoardColl.get().getChunks(faction); Set<PS> chunks = BoardColl.get().getChunks(faction);

View File

@ -1,9 +1,9 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.event.EventFactionsHomeChange; import com.massivecraft.factions.event.EventFactionsHomeChange;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
@ -39,8 +39,8 @@ public class CmdFactionsUnsethome extends FactionsCommandHome
// Other Perm // Other Perm
if (faction != msenderFaction && !Perm.HOME_OTHER.has(sender, true)) return; if (faction != msenderFaction && !Perm.HOME_OTHER.has(sender, true)) return;
// FPerm // MPerm
if ( ! FPerm.SETHOME.has(msender, faction, true)) return; if ( ! MPerm.getSethome().has(msender, faction, true)) return;
// NoChange // NoChange
if ( ! faction.hasHome()) if ( ! faction.hasHome())

View File

@ -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<FPerm>
{
// -------------------------------------------- //
// 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<String> altNames(CommandSender sender)
{
List<String> ret = new ArrayList<String>();
for (FPerm fperm : FPerm.values())
{
ret.add(Txt.getNicedEnum(fperm));
}
return ret;
}
}

View File

@ -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<MPerm>
{
// -------------------------------------------- //
// 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<String> altNames(CommandSender sender)
{
List<String> ret = new ArrayList<String>();
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());
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FactionEqualsPredictate; import com.massivecraft.factions.FactionEqualsPredictate;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Lang; import com.massivecraft.factions.Lang;
@ -50,7 +49,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.setInvitedPlayerIds(that.invitedPlayerIds); this.setInvitedPlayerIds(that.invitedPlayerIds);
this.setRelationWishes(that.relationWishes); this.setRelationWishes(that.relationWishes);
this.setFlagIds(that.flags); this.setFlagIds(that.flags);
this.setPerms(that.perms); this.setPermIds(that.perms);
return this; return this;
} }
@ -123,7 +122,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// The perm overrides are modifications to the default values. // The perm overrides are modifications to the default values.
// Null means default. // Null means default.
private Map<FPerm, Set<Rel>> perms = null; private Map<String, Set<Rel>> perms = null;
// -------------------------------------------- // // -------------------------------------------- //
// FIELD: id // FIELD: id
@ -546,15 +545,24 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
ret.put(mflag, mflag.isStandard()); 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) if (this.flags != null)
{ {
// ... we we use that info. Iterator<Entry<String, Boolean>> iter = this.flags.entrySet().iterator();
for (Entry<String, Boolean> entry : this.flags.entrySet()) while (iter.hasNext())
{ {
String id = entry.getKey(); // ... for each entry ...
if (id == null) continue; Entry<String, Boolean> 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); MFlag mflag = MFlag.get(id);
if (mflag == null) continue; if (mflag == null) continue;
@ -580,8 +588,18 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
Iterator<Entry<String, Boolean>> iter = target.entrySet().iterator(); Iterator<Entry<String, Boolean>> iter = target.entrySet().iterator();
while (iter.hasNext()) while (iter.hasNext())
{ {
// For each entry ...
Entry<String, Boolean> entry = iter.next(); Entry<String, Boolean> entry = iter.next();
// ... extract id and remove null values ...
String id = entry.getKey(); String id = entry.getKey();
if (id == null)
{
iter.remove();
continue;
}
// ... remove if known and standard ...
MFlag mflag = MFlag.get(id); MFlag mflag = MFlag.get(id);
if (mflag != null && mflag.isStandard() == entry.getValue()) if (mflag != null && mflag.isStandard() == entry.getValue())
{ {
@ -632,62 +650,76 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// RAW // RAW
public Map<FPerm, Set<Rel>> getPerms() public Map<MPerm, Set<Rel>> getPerms()
{ {
Map<FPerm, Set<Rel>> ret = new LinkedHashMap<FPerm, Set<Rel>>(); // We start with default values ...
Map<MPerm, Set<Rel>> ret = new LinkedHashMap<MPerm, Set<Rel>>();
for (FPerm fperm : FPerm.values()) for (MPerm mperm : MPerm.getAll())
{ {
ret.put(fperm, fperm.getDefault()); ret.put(mperm, new LinkedHashSet<Rel>(mperm.getStandard()));
} }
// ... and if anything is explicitly set we use that info ...
if (this.perms != null) if (this.perms != null)
{ {
for (Entry<FPerm, Set<Rel>> entry : this.perms.entrySet()) Iterator<Entry<String, Set<Rel>>> iter = this.perms.entrySet().iterator();
while (iter.hasNext())
{ {
ret.put(entry.getKey(), new LinkedHashSet<Rel>(entry.getValue())); // ... for each entry ...
Entry<String, Set<Rel>> entry = iter.next();
// ... extract id and remove null values ...
String id = entry.getKey();
if (id == null)
{
iter.remove();
continue;
}
// ... resolve object and skip unknowns ...
MPerm mperm = MPerm.get(id);
if (mperm == null) continue;
ret.put(mperm, new LinkedHashSet<Rel>(entry.getValue()));
} }
} }
return ret; return ret;
} }
public void setPerms(Map<FPerm, Set<Rel>> perms) public void setPermIds(Map<String, Set<Rel>> perms)
{ {
// Clean input // Clean input
Map<FPerm, Set<Rel>> target; Map<String, Set<Rel>> target = null;
if (perms == null) if (perms != null)
{ {
target = null; // We start out with what was suggested
} target = new LinkedHashMap<String, Set<Rel>>();
else for (Entry<String, Set<Rel>> entry : perms.entrySet())
{
target = new LinkedHashMap<FPerm, Set<Rel>>();
for (Entry<FPerm, Set<Rel>> entry : perms.entrySet())
{ {
target.put(entry.getKey(), new LinkedHashSet<Rel>(entry.getValue())); target.put(entry.getKey(), new LinkedHashSet<Rel>(entry.getValue()));
} }
// However if the context is fully live we try to throw some default values away.
if (this.attached() && Factions.get().isDatabaseInitialized()) if (this.attached() && Factions.get().isDatabaseInitialized())
{ {
Iterator<Entry<FPerm, Set<Rel>>> iter = target.entrySet().iterator(); Iterator<Entry<String, Set<Rel>>> iter = target.entrySet().iterator();
while (iter.hasNext()) while (iter.hasNext())
{ {
Entry<FPerm, Set<Rel>> entry = iter.next(); // For each entry ...
Entry<String, Set<Rel>> entry = iter.next();
FPerm key = entry.getKey(); // ... extract id and remove null values ...
if (key == null) 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(); iter.remove();
continue; continue;
} }
Set<Rel> keyDefault = key.getDefault(); // ... remove if known and standard ...
Set<Rel> value = entry.getValue(); MPerm mperm = MPerm.get(id);
if (mperm != null && mperm.getStandard().equals(entry.getValue()))
if (keyDefault.equals(value))
{ {
iter.remove(); iter.remove();
} }
@ -707,33 +739,40 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.changed(); this.changed();
} }
public void setPerms(Map<MPerm, Set<Rel>> perms)
{
Map<String, Set<Rel>> permIds = new LinkedHashMap<String, Set<Rel>>();
for (Entry<MPerm, Set<Rel>> entry : perms.entrySet())
{
permIds.put(entry.getKey().getId(), entry.getValue());
}
setPermIds(permIds);
}
// FINER // FINER
public Set<Rel> getPermittedRelations(FPerm perm) public Set<Rel> getPermittedRelations(MPerm perm)
{ {
return this.getPerms().get(perm); return this.getPerms().get(perm);
} }
public void setPermittedRelations(FPerm perm, Set<Rel> rels) public void setPermittedRelations(MPerm perm, Set<Rel> rels)
{ {
Map<FPerm, Set<Rel>> perms = this.getPerms(); Map<MPerm, Set<Rel>> perms = this.getPerms();
perms.put(perm, rels); perms.put(perm, rels);
this.setPerms(perms); this.setPerms(perms);
} }
public void setPermittedRelations(FPerm perm, Rel... rels) public void setPermittedRelations(MPerm perm, Rel... rels)
{ {
Set<Rel> temp = new HashSet<Rel>(); Set<Rel> temp = new HashSet<Rel>();
temp.addAll(Arrays.asList(rels)); temp.addAll(Arrays.asList(rels));
this.setPermittedRelations(perm, temp); this.setPermittedRelations(perm, temp);
} }
public void setRelationPermitted(FPerm perm, Rel rel, boolean permitted) public void setRelationPermitted(MPerm perm, Rel rel, boolean permitted)
{ {
Map<FPerm, Set<Rel>> perms = this.getPerms(); Map<MPerm, Set<Rel>> perms = this.getPerms();
//System.out.println("setRelationPermitted before:");
//System.out.println(Factions.get().gson.toJson(perms, new TypeToken<Map<FPerm, Set<Rel>>>(){}.getType()));
Set<Rel> rels = perms.get(perm); Set<Rel> rels = perms.get(perm);
@ -746,9 +785,6 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
rels.remove(rel); rels.remove(rel);
} }
//System.out.println("setRelationPermitted after:");
//System.out.println(Factions.get().gson.toJson(perms, new TypeToken<Map<FPerm, Set<Rel>>>(){}.getType()));
this.setPerms(perms); this.setPerms(perms);
} }

View File

@ -8,7 +8,6 @@ import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.store.MStore; import com.massivecraft.massivecore.store.MStore;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.factions.Const; import com.massivecraft.factions.Const;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
@ -106,11 +105,11 @@ public class FactionColl extends Coll<Faction>
faction.setFlag(MFlag.getFirespread(), true); faction.setFlag(MFlag.getFirespread(), true);
faction.setFlag(MFlag.getEndergrief(), 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(MPerm.getBuild(), 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(MPerm.getDoor(), 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(MPerm.getContainer(), 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(MPerm.getButton(), 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.getLever(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.RECRUIT, Rel.ALLY, Rel.TRUCE, Rel.NEUTRAL, Rel.ENEMY);
return faction; return faction;
} }
@ -139,11 +138,11 @@ public class FactionColl extends Coll<Faction>
faction.setFlag(MFlag.getFirespread(), false); faction.setFlag(MFlag.getFirespread(), false);
faction.setFlag(MFlag.getEndergrief(), 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(MPerm.getDoor(), 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(MPerm.getContainer(), 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(MPerm.getButton(), 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.getLever(), 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.getTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
return faction; return faction;
} }
@ -172,11 +171,11 @@ public class FactionColl extends Coll<Faction>
faction.setFlag(MFlag.getFirespread(), true); faction.setFlag(MFlag.getFirespread(), true);
faction.setFlag(MFlag.getEndergrief(), 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(MPerm.getDoor(), 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(MPerm.getContainer(), 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(MPerm.getButton(), 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.getLever(), 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.getTerritory(), Rel.LEADER, Rel.OFFICER, Rel.MEMBER);
return faction; return faction;
} }

View File

@ -12,7 +12,6 @@ import org.bukkit.Material;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.WorldExceptionSet; import com.massivecraft.factions.WorldExceptionSet;
@ -103,8 +102,6 @@ public class MConf extends Entity<MConf>
public String defaultPlayerFactionId = Factions.ID_NONE; public String defaultPlayerFactionId = Factions.ID_NONE;
public Rel defaultPlayerRole = Rel.RECRUIT; public Rel defaultPlayerRole = Rel.RECRUIT;
public double defaultPlayerPower = 0.0; public double defaultPlayerPower = 0.0;
public Map<FPerm, Set<Rel>> defaultFactionPerms = FPerm.getDefaultDefaults();
// -------------------------------------------- // // -------------------------------------------- //
// POWER // POWER

View File

@ -152,7 +152,7 @@ public class MFlag extends Entity<MFlag> implements Prioritized, Registerable
public boolean isStandard() { return this.standard; } public boolean isStandard() { return this.standard; }
public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; } 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) // Example: true (if players want to turn mob spawning on I guess they should be able to)
private boolean editable = false; private boolean editable = false;
public boolean isEditable() { return this.editable; } public boolean isEditable() { return this.editable; }

View File

@ -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<MPerm> 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<MPerm> 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<Rel>(), 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<Rel> 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<Rel> standard = new LinkedHashSet<Rel>();
public Set<Rel> getStandard() { return this.standard; }
public MPerm setStandard(Set<Rel> 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<Rel> 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<b> does not allow you to %s<b>.", hostFaction.describeTo(mplayer, true), this.getDesc());
if (Perm.ADMIN.has(mplayer.getPlayer()))
{
ret += Txt.parse("\n<i>You 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<Rel> value, boolean withDesc)
{
String ret = "";
for (Rel rel : Rel.values())
{
if (value.contains(rel))
{
ret += "<g>YES";
}
else
{
ret += "<b>NOO";
}
ret += " ";
}
String color = "<aqua>";
if (!this.isVisible())
{
color = "<silver>";
}
else if (this.isEditable())
{
color = "<pink>";
}
ret += color;
ret += this.getName();
ret = Txt.parse(ret);
if (withDesc) ret += " <i>" + this.getDesc();
return ret;
}
}

View File

@ -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<MPerm>
{
// -------------------------------------------- //
// 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<MPerm> getAll(boolean registered)
{
List<MPerm> ret = new ArrayList<MPerm>();
for (MPerm mperm : this.getAll())
{
if (mperm.isRegistered() != registered) continue;
ret.add(mperm);
}
return ret;
}
}

View File

@ -7,7 +7,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Lang; import com.massivecraft.factions.Lang;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
@ -711,7 +710,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
return false; return false;
} }
if (!FPerm.TERRITORY.has(this, newFaction, true)) if (!MPerm.getTerritory().has(this, newFaction, true))
{ {
return false; return false;
} }
@ -761,7 +760,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
if (oldFaction.isNormal()) if (oldFaction.isNormal())
{ {
if (!FPerm.TERRITORY.has(this, oldFaction, false)) if (!MPerm.getTerritory().has(this, oldFaction, false))
{ {
if (!mconf.claimingFromOthersAllowed) if (!mconf.claimingFromOthersAllowed)
{ {

View File

@ -4,8 +4,8 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import com.massivecraft.factions.EconomyParticipator; import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
@ -88,8 +88,8 @@ public class Econ
// Factions can be controlled by those that have permissions // Factions can be controlled by those that have permissions
if (you instanceof Faction) if (you instanceof Faction)
{ {
if (i instanceof Faction && FPerm.WITHDRAW.has((Faction)i, fYou)) return true; if (i instanceof Faction && MPerm.getWithdraw().has((Faction)i, fYou)) return true;
if (i instanceof MPlayer && FPerm.WITHDRAW.has((MPlayer)i, fYou, false)) return true; if (i instanceof MPlayer && MPerm.getWithdraw().has((MPlayer)i, fYou, false)) return true;
} }
// Otherwise you may not! ;,,; // Otherwise you may not! ;,,;

View File

@ -54,12 +54,12 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
@ -717,7 +717,7 @@ public class FactionsListenerMain implements Listener
if (mplayer.isUsingAdminMode()) return true; 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) if (verboose)
{ {
@ -732,7 +732,7 @@ public class FactionsListenerMain implements Listener
return true; return true;
} }
return FPerm.BUILD.has(mplayer, ps, verboose); return MPerm.getBuild().has(mplayer, ps, verboose);
} }
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@ -822,7 +822,7 @@ public class FactionsListenerMain implements Listener
if (targetFaction == pistonFaction) return; if (targetFaction == pistonFaction) return;
// if potentially pushing into air/water/lava in another territory, we need to check it out // 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); event.setCancelled(true);
} }
@ -852,7 +852,7 @@ public class FactionsListenerMain implements Listener
Faction targetFaction = BoardColl.get().getFactionAt(retractPs); Faction targetFaction = BoardColl.get().getFactionAt(retractPs);
if (targetFaction == pistonFaction) return; if (targetFaction == pistonFaction) return;
if (!FPerm.BUILD.has(pistonFaction, targetFaction)) if (!MPerm.getBuild().has(pistonFaction, targetFaction))
{ {
event.setCancelled(true); event.setCancelled(true);
} }
@ -900,7 +900,7 @@ public class FactionsListenerMain implements Listener
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
if (mplayer.isUsingAdminMode()) return true; 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) public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck)
@ -914,11 +914,11 @@ public class FactionsListenerMain implements Listener
PS ps = PS.valueOf(block); PS ps = PS.valueOf(block);
Material material = block.getType(); Material material = block.getType();
if (MConf.get().materialsEditOnInteract.contains(material) && ! FPerm.BUILD.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) && ! FPerm.CONTAINER.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) && ! FPerm.DOOR.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 && ! FPerm.BUTTON.has(me, ps, ! justCheck)) return false; if (material == Material.STONE_BUTTON && ! MPerm.getButton().has(me, ps, ! justCheck)) return false;
if (material == Material.LEVER && ! FPerm.LEVER.has(me, ps, ! justCheck)) return false; if (material == Material.LEVER && ! MPerm.getLever().has(me, ps, ! justCheck)) return false;
return true; return true;
} }

View File

@ -2,11 +2,9 @@ package com.massivecraft.factions.update;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.event.EventFactionsChunkChangeType; import com.massivecraft.factions.event.EventFactionsChunkChangeType;
@ -29,7 +27,7 @@ public class OldConf extends Entity<OldConf>
mconf.defaultPlayerPower = this.defaultPlayerPower; mconf.defaultPlayerPower = this.defaultPlayerPower;
//mconf.defaultFactionOpen = this.defaultFactionOpen; //mconf.defaultFactionOpen = this.defaultFactionOpen;
//mconf.defaultFactionFlags = this.defaultFactionFlags; //mconf.defaultFactionFlags = this.defaultFactionFlags;
mconf.defaultFactionPerms = this.defaultFactionPerms; //mconf.defaultFactionPerms = this.defaultFactionPerms;
mconf.powerMax = this.powerMax; mconf.powerMax = this.powerMax;
mconf.powerMin = this.powerMin; mconf.powerMin = this.powerMin;
mconf.powerPerHour = this.powerPerHour; mconf.powerPerHour = this.powerPerHour;
@ -106,9 +104,9 @@ public class OldConf extends Entity<OldConf>
public Rel defaultPlayerRole = null; public Rel defaultPlayerRole = null;
public double defaultPlayerPower = 0.0; public double defaultPlayerPower = 0.0;
public boolean defaultFactionOpen = false; //public boolean defaultFactionOpen = false;
//public Map<FFlag, Boolean> defaultFactionFlags = null; //public Map<FFlag, Boolean> defaultFactionFlags = null;
public Map<FPerm, Set<Rel>> defaultFactionPerms = null; //public Map<FPerm, Set<Rel>> defaultFactionPerms = null;
// -------------------------------------------- // // -------------------------------------------- //
// MESSAGES // MESSAGES