From 98c52306556d7ddf9b29614208fbe9e02f0104dd Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sun, 23 Oct 2011 20:50:49 +0200 Subject: [PATCH] Wheeerp --- plugin.yml | 9 +- src/com/massivecraft/factions/Conf.java | 38 ++++++++ src/com/massivecraft/factions/FPlayer.java | 3 +- src/com/massivecraft/factions/Faction.java | 45 +++++++--- src/com/massivecraft/factions/P.java | 2 +- .../massivecraft/factions/cmd/CmdDisband.java | 3 +- .../massivecraft/factions/cmd/CmdFlag.java | 88 +++++++++++++++++++ .../massivecraft/factions/cmd/CmdHelp.java | 2 - .../massivecraft/factions/cmd/CmdKick.java | 3 +- .../factions/cmd/CmdPermanent.java | 59 ------------- .../factions/cmd/CmdPermanentPower.java | 50 ----------- .../factions/cmd/CmdRelationTruce.java | 12 +++ .../massivecraft/factions/cmd/CmdShow.java | 3 +- .../massivecraft/factions/cmd/FCmdRoot.java | 6 +- .../massivecraft/factions/cmd/FCommand.java | 36 ++++++++ .../factions/struct/FactionFlag.java | 79 ++++++++++++++--- ...actionPlayerPerm.java => FactionPerm.java} | 5 +- .../factions/struct/Permission.java | 4 +- .../factions/util/RelationUtil.java | 5 ++ 19 files changed, 297 insertions(+), 155 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CmdFlag.java delete mode 100644 src/com/massivecraft/factions/cmd/CmdPermanent.java delete mode 100644 src/com/massivecraft/factions/cmd/CmdPermanentPower.java create mode 100644 src/com/massivecraft/factions/cmd/CmdRelationTruce.java rename src/com/massivecraft/factions/struct/{FactionPlayerPerm.java => FactionPerm.java} (77%) diff --git a/plugin.yml b/plugin.yml index 9b71c006..88055dcf 100644 --- a/plugin.yml +++ b/plugin.yml @@ -26,7 +26,6 @@ permissions: factions.kit.halfmod: true factions.disband.any: true factions.setpermanent: true - factions.setpermanentpower: true factions.setpeaceful: true factions.sethome.any: true factions.money.*: true @@ -37,6 +36,7 @@ permissions: factions.managesafezone: true factions.managewarzone: true factions.bypass: true + factions.flag.any: true factions.kick.any: true factions.ownershipbypass: true factions.kit.fullplayer: @@ -55,6 +55,7 @@ permissions: factions.deinvite: true factions.description: true factions.disband: true + factions.flag: true factions.help: true factions.home: true factions.invite: true @@ -101,6 +102,10 @@ permissions: description: disband a faction factions.disband.any: description: disband an other faction + factions.flag: + description: change faction flags + factions.flag.any: + description: change all flags for all factions factions.help: description: display a help page factions.home: @@ -176,8 +181,6 @@ permissions: description: designate a faction as peaceful factions.setpermanent: description: designate a faction as permanent - factions.setpermanentpower: - description: set permanent power for a faction factions.power: description: show player power info factions.power.any: diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 0ca6287f..a5bd3dcf 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -5,6 +5,8 @@ import java.util.*; import org.bukkit.*; import org.bukkit.entity.CreatureType; +import com.massivecraft.factions.struct.FactionFlag; + public class Conf { public static List baseCommandAliases = new ArrayList(); @@ -20,6 +22,16 @@ public class Conf public static ChatColor colorWar = ChatColor.DARK_RED; //public static ChatColor colorWilderness = ChatColor.DARK_GREEN; + + // REFACTOR ASJDKJASDKFJKASDF + public static Map factionFlagDefaults; + public static Map factionFlagIsChangeable; + + // REFACTOR ASJDKJASDKFJKASDF EEEEEENNNNDD + + + + // Power public static double powerPlayerMax = 10.0; public static double powerPlayerMin = -10.0; @@ -245,6 +257,32 @@ public class Conf { baseCommandAliases.add("f"); + factionFlagDefaults = new LinkedHashMap(); + factionFlagDefaults.put(FactionFlag.PERMANENT, FactionFlag.PERMANENT.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.PEACEFUL, FactionFlag.PEACEFUL.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.INFPOWER, FactionFlag.INFPOWER.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.POWERLOSS, FactionFlag.POWERLOSS.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.PVP, FactionFlag.PVP.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.FRIENDLYFIRE, FactionFlag.FRIENDLYFIRE.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.MONSTERS, FactionFlag.MONSTERS.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.EXPLOSIONS, FactionFlag.EXPLOSIONS.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.FIRESPREAD, FactionFlag.FIRESPREAD.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.LIGHTNING, FactionFlag.LIGHTNING.defaultDefaultValue); + factionFlagDefaults.put(FactionFlag.ENDERGRIEF, FactionFlag.ENDERGRIEF.defaultDefaultValue); + + factionFlagIsChangeable = new LinkedHashMap(); + factionFlagIsChangeable.put(FactionFlag.PERMANENT, FactionFlag.PERMANENT.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.PEACEFUL, FactionFlag.PEACEFUL.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.INFPOWER, FactionFlag.INFPOWER.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.POWERLOSS, FactionFlag.POWERLOSS.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.PVP, FactionFlag.PVP.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.FRIENDLYFIRE, FactionFlag.FRIENDLYFIRE.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.MONSTERS, FactionFlag.MONSTERS.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.EXPLOSIONS, FactionFlag.EXPLOSIONS.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.FIRESPREAD, FactionFlag.FIRESPREAD.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.LIGHTNING, FactionFlag.LIGHTNING.defaultDefaultChangeable); + factionFlagIsChangeable.put(FactionFlag.ENDERGRIEF, FactionFlag.ENDERGRIEF.defaultDefaultChangeable); + territoryEnemyDenyCommands.add("home"); territoryEnemyDenyCommands.add("sethome"); territoryEnemyDenyCommands.add("spawn"); diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 98d87a56..40cd1e42 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -14,6 +14,7 @@ import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.struct.ChatMode; +import com.massivecraft.factions.struct.FactionFlag; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.RelationUtil; @@ -574,7 +575,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator public void leave(boolean makePay) { Faction myFaction = this.getFaction(); - boolean perm = myFaction.isPermanent(); + boolean perm = myFaction.getFlag(FactionFlag.PERMANENT); if (!perm && this.getRole() == Rel.LEADER && myFaction.getFPlayers().size() > 1) { diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 9f2f233b..153188d3 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Player; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.struct.FactionFlag; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.*; @@ -53,9 +54,9 @@ public class Faction extends Entity implements EconomyParticipator // FIELD: permanent // "permanent" status can only be set by server admins/moderators/ops, and allows the faction to remain even with 0 members - private boolean permanent; - public boolean isPermanent() { return permanent; } - public void setPermanent(boolean isPermanent) { permanent = isPermanent; } + //private boolean permanent; + //public boolean isPermanent() { return permanent; } + //public void setPermanent(boolean isPermanent) { permanent = isPermanent; } // FIELD: tag private String tag; @@ -128,11 +129,27 @@ public class Faction extends Entity implements EconomyParticipator return Econ.getMethod().getAccount(aid); } - // FIELD: permanentPower - private Integer permanentPower; - public Integer getPermanentPower() { return this.permanentPower; } - public void setPermanentPower(Integer permanentPower) { this.permanentPower = permanentPower; } - public boolean hasPermanentPower() { return this.permanentPower != null; } + // FIELDS: Flag management + // TODO: This will save... defaults if they where changed to... + private Map flagOverrides; // Contains the modifications to the default values + public boolean getFlag(FactionFlag flag) + { + Boolean ret = this.flagOverrides.get(flag); + if (ret == null) ret = flag.getDefault(); + return ret; + } + public void setFlag(FactionFlag flag, boolean value) + { + if (Conf.factionFlagDefaults.get(flag) == value) + { + this.flagOverrides.remove(flag); + return; + } + this.flagOverrides.put(flag, value); + } + + // FIELDS: Permission <-> Groups management + // -------------------------------------------- // // Construct @@ -148,8 +165,8 @@ public class Faction extends Entity implements EconomyParticipator this.lastPlayerLoggedOffTime = 0; this.peaceful = false; this.peacefulExplosionsEnabled = false; - this.permanent = false; this.money = 0.0; + this.flagOverrides = new LinkedHashMap(); } // -------------------------------------------- // @@ -166,6 +183,8 @@ public class Faction extends Entity implements EconomyParticipator // Understand the types // ------------------------------- + // TODO: These should be gone after the refactoring... + public boolean isNormal() { return ! (this.isNone() || this.isSafeZone() || this.isWarZone()); @@ -252,9 +271,9 @@ public class Faction extends Entity implements EconomyParticipator //----------------------------------------------// public double getPower() { - if (this.hasPermanentPower()) + if (this.getFlag(FactionFlag.INFPOWER)) { - return this.getPermanentPower(); + return 999999; } double ret = 0; @@ -271,9 +290,9 @@ public class Faction extends Entity implements EconomyParticipator public double getPowerMax() { - if (this.hasPermanentPower()) + if (this.getFlag(FactionFlag.INFPOWER)) { - return this.getPermanentPower(); + return 999999; } double ret = 0; diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index 5eaf0cdb..5e15dfa5 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -151,7 +151,7 @@ public class P extends MPlugin .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE) .registerTypeAdapter(Location.class, new MyLocationTypeAdapter()) .registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()) - .registerTypeAdapter(Rel.class, new MyRelTypeAdapter()); + .registerTypeAdapter(Rel.class, new MyRelTypeAdapter()); // This one is for users upgrading from 1.6 to 1.7... should be removed some time in the future. } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdDisband.java b/src/com/massivecraft/factions/cmd/CmdDisband.java index e401cf84..3ee18644 100644 --- a/src/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdDisband.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.factions.struct.FactionFlag; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; @@ -49,7 +50,7 @@ public class CmdDisband extends FCommand } } - if (faction.isPermanent()) + if (faction.getFlag(FactionFlag.PERMANENT)) { msg("This faction is designated as permanent, so you cannot disband it."); return; diff --git a/src/com/massivecraft/factions/cmd/CmdFlag.java b/src/com/massivecraft/factions/cmd/CmdFlag.java new file mode 100644 index 00000000..6b7ee848 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFlag.java @@ -0,0 +1,88 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.FactionFlag; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.struct.Rel; + +public class CmdFlag extends FCommand +{ + + public CmdFlag() + { + super(); + this.aliases.add("flag"); + + //this.requiredArgs.add(""); + this.optionalArgs.put("faction", "your"); + this.optionalArgs.put("flag", "all"); + this.optionalArgs.put("on/off", "read"); + + this.permission = Permission.FLAG.node; + this.disableOnLock = true; + + senderMustBePlayer = false; + senderMustBeMember = false; + senderMustBeOfficer = false; + senderMustBeLeader = false; + } + + @Override + public void perform() + { + Faction faction = myFaction; + if (this.argIsSet(0)) + { + faction = this.argAsFaction(0); + } + if (faction == null) return; + + msg(p.txt.titleize("Flag(s) for " + faction.describeTo(fme))); + + if ( ! this.argIsSet(1)) + { + for (FactionFlag flag : FactionFlag.values()) + { + msg(flag.getStateInfo(faction.getFlag(flag), true)); + } + return; + } + + FactionFlag flag = this.argAsFactionFlag(1); + if (flag == null) return; + if ( ! this.argIsSet(2)) + { + msg(flag.getStateInfo(faction.getFlag(flag), true)); + return; + } + + Boolean targetValue = this.argAsBool(2); + if (targetValue == null) return; + + // Do the sender have the right to change flags for this faction? + if (Permission.FLAG_ANY.has(sender)) + { + // This sender may modify any flag for anyone + } + else if ( ! flag.isChangeable()) + { + msg("Only server operators can change this flag."); + return; + } + else if (faction != myFaction) + { + msg("You are not a member in that faction."); + return; + } + else if (fme.getRole().isLessThan(Rel.OFFICER)) + { + msg("You must be faction leader or officer to change your faction flags."); + return; + } + + // Do the change + faction.setFlag(flag, targetValue); + msg(flag.getStateInfo(faction.getFlag(flag), true)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdHelp.java b/src/com/massivecraft/factions/cmd/CmdHelp.java index 9c74a0b9..3d50a115 100644 --- a/src/com/massivecraft/factions/cmd/CmdHelp.java +++ b/src/com/massivecraft/factions/cmd/CmdHelp.java @@ -168,8 +168,6 @@ public class CmdHelp extends FCommand pageLines = new ArrayList(); pageLines.add(p.txt.parse("More commands for server admins:")); pageLines.add( p.cmdBase.cmdPeaceful.getUseageTemplate(true) ); - pageLines.add( p.cmdBase.cmdPermanent.getUseageTemplate(true) ); - pageLines.add( p.cmdBase.cmdPermanentPower.getUseageTemplate(true) ); pageLines.add(p.txt.parse("Peaceful factions are protected from PvP and land capture.")); pageLines.add( p.cmdBase.cmdLock.getUseageTemplate(true) ); pageLines.add( p.cmdBase.cmdReload.getUseageTemplate(true) ); diff --git a/src/com/massivecraft/factions/cmd/CmdKick.java b/src/com/massivecraft/factions/cmd/CmdKick.java index 51ac8d57..e00b2e21 100644 --- a/src/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/com/massivecraft/factions/cmd/CmdKick.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.FactionFlag; import com.massivecraft.factions.struct.Permission; public class CmdKick extends FCommand @@ -77,7 +78,7 @@ public class CmdKick extends FCommand yourFaction.deinvite(you); you.resetFactionData(); - if (yourFaction.getFPlayers().isEmpty() && !yourFaction.isPermanent()) + if (yourFaction.getFPlayers().isEmpty() && !yourFaction.getFlag(FactionFlag.PERMANENT)) { // Remove this faction for (FPlayer fplayer : FPlayers.i.getOnline()) diff --git a/src/com/massivecraft/factions/cmd/CmdPermanent.java b/src/com/massivecraft/factions/cmd/CmdPermanent.java deleted file mode 100644 index dd152ce9..00000000 --- a/src/com/massivecraft/factions/cmd/CmdPermanent.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.struct.Permission; - - -public class CmdPermanent extends FCommand -{ - public CmdPermanent() - { - super(); - this.aliases.add("permanent"); - - this.requiredArgs.add("faction tag"); - //this.optionalArgs.put("", ""); - - this.permission = Permission.SET_PERMANENT.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; - } - - @Override - public void perform() - { - Faction faction = this.argAsFaction(0); - if (faction == null) return; - - String change; - if(faction.isPermanent()) - { - change = "removed permanent status from"; - faction.setPermanent(false); - } - else - { - change = "added permanent status to"; - faction.setPermanent(true); - } - - // Inform all players - for (FPlayer fplayer : FPlayers.i.getOnline()) - { - if (fplayer.getFaction() == faction) - { - fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true))+" has "+change+" your faction."); - } - else - { - fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true))+" has "+change+" the faction \"" + faction.getTag(fplayer) + "\"."); - } - } - } -} diff --git a/src/com/massivecraft/factions/cmd/CmdPermanentPower.java b/src/com/massivecraft/factions/cmd/CmdPermanentPower.java deleted file mode 100644 index 5a8cb105..00000000 --- a/src/com/massivecraft/factions/cmd/CmdPermanentPower.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.struct.Permission; - -public class CmdPermanentPower extends FCommand -{ - public CmdPermanentPower() - { - super(); - this.aliases.add("permanentpower"); - - this.requiredArgs.add("faction"); - this.optionalArgs.put("power", "reset"); - - this.permission = Permission.SET_PERMANENTPOWER.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; - } - - @Override - public void perform() - { - Faction targetFaction = this.argAsFaction(0); - if (targetFaction == null) return; - - Integer targetPower = this.argAsInt(1); - - targetFaction.setPermanentPower(targetPower); - - String change = "removed permanentpower status from"; - if(targetFaction.hasPermanentPower()) - { - change = "added permanentpower status to"; - } - - msg("You %s %s.", change, targetFaction.describeTo(fme)); - - // Inform all players - for (FPlayer fplayer : targetFaction.getFPlayersWhereOnline(true)) - { - fplayer.msg((fme == null ? "A server admin" : fme.describeTo(fplayer, true))+" "+change+" your faction."); - } - } -} diff --git a/src/com/massivecraft/factions/cmd/CmdRelationTruce.java b/src/com/massivecraft/factions/cmd/CmdRelationTruce.java new file mode 100644 index 00000000..f43cf908 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdRelationTruce.java @@ -0,0 +1,12 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.struct.Rel; + +public class CmdRelationTruce extends FRelationCommand +{ + public CmdRelationTruce() + { + aliases.add("neutral"); + targetRelation = Rel.NEUTRAL; + } +} diff --git a/src/com/massivecraft/factions/cmd/CmdShow.java b/src/com/massivecraft/factions/cmd/CmdShow.java index 7605aa90..fa7d64b5 100644 --- a/src/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/com/massivecraft/factions/cmd/CmdShow.java @@ -7,6 +7,7 @@ import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.struct.FactionFlag; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; @@ -63,7 +64,7 @@ public class CmdShow extends FCommand msg("Joining: "+(faction.getOpen() ? "no invitation is needed" : "invitation is required")+peaceStatus); msg("Land / Power / Maxpower: %d/%d/%d", faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded()); - if (faction.isPermanent()) + if (faction.getFlag(FactionFlag.PERMANENT)) { msg("This faction is permanent, remaining even with no members."); } diff --git a/src/com/massivecraft/factions/cmd/FCmdRoot.java b/src/com/massivecraft/factions/cmd/FCmdRoot.java index 7576bfb2..add68149 100644 --- a/src/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/com/massivecraft/factions/cmd/FCmdRoot.java @@ -17,6 +17,7 @@ public class FCmdRoot extends FCommand public CmdDeinvite cmdDeinvite = new CmdDeinvite(); public CmdDescription cmdDescription = new CmdDescription(); public CmdDisband cmdDisband = new CmdDisband(); + public CmdFlag cmdFlag = new CmdFlag(); public CmdHelp cmdHelp = new CmdHelp(); public CmdHome cmdHome = new CmdHome(); public CmdInvite cmdInvite = new CmdInvite(); @@ -32,8 +33,6 @@ public class FCmdRoot extends FCommand public CmdOwner cmdOwner = new CmdOwner(); public CmdOwnerList cmdOwnerList = new CmdOwnerList(); public CmdPeaceful cmdPeaceful = new CmdPeaceful(); - public CmdPermanent cmdPermanent = new CmdPermanent(); - public CmdPermanentPower cmdPermanentPower = new CmdPermanentPower(); public CmdPower cmdPower = new CmdPower(); public CmdRelationAlly cmdRelationAlly = new CmdRelationAlly(); public CmdRelationEnemy cmdRelationEnemy = new CmdRelationEnemy(); @@ -83,6 +82,7 @@ public class FCmdRoot extends FCommand this.addSubCommand(this.cmdDeinvite); this.addSubCommand(this.cmdDescription); this.addSubCommand(this.cmdDisband); + this.addSubCommand(this.cmdFlag); this.addSubCommand(this.cmdHelp); this.addSubCommand(this.cmdHome); this.addSubCommand(this.cmdInvite); @@ -98,8 +98,6 @@ public class FCmdRoot extends FCommand this.addSubCommand(this.cmdOwner); this.addSubCommand(this.cmdOwnerList); this.addSubCommand(this.cmdPeaceful); - this.addSubCommand(this.cmdPermanent); - this.addSubCommand(this.cmdPermanentPower); this.addSubCommand(this.cmdPower); this.addSubCommand(this.cmdRelationAlly); this.addSubCommand(this.cmdRelationEnemy); diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index 63bd4e8c..ebb5e593 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -12,6 +12,7 @@ import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.P; +import com.massivecraft.factions.struct.FactionFlag; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.zcore.MCommand; @@ -273,6 +274,41 @@ public abstract class FCommand extends MCommand

return this.argAsFaction(idx, null); } + // FACTION FLAG ====================== + public FactionFlag strAsFactionFlag(String name, FactionFlag def, boolean msg) + { + FactionFlag ret = def; + + if (name != null) + { + FactionFlag flag = FactionFlag.parse(name); + if (flag != null) + { + ret = flag; + } + } + + if (msg && ret == null) + { + this.msg("The faction-flag \"

%s\" could not be found.", name); + } + + return ret; + } + public FactionFlag argAsFactionFlag(int idx, FactionFlag def, boolean msg) + { + return this.strAsFactionFlag(this.argAsString(idx), def, msg); + } + public FactionFlag argAsFactionFlag(int idx, FactionFlag def) + { + return this.argAsFactionFlag(idx, def, true); + } + public FactionFlag argAsFactionFlag(int idx) + { + return this.argAsFactionFlag(idx, null); + } + + // -------------------------------------------- // // Commonly used logic // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/struct/FactionFlag.java b/src/com/massivecraft/factions/struct/FactionFlag.java index dd25a5d6..453e4576 100644 --- a/src/com/massivecraft/factions/struct/FactionFlag.java +++ b/src/com/massivecraft/factions/struct/FactionFlag.java @@ -1,5 +1,7 @@ package com.massivecraft.factions.struct; +import com.massivecraft.factions.Conf; + /** * Flags that describe the nature of a faction and it's territory. * Can monsters spawn there? May fire spread etc? Is the faction permanent? @@ -10,27 +12,51 @@ package com.massivecraft.factions.struct; public enum FactionFlag { // Faction flags - PERMANENT, - PEACEFUL, // This faction is friends with everyone - INFPOWER, // This faction has infinite power: TODO: Add faction has enough method. Replace the permanentpower level + PERMANENT("permanent", "A permanent faction will never be deleted.", false, false), + PEACEFUL("peaceful", "Allways in truce with other factions.", false, false), + INFPOWER("infpower", "This flag gives the faction infinite power.", false, false), + // This faction has infinite power: TODO: Add faction has enough method. Replace the permanentpower level // (Faction) Territory flags - POWERLOSS, // Regardless of death-reason players loose power on death IF powerloss is true in this territory - PVP, - FRIENDLYFIRE, // Can members/allies/friends damage eachother in this territory? - MONSTERS, - EXPLOSIONS, - FIRESPREAD, - LIGHTNING, + POWERLOSS("powerloss", "Is power lost on death in this territory?", true, false), + PVP("pvp", "Can you PVP in territory?", true, false), + FRIENDLYFIRE("friendlyfire", "Can friends hurt eachother here?", false, false), + MONSTERS("monsters", "Can monsters spawn in this territory?", true, false), + EXPLOSIONS("explosions", "Can explosions occur in this territory?", true, false), + FIRESPREAD("firespread", "Can fire spread in territory?", true, false), + LIGHTNING("lightning", "Can lightning strike in this territory?", true, false), + ENDERGRIEF("endergrief", "Can endermen grief in this territory?", false, true), ; + private final String nicename; + private final String desc; + public final boolean defaultDefaultValue; + public final boolean defaultDefaultChangeable; + + private FactionFlag(final String nicename, final String desc, final boolean defaultDefaultValue, final boolean defaultDefaultChangeable) + { + this.nicename = nicename; + this.desc = desc; + this.defaultDefaultValue = defaultDefaultValue; + this.defaultDefaultChangeable = defaultDefaultChangeable; + } + + public String getNicename() + { + return this.nicename; + } + + public String getDescription() + { + return this.desc; + } + /** * The state for newly created factions. */ public boolean getDefault() { - // Use config file for this later. - return true; + return Conf.factionFlagDefaults.get(this); } /** @@ -40,7 +66,32 @@ public enum FactionFlag */ public boolean isChangeable() { - // TODO: Use config file - return true; + return Conf.factionFlagIsChangeable.get(this); + } + + public static FactionFlag 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("e")) return EXPLOSIONS; + if (str.startsWith("fi")) return FIRESPREAD; + if (str.startsWith("l")) return LIGHTNING; + return null; + } + + public String getStateInfo(boolean value, boolean withDesc) + { + String ret = (value ? "YES" : "NOT") + " " + this.getNicename(); + if (withDesc) + { + ret += " " + this.getDescription(); + } + return ret; } } diff --git a/src/com/massivecraft/factions/struct/FactionPlayerPerm.java b/src/com/massivecraft/factions/struct/FactionPerm.java similarity index 77% rename from src/com/massivecraft/factions/struct/FactionPlayerPerm.java rename to src/com/massivecraft/factions/struct/FactionPerm.java index e62b6fe2..7edce88e 100644 --- a/src/com/massivecraft/factions/struct/FactionPlayerPerm.java +++ b/src/com/massivecraft/factions/struct/FactionPerm.java @@ -2,10 +2,9 @@ package com.massivecraft.factions.struct; /** * Permissions that you (a player) may or may not have in the territory of a certain faction. - * - * You need a certain rel to be able + * Each faction have many Rel's assigned to each one of these Perms. */ -public enum FactionPlayerPerm +public enum FactionPerm { BUILD, // This player can build in the faction PAINBUILD, // This player can build in the faction BUT will take damage each time. This is overridden by BUILD if player has both diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index de2ccf91..66c36f61 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -20,6 +20,8 @@ public enum Permission DESCRIPTION("description"), DISBAND("disband"), DISBAND_ANY("disband.any"), + FLAG("flag"), + FLAG_ANY("flag.any"), HELP("help"), HOME("home"), INVITE("invite"), @@ -44,8 +46,6 @@ public enum Permission OWNER("owner"), OWNERLIST("ownerlist"), SET_PEACEFUL("setpeaceful"), - SET_PERMANENT("setpermanent"), - SET_PERMANENTPOWER("setpermanentpower"), POWER("power"), POWER_ANY("power.any"), RELATION("relation"), diff --git a/src/com/massivecraft/factions/util/RelationUtil.java b/src/com/massivecraft/factions/util/RelationUtil.java index 2036fdbb..746acfd5 100644 --- a/src/com/massivecraft/factions/util/RelationUtil.java +++ b/src/com/massivecraft/factions/util/RelationUtil.java @@ -15,6 +15,11 @@ public class RelationUtil { String ret = ""; + if (that == null) + { + return "A server admin"; + } + Faction thatFaction = getFaction(that); if (thatFaction == null) return "ERROR"; // ERROR