From 72db45e45e8f31e0516bcb987fbbd04d864c4797 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 25 Oct 2011 21:18:08 +0200 Subject: [PATCH] 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 / --- README.md | 23 ----- plugin.yml | 73 ++++++---------- src/com/massivecraft/factions/Board.java | 10 +++ src/com/massivecraft/factions/Conf.java | 6 +- src/com/massivecraft/factions/FPlayer.java | 41 +++------ src/com/massivecraft/factions/Faction.java | 19 ++++- src/com/massivecraft/factions/P.java | 20 +++-- .../factions/adapters/FFlagTypeAdapter.java | 18 ++++ .../FLocToStringSetTypeAdapter.java} | 4 +- .../factions/adapters/FPermTypeAdapter.java | 18 ++++ .../LocationTypeAdapter.java} | 4 +- .../RelTypeAdapter.java} | 7 +- .../cmd/{CmdBypass.java => CmdAdmin.java} | 15 ++-- .../factions/cmd/CmdAutoClaim.java | 14 +-- .../massivecraft/factions/cmd/CmdDisband.java | 16 +--- .../massivecraft/factions/cmd/CmdFlag.java | 24 +----- .../massivecraft/factions/cmd/CmdJoin.java | 2 +- .../massivecraft/factions/cmd/CmdKick.java | 32 ++----- .../massivecraft/factions/cmd/CmdPerm.java | 27 +++--- .../massivecraft/factions/cmd/CmdSethome.java | 13 +-- .../massivecraft/factions/cmd/CmdUnclaim.java | 33 +------ .../massivecraft/factions/cmd/FCmdRoot.java | 2 +- .../massivecraft/factions/cmd/FCommand.java | 2 +- .../factions/integration/Econ.java | 2 +- .../listeners/FactionsBlockListener.java | 33 ++++++- .../listeners/FactionsEntityListener.java | 17 ++-- .../listeners/FactionsPlayerListener.java | 8 +- .../massivecraft/factions/struct/FFlag.java | 41 +++------ .../massivecraft/factions/struct/FPerm.java | 85 +++++++++++++------ .../factions/struct/Permission.java | 19 ++--- 30 files changed, 285 insertions(+), 343 deletions(-) create mode 100644 src/com/massivecraft/factions/adapters/FFlagTypeAdapter.java rename src/com/massivecraft/factions/{util/MapFLocToStringSetTypeAdapter.java => adapters/FLocToStringSetTypeAdapter.java} (94%) create mode 100644 src/com/massivecraft/factions/adapters/FPermTypeAdapter.java rename src/com/massivecraft/factions/{util/MyLocationTypeAdapter.java => adapters/LocationTypeAdapter.java} (94%) rename src/com/massivecraft/factions/{util/MyRelTypeAdapter.java => adapters/RelTypeAdapter.java} (64%) rename src/com/massivecraft/factions/cmd/{CmdBypass.java => CmdAdmin.java} (61%) diff --git a/README.md b/README.md index d35ba159..22ee9866 100644 --- a/README.md +++ b/README.md @@ -12,33 +12,10 @@ Usage --------- Read the full userguide here: [http://massivecraft.com/dev/factions](http://massivecraft.com/dev/factions) -The chat console command is: - - * `/f` - -This command has subcommands like: - -* `/f create MyFactionName` -* `/f invite MyFriendsName` -* `/f claim` -* `/f map` -* ... etc - -You may also read the documentation ingame as the plugin ships with an ingame help manual. Read the help pages like this: - -* `/f help 1` -* `/f help 2` -* `/f help 3` - -Note that you may optionally skip the slash and just write - -* `f` - Installing ---------- 1. Download the latest release: [https://github.com/MassiveCraft/Factions/downloads](https://github.com/MassiveCraft/Factions/downloads)
1. Put Factions.jar in the plugins folder. -1. [Download gson.jar to your lib folder](http://massivecraft.com/plugins/libraries) A default config file will be created on the first run. diff --git a/plugin.yml b/plugin.yml index 015e7edd..20a84d8a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -24,17 +24,12 @@ permissions: description: All faction permissions but configuration and persistance. children: factions.kit.halfmod: true - factions.disband.any: true - factions.sethome.any: true - factions.money.*: true + factions.flag.set: true factions.kit.halfmod: - description: Zones, bypassing, and kicking + description: Can use adminmode children: factions.kit.fullplayer: true - factions.bypass: true - factions.flag.any: true - factions.perm.any: true - factions.kick.any: true + factions.adminmode: true factions.kit.fullplayer: default: true description: Can also create new factions. @@ -44,7 +39,6 @@ permissions: factions.kit.halfplayer: description: Can do all but create factions. children: - factions.leader: true factions.autoclaim: true factions.chat: true factions.claim: true @@ -52,18 +46,19 @@ permissions: factions.description: true factions.disband: true factions.flag: true - factions.perm: true factions.help: true factions.home: true factions.invite: true factions.join: true factions.kick: true + factions.leader: true factions.leave: true factions.list: true factions.map: true + factions.money.*: true factions.officer: true - factions.money.kit.standard: true factions.open: true + factions.perm: true factions.power: true factions.power.any: true factions.relation: true @@ -71,15 +66,13 @@ permissions: factions.show: true factions.tag: true factions.title: true - factions.version: true factions.unclaim: true factions.unclaimall: true - factions.leader: - description: hand over your leader rights + factions.version: true + factions.adminmode: + description: enable admin bypass mode factions.autoclaim: description: auto-claim land as you walk around - factions.bypass: - description: enable admin bypass mode factions.chat: description: change chat mode factions.claim: @@ -94,16 +87,10 @@ permissions: description: change the faction description factions.disband: 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.perm: - description: change faction permissions - factions.perm.any: - description: change all permissions for all factions + description: read faction flags + factions.flag.set: + description: set faction flags factions.help: description: display a help page factions.home: @@ -114,8 +101,8 @@ permissions: description: join a faction factions.kick: description: kick a player from the faction - factions.kick.any: - description: kick anyone from any faction + factions.leader: + description: hand over your leader rights factions.leave: description: leave your faction factions.list: @@ -124,45 +111,35 @@ permissions: description: lock all write stuff factions.map: description: show the territory map, and set optional auto update - factions.officer: - description: give or revoke officer rights factions.money.balance: description: show your factions current money balance factions.money.balance.any: description: show money balance for factions other than your own factions.money.deposit: description: deposit money into a faction bank - factions.money.withdraw: - description: withdraw money from your faction bank - factions.money.withdraw.any: - description: withdraw money from your factions other than your own factions.money.f2f: description: transfer money from faction to faction factions.money.f2p: description: transfer money from faction to player factions.money.p2f: description: transfer money from player to faction - factions.money.kit.standard: + factions.money.withdraw: + description: withdraw money from your faction bank + factions.money.*: children: factions.money.balance: true factions.money.balance.any: true factions.money.deposit: true - factions.money.withdraw: true factions.money.f2f: true factions.money.f2p: true factions.money.p2f: true - factions.money.*: - children: - factions.money.kit.standard: true - factions.money.balance.any: true - factions.money.deposit: true factions.money.withdraw: true - factions.money.withdraw.any: true - factions.money.f2f: true - factions.money.f2p: true - factions.money.p2f: true + factions.officer: + description: give or revoke officer rights factions.open: description: switch if invitation is required to join + factions.perm: + description: change faction permissions factions.power: description: show player power info factions.power.any: @@ -175,17 +152,15 @@ permissions: description: save all data to disk factions.sethome: description: set the faction home - factions.sethome.any: - description: set faction home for another faction factions.show: description: show faction information factions.tag: description: change the faction tag factions.title: description: set or remove a players title - factions.version: - description: see the version of the plugin factions.unclaim: description: unclaim the land where you are standing factions.unclaimall: - description: unclaim all of your factions land \ No newline at end of file + description: unclaim all of your factions land + factions.version: + description: see the version of the plugin \ No newline at end of file diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index f50c410d..f57580bd 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -10,6 +10,8 @@ import java.util.Map.Entry; import java.util.TreeMap; import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.block.Block; import com.google.gson.reflect.TypeToken; import com.massivecraft.factions.iface.RelationParticipator; @@ -39,6 +41,14 @@ public class Board { return Factions.i.get(getIdAt(flocation)); } + public static Faction getFactionAt(Location location) + { + return getFactionAt(new FLocation(location)); + } + public static Faction getFactionAt(Block block) + { + return getFactionAt(new FLocation(block)); + } public static void setIdAt(String id, FLocation flocation) { diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 730b2b11..927af3ec 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -16,8 +16,8 @@ public class Conf // Colors public static ChatColor colorMember = ChatColor.GREEN; - public static ChatColor colorAlly = ChatColor.LIGHT_PURPLE; - public static ChatColor colorTruce = ChatColor.DARK_PURPLE; + public static ChatColor colorAlly = ChatColor.DARK_PURPLE; + public static ChatColor colorTruce = ChatColor.LIGHT_PURPLE; public static ChatColor colorNeutral = ChatColor.WHITE; public static ChatColor colorEnemy = ChatColor.RED; @@ -206,11 +206,9 @@ public class Conf baseCommandAliases.add("f"); factionFlagDefaults = new LinkedHashMap(); - factionFlagIsChangeable = new LinkedHashMap(); for (FFlag flag : FFlag.values()) { factionFlagDefaults.put(flag, flag.defaultDefaultValue); - factionFlagIsChangeable.put(flag, flag.defaultDefaultChangeable); } factionPermDefaults = new LinkedHashMap>(); diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index be1e99eb..d058a332 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -15,6 +15,7 @@ import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.FFlag; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.zcore.persist.PlayerEntity; @@ -80,9 +81,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator public Faction getAutoClaimFor() { return autoClaimFor; } public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; } - private transient boolean isAdminBypassing = false; - public boolean isAdminBypassing() { return this.isAdminBypassing; } - public void setIsAdminBypassing(boolean val) { this.isAdminBypassing = val; } + private transient boolean hasAdminMode = false; + public boolean hasAdminMode() { return this.hasAdminMode; } + public void setHasAdminMode(boolean val) { this.hasAdminMode = val; } // FIELD: loginPvpDisabled private transient boolean loginPvpDisabled; @@ -470,7 +471,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator } // if economy is enabled and they're not on the bypass list, make 'em pay - if (makePay && Econ.shouldBeUsed() && ! this.isAdminBypassing()) + if (makePay && Econ.shouldBeUsed() && ! this.hasAdminMode()) { double cost = Conf.econCostLeave; if ( ! Econ.modifyMoney(this, -cost, "to leave your faction.", "for leaving your faction.")) return; @@ -511,24 +512,6 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator P.p.log("The faction "+myFaction.getTag()+" ("+myFaction.getId()+") was disbanded due to the last player ("+this.getName()+") leaving."); } } - - public boolean canClaimForFaction(Faction forFaction) - { - if (forFaction.isNone()) return false; - - if - ( - this.isAdminBypassing() - || (forFaction == this.getFaction() && this.getRole().isAtLeast(Role.MODERATOR)) - || (forFaction.isSafeZone() && Permission.MANAGE_SAFE_ZONE.has(getPlayer())) - || (forFaction.isWarZone() && Permission.MANAGE_WAR_ZONE.has(getPlayer())) - ) - { - return true; - } - - return false; - } public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure) { @@ -547,21 +530,17 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { error = P.p.txt.parse("Sorry, this world has land claiming disabled."); } - else if (this.isAdminBypassing()) + else if (this.hasAdminMode()) { return true; } - else if (myFaction != forFaction) - { - error = P.p.txt.parse("You can't claim land for %s.", forFaction.describeTo(this)); - } else if (forFaction == currentFaction) { error = P.p.txt.parse("%s already own this land.", forFaction.describeTo(this, true)); } - else if ( ! this.getRole().isAtLeast(Rel.OFFICER)) + else if ( ! FPerm.TERRITORY.has(this, forFaction, true)) { - error = P.p.txt.parse("You must be %s to claim land.", Rel.OFFICER.toString()); + return false; } else if (forFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers) { @@ -578,7 +557,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator else if ( Conf.claimsMustBeConnected - && ! this.isAdminBypassing() + && ! this.hasAdminMode() && myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, myFaction) && (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) @@ -624,7 +603,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator // if economy is enabled and they're not on the bypass list, make 'em pay // TODO: Add flag no costs?? //if (Econ.shouldBeUsed() && ! this.isAdminBypassing() && ! forFaction.isSafeZone() && ! forFaction.isWarZone()) - if (Econ.shouldBeUsed() && ! this.isAdminBypassing()) + if (Econ.shouldBeUsed() && ! this.hasAdminMode()) { double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal()); //String costString = Econ.moneyString(cost); diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index f93b77da..341d13ed 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -122,9 +122,26 @@ public class Faction extends Entity implements EconomyParticipator if (ret == null) ret = perm.getDefault(); return ret; } + + public void addPermittedRelation(FPerm perm, Rel rel) + { + Set newPermittedRelations = EnumSet.noneOf(Rel.class); + newPermittedRelations.addAll(this.getPermittedRelations(perm)); + newPermittedRelations.add(rel); + this.setPermittedRelations(perm, newPermittedRelations); + } + + public void removePermittedRelation(FPerm perm, Rel rel) + { + Set newPermittedRelations = EnumSet.noneOf(Rel.class); + newPermittedRelations.addAll(this.getPermittedRelations(perm)); + newPermittedRelations.remove(rel); + this.setPermittedRelations(perm, newPermittedRelations); + } + public void setPermittedRelations(FPerm perm, Set rels) { - if (Conf.factionPermDefaults.get(perm).equals(rels)) + if (perm.getDefault().equals(rels)) { this.permOverrides.remove(perm); return; diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index 7b1bd9e6..559358e6 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -14,6 +14,11 @@ import org.bukkit.event.Event; import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.plugin.Plugin; +import com.massivecraft.factions.adapters.FFlagTypeAdapter; +import com.massivecraft.factions.adapters.FLocToStringSetTypeAdapter; +import com.massivecraft.factions.adapters.FPermTypeAdapter; +import com.massivecraft.factions.adapters.LocationTypeAdapter; +import com.massivecraft.factions.adapters.RelTypeAdapter; import com.massivecraft.factions.cmd.*; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; @@ -24,10 +29,9 @@ import com.massivecraft.factions.listeners.FactionsEntityListener; import com.massivecraft.factions.listeners.FactionsPlayerListener; import com.massivecraft.factions.listeners.FactionsServerListener; import com.massivecraft.factions.struct.ChatMode; +import com.massivecraft.factions.struct.FFlag; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; -import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter; -import com.massivecraft.factions.util.MyLocationTypeAdapter; -import com.massivecraft.factions.util.MyRelTypeAdapter; import com.massivecraft.factions.zcore.MPlugin; import com.nijiko.permissions.PermissionHandler; @@ -132,6 +136,8 @@ public class P extends MPlugin this.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Event.Priority.Normal); this.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, this.blockListener, Event.Priority.Normal); this.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, this.blockListener, Event.Priority.Normal); + this.registerEvent(Event.Type.BLOCK_SPREAD, this.blockListener, Event.Priority.Normal); + this.registerEvent(Event.Type.BLOCK_BURN, this.blockListener, Event.Priority.Normal); // Server Events this.registerEvent(Event.Type.PLUGIN_ENABLE, this.serverListener, Event.Priority.Monitor); @@ -149,9 +155,11 @@ public class P extends MPlugin .setPrettyPrinting() .disableHtmlEscaping() .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE) - .registerTypeAdapter(Location.class, new MyLocationTypeAdapter()) - .registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()) - .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. + .registerTypeAdapter(Location.class, new LocationTypeAdapter()) + .registerTypeAdapter(mapFLocToStringSetType, new FLocToStringSetTypeAdapter()) + .registerTypeAdapter(Rel.class, new RelTypeAdapter()) + .registerTypeAdapter(FPerm.class, new FPermTypeAdapter()) + .registerTypeAdapter(FFlag.class, new FFlagTypeAdapter()); } @Override diff --git a/src/com/massivecraft/factions/adapters/FFlagTypeAdapter.java b/src/com/massivecraft/factions/adapters/FFlagTypeAdapter.java new file mode 100644 index 00000000..794971c9 --- /dev/null +++ b/src/com/massivecraft/factions/adapters/FFlagTypeAdapter.java @@ -0,0 +1,18 @@ +package com.massivecraft.factions.adapters; + +import java.lang.reflect.Type; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.massivecraft.factions.struct.FFlag; + +public class FFlagTypeAdapter implements JsonDeserializer +{ + @Override + public FFlag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException + { + return FFlag.parse(json.getAsString()); + } +} diff --git a/src/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java b/src/com/massivecraft/factions/adapters/FLocToStringSetTypeAdapter.java similarity index 94% rename from src/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java rename to src/com/massivecraft/factions/adapters/FLocToStringSetTypeAdapter.java index 23231cc0..58f1225a 100644 --- a/src/com/massivecraft/factions/util/MapFLocToStringSetTypeAdapter.java +++ b/src/com/massivecraft/factions/adapters/FLocToStringSetTypeAdapter.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.util; +package com.massivecraft.factions.adapters; import java.lang.reflect.Type; import java.util.concurrent.ConcurrentHashMap; @@ -23,7 +23,7 @@ import com.massivecraft.factions.P; // TODO: Is this one even used anymore?? -public class MapFLocToStringSetTypeAdapter implements JsonDeserializer>>, JsonSerializer>> +public class FLocToStringSetTypeAdapter implements JsonDeserializer>>, JsonSerializer>> { @Override diff --git a/src/com/massivecraft/factions/adapters/FPermTypeAdapter.java b/src/com/massivecraft/factions/adapters/FPermTypeAdapter.java new file mode 100644 index 00000000..d3571679 --- /dev/null +++ b/src/com/massivecraft/factions/adapters/FPermTypeAdapter.java @@ -0,0 +1,18 @@ +package com.massivecraft.factions.adapters; + +import java.lang.reflect.Type; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonParseException; +import com.massivecraft.factions.struct.FPerm; + +public class FPermTypeAdapter implements JsonDeserializer +{ + @Override + public FPerm deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException + { + return FPerm.parse(json.getAsString()); + } +} diff --git a/src/com/massivecraft/factions/util/MyLocationTypeAdapter.java b/src/com/massivecraft/factions/adapters/LocationTypeAdapter.java similarity index 94% rename from src/com/massivecraft/factions/util/MyLocationTypeAdapter.java rename to src/com/massivecraft/factions/adapters/LocationTypeAdapter.java index 7135375a..c94506ea 100644 --- a/src/com/massivecraft/factions/util/MyLocationTypeAdapter.java +++ b/src/com/massivecraft/factions/adapters/LocationTypeAdapter.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.util; +package com.massivecraft.factions.adapters; import java.lang.reflect.Type; import java.util.logging.Level; @@ -16,7 +16,7 @@ import com.google.gson.JsonSerializer; import com.massivecraft.factions.P; -public class MyLocationTypeAdapter implements JsonDeserializer, JsonSerializer +public class LocationTypeAdapter implements JsonDeserializer, JsonSerializer { private static final String WORLD = "world"; private static final String X = "x"; diff --git a/src/com/massivecraft/factions/util/MyRelTypeAdapter.java b/src/com/massivecraft/factions/adapters/RelTypeAdapter.java similarity index 64% rename from src/com/massivecraft/factions/util/MyRelTypeAdapter.java rename to src/com/massivecraft/factions/adapters/RelTypeAdapter.java index d9304c82..068436ef 100644 --- a/src/com/massivecraft/factions/util/MyRelTypeAdapter.java +++ b/src/com/massivecraft/factions/adapters/RelTypeAdapter.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.util; +package com.massivecraft.factions.adapters; import java.lang.reflect.Type; @@ -8,10 +8,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import com.massivecraft.factions.struct.Rel; -/** - * This is a legacy solution. Since Relation and Role enums have ben merged AND the rename ADMIN -> LEADER, MODERATOR -> OFFICER - */ -public class MyRelTypeAdapter implements JsonDeserializer +public class RelTypeAdapter implements JsonDeserializer { @Override public Rel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException diff --git a/src/com/massivecraft/factions/cmd/CmdBypass.java b/src/com/massivecraft/factions/cmd/CmdAdmin.java similarity index 61% rename from src/com/massivecraft/factions/cmd/CmdBypass.java rename to src/com/massivecraft/factions/cmd/CmdAdmin.java index a6b7a465..d894ab6d 100644 --- a/src/com/massivecraft/factions/cmd/CmdBypass.java +++ b/src/com/massivecraft/factions/cmd/CmdAdmin.java @@ -3,17 +3,17 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.P; import com.massivecraft.factions.struct.Permission; -public class CmdBypass extends FCommand +public class CmdAdmin extends FCommand { - public CmdBypass() + public CmdAdmin() { super(); - this.aliases.add("bypass"); + this.aliases.add("admin"); //this.requiredArgs.add(""); this.optionalArgs.put("on/off", "flip"); - this.permission = Permission.BYPASS.node; + this.permission = Permission.ADMIN.node; this.disableOnLock = false; senderMustBePlayer = true; @@ -25,12 +25,11 @@ public class CmdBypass extends FCommand @Override public void perform() { - fme.setIsAdminBypassing(this.argAsBool(0, ! fme.isAdminBypassing())); + fme.setHasAdminMode(this.argAsBool(0, ! fme.hasAdminMode())); - // TODO: Move this to a transient field in the model?? - if ( fme.isAdminBypassing()) + if ( fme.hasAdminMode()) { - fme.msg("You have enabled admin bypass mode. You will be able to build or destroy anywhere."); + fme.msg("You have enabled admin bypass mode."); P.p.log(fme.getName() + " has ENABLED admin bypass mode."); } else diff --git a/src/com/massivecraft/factions/cmd/CmdAutoClaim.java b/src/com/massivecraft/factions/cmd/CmdAutoClaim.java index 509ae61b..2e094cb6 100644 --- a/src/com/massivecraft/factions/cmd/CmdAutoClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdAutoClaim.java @@ -1,8 +1,8 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Role; public class CmdAutoClaim extends FCommand { @@ -33,16 +33,8 @@ public class CmdAutoClaim extends FCommand msg("Auto-claiming of land disabled."); return; } - - if (! fme.canClaimForFaction(forFaction)) - { - if (myFaction == forFaction) - msg("You must be %s to claim land.", Role.MODERATOR.toString()); - else - msg("You can't claim land for %s.", forFaction.describeTo(fme)); - - return; - } + + if ( ! FPerm.TERRITORY.has(fme, forFaction, true)) return; fme.setAutoClaimFor(forFaction); diff --git a/src/com/massivecraft/factions/cmd/CmdDisband.java b/src/com/massivecraft/factions/cmd/CmdDisband.java index f41e3480..eeddf0b0 100644 --- a/src/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdDisband.java @@ -8,8 +8,8 @@ import com.massivecraft.factions.P; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.FFlag; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Rel; public class CmdDisband extends FCommand { @@ -37,19 +37,7 @@ public class CmdDisband extends FCommand Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); if (faction == null) return; - boolean isMyFaction = fme == null ? false : faction == myFaction; - - if (isMyFaction) - { - if ( ! assertMinRole(Rel.LEADER)) return; - } - else - { - if ( ! Permission.DISBAND_ANY.has(sender, true)) - { - return; - } - } + if ( ! FPerm.DISBAND.has(sender, faction, true)) return; if (faction.getFlag(FFlag.PERMANENT)) { diff --git a/src/com/massivecraft/factions/cmd/CmdFlag.java b/src/com/massivecraft/factions/cmd/CmdFlag.java index 7c73c9db..1aa7ef7f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFlag.java +++ b/src/com/massivecraft/factions/cmd/CmdFlag.java @@ -3,7 +3,6 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.Faction; import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Rel; public class CmdFlag extends FCommand { @@ -12,6 +11,7 @@ public class CmdFlag extends FCommand { super(); this.aliases.add("flag"); + this.aliases.add("flags"); //this.requiredArgs.add(""); this.optionalArgs.put("faction", "your"); @@ -59,26 +59,8 @@ public class CmdFlag extends FCommand 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 sender have the right to change flags? + if ( ! Permission.FLAG_SET.has(sender, true)) return; // Do the change msg(p.txt.titleize("Flag for " + faction.describeTo(fme, true))); diff --git a/src/com/massivecraft/factions/cmd/CmdJoin.java b/src/com/massivecraft/factions/cmd/CmdJoin.java index 755bba7e..70eba562 100644 --- a/src/com/massivecraft/factions/cmd/CmdJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdJoin.java @@ -54,7 +54,7 @@ public class CmdJoin extends FCommand return; } - if( ! (faction.getOpen() || faction.isInvited(fme) || fme.isAdminBypassing())) + if( ! (faction.getOpen() || faction.isInvited(fme) || fme.hasAdminMode())) { msg("This faction requires invitation."); faction.msg("%s tried to join your faction.", fme.describeTo(faction, true)); diff --git a/src/com/massivecraft/factions/cmd/CmdKick.java b/src/com/massivecraft/factions/cmd/CmdKick.java index b7791c26..87993e20 100644 --- a/src/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/com/massivecraft/factions/cmd/CmdKick.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; import com.massivecraft.factions.struct.FFlag; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; public class CmdKick extends FCommand @@ -41,31 +42,16 @@ public class CmdKick extends FCommand return; } + if ( ! Conf.canLeaveWithNegativePower && you.getPower() < 0) + { + msg("You cannot kick that member until their power is positive."); + return; + } + Faction yourFaction = you.getFaction(); - // players with admin-level "disband" permission can bypass these requirements - if ( ! Permission.KICK_ANY.has(sender)) - { - if (yourFaction != myFaction) - { - msg("%s is not a member of %s", you.describeTo(fme, true), myFaction.describeTo(fme)); - return; - } - - if (you.getRole().isAtLeast(fme.getRole())) - { - // TODO add more informative messages. - msg("Your rank is too low to kick this player."); - return; - } - - if ( ! Conf.canLeaveWithNegativePower && you.getPower() < 0) - { - msg("You cannot kick that member until their power is positive."); - return; - } - } - + if (fme != null && ! FPerm.KICK.has(fme, yourFaction)) return; + // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(Conf.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) return; diff --git a/src/com/massivecraft/factions/cmd/CmdPerm.java b/src/com/massivecraft/factions/cmd/CmdPerm.java index 106d53ca..f104bd42 100644 --- a/src/com/massivecraft/factions/cmd/CmdPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdPerm.java @@ -15,6 +15,7 @@ public class CmdPerm extends FCommand { super(); this.aliases.add("perm"); + this.aliases.add("perms"); //this.requiredArgs.add(""); this.optionalArgs.put("faction", "your"); @@ -63,26 +64,20 @@ public class CmdPerm extends FCommand return; } - Set targetValue = FPerm.parseRelDeltas(TextUtil.implode(args.subList(2, args.size()), " "), faction.getPermittedRelations(perm)); - // Do the sender have the right to change perms for this faction? - if (Permission.PERM_ANY.has(sender)) - { - // This sender may modify any perm for anyone - } - 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 permissions."); - return; - } + if ( ! FPerm.PERMS.has(sender, faction, true)) return; // Do the change + Set targetValue = FPerm.parseRelDeltas(TextUtil.implode(args.subList(2, args.size()), " "), faction.getPermittedRelations(perm)); + + // The following is to make sure the leader always has the right to change perms if that is our goal. + if (perm == FPerm.PERMS && FPerm.PERMS.getDefault().contains(Rel.LEADER)) + { + targetValue.add(Rel.LEADER); + } + faction.setPermittedRelations(perm, targetValue); + msg(p.txt.titleize("Perm for " + faction.describeTo(fme, true))); msg(FPerm.getStateHeaders()); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); diff --git a/src/com/massivecraft/factions/cmd/CmdSethome.java b/src/com/massivecraft/factions/cmd/CmdSethome.java index 219f76db..03e8d63b 100644 --- a/src/com/massivecraft/factions/cmd/CmdSethome.java +++ b/src/com/massivecraft/factions/cmd/CmdSethome.java @@ -4,8 +4,8 @@ import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Rel; public class CmdSethome extends FCommand { @@ -38,19 +38,12 @@ public class CmdSethome extends FCommand if (faction == null) return; // Can the player set the home for this faction? - if (faction == myFaction) - { - if ( ! Permission.SETHOME_ANY.has(sender) && ! assertMinRole(Rel.OFFICER)) return; - } - else - { - if (Permission.SETHOME_ANY.has(sender, true)) return; - } + if ( ! FPerm.SETHOME.has(sender, faction, true)) return; // Can the player set the faction home HERE? if ( - ! Permission.BYPASS.has(me) + ! fme.hasAdminMode() && Conf.homesMustBeInClaimedTerritory && diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaim.java b/src/com/massivecraft/factions/cmd/CmdUnclaim.java index 037e7c5d..7594af08 100644 --- a/src/com/massivecraft/factions/cmd/CmdUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdUnclaim.java @@ -7,8 +7,8 @@ import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; +import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.struct.Rel; public class CmdUnclaim extends FCommand { @@ -34,37 +34,8 @@ public class CmdUnclaim extends FCommand { FLocation flocation = new FLocation(fme); Faction otherFaction = Board.getFactionAt(flocation); - - if (fme.isAdminBypassing()) - { - Board.removeAt(flocation); - SpoutFeatures.updateTerritoryDisplayLoc(flocation); - otherFaction.msg("%s unclaimed some of your land.", fme.describeTo(otherFaction, true)); - msg("You unclaimed this land."); - - if (Conf.logLandUnclaims) - P.p.log(fme.getName()+" unclaimed land at ("+flocation.getCoordString()+") from the faction: "+otherFaction.getTag()); - - return; - } - - if ( ! assertHasFaction()) - { - return; - } - - if ( ! assertMinRole(Rel.OFFICER)) - { - return; - } - - - if ( myFaction != otherFaction) - { - msg("You don't own this land."); - return; - } + if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; //String moneyBack = ""; if (Econ.shouldBeUsed()) diff --git a/src/com/massivecraft/factions/cmd/FCmdRoot.java b/src/com/massivecraft/factions/cmd/FCmdRoot.java index 552f5a48..36ca91ae 100644 --- a/src/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/com/massivecraft/factions/cmd/FCmdRoot.java @@ -8,7 +8,7 @@ public class FCmdRoot extends FCommand { public CmdLeader cmdLeader = new CmdLeader(); public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim(); - public CmdBypass cmdBypass = new CmdBypass(); + public CmdAdmin cmdBypass = new CmdAdmin(); public CmdChat cmdChat = new CmdChat(); public CmdClaim cmdClaim = new CmdClaim(); public CmdConfig cmdConfig = new CmdConfig(); diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index 4702e422..bea6cf04 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -387,7 +387,7 @@ public abstract class FCommand extends MCommand

// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost public boolean payForCommand(double cost, String toDoThis, String forDoingThis) { - if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) return true; + if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true; if(Conf.bankFactionPaysLandCosts && fme.hasFaction()) { diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index 6fb310cb..6826d3b8 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -92,7 +92,7 @@ public class Econ if (fI == null) return true; // Bypassing players can do any kind of transaction - if (i instanceof FPlayer && ((FPlayer)i).isAdminBypassing()) return true; + if (i instanceof FPlayer && ((FPlayer)i).hasAdminMode()) return true; // You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again. if (i == you) return true; diff --git a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java index d0db889a..8c1df823 100644 --- a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -4,11 +4,13 @@ import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockBurnEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; +import org.bukkit.event.block.BlockSpreadEvent; import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; @@ -17,6 +19,7 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; +import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FPerm; @@ -28,17 +31,40 @@ public class FactionsBlockListener extends BlockListener this.p = p; } + @Override + public void onBlockSpread(BlockSpreadEvent event) + { + if (event.isCancelled()) return; + if (event.getSource().getTypeId() != 51) return; // Must be Fire + Faction faction = Board.getFactionAt(event.getBlock()); + if (faction.getFlag(FFlag.FIRESPREAD) == false) + { + event.setCancelled(true); + } + } + + @Override + public void onBlockBurn(BlockBurnEvent event) + { + if (event.isCancelled()) return; + Faction faction = Board.getFactionAt(event.getBlock()); + if (faction.getFlag(FFlag.FIRESPREAD) == false) + { + event.setCancelled(true); + } + } + public static boolean playerCanBuildDestroyBlock(Player player, Block block, String action, boolean justCheck) { FPlayer me = FPlayers.i.get(player); - if (me.isAdminBypassing()) return true; + if (me.hasAdminMode()) return true; Location location = block.getLocation(); FLocation loc = new FLocation(location); Faction factionHere = Board.getFactionAt(loc); - if (FPerm.PAINBUILD.has(me, location)) + if ( ! FPerm.BUILD.has(me, location) && FPerm.PAINBUILD.has(me, location)) { if (!justCheck) { @@ -48,7 +74,7 @@ public class FactionsBlockListener extends BlockListener return true; } - return FPerm.BUILD.has(me, location, true); + return FPerm.BUILD.has(me, loc, true); } @Override @@ -106,7 +132,6 @@ public class FactionsBlockListener extends BlockListener // if potentially pushing into air in another territory, we need to check it out - if (targetBlock.isEmpty() && ! FPerm.BUILD.has(pistonFaction, targetBlock.getLocation())) { event.setCancelled(true); diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index 9b530919..1e471af6 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.listeners; import java.text.MessageFormat; import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; @@ -91,15 +92,15 @@ public class FactionsEntityListener extends EntityListener { if ( event.isCancelled()) return; - Location loc = event.getLocation(); - - Faction faction = Board.getFactionAt(new FLocation(loc)); - - if (faction.getFlag(FFlag.EXPLOSIONS) == false) + for (Block block : event.blockList()) { - // faction is peaceful and has explosions set to disabled - event.setCancelled(true); - return; + Faction faction = Board.getFactionAt(new FLocation(block)); + if (faction.getFlag(FFlag.EXPLOSIONS) == false) + { + // faction is peaceful and has explosions set to disabled + event.setCancelled(true); + return; + } } } diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 59ba6c0c..439b2e41 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -242,14 +242,14 @@ public class FactionsPlayerListener extends PlayerListener public static boolean playerCanUseItemHere(Player player, Location loc, Material material, boolean justCheck) { FPlayer me = FPlayers.i.get(player); - if (me.isAdminBypassing()) return true; + if (me.hasAdminMode()) return true; if (Conf.materialsEditTools.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; return true; } public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) { FPlayer me = FPlayers.i.get(player); - if (me.isAdminBypassing()) return true; + if (me.hasAdminMode()) return true; Location loc = block.getLocation(); Material material = block.getType(); @@ -350,7 +350,7 @@ public class FactionsPlayerListener extends PlayerListener && ! Conf.territoryNeutralDenyCommands.isEmpty() && - ! me.isAdminBypassing() + ! me.hasAdminMode() ) { Iterator iter = Conf.territoryNeutralDenyCommands.iterator(); @@ -378,7 +378,7 @@ public class FactionsPlayerListener extends PlayerListener && ! Conf.territoryEnemyDenyCommands.isEmpty() && - ! me.isAdminBypassing() + ! me.hasAdminMode() ) { Iterator iter = Conf.territoryEnemyDenyCommands.iterator(); diff --git a/src/com/massivecraft/factions/struct/FFlag.java b/src/com/massivecraft/factions/struct/FFlag.java index 1b99e5b2..43a2bad7 100644 --- a/src/com/massivecraft/factions/struct/FFlag.java +++ b/src/com/massivecraft/factions/struct/FFlag.java @@ -12,34 +12,32 @@ import com.massivecraft.factions.Conf; public enum FFlag { // Faction flags - 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), + PERMANENT("permanent", "A permanent faction will never be deleted.", false), + PEACEFUL("peaceful", "Allways in truce with other factions.", false), + INFPOWER("infpower", "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", "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), Possible to add later. - ENDERGRIEF("endergrief", "Can endermen grief in this territory?", false, true), + POWERLOSS("powerloss", "Is power lost on death in this territory?", true), + PVP("pvp", "Can you PVP in territory?", true), + FRIENDLYFIRE("friendlyfire", "Can friends hurt eachother here?", false), + MONSTERS("monsters", "Can monsters spawn in this territory?", true), + EXPLOSIONS("explosions", "Can explosions occur in this territory?", true), + FIRESPREAD("firespread", "Can fire spread in territory?", true), + //LIGHTNING("lightning", "Can lightning strike in this territory?", true), Possible to add later. + ENDERGRIEF("endergrief", "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; } diff --git a/src/com/massivecraft/factions/struct/FPerm.java b/src/com/massivecraft/factions/struct/FPerm.java index 313bffa2..e6c4576f 100644 --- a/src/com/massivecraft/factions/struct/FPerm.java +++ b/src/com/massivecraft/factions/struct/FPerm.java @@ -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 = "%s can't %s in the territory of %s."; - public boolean has(RelationParticipator testSubject, Faction hostFaction, boolean informIfNot) + private static final String errorpattern = "%s does not allow you to %s."; + 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("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); } diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index 565fdb3d..e66c3313 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -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"),