Updated readme, Fixed admin bypass command and corresponding permissions, Swapped colors for ally and truce, added new faction permissions, improved explosion protection and implemented firespread protection, fixed painbuild check order, flags can only be changed by server admins now and implemented type adapters for some enumerations for future changes to be non breaking. That it \:D /

This commit is contained in:
Olof Larsson
2011-10-25 21:18:08 +02:00
parent 57c4b70dad
commit 72db45e45e
30 changed files with 285 additions and 343 deletions

View File

@ -12,34 +12,32 @@ import com.massivecraft.factions.Conf;
public enum FFlag
{
// Faction flags
PERMANENT("permanent", "<i>A permanent faction will never be deleted.", false, false),
PEACEFUL("peaceful", "<i>Allways in truce with other factions.", false, false),
INFPOWER("infpower", "<i>This flag gives the faction infinite power.", false, false),
PERMANENT("permanent", "<i>A permanent faction will never be deleted.", false),
PEACEFUL("peaceful", "<i>Allways in truce with other factions.", false),
INFPOWER("infpower", "<i>This flag gives the faction infinite power.", false),
// This faction has infinite power: TODO: Add faction has enough method. Replace the permanentpower level
// (Faction) Territory flags
// If a faction later could have many different territories this would probably be in another enum
POWERLOSS("powerloss", "<i>Is power lost on death in this territory?", true, false),
PVP("pvp", "<i>Can you PVP in territory?", true, false),
FRIENDLYFIRE("friendlyfire", "<i>Can friends hurt eachother here?", false, false),
MONSTERS("monsters", "<i>Can monsters spawn in this territory?", true, false),
EXPLOSIONS("explosions", "<i>Can explosions occur in this territory?", true, false),
FIRESPREAD("firespread", "<i>Can fire spread in territory?", true, false),
//LIGHTNING("lightning", "<i>Can lightning strike in this territory?", true, false), Possible to add later.
ENDERGRIEF("endergrief", "<i>Can endermen grief in this territory?", false, true),
POWERLOSS("powerloss", "<i>Is power lost on death in this territory?", true),
PVP("pvp", "<i>Can you PVP in territory?", true),
FRIENDLYFIRE("friendlyfire", "<i>Can friends hurt eachother here?", false),
MONSTERS("monsters", "<i>Can monsters spawn in this territory?", true),
EXPLOSIONS("explosions", "<i>Can explosions occur in this territory?", true),
FIRESPREAD("firespread", "<i>Can fire spread in territory?", true),
//LIGHTNING("lightning", "<i>Can lightning strike in this territory?", true), Possible to add later.
ENDERGRIEF("endergrief", "<i>Can endermen grief in this territory?", false),
;
private final String nicename;
private final String desc;
public final boolean defaultDefaultValue;
public final boolean defaultDefaultChangeable;
private FFlag(final String nicename, final String desc, final boolean defaultDefaultValue, final boolean defaultDefaultChangeable)
private FFlag(final String nicename, final String desc, final boolean defaultDefaultValue)
{
this.nicename = nicename;
this.desc = desc;
this.defaultDefaultValue = defaultDefaultValue;
this.defaultDefaultChangeable = defaultDefaultChangeable;
}
public String getNicename()
@ -62,18 +60,6 @@ public enum FFlag
return ret;
}
/**
* Is this flag changeable by the faction leaders or not?
* The normal faction members can never change these flags.
* Note that server operators and admin bypassers can change all flags.
*/
public boolean isChangeable()
{
Boolean ret = Conf.factionFlagIsChangeable.get(this);
if (ret == null) return this.defaultDefaultChangeable;
return ret;
}
public static FFlag parse(String str)
{
str = str.toLowerCase();
@ -84,9 +70,10 @@ public enum FFlag
if (str.startsWith("pvp")) return PVP;
if (str.startsWith("fr") || str.startsWith("ff")) return FRIENDLYFIRE;
if (str.startsWith("m")) return MONSTERS;
if (str.startsWith("e")) return EXPLOSIONS;
if (str.startsWith("ex")) return EXPLOSIONS;
if (str.startsWith("fi")) return FIRESPREAD;
//if (str.startsWith("l")) return LIGHTNING;
if (str.startsWith("en")) return ENDERGRIEF;
return null;
}

View File

@ -7,12 +7,16 @@ import java.util.List;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.iface.RelationParticipator;
/**
@ -21,13 +25,18 @@ import com.massivecraft.factions.iface.RelationParticipator;
*/
public enum FPerm
{
BUILD("build", "edit the terrain", Rel.LEADER, Rel.OFFICER, Rel.MEMBER),
BUILD("build", "edit the terrain", Rel.LEADER, Rel.OFFICER, Rel.MEMBER),
PAINBUILD("painbuild", "edit but take damage", Rel.ALLY),
DOOR("door", "use doors", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
CONTAINER("container", "use containers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER),
BUTTON("button", "use stone buttons", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
LEVER("lever", "use levers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
WITHDRAW("withdraw", "withdraw faction money", Rel.LEADER, Rel.OFFICER),
DOOR("door", "use doors", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
BUTTON("button", "use stone buttons", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
LEVER("lever", "use levers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY),
CONTAINER("container", "use containers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER),
KICK("kick", "kick members", Rel.LEADER, Rel.OFFICER),
SETHOME("sethome", "set the home", Rel.LEADER, Rel.OFFICER),
WITHDRAW("withdraw", "withdraw money", Rel.LEADER, Rel.OFFICER),
TERRITORY("territory", "claim or unclaim", Rel.LEADER, Rel.OFFICER),
DISBAND("disband", "disband the faction", Rel.LEADER),
PERMS("perms", "manage permissions", Rel.LEADER),
;
private final String nicename;
@ -63,12 +72,17 @@ public enum FPerm
{
str = str.toLowerCase();
if (str.startsWith("bui")) return BUILD;
if (str.startsWith("p")) return PAINBUILD;
if (str.startsWith("d")) return DOOR;
if (str.startsWith("c")) return CONTAINER;
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("w")) return WITHDRAW;
if (str.startsWith("l")) return LEVER;
if (str.startsWith("co")) return CONTAINER;
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;
return null;
}
@ -145,44 +159,63 @@ public enum FPerm
return ret;
}
private static final String errorpattern = "<b>%s<b> can't %s in the territory of %s<b>.";
public boolean has(RelationParticipator testSubject, Faction hostFaction, boolean informIfNot)
private static final String errorpattern = "%s<b> does not allow you to %s<b>.";
public boolean has(Object testSubject, Faction hostFaction, boolean informIfNot)
{
//Faction factionDoer = RelationUtil.getFaction(testSubject);
//P.p.log("Testing the permission "+this.toString()+" for a "+testSubject.getClass().getSimpleName());
//P.p.log("hostFaction: "+hostFaction);
Rel rel = testSubject.getRelationTo(hostFaction);
if (testSubject instanceof ConsoleCommandSender) return true;
//P.p.log("rel: "+rel);
RelationParticipator rpSubject = null;
if (testSubject instanceof Player)
{
rpSubject = FPlayers.i.get((Player)testSubject);
}
else if (testSubject instanceof RelationParticipator)
{
rpSubject = (RelationParticipator) testSubject;
}
else
{
return false;
}
Rel rel = rpSubject.getRelationTo(hostFaction);
// TODO: Create better description messages like: "You must at least be officer".
boolean ret = hostFaction.getPermittedRelations(this).contains(rel);
if (!ret && informIfNot && testSubject instanceof FPlayer)
if (rpSubject instanceof FPlayer && ret == false && ((FPlayer)rpSubject).hasAdminMode()) ret = true;
if (!ret && informIfNot && rpSubject instanceof FPlayer)
{
FPlayer fplayer = (FPlayer)testSubject;
fplayer.msg(errorpattern, fplayer.describeTo(fplayer, true), this.getDescription(), hostFaction.describeTo(fplayer));
FPlayer fplayer = (FPlayer)rpSubject;
fplayer.msg(errorpattern, hostFaction.describeTo(fplayer, true), this.getDescription());
if (Permission.ADMIN.has(fplayer.getPlayer()))
{
fplayer.msg("<i>You can bypass by using " + P.p.cmdBase.cmdBypass.getUseageTemplate(false));
}
}
return ret;
}
public boolean has(RelationParticipator testSubject, Faction hostFaction)
public boolean has(Object testSubject, Faction hostFaction)
{
return this.has(testSubject, hostFaction, false);
}
public boolean has(RelationParticipator testSubject, FLocation floc, boolean informIfNot)
public boolean has(Object testSubject, FLocation floc, boolean informIfNot)
{
Faction factionThere = Board.getFactionAt(floc);
return this.has(testSubject, factionThere, informIfNot);
}
public boolean has(RelationParticipator testSubject, Location loc, boolean informIfNot)
public boolean has(Object testSubject, Location loc, boolean informIfNot)
{
FLocation floc = new FLocation(loc);
return this.has(testSubject, floc, informIfNot);
}
public boolean has(RelationParticipator testSubject, Location loc)
public boolean has(Object testSubject, Location loc)
{
return this.has(testSubject, loc, false);
}
public boolean has(RelationParticipator testSubject, FLocation floc)
public boolean has(Object testSubject, FLocation floc)
{
return this.has(testSubject, floc, false);
}

View File

@ -1,14 +1,12 @@
package com.massivecraft.factions.struct;
import org.bukkit.command.CommandSender;
import com.massivecraft.factions.P;
public enum Permission
{
LEADER("leader"),
ADMIN("adminmode"),
AUTOCLAIM("autoclaim"),
BYPASS("bypass"),
CHAT("chat"),
CLAIM("claim"),
CONFIG("config"),
@ -16,39 +14,34 @@ public enum Permission
DEINVITE("deinvite"),
DESCRIPTION("description"),
DISBAND("disband"),
DISBAND_ANY("disband.any"), // WHAT TO DO?
FLAG("flag"),
FLAG_ANY("flag.any"),
PERM("perm"),
PERM_ANY("perm.any"),
FLAG_SET("flag.set"),
HELP("help"),
HOME("home"),
INVITE("invite"),
JOIN("join"),
KICK("kick"),
KICK_ANY("kick.any"),
LEADER("leader"),
LEAVE("leave"),
LIST("list"),
LOCK("lock"),
MAP("map"),
OFFICER("officer"),
MONEY_BALANCE("money.balance"),
MONEY_BALANCE_ANY("money.balance.any"),
MONEY_DEPOSIT("money.deposit"),
MONEY_WITHDRAW("money.withdraw"),
MONEY_WITHDRAW_ANY("money.withdraw.any"), // WHAT TO DO?
MONEY_F2F("money.f2f"),
MONEY_F2P("money.f2p"),
MONEY_P2F("money.p2f"),
MONEY_WITHDRAW("money.withdraw"),
OFFICER("officer"),
OPEN("open"),
SET_PEACEFUL("setpeaceful"),
PERM("perm"),
POWER("power"),
POWER_ANY("power.any"),
RELATION("relation"),
RELOAD("reload"),
SAVE("save"),
SETHOME("sethome"),
SETHOME_ANY("sethome.any"), // WHAT TO DO?
SHOW("show"),
TAG("tag"),
TITLE("title"),