Better flag system. Permission to change faction flags of choice. Possibility for other plugins to add faction flags, and more.

This commit is contained in:
Olof Larsson 2014-10-02 11:45:06 +02:00
parent 2f021ecc72
commit 670d8e4a5f
31 changed files with 565 additions and 418 deletions

View File

@ -8,6 +8,8 @@ public class Const
public static final String COLLECTION_BOARD = BASENAME_+"board";
public static final String COLLECTION_FACTION = BASENAME_+"faction";
public static final String COLLECTION_MFLAG = BASENAME_+"mflag";
public static final String COLLECTION_MPERM = BASENAME_+"mperm";
public static final String COLLECTION_MPLAYER = BASENAME_+"mplayer";
public static final String COLLECTION_MCONF = BASENAME_+"mconf";

View File

@ -1,122 +0,0 @@
package com.massivecraft.factions;
import java.util.LinkedHashMap;
import java.util.Map;
import com.massivecraft.factions.entity.MConf;
/**
* Flags that describe the nature of a faction and it's territory.
* Can monsters spawn there? May fire spread etc? Is the faction permanent?
* These flags have nothing to do with player-permission.
*
* The flags are either true or false.
*/
public enum FFlag
{
// -------------------------------------------- //
// ENUM
// -------------------------------------------- //
// Faction flags
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),
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),
OFFLINE_EXPLOSIONS("offlineexplosions", "<i>Can explosions occur if faction is offline?", false),
FIRESPREAD("firespread", "<i>Can fire spread in territory?", true),
ENDERGRIEF("endergrief", "<i>Can endermen grief in this territory?", false),
// END OF LIST
;
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final String nicename;
public String getNicename() { return this.nicename; }
private final String desc;
public String getDescription() { return this.desc; }
public final boolean defaultDefault;
public boolean getDefaultDefault() { return this.defaultDefault; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
private FFlag(String nicename, final String desc, boolean defaultDefault)
{
this.nicename = nicename;
this.desc = desc;
this.defaultDefault = defaultDefault;
}
// -------------------------------------------- //
// DEFAULTS
// -------------------------------------------- //
public boolean getDefault()
{
Boolean ret = MConf.get().defaultFactionFlags.get(this);
if (ret == null) return this.getDefaultDefault();
return ret;
}
public static Map<FFlag, Boolean> getDefaultDefaults()
{
Map<FFlag, Boolean> ret = new LinkedHashMap<FFlag, Boolean>();
for (FFlag flag : values())
{
ret.put(flag, flag.getDefaultDefault());
}
return ret;
}
// -------------------------------------------- //
// PARSE
// -------------------------------------------- //
public static FFlag parse(String str)
{
str = str.toLowerCase();
if (str.startsWith("per")) return PERMANENT;
if (str.startsWith("pea")) return PEACEFUL;
if (str.startsWith("i")) return INFPOWER;
if (str.startsWith("pow")) return POWERLOSS;
if (str.startsWith("pvp")) return PVP;
if (str.startsWith("fr") || str.startsWith("ff")) return FRIENDLYFIRE;
if (str.startsWith("m")) return MONSTERS;
if (str.startsWith("ex")) return EXPLOSIONS;
if (str.startsWith("o")) return OFFLINE_EXPLOSIONS;
if (str.startsWith("fi")) return FIRESPREAD;
if (str.startsWith("en")) return ENDERGRIEF;
return null;
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public String getStateInfo(boolean value, boolean withDesc)
{
String ret = (value ? "<g>YES" : "<b>NOO") + "<c> " + this.getNicename();
if (withDesc)
{
ret += " " + this.getDescription();
}
return ret;
}
}

View File

@ -39,6 +39,7 @@ public enum FPerm
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
;
@ -118,6 +119,7 @@ public enum FPerm
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;
}

View File

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

View File

@ -24,7 +24,6 @@ public enum Perm
DISBAND("disband"),
FACTION("faction"),
FLAG("flag"),
FLAG_SET("flag.set"),
HOME("home"),
HOME_OTHER("home.other"),
INVITE("invite"),

View File

@ -1,29 +0,0 @@
package com.massivecraft.factions.adapter;
import java.lang.reflect.Type;
import com.massivecraft.factions.FFlag;
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 FFlagAdapter implements JsonDeserializer<FFlag>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static FFlagAdapter i = new FFlagAdapter();
public static FFlagAdapter get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public FFlag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
return FFlag.parse(json.getAsString());
}
}

View File

@ -26,7 +26,6 @@ public class CmdFactions extends FactionsCommand
public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription();
public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome();
public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome();
public CmdFactionsOpen cmdFactionsOpen = new CmdFactionsOpen();
public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite();
public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick();
public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle();
@ -72,7 +71,6 @@ public class CmdFactions extends FactionsCommand
this.addSubCommand(this.cmdFactionsDescription);
this.addSubCommand(this.cmdFactionsSethome);
this.addSubCommand(this.cmdFactionsUnsethome);
this.addSubCommand(this.cmdFactionsOpen);
this.addSubCommand(this.cmdFactionsInvite);
this.addSubCommand(this.cmdFactionsKick);
this.addSubCommand(this.cmdFactionsTitle);

View File

@ -4,6 +4,8 @@ import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.Txt;
public class CmdFactionsAdmin extends FactionsCommand
{
@ -20,7 +22,6 @@ public class CmdFactionsAdmin extends FactionsCommand
this.addOptionalArg("on/off", "flip");
// Requirements
// this.addRequirements(ReqFactionsEnabled.get());
this.addRequirements(ReqHasPerm.get(Perm.ADMIN.node));
}
@ -30,22 +31,22 @@ public class CmdFactionsAdmin extends FactionsCommand
@Override
public void perform()
{
{
// Args
Boolean target = this.arg(0, ARBoolean.get(), !msender.isUsingAdminMode());
if (target == null) return;
// Apply
msender.setUsingAdminMode(target);
if (msender.isUsingAdminMode())
{
msender.msg("<i>You have enabled admin bypass mode.");
Factions.get().log(msender.getId() + " has ENABLED admin bypass mode.");
}
else
{
msender.msg("<i>You have disabled admin bypass mode.");
Factions.get().log(msender.getId() + " DISABLED admin bypass mode.");
}
// Inform
String desc = Txt.parse(msender.isUsingAdminMode() ? "<g>ENABLED" : "<b>DISABLED");
String messageYou = Txt.parse("<i>%s %s <i>admin bypass mode.", msender.getDisplayName(msender), desc);
String messageLog = Txt.parse("<i>%s %s <i>admin bypass mode.", msender.getDisplayName(IdUtil.getConsole()), desc);
msender.sendMessage(messageYou);
Factions.get().log(messageLog);
}
}

View File

@ -2,13 +2,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.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.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
@ -49,7 +49,7 @@ public class CmdFactionsDisband extends FactionsCommand
if ( ! FPerm.DISBAND.has(msender, faction, true)) return;
// Verify
if (faction.getFlag(FFlag.PERMANENT))
if (faction.getFlag(MFlag.getPermanent()))
{
msg("<i>This faction is designated as permanent, so you cannot disband it.");
return;

View File

@ -8,11 +8,11 @@ import java.util.Map;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.PlayerRoleComparator;
import com.massivecraft.factions.Rel;
@ -59,6 +59,12 @@ public class CmdFactionsFaction extends FactionsCommand
// INFO: Title
msg(Txt.titleize("Faction " + faction.getName(msender)));
// INFO: Id (admin mode output only)
if (msender.isUsingAdminMode())
{
msg("<a>ID: <i>%s", faction.getId());
}
// INFO: Description
msg("<a>Description: <i>%s", faction.getDescription());
@ -71,7 +77,8 @@ public class CmdFactionsFaction extends FactionsCommand
msg("<a>Age: <i>%s", ageString);
// INFO: Open
msg("<a>Open: <i>"+(faction.isOpen() ? "<lime>Yes<i>, anyone can join" : "<rose>No<i>, only invited people can join"));
// TODO: Why hardcode displaying the open flag only? We should rather display everything publicly editable.
msg("<a>Open: <i>"+(faction.getFlag(MFlag.getOpen()) ? "<lime>Yes<i>, anyone can join" : "<rose>No<i>, only invited people can join"));
// INFO: Power
double powerBoost = faction.getPowerBoost();
@ -113,12 +120,12 @@ public class CmdFactionsFaction extends FactionsCommand
// Display important flags
// TODO: Find the non default flags, and display them instead.
if (faction.getFlag(FFlag.PERMANENT))
if (faction.getFlag(MFlag.getPermanent()))
{
msg("<a>This faction is permanent - remaining even with no followers.");
}
if (faction.getFlag(FFlag.PEACEFUL))
if (faction.getFlag(MFlag.getPeaceful()))
{
msg("<a>This faction is peaceful - in truce with everyone.");
}
@ -129,7 +136,7 @@ public class CmdFactionsFaction extends FactionsCommand
// List the relations to other factions
Map<Rel, List<String>> relationNames = faction.getFactionNamesPerRelation(msender, true);
if (faction.getFlag(FFlag.PEACEFUL))
if (faction.getFlag(MFlag.getPeaceful()))
{
sendMessage(Txt.parse("<a>In Truce with:<i> *everyone*"));
}

View File

@ -1,10 +1,12 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARFFlag;
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.event.EventFactionsFlagChange;
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.util.Txt;
@ -36,39 +38,67 @@ public class CmdFactionsFlag 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("Flags for " + faction.describeTo(msender, true)));
for (FFlag flag : FFlag.values())
for (MFlag mflag : MFlag.getAll())
{
msg(flag.getStateInfo(faction.getFlag(flag), true));
if (!mflag.isVisible() && !msender.isUsingAdminMode()) continue;
msg(mflag.getStateInfo(faction.getFlag(mflag), true));
}
return;
}
FFlag flag = this.arg(1, ARFFlag.get());
if (flag == null) return;
// Arg: MFlag
MFlag mflag = this.arg(1, ARMFlag.get());
if (mflag == null) return;
// Case: Show One
if ( ! this.argIsSet(2))
{
msg(Txt.titleize("Flag for " + faction.describeTo(msender, true)));
msg(flag.getStateInfo(faction.getFlag(flag), true));
msg(mflag.getStateInfo(faction.getFlag(mflag), true));
return;
}
// Do the sender have the right to change flags for this faction?
if ( ! FPerm.PERMS.has(msender, faction, true)) return;
// Is this flag editable?
if (!msender.isUsingAdminMode() && !mflag.isEditable())
{
msg("<b>The flag <h>%s <b>is not editable.", mflag.getName());
return;
}
// Arg: Target Value
Boolean targetValue = this.arg(2, ARBoolean.get());
if (targetValue == null) return;
// Do the sender have the right to change flags?
if ( ! Perm.FLAG_SET.has(sender, true)) return;
// Do the change
msg(Txt.titleize("Flag for " + faction.describeTo(msender, true)));
faction.setFlag(flag, targetValue);
msg(flag.getStateInfo(faction.getFlag(flag), true));
// Event
EventFactionsFlagChange event = new EventFactionsFlagChange(sender, faction, mflag, targetValue);
event.run();
if (event.isCancelled()) return;
targetValue = event.isNewValue();
// Apply
faction.setFlag(mflag, targetValue);
// Inform
String stateInfo = mflag.getStateInfo(faction.getFlag(mflag), true);
if (msender.getFaction() != faction)
{
// Send message to sender
msg("<h>%s <i>set a flag for <h>%s", msender.describeTo(msender, true), faction.describeTo(msender, true));
msg(stateInfo);
}
faction.msg("<h>%s <i>set a flag for <h>%s", msender.describeTo(faction, true), faction.describeTo(faction, true));
faction.msg(stateInfo);
}
}

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
@ -12,6 +11,7 @@ import com.massivecraft.factions.Rel;
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.MPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.event.EventFactionsHomeTeleport;
@ -98,7 +98,7 @@ public class CmdFactionsHome extends FactionsCommandHome
(
MConf.get().homesTeleportAllowedEnemyDistance > 0
&&
factionHere.getFlag(FFlag.PVP)
factionHere.getFlag(MFlag.getPvp())
&&
(
! msender.isInOwnTerritory()

View File

@ -5,6 +5,7 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARMPlayer;
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.event.EventFactionsMembershipChange;
@ -79,7 +80,7 @@ public class CmdFactionsJoin extends FactionsCommand
return;
}
if( ! (faction.isOpen() || faction.isInvited(mplayer) || msender.isUsingAdminMode() || Perm.JOIN_ANY.has(sender, false)))
if( ! (faction.getFlag(MFlag.getOpen()) || faction.isInvited(mplayer) || msender.isUsingAdminMode() || Perm.JOIN_ANY.has(sender, false)))
{
msg("<i>This faction requires invitation.");
if (samePlayer)

View File

@ -1,56 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.event.EventFactionsOpenChange;
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
public class CmdFactionsOpen extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsOpen()
{
// Aliases
this.addAliases("open");
// Args
this.addOptionalArg("yes/no", "toggle");
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.OPEN.node));
this.addRequirements(ReqHasFaction.get());
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
// Args
Boolean newOpen = this.arg(0, ARBoolean.get(), !msenderFaction.isOpen());
if (newOpen == null) return;
// Event
EventFactionsOpenChange event = new EventFactionsOpenChange(sender, msenderFaction, newOpen);
event.run();
if (event.isCancelled()) return;
newOpen = event.isNewOpen();
// Apply
msenderFaction.setOpen(newOpen);
// Inform
String descTarget = msenderFaction.isOpen() ? "open" : "closed";
msenderFaction.msg("%s<i> changed the faction to <h>%s<i>.", msender.describeTo(msenderFaction, true), descTarget);
}
}

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARFaction;
@ -8,6 +7,7 @@ import com.massivecraft.factions.cmd.req.ReqHasFaction;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.event.EventFactionsRelationChange;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
@ -89,13 +89,13 @@ public abstract class CmdFactionsRelationAbstract extends FactionsCommand
// TODO: The ally case should work!!
// * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only
if ( newRelation != Rel.TRUCE && otherFaction.getFlag(FFlag.PEACEFUL))
if ( newRelation != Rel.TRUCE && otherFaction.getFlag(MFlag.getPeaceful()))
{
otherFaction.msg("<i>This will have no effect while your faction is peaceful.");
msenderFaction.msg("<i>This will have no effect while their faction is peaceful.");
}
if ( newRelation != Rel.TRUCE && msenderFaction.getFlag(FFlag.PEACEFUL))
if ( newRelation != Rel.TRUCE && msenderFaction.getFlag(MFlag.getPeaceful()))
{
otherFaction.msg("<i>This will have no effect while their faction is peaceful.");
msenderFaction.msg("<i>This will have no effect while your faction is peaceful.");

View File

@ -24,7 +24,6 @@ public class CmdFactionsSeeChunk extends FactionsCommand
this.addAliases("sc", "seechunk");
// Requirements
// this.addRequirements(ReqFactionsEnabled.get());
this.addRequirements(ReqHasPerm.get(Perm.SEE_CHUNK.node));
this.addRequirements(ReqIsPlayer.get());
}

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.FFlag;
import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect;
import com.massivecraft.massivecore.util.Txt;
public class ARFFlag extends ARAbstractSelect<FFlag>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ARFFlag i = new ARFFlag();
public static ARFFlag get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String typename()
{
return "faction flag";
}
@Override
public FFlag select(String str, CommandSender sender)
{
return FFlag.parse(str);
}
@Override
public Collection<String> altNames(CommandSender sender)
{
List<String> ret = new ArrayList<String>();
for (FFlag fflag : FFlag.values())
{
ret.add(Txt.getNicedEnum(fflag));
}
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.MFlag;
import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect;
import com.massivecraft.massivecore.util.Txt;
public class ARMFlag extends ARAbstractSelect<MFlag>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static ARMFlag i = new ARMFlag();
public static ARMFlag get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public String typename()
{
return "faction flag";
}
@Override
public MFlag select(String arg, CommandSender sender)
{
if (arg == null) return null;
arg = getComparable(arg);
// Algorithmic General Detection
int startswithCount = 0;
MFlag startswith = null;
for (MFlag mflag : MFlag.getAll())
{
String comparable = getComparable(mflag);
if (comparable.equals(arg)) return mflag;
if (comparable.startsWith(arg))
{
startswith = mflag;
startswithCount++;
}
}
if (startswithCount == 1)
{
return startswith;
}
// Nothing found
return null;
}
@Override
public Collection<String> altNames(CommandSender sender)
{
List<String> ret = new ArrayList<String>();
for (MFlag mflag : MFlag.getAll())
{
ret.add(Txt.upperCaseFirst(mflag.getName()));
}
return ret;
}
// -------------------------------------------- //
// UTIL
// -------------------------------------------- //
public static String getComparable(String string)
{
return string.toLowerCase();
}
public static String getComparable(MFlag mflag)
{
return getComparable(mflag.getName());
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FactionEqualsPredictate;
import com.massivecraft.factions.Factions;
@ -48,10 +47,9 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.setCreatedAtMillis(that.createdAtMillis);
this.setHome(that.home);
this.setPowerBoost(that.powerBoost);
this.setOpen(that.open);
this.setInvitedPlayerIds(that.invitedPlayerIds);
this.setRelationWishes(that.relationWishes);
this.setFlags(that.flags);
this.setFlagIds(that.flags);
this.setPerms(that.perms);
return this;
@ -108,7 +106,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// If the faction is open they can.
// If the faction is closed an invite is required.
// Null means default.
private Boolean open = null;
// private Boolean open = null;
// This is the ids of the invited players.
// They are actually "senderIds" since you can invite "@console" to your faction.
@ -121,7 +119,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// The flag overrides are modifications to the default values.
// Null means default.
private Map<FFlag, Boolean> flags = null;
private Map<String, Boolean> flags = null;
// The perm overrides are modifications to the default values.
// Null means default.
@ -338,6 +336,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// FIELD: open
// -------------------------------------------- //
/*
public boolean isDefaultOpen()
{
return MConf.get().defaultFactionOpen;
@ -363,7 +362,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// Mark as changed
this.changed();
}
}*/
// -------------------------------------------- //
// FIELD: invitedPlayerIds
@ -538,45 +537,53 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
// RAW
public Map<FFlag, Boolean> getFlags()
public Map<MFlag, Boolean> getFlags()
{
Map<FFlag, Boolean> ret = new LinkedHashMap<FFlag, Boolean>();
for (FFlag fflag : FFlag.values())
// We start with default values ...
Map<MFlag, Boolean> ret = new LinkedHashMap<MFlag, Boolean>();
for (MFlag mflag : MFlag.getAll())
{
ret.put(fflag, fflag.getDefault());
ret.put(mflag, mflag.isStandard());
}
// ... and if anything is explicitly set ...
if (this.flags != null)
{
for (Entry<FFlag, Boolean> entry : this.flags.entrySet())
// ... we we use that info.
for (Entry<String, Boolean> entry : this.flags.entrySet())
{
ret.put(entry.getKey(), entry.getValue());
String id = entry.getKey();
if (id == null) continue;
MFlag mflag = MFlag.get(id);
if (mflag == null) continue;
ret.put(mflag, entry.getValue());
}
}
return ret;
}
public void setFlags(Map<FFlag, Boolean> flags)
public void setFlagIds(Map<String, Boolean> flags)
{
// Clean input
Map<FFlag, Boolean> target;
if (flags == null)
Map<String, Boolean> target = null;
if (flags != null)
{
target = null;
}
else
{
target = new LinkedHashMap<FFlag, Boolean>(flags);
// We start out with what was suggested
target = new LinkedHashMap<String, Boolean>(flags);
// However if the context is fully live we try to throw some default values away.
if (this.attached() && Factions.get().isDatabaseInitialized())
{
Iterator<Entry<FFlag, Boolean>> iter = target.entrySet().iterator();
Iterator<Entry<String, Boolean>> iter = target.entrySet().iterator();
while (iter.hasNext())
{
Entry<FFlag, Boolean> entry = iter.next();
if (entry.getKey().getDefault() == entry.getValue())
Entry<String, Boolean> entry = iter.next();
String id = entry.getKey();
MFlag mflag = MFlag.get(id);
if (mflag != null && mflag.isStandard() == entry.getValue())
{
iter.remove();
}
@ -596,15 +603,25 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
this.changed();
}
public void setFlags(Map<MFlag, Boolean> flags)
{
Map<String, Boolean> flagIds = new LinkedHashMap<String, Boolean>();
for (Entry<MFlag, Boolean> entry : flags.entrySet())
{
flagIds.put(entry.getKey().getId(), entry.getValue());
}
setFlagIds(flagIds);
}
// FINER
public boolean getFlag(FFlag flag)
public boolean getFlag(MFlag flag)
{
return this.getFlags().get(flag);
}
public void setFlag(FFlag flag, boolean value)
public void setFlag(MFlag flag, boolean value)
{
Map<FFlag, Boolean> flags = this.getFlags();
Map<MFlag, Boolean> flags = this.getFlags();
flags.put(flag, value);
this.setFlags(flags);
}
@ -776,7 +793,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public double getPower()
{
if (this.getFlag(FFlag.INFPOWER)) return 999999;
if (this.getFlag(MFlag.getInfpower())) return 999999;
double ret = 0;
for (MPlayer mplayer : this.getMPlayers())
@ -797,7 +814,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public double getPowerMax()
{
if (this.getFlag(FFlag.INFPOWER)) return 999999;
if (this.getFlag(MFlag.getInfpower())) return 999999;
double ret = 0;
for (MPlayer mplayer : this.getMPlayers())
@ -956,7 +973,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public void promoteNewLeader()
{
if ( ! this.isNormal()) return;
if (this.getFlag(FFlag.PERMANENT) && MConf.get().permanentFactionsDisableLeaderPromotion) return;
if (this.getFlag(MFlag.getPermanent()) && MConf.get().permanentFactionsDisableLeaderPromotion) return;
MPlayer oldLeader = this.getLeader();
@ -970,7 +987,7 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
if (replacements == null || replacements.isEmpty())
{
// faction leader is the only member; one-man faction
if (this.getFlag(FFlag.PERMANENT))
if (this.getFlag(MFlag.getPermanent()))
{
if (oldLeader != null)
{
@ -1032,8 +1049,8 @@ public class Faction extends Entity<Faction> implements EconomyParticipator
public boolean isExplosionsAllowed()
{
boolean explosions = this.getFlag(FFlag.EXPLOSIONS);
boolean offlineexplosions = this.getFlag(FFlag.OFFLINE_EXPLOSIONS);
boolean explosions = this.getFlag(MFlag.getExplosions());
boolean offlineexplosions = this.getFlag(MFlag.getOfflineexplosions());
boolean online = this.isFactionConsideredOnline();
return (online && explosions) || (!online && offlineexplosions);

View File

@ -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.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel;
@ -93,19 +92,19 @@ public class FactionColl extends Coll<Faction>
faction.setName(ChatColor.DARK_GREEN+"Wilderness");
faction.setDescription(null);
faction.setOpen(false);
faction.setFlag(FFlag.PERMANENT, true);
faction.setFlag(FFlag.PEACEFUL, false);
faction.setFlag(FFlag.INFPOWER, true);
faction.setFlag(FFlag.POWERLOSS, true);
faction.setFlag(FFlag.PVP, true);
faction.setFlag(FFlag.FRIENDLYFIRE, false);
faction.setFlag(FFlag.MONSTERS, true);
faction.setFlag(FFlag.EXPLOSIONS, true);
faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, true);
faction.setFlag(FFlag.FIRESPREAD, true);
faction.setFlag(FFlag.ENDERGRIEF, true);
faction.setFlag(MFlag.getOpen(), false);
faction.setFlag(MFlag.getPermanent(), true);
faction.setFlag(MFlag.getPeaceful(), false);
faction.setFlag(MFlag.getInfpower(), true);
faction.setFlag(MFlag.getPowerloss(), true);
faction.setFlag(MFlag.getPvp(), true);
faction.setFlag(MFlag.getFriendlyire(), false);
faction.setFlag(MFlag.getMonsters(), true);
faction.setFlag(MFlag.getExplosions(), true);
faction.setFlag(MFlag.getOfflineexplosions(), true);
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);
@ -126,19 +125,19 @@ public class FactionColl extends Coll<Faction>
faction.setName("SafeZone");
faction.setDescription("Free from PVP and monsters");
faction.setOpen(false);
faction.setFlag(FFlag.PERMANENT, true);
faction.setFlag(FFlag.PEACEFUL, true);
faction.setFlag(FFlag.INFPOWER, true);
faction.setFlag(FFlag.POWERLOSS, false);
faction.setFlag(FFlag.PVP, false);
faction.setFlag(FFlag.FRIENDLYFIRE, false);
faction.setFlag(FFlag.MONSTERS, false);
faction.setFlag(FFlag.EXPLOSIONS, false);
faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, false);
faction.setFlag(FFlag.FIRESPREAD, false);
faction.setFlag(FFlag.ENDERGRIEF, false);
faction.setFlag(MFlag.getOpen(), false);
faction.setFlag(MFlag.getPermanent(), true);
faction.setFlag(MFlag.getPeaceful(), true);
faction.setFlag(MFlag.getInfpower(), true);
faction.setFlag(MFlag.getPowerloss(), false);
faction.setFlag(MFlag.getPvp(), false);
faction.setFlag(MFlag.getFriendlyire(), false);
faction.setFlag(MFlag.getMonsters(), false);
faction.setFlag(MFlag.getExplosions(), false);
faction.setFlag(MFlag.getOfflineexplosions(), false);
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);
@ -159,19 +158,19 @@ public class FactionColl extends Coll<Faction>
faction.setName("WarZone");
faction.setDescription("Not the safest place to be");
faction.setOpen(false);
faction.setFlag(FFlag.PERMANENT, true);
faction.setFlag(FFlag.PEACEFUL, true);
faction.setFlag(FFlag.INFPOWER, true);
faction.setFlag(FFlag.POWERLOSS, true);
faction.setFlag(FFlag.PVP, true);
faction.setFlag(FFlag.FRIENDLYFIRE, true);
faction.setFlag(FFlag.MONSTERS, true);
faction.setFlag(FFlag.EXPLOSIONS, true);
faction.setFlag(FFlag.OFFLINE_EXPLOSIONS, true);
faction.setFlag(FFlag.FIRESPREAD, true);
faction.setFlag(FFlag.ENDERGRIEF, true);
faction.setFlag(MFlag.getOpen(), false);
faction.setFlag(MFlag.getPermanent(), true);
faction.setFlag(MFlag.getPeaceful(), true);
faction.setFlag(MFlag.getInfpower(), true);
faction.setFlag(MFlag.getPowerloss(), true);
faction.setFlag(MFlag.getPvp(), true);
faction.setFlag(MFlag.getFriendlyire(), true);
faction.setFlag(MFlag.getMonsters(), true);
faction.setFlag(MFlag.getExplosions(), true);
faction.setFlag(MFlag.getOfflineexplosions(), true);
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);
@ -197,7 +196,7 @@ public class FactionColl extends Coll<Faction>
for (Faction faction : this.getAll())
{
int landCount = faction.getLandCount();
if (!faction.getFlag(FFlag.PEACEFUL) && landCount > 0)
if (!faction.getFlag(MFlag.getPeaceful()) && landCount > 0)
{
List<MPlayer> players = faction.getMPlayers();
int playerCount = players.size();

View File

@ -12,7 +12,6 @@ import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventPriority;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel;
@ -105,8 +104,6 @@ public class MConf extends Entity<MConf>
public Rel defaultPlayerRole = Rel.RECRUIT;
public double defaultPlayerPower = 0.0;
public boolean defaultFactionOpen = false;
public Map<FFlag, Boolean> defaultFactionFlags = FFlag.getDefaultDefaults();
public Map<FPerm, Set<Rel>> defaultFactionPerms = FPerm.getDefaultDefaults();
// -------------------------------------------- //
@ -429,7 +426,7 @@ public class MConf extends Entity<MConf>
public double econCostName = 0.0;
public double econCostDescription = 0.0;
public double econCostTitle = 0.0;
public double econCostOpen = 0.0;
public double econCostFlag = 0.0;
public Map<Rel, Double> econRelCost = MUtil.map(
Rel.ENEMY, 0.0,

View File

@ -0,0 +1,214 @@
package com.massivecraft.factions.entity;
import java.util.List;
import com.massivecraft.massivecore.PredictateIsRegistered;
import com.massivecraft.massivecore.Prioritized;
import com.massivecraft.massivecore.Registerable;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.Txt;
public class MFlag extends Entity<MFlag> implements Prioritized, Registerable
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public final static transient String ID_OPEN = "open";
public final static transient String ID_MONSTERS = "monsters";
public final static transient String ID_POWERLOSS = "powerloss";
public final static transient String ID_PVP = "pvp";
public final static transient String ID_FRIENDLYFIRE = "friendlyfire";
public final static transient String ID_EXPLOSIONS = "explosions";
public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions";
public final static transient String ID_FIRESPREAD = "firespread";
public final static transient String ID_ENDERGRIEF = "endergrief";
public final static transient String ID_PERMANENT = "permanent";
public final static transient String ID_PEACEFUL = "peaceful";
public final static transient String ID_INFPOWER = "infpower";
public final static transient int PRIORITY_OPEN = 1000;
public final static transient int PRIORITY_MONSTERS = 2000;
public final static transient int PRIORITY_POWERLOSS = 3000;
public final static transient int PRIORITY_PVP = 4000;
public final static transient int PRIORITY_FRIENDLYFIRE = 5000;
public final static transient int PRIORITY_EXPLOSIONS = 6000;
public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 7000;
public final static transient int PRIORITY_FIRESPREAD = 8000;
public final static transient int PRIORITY_ENDERGRIEF = 9000;
public final static transient int PRIORITY_PERMANENT = 10000;
public final static transient int PRIORITY_PEACEFUL = 11000;
public final static transient int PRIORITY_INFPOWER = 12000;
// -------------------------------------------- //
// META: CORE
// -------------------------------------------- //
public static MFlag get(Object oid)
{
return MFlagColl.get().get(oid);
}
public static List<MFlag> getAll()
{
return MFlagColl.get().getAll(PredictateIsRegistered.get());
}
public static void setupStandardFlags()
{
getOpen();
getMonsters();
getPowerloss();
getPvp();
getFriendlyire();
getExplosions();
getOfflineexplosions();
getFirespread();
getEndergrief();
getPermanent();
getPeaceful();
getInfpower();
}
public static MFlag getOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Open factions can be joined without invite.", false, true, true); }
public static MFlag getMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", false, true, true); }
public static MFlag getPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", true, false, true); }
public static MFlag getPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", true, false, true); }
public static MFlag getFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother here?", false, false, true); }
public static MFlag getExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", true, false, true); }
public static MFlag getOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", false, false, true); }
public static MFlag getFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", true, false, true); }
public static MFlag getEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", false, false, true); }
public static MFlag getPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "A permanent faction will never be deleted.", false, false, true); }
public static MFlag getPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Always in truce with other factions.", false, false, true); }
public static MFlag getInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "This flag gives the faction infinite power.", false, false, true); }
public static MFlag getCreative(int priority, String id, String name, String desc, boolean standard, boolean editable, boolean visible)
{
MFlag ret = MFlagColl.get().get(id, false);
if (ret != null)
{
ret.setRegistered(true);
return ret;
}
ret = new MFlag(priority, name, desc, standard, editable, visible);
MFlagColl.get().attach(ret, id);
ret.setRegistered(true);
ret.sync();
return ret;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public MFlag load(MFlag that)
{
this.priority = that.priority;
this.name = that.name;
this.desc = that.desc;
this.standard = that.standard;
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 MFlag setPriority(int priority) { this.priority = priority; this.changed(); return this; }
// Nice name / Display name
// Example: "monsters"
private String name = "defaultName";
public String getName() { return this.name; }
public MFlag setName(String name) { this.name = name; this.changed(); return this; }
// Short description
// Example: "Can monsters spawn in this territory?"
private String desc = "defaultDesc";
public String getDesc() { return this.desc; }
public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; }
// Standard value
// Example: false (per default monsters do not spawn in faction territory)
private boolean standard = true;
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)
// 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; }
public MFlag 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 flag)
// Explanation: Some flags are rendered meaningless by other plugins. Say we have a creative mode server without any mobs. The server owner might want to hide this flag.
private boolean visible = true;
public boolean isVisible() { return this.visible; }
public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public MFlag()
{
// No argument constructor for GSON
}
public MFlag(int priority, String name, String desc, boolean standard, boolean editable, boolean visible)
{
this.priority = priority;
this.name = name;
this.desc = desc;
this.standard = standard;
this.editable = editable;
this.visible = visible;
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public String getStateInfo(boolean value, boolean withDesc)
{
String valueDesc = value ? "<g>YES" : "<b>NOO";
String color = "<aqua>";
if (!this.isVisible())
{
color = "<silver>";
}
else if (this.isEditable())
{
color = "<pink>";
}
String ret = valueDesc + " " + color + this.getName();
if (withDesc) ret += " <i>" + this.getDesc();
ret = Txt.parse(ret);
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 MFlagColl extends Coll<MFlag>
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static MFlagColl i = new MFlagColl();
public static MFlagColl get() { return i; }
private MFlagColl()
{
super(Const.COLLECTION_MFLAG, MFlag.class, MStore.getDb(), Factions.get(), false, false, true, null, PriorityComparator.get());
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void init()
{
super.init();
MFlag.setupStandardFlags();
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public List<MFlag> getAll(boolean registered)
{
List<MFlag> ret = new ArrayList<MFlag>();
for (MFlag mflag : this.getAll())
{
if (mflag.isRegistered() != registered) continue;
ret.add(mflag);
}
return ret;
}
}

View File

@ -7,7 +7,6 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.massivecraft.factions.EconomyParticipator;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Lang;
@ -635,7 +634,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
{
Faction myFaction = this.getFaction();
boolean permanent = myFaction.getFlag(FFlag.PERMANENT);
boolean permanent = myFaction.getFlag(MFlag.getPermanent());
if (myFaction.getMPlayers().size() > 1)
{
@ -725,7 +724,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
int ownedLand = newFaction.getLandCount();
if (mconf.claimedLandsMax != 0 && ownedLand >= mconf.claimedLandsMax && ! newFaction.getFlag(FFlag.INFPOWER))
if (mconf.claimedLandsMax != 0 && ownedLand >= mconf.claimedLandsMax && ! newFaction.getFlag(MFlag.getInfpower()))
{
msg("<b>Limit reached. You can't claim more land.");
return false;

View File

@ -4,8 +4,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MFlag;
public class EventFactionsOpenChange extends EventFactionsAbstractSender
public class EventFactionsFlagChange extends EventFactionsAbstractSender
{
// -------------------------------------------- //
// REQUIRED EVENT CODE
@ -22,19 +23,23 @@ public class EventFactionsOpenChange extends EventFactionsAbstractSender
private final Faction faction;
public Faction getFaction() { return this.faction; }
private boolean newOpen;
public boolean isNewOpen() { return this.newOpen; }
public void setNewOpen(boolean newOpen) { this.newOpen = newOpen; }
private final MFlag flag;
public MFlag getFlag() { return this.flag; }
private boolean newValue;
public boolean isNewValue() { return this.newValue; }
public void setNewValue(boolean newValue) { this.newValue = newValue; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public EventFactionsOpenChange(CommandSender sender, Faction faction, boolean newOpen)
public EventFactionsFlagChange(CommandSender sender, Faction faction, MFlag flag, boolean newValue)
{
super(sender);
this.faction = faction;
this.newOpen = newOpen;
this.flag = flag;
this.newValue = newValue;
}
}

View File

@ -22,7 +22,6 @@ import org.dynmap.markers.MarkerSet;
import org.dynmap.markers.PlayerSet;
import org.dynmap.utils.TileFlags;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.TerritoryAccess;
@ -31,6 +30,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.MFlag;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.money.Money;
@ -759,10 +759,10 @@ public class EngineDynmap extends EngineAbstract
// Flags and Open
Map<String, Boolean> flags = new HashMap<String, Boolean>();
flags.put("open", faction.isOpen());
for (FFlag fflag : FFlag.values())
for (MFlag mflag : MFlag.getAll())
{
flags.put(fflag.getNicename(), faction.getFlag(fflag));
if (!mflag.isVisible()) continue;
flags.put(mflag.getName(), faction.getFlag(mflag));
}
for (Entry<String, Boolean> entry : flags.entrySet())
{

View File

@ -21,7 +21,7 @@ import com.massivecraft.factions.event.EventFactionsInvitedChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.event.EventFactionsNameChange;
import com.massivecraft.factions.event.EventFactionsOpenChange;
import com.massivecraft.factions.event.EventFactionsFlagChange;
import com.massivecraft.factions.event.EventFactionsRelationChange;
import com.massivecraft.factions.event.EventFactionsTitleChange;
import com.massivecraft.factions.integration.Econ;
@ -209,10 +209,10 @@ public class FactionsListenerEcon implements Listener
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsOpenChange event)
public void payForCommand(EventFactionsFlagChange event)
{
Double cost = MConf.get().econCostOpen;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsOpen.getDesc();
Double cost = MConf.get().econCostFlag;
String desc = Factions.get().getOuterCmdFactions().cmdFactionsFlag.getDesc();
payForAction(event, cost, desc);
}

View File

@ -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.FFlag;
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.MPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
@ -195,7 +195,7 @@ public class FactionsListenerMain implements Listener
// ... and powerloss can happen here ...
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player));
if (!faction.getFlag(FFlag.POWERLOSS))
if (!faction.getFlag(MFlag.getPowerloss()))
{
mplayer.msg("<i>You didn't lose any power since the territory you died in works that way.");
return;
@ -298,7 +298,7 @@ public class FactionsListenerMain implements Listener
Faction defenderPsFaction = BoardColl.get().getFactionAt(defenderPs);
// ... PVP flag may cause a damage block ...
if (defenderPsFaction.getFlag(FFlag.PVP) == false)
if (defenderPsFaction.getFlag(MFlag.getPvp()) == false)
{
if (eattacker == null)
{
@ -316,7 +316,7 @@ public class FactionsListenerMain implements Listener
}
return ret;
}
return defenderPsFaction.getFlag(FFlag.MONSTERS);
return defenderPsFaction.getFlag(MFlag.getMonsters());
}
// ... and if the attacker is a player ...
@ -334,7 +334,7 @@ public class FactionsListenerMain implements Listener
// ... PVP flag may cause a damage block ...
// (just checking the defender as above isn't enough. What about the attacker? It could be in a no-pvp area)
// NOTE: This check is probably not that important but we could keep it anyways.
if (attackerPsFaction.getFlag(FFlag.PVP) == false)
if (attackerPsFaction.getFlag(MFlag.getPvp()) == false)
{
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, event);
if (!ret && notify) uattacker.msg("<i>PVP is disabled in %s.", attackerPsFaction.describeTo(uattacker));
@ -371,7 +371,7 @@ public class FactionsListenerMain implements Listener
Rel relation = defendFaction.getRelationTo(attackFaction);
// Check the relation
if (udefender.hasFaction() && relation.isFriend() && defenderPsFaction.getFlag(FFlag.FRIENDLYFIRE) == false)
if (udefender.hasFaction() && relation.isFriend() && defenderPsFaction.getFlag(MFlag.getFriendlyire()) == false)
{
ret = falseUnlessDisallowedPvpEventCancelled(attacker, defender, event);
if (!ret && notify) uattacker.msg("<i>You can't hurt %s<i>.", relation.getDescPlayerMany());
@ -474,7 +474,7 @@ public class FactionsListenerMain implements Listener
command = command.trim();
// ... the command may be denied for members of permanent factions ...
if (mplayer.hasFaction() && mplayer.getFaction().getFlag(FFlag.PERMANENT) && containsCommand(command, MConf.get().denyCommandsPermanentFactionMember))
if (mplayer.hasFaction() && mplayer.getFaction().getFlag(MFlag.getPermanent()) && containsCommand(command, MConf.get().denyCommandsPermanentFactionMember))
{
mplayer.msg("<b>You can't use \"<h>/%s<b>\" as member of a permanent faction.", command);
event.setCancelled(true);
@ -528,7 +528,7 @@ public class FactionsListenerMain implements Listener
// ... at a place where monsters are forbidden ...
PS ps = PS.valueOf(event.getLocation());
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(FFlag.MONSTERS)) return;
if (faction.getFlag(MFlag.getMonsters())) return;
// ... block the spawn.
event.setCancelled(true);
@ -547,7 +547,7 @@ public class FactionsListenerMain implements Listener
// ... at a place where monsters are forbidden ...
PS ps = PS.valueOf(target);
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(FFlag.MONSTERS)) return;
if (faction.getFlag(MFlag.getMonsters())) return;
// ... then if ghast target nothing ...
if (event.getEntityType() == EntityType.GHAST)
@ -651,7 +651,7 @@ public class FactionsListenerMain implements Listener
// ... and the faction there has endergrief disabled ...
PS ps = PS.valueOf(event.getBlock());
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(FFlag.ENDERGRIEF)) return;
if (faction.getFlag(MFlag.getEndergrief())) return;
// ... stop the block alteration.
event.setCancelled(true);
@ -667,7 +667,7 @@ public class FactionsListenerMain implements Listener
PS ps = PS.valueOf(block);
Faction faction = BoardColl.get().getFactionAt(ps);
if (faction.getFlag(FFlag.FIRESPREAD)) return;
if (faction.getFlag(MFlag.getFirespread())) return;
// then cancel the event.
cancellable.setCancelled(true);

View File

@ -6,7 +6,6 @@ import java.util.Set;
import org.bukkit.event.EventPriority;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.entity.MConf;
@ -28,8 +27,8 @@ public class OldConf extends Entity<OldConf>
mconf.defaultPlayerFactionId = this.defaultPlayerFactionId;
mconf.defaultPlayerRole = this.defaultPlayerRole;
mconf.defaultPlayerPower = this.defaultPlayerPower;
mconf.defaultFactionOpen = this.defaultFactionOpen;
mconf.defaultFactionFlags = this.defaultFactionFlags;
//mconf.defaultFactionOpen = this.defaultFactionOpen;
//mconf.defaultFactionFlags = this.defaultFactionFlags;
mconf.defaultFactionPerms = this.defaultFactionPerms;
mconf.powerMax = this.powerMax;
mconf.powerMin = this.powerMin;
@ -78,7 +77,7 @@ public class OldConf extends Entity<OldConf>
mconf.econCostName = this.econCostName;
mconf.econCostDescription = this.econCostDescription;
mconf.econCostTitle = this.econCostTitle;
mconf.econCostOpen = this.econCostOpen;
mconf.econCostFlag = this.econCostOpen;
mconf.econRelCost = this.econRelCost;
mconf.bankEnabled = this.bankEnabled;
mconf.bankFactionPaysCosts = this.bankFactionPaysCosts;
@ -108,7 +107,7 @@ public class OldConf extends Entity<OldConf>
public double defaultPlayerPower = 0.0;
public boolean defaultFactionOpen = false;
public Map<FFlag, Boolean> defaultFactionFlags = null;
//public Map<FFlag, Boolean> defaultFactionFlags = null;
public Map<FPerm, Set<Rel>> defaultFactionPerms = null;
// -------------------------------------------- //

View File

@ -2,9 +2,9 @@ package com.massivecraft.factions.util;
import org.bukkit.ChatColor;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
@ -108,7 +108,7 @@ public class RelationUtil
//P.p.log("getRelationOfThatToMe it was a player and role is "+ret);
}
}
else if (!ignorePeaceful && (thatFaction.getFlag(FFlag.PEACEFUL) || myFaction.getFlag(FFlag.PEACEFUL)))
else if (!ignorePeaceful && (thatFaction.getFlag(MFlag.getPeaceful()) || myFaction.getFlag(MFlag.getPeaceful())))
{
ret = Rel.TRUCE;
}
@ -137,12 +137,12 @@ public class RelationUtil
Faction thatFaction = getFaction(that);
if (thatFaction != null && thatFaction != getFaction(me))
{
if (thatFaction.getFlag(FFlag.FRIENDLYFIRE) == true)
if (thatFaction.getFlag(MFlag.getFriendlyire()) == true)
{
return MConf.get().colorFriendlyFire;
}
if (thatFaction.getFlag(FFlag.PVP) == false)
if (thatFaction.getFlag(MFlag.getPvp()) == false)
{
return MConf.get().colorNoPVP;
}

View File

@ -24,7 +24,6 @@ permissions:
factions.disband: {description: disband faction, default: false}
factions.faction: {description: show faction information, default: false}
factions.flag: {description: manage faction flags, default: false}
factions.flag.set: {description: set faction flags, default: false}
factions.home: {description: teleport to faction home, default: false}
factions.home.other: {description: teleport to another faction home, default: false}
factions.invite: {description: set if player is invited, default: false}
@ -82,7 +81,6 @@ permissions:
factions.disband: true
factions.faction: true
factions.flag: true
factions.flag.set: true
factions.home: true
factions.home.other: true
factions.invite: true
@ -136,7 +134,6 @@ permissions:
default: false
children:
factions.kit.rank1: true
factions.flag.set: true
factions.powerboost: true
factions.join.any: true
factions.join.others: true