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

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

View File

@ -12,33 +12,10 @@ Usage
--------- ---------
<b>Read the full userguide here: [http://massivecraft.com/dev/factions](http://massivecraft.com/dev/factions)</b> <b>Read the full userguide here: [http://massivecraft.com/dev/factions](http://massivecraft.com/dev/factions)</b>
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 Installing
---------- ----------
1. Download the latest release: [https://github.com/MassiveCraft/Factions/downloads](https://github.com/MassiveCraft/Factions/downloads)<br> 1. Download the latest release: [https://github.com/MassiveCraft/Factions/downloads](https://github.com/MassiveCraft/Factions/downloads)<br>
1. Put Factions.jar in the plugins folder. 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. A default config file will be created on the first run.

View File

@ -24,17 +24,12 @@ permissions:
description: All faction permissions but configuration and persistance. description: All faction permissions but configuration and persistance.
children: children:
factions.kit.halfmod: true factions.kit.halfmod: true
factions.disband.any: true factions.flag.set: true
factions.sethome.any: true
factions.money.*: true
factions.kit.halfmod: factions.kit.halfmod:
description: Zones, bypassing, and kicking description: Can use adminmode
children: children:
factions.kit.fullplayer: true factions.kit.fullplayer: true
factions.bypass: true factions.adminmode: true
factions.flag.any: true
factions.perm.any: true
factions.kick.any: true
factions.kit.fullplayer: factions.kit.fullplayer:
default: true default: true
description: Can also create new factions. description: Can also create new factions.
@ -44,7 +39,6 @@ permissions:
factions.kit.halfplayer: factions.kit.halfplayer:
description: Can do all but create factions. description: Can do all but create factions.
children: children:
factions.leader: true
factions.autoclaim: true factions.autoclaim: true
factions.chat: true factions.chat: true
factions.claim: true factions.claim: true
@ -52,18 +46,19 @@ permissions:
factions.description: true factions.description: true
factions.disband: true factions.disband: true
factions.flag: true factions.flag: true
factions.perm: true
factions.help: true factions.help: true
factions.home: true factions.home: true
factions.invite: true factions.invite: true
factions.join: true factions.join: true
factions.kick: true factions.kick: true
factions.leader: true
factions.leave: true factions.leave: true
factions.list: true factions.list: true
factions.map: true factions.map: true
factions.money.*: true
factions.officer: true factions.officer: true
factions.money.kit.standard: true
factions.open: true factions.open: true
factions.perm: true
factions.power: true factions.power: true
factions.power.any: true factions.power.any: true
factions.relation: true factions.relation: true
@ -71,15 +66,13 @@ permissions:
factions.show: true factions.show: true
factions.tag: true factions.tag: true
factions.title: true factions.title: true
factions.version: true
factions.unclaim: true factions.unclaim: true
factions.unclaimall: true factions.unclaimall: true
factions.leader: factions.version: true
description: hand over your leader rights factions.adminmode:
description: enable admin bypass mode
factions.autoclaim: factions.autoclaim:
description: auto-claim land as you walk around description: auto-claim land as you walk around
factions.bypass:
description: enable admin bypass mode
factions.chat: factions.chat:
description: change chat mode description: change chat mode
factions.claim: factions.claim:
@ -94,16 +87,10 @@ permissions:
description: change the faction description description: change the faction description
factions.disband: factions.disband:
description: disband a faction description: disband a faction
factions.disband.any:
description: disband an other faction
factions.flag: factions.flag:
description: change faction flags description: read faction flags
factions.flag.any: factions.flag.set:
description: change all flags for all factions description: set faction flags
factions.perm:
description: change faction permissions
factions.perm.any:
description: change all permissions for all factions
factions.help: factions.help:
description: display a help page description: display a help page
factions.home: factions.home:
@ -114,8 +101,8 @@ permissions:
description: join a faction description: join a faction
factions.kick: factions.kick:
description: kick a player from the faction description: kick a player from the faction
factions.kick.any: factions.leader:
description: kick anyone from any faction description: hand over your leader rights
factions.leave: factions.leave:
description: leave your faction description: leave your faction
factions.list: factions.list:
@ -124,45 +111,35 @@ permissions:
description: lock all write stuff description: lock all write stuff
factions.map: factions.map:
description: show the territory map, and set optional auto update description: show the territory map, and set optional auto update
factions.officer:
description: give or revoke officer rights
factions.money.balance: factions.money.balance:
description: show your factions current money balance description: show your factions current money balance
factions.money.balance.any: factions.money.balance.any:
description: show money balance for factions other than your own description: show money balance for factions other than your own
factions.money.deposit: factions.money.deposit:
description: deposit money into a faction bank 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: factions.money.f2f:
description: transfer money from faction to faction description: transfer money from faction to faction
factions.money.f2p: factions.money.f2p:
description: transfer money from faction to player description: transfer money from faction to player
factions.money.p2f: factions.money.p2f:
description: transfer money from player to faction description: transfer money from player to faction
factions.money.kit.standard: factions.money.withdraw:
description: withdraw money from your faction bank
factions.money.*:
children: children:
factions.money.balance: true factions.money.balance: true
factions.money.balance.any: true factions.money.balance.any: true
factions.money.deposit: true factions.money.deposit: true
factions.money.withdraw: true
factions.money.f2f: true factions.money.f2f: true
factions.money.f2p: true factions.money.f2p: true
factions.money.p2f: 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: true
factions.money.withdraw.any: true factions.officer:
factions.money.f2f: true description: give or revoke officer rights
factions.money.f2p: true
factions.money.p2f: true
factions.open: factions.open:
description: switch if invitation is required to join description: switch if invitation is required to join
factions.perm:
description: change faction permissions
factions.power: factions.power:
description: show player power info description: show player power info
factions.power.any: factions.power.any:
@ -175,17 +152,15 @@ permissions:
description: save all data to disk description: save all data to disk
factions.sethome: factions.sethome:
description: set the faction home description: set the faction home
factions.sethome.any:
description: set faction home for another faction
factions.show: factions.show:
description: show faction information description: show faction information
factions.tag: factions.tag:
description: change the faction tag description: change the faction tag
factions.title: factions.title:
description: set or remove a players title description: set or remove a players title
factions.version:
description: see the version of the plugin
factions.unclaim: factions.unclaim:
description: unclaim the land where you are standing description: unclaim the land where you are standing
factions.unclaimall: factions.unclaimall:
description: unclaim all of your factions land description: unclaim all of your factions land
factions.version:
description: see the version of the plugin

View File

@ -10,6 +10,8 @@ import java.util.Map.Entry;
import java.util.TreeMap; import java.util.TreeMap;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
@ -39,6 +41,14 @@ public class Board
{ {
return Factions.i.get(getIdAt(flocation)); 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) public static void setIdAt(String id, FLocation flocation)
{ {

View File

@ -16,8 +16,8 @@ public class Conf
// Colors // Colors
public static ChatColor colorMember = ChatColor.GREEN; public static ChatColor colorMember = ChatColor.GREEN;
public static ChatColor colorAlly = ChatColor.LIGHT_PURPLE; public static ChatColor colorAlly = ChatColor.DARK_PURPLE;
public static ChatColor colorTruce = ChatColor.DARK_PURPLE; public static ChatColor colorTruce = ChatColor.LIGHT_PURPLE;
public static ChatColor colorNeutral = ChatColor.WHITE; public static ChatColor colorNeutral = ChatColor.WHITE;
public static ChatColor colorEnemy = ChatColor.RED; public static ChatColor colorEnemy = ChatColor.RED;
@ -206,11 +206,9 @@ public class Conf
baseCommandAliases.add("f"); baseCommandAliases.add("f");
factionFlagDefaults = new LinkedHashMap<FFlag, Boolean>(); factionFlagDefaults = new LinkedHashMap<FFlag, Boolean>();
factionFlagIsChangeable = new LinkedHashMap<FFlag, Boolean>();
for (FFlag flag : FFlag.values()) for (FFlag flag : FFlag.values())
{ {
factionFlagDefaults.put(flag, flag.defaultDefaultValue); factionFlagDefaults.put(flag, flag.defaultDefaultValue);
factionFlagIsChangeable.put(flag, flag.defaultDefaultChangeable);
} }
factionPermDefaults = new LinkedHashMap<FPerm, Set<Rel>>(); factionPermDefaults = new LinkedHashMap<FPerm, Set<Rel>>();

View File

@ -15,6 +15,7 @@ import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.struct.ChatMode; import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.struct.Rel;
import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.factions.util.RelationUtil;
import com.massivecraft.factions.zcore.persist.PlayerEntity; import com.massivecraft.factions.zcore.persist.PlayerEntity;
@ -80,9 +81,9 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
public Faction getAutoClaimFor() { return autoClaimFor; } public Faction getAutoClaimFor() { return autoClaimFor; }
public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; } public void setAutoClaimFor(Faction faction) { this.autoClaimFor = faction; }
private transient boolean isAdminBypassing = false; private transient boolean hasAdminMode = false;
public boolean isAdminBypassing() { return this.isAdminBypassing; } public boolean hasAdminMode() { return this.hasAdminMode; }
public void setIsAdminBypassing(boolean val) { this.isAdminBypassing = val; } public void setHasAdminMode(boolean val) { this.hasAdminMode = val; }
// FIELD: loginPvpDisabled // FIELD: loginPvpDisabled
private transient boolean 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 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; double cost = Conf.econCostLeave;
if ( ! Econ.modifyMoney(this, -cost, "to leave your faction.", "for leaving your faction.")) return; if ( ! Econ.modifyMoney(this, -cost, "to leave your faction.", "for leaving your faction.")) return;
@ -512,24 +513,6 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
} }
} }
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) public boolean canClaimForFactionAtLocation(Faction forFaction, Location location, boolean notifyFailure)
{ {
String error = null; String error = null;
@ -547,21 +530,17 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
{ {
error = P.p.txt.parse("<b>Sorry, this world has land claiming disabled."); error = P.p.txt.parse("<b>Sorry, this world has land claiming disabled.");
} }
else if (this.isAdminBypassing()) else if (this.hasAdminMode())
{ {
return true; return true;
} }
else if (myFaction != forFaction)
{
error = P.p.txt.parse("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(this));
}
else if (forFaction == currentFaction) else if (forFaction == currentFaction)
{ {
error = P.p.txt.parse("%s<i> already own this land.", forFaction.describeTo(this, true)); error = P.p.txt.parse("%s<i> 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("<b>You must be <h>%s<b> to claim land.", Rel.OFFICER.toString()); return false;
} }
else if (forFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers) else if (forFaction.getFPlayers().size() < Conf.claimsRequireMinFactionMembers)
{ {
@ -578,7 +557,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator
else if else if
( (
Conf.claimsMustBeConnected Conf.claimsMustBeConnected
&& ! this.isAdminBypassing() && ! this.hasAdminMode()
&& myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && myFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0
&& !Board.isConnectedLocation(flocation, myFaction) && !Board.isConnectedLocation(flocation, myFaction)
&& (!Conf.claimsCanBeUnconnectedIfOwnedByOtherFaction || !currentFaction.isNormal()) && (!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 // if economy is enabled and they're not on the bypass list, make 'em pay
// TODO: Add flag no costs?? // TODO: Add flag no costs??
//if (Econ.shouldBeUsed() && ! this.isAdminBypassing() && ! forFaction.isSafeZone() && ! forFaction.isWarZone()) //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()); double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal());
//String costString = Econ.moneyString(cost); //String costString = Econ.moneyString(cost);

View File

@ -122,9 +122,26 @@ public class Faction extends Entity implements EconomyParticipator
if (ret == null) ret = perm.getDefault(); if (ret == null) ret = perm.getDefault();
return ret; return ret;
} }
public void addPermittedRelation(FPerm perm, Rel rel)
{
Set<Rel> 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<Rel> newPermittedRelations = EnumSet.noneOf(Rel.class);
newPermittedRelations.addAll(this.getPermittedRelations(perm));
newPermittedRelations.remove(rel);
this.setPermittedRelations(perm, newPermittedRelations);
}
public void setPermittedRelations(FPerm perm, Set<Rel> rels) public void setPermittedRelations(FPerm perm, Set<Rel> rels)
{ {
if (Conf.factionPermDefaults.get(perm).equals(rels)) if (perm.getDefault().equals(rels))
{ {
this.permOverrides.remove(perm); this.permOverrides.remove(perm);
return; return;

View File

@ -14,6 +14,11 @@ import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.plugin.Plugin; 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.cmd.*;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.SpoutFeatures; 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.FactionsPlayerListener;
import com.massivecraft.factions.listeners.FactionsServerListener; import com.massivecraft.factions.listeners.FactionsServerListener;
import com.massivecraft.factions.struct.ChatMode; 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.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.massivecraft.factions.zcore.MPlugin;
import com.nijiko.permissions.PermissionHandler; 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_PLACE, this.blockListener, Event.Priority.Normal);
this.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, 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_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 // Server Events
this.registerEvent(Event.Type.PLUGIN_ENABLE, this.serverListener, Event.Priority.Monitor); this.registerEvent(Event.Type.PLUGIN_ENABLE, this.serverListener, Event.Priority.Monitor);
@ -149,9 +155,11 @@ public class P extends MPlugin
.setPrettyPrinting() .setPrettyPrinting()
.disableHtmlEscaping() .disableHtmlEscaping()
.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE) .excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE)
.registerTypeAdapter(Location.class, new MyLocationTypeAdapter()) .registerTypeAdapter(Location.class, new LocationTypeAdapter())
.registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()) .registerTypeAdapter(mapFLocToStringSetType, new FLocToStringSetTypeAdapter())
.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(Rel.class, new RelTypeAdapter())
.registerTypeAdapter(FPerm.class, new FPermTypeAdapter())
.registerTypeAdapter(FFlag.class, new FFlagTypeAdapter());
} }
@Override @Override

View File

@ -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<FFlag>
{
@Override
public FFlag deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
return FFlag.parse(json.getAsString());
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.factions.util; package com.massivecraft.factions.adapters;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -23,7 +23,7 @@ import com.massivecraft.factions.P;
// TODO: Is this one even used anymore?? // TODO: Is this one even used anymore??
public class MapFLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLocation, Set<String>>>, JsonSerializer<Map<FLocation, Set<String>>> public class FLocToStringSetTypeAdapter implements JsonDeserializer<Map<FLocation, Set<String>>>, JsonSerializer<Map<FLocation, Set<String>>>
{ {
@Override @Override

View File

@ -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<FPerm>
{
@Override
public FPerm deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException
{
return FPerm.parse(json.getAsString());
}
}

View File

@ -1,4 +1,4 @@
package com.massivecraft.factions.util; package com.massivecraft.factions.adapters;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.logging.Level; import java.util.logging.Level;
@ -16,7 +16,7 @@ import com.google.gson.JsonSerializer;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
public class MyLocationTypeAdapter implements JsonDeserializer<Location>, JsonSerializer<Location> public class LocationTypeAdapter implements JsonDeserializer<Location>, JsonSerializer<Location>
{ {
private static final String WORLD = "world"; private static final String WORLD = "world";
private static final String X = "x"; private static final String X = "x";

View File

@ -1,4 +1,4 @@
package com.massivecraft.factions.util; package com.massivecraft.factions.adapters;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -8,10 +8,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonParseException; import com.google.gson.JsonParseException;
import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.struct.Rel;
/** public class RelTypeAdapter implements JsonDeserializer<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<Rel>
{ {
@Override @Override
public Rel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException public Rel deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException

View File

@ -3,17 +3,17 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
public class CmdBypass extends FCommand public class CmdAdmin extends FCommand
{ {
public CmdBypass() public CmdAdmin()
{ {
super(); super();
this.aliases.add("bypass"); this.aliases.add("admin");
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("on/off", "flip"); this.optionalArgs.put("on/off", "flip");
this.permission = Permission.BYPASS.node; this.permission = Permission.ADMIN.node;
this.disableOnLock = false; this.disableOnLock = false;
senderMustBePlayer = true; senderMustBePlayer = true;
@ -25,12 +25,11 @@ public class CmdBypass extends FCommand
@Override @Override
public void perform() 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.hasAdminMode())
if ( fme.isAdminBypassing())
{ {
fme.msg("<i>You have enabled admin bypass mode. You will be able to build or destroy anywhere."); fme.msg("<i>You have enabled admin bypass mode.");
P.p.log(fme.getName() + " has ENABLED admin bypass mode."); P.p.log(fme.getName() + " has ENABLED admin bypass mode.");
} }
else else

View File

@ -1,8 +1,8 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
public class CmdAutoClaim extends FCommand public class CmdAutoClaim extends FCommand
{ {
@ -34,15 +34,7 @@ public class CmdAutoClaim extends FCommand
return; return;
} }
if (! fme.canClaimForFaction(forFaction)) if ( ! FPerm.TERRITORY.has(fme, forFaction, true)) return;
{
if (myFaction == forFaction)
msg("<b>You must be <h>%s<b> to claim land.", Role.MODERATOR.toString());
else
msg("<b>You can't claim land for <h>%s<b>.", forFaction.describeTo(fme));
return;
}
fme.setAutoClaimFor(forFaction); fme.setAutoClaimFor(forFaction);

View File

@ -8,8 +8,8 @@ import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Rel;
public class CmdDisband extends FCommand public class CmdDisband extends FCommand
{ {
@ -37,19 +37,7 @@ public class CmdDisband extends FCommand
Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); Faction faction = this.argAsFaction(0, fme == null ? null : myFaction);
if (faction == null) return; if (faction == null) return;
boolean isMyFaction = fme == null ? false : faction == myFaction; if ( ! FPerm.DISBAND.has(sender, faction, true)) return;
if (isMyFaction)
{
if ( ! assertMinRole(Rel.LEADER)) return;
}
else
{
if ( ! Permission.DISBAND_ANY.has(sender, true))
{
return;
}
}
if (faction.getFlag(FFlag.PERMANENT)) if (faction.getFlag(FFlag.PERMANENT))
{ {

View File

@ -3,7 +3,6 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Rel;
public class CmdFlag extends FCommand public class CmdFlag extends FCommand
{ {
@ -12,6 +11,7 @@ public class CmdFlag extends FCommand
{ {
super(); super();
this.aliases.add("flag"); this.aliases.add("flag");
this.aliases.add("flags");
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("faction", "your"); this.optionalArgs.put("faction", "your");
@ -59,26 +59,8 @@ public class CmdFlag extends FCommand
Boolean targetValue = this.argAsBool(2); Boolean targetValue = this.argAsBool(2);
if (targetValue == null) return; if (targetValue == null) return;
// Do the sender have the right to change flags for this faction? // Do the sender have the right to change flags?
if (Permission.FLAG_ANY.has(sender)) if ( ! Permission.FLAG_SET.has(sender, true)) return;
{
// This sender may modify any flag for anyone
}
else if ( ! flag.isChangeable())
{
msg("<b>Only server operators can change this flag.");
return;
}
else if (faction != myFaction)
{
msg("<b>You are not a member in that faction.");
return;
}
else if (fme.getRole().isLessThan(Rel.OFFICER))
{
msg("<b>You must be faction leader or officer to change your faction flags.");
return;
}
// Do the change // Do the change
msg(p.txt.titleize("Flag for " + faction.describeTo(fme, true))); msg(p.txt.titleize("Flag for " + faction.describeTo(fme, true)));

View File

@ -54,7 +54,7 @@ public class CmdJoin extends FCommand
return; return;
} }
if( ! (faction.getOpen() || faction.isInvited(fme) || fme.isAdminBypassing())) if( ! (faction.getOpen() || faction.isInvited(fme) || fme.hasAdminMode()))
{ {
msg("<i>This faction requires invitation."); msg("<i>This faction requires invitation.");
faction.msg("%s<i> tried to join your faction.", fme.describeTo(faction, true)); faction.msg("%s<i> tried to join your faction.", fme.describeTo(faction, true));

View File

@ -6,6 +6,7 @@ import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
public class CmdKick extends FCommand public class CmdKick extends FCommand
@ -41,30 +42,15 @@ public class CmdKick extends FCommand
return; return;
} }
if ( ! Conf.canLeaveWithNegativePower && you.getPower() < 0)
{
msg("<b>You cannot kick that member until their power is positive.");
return;
}
Faction yourFaction = you.getFaction(); Faction yourFaction = you.getFaction();
// players with admin-level "disband" permission can bypass these requirements if (fme != null && ! FPerm.KICK.has(fme, yourFaction)) return;
if ( ! Permission.KICK_ANY.has(sender))
{
if (yourFaction != myFaction)
{
msg("%s<b> 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("<b>Your rank is too low to kick this player.");
return;
}
if ( ! Conf.canLeaveWithNegativePower && you.getPower() < 0)
{
msg("<b>You cannot kick that member until their power is positive.");
return;
}
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay // 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; if ( ! payForCommand(Conf.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) return;

View File

@ -15,6 +15,7 @@ public class CmdPerm extends FCommand
{ {
super(); super();
this.aliases.add("perm"); this.aliases.add("perm");
this.aliases.add("perms");
//this.requiredArgs.add(""); //this.requiredArgs.add("");
this.optionalArgs.put("faction", "your"); this.optionalArgs.put("faction", "your");
@ -63,26 +64,20 @@ public class CmdPerm extends FCommand
return; return;
} }
Set<Rel> 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? // Do the sender have the right to change perms for this faction?
if (Permission.PERM_ANY.has(sender)) if ( ! FPerm.PERMS.has(sender, faction, true)) return;
{
// This sender may modify any perm for anyone
}
else if (faction != myFaction)
{
msg("<b>You are not a member in that faction.");
return;
}
else if (fme.getRole().isLessThan(Rel.OFFICER))
{
msg("<b>You must be faction leader or officer to change your faction permissions.");
return;
}
// Do the change // Do the change
Set<Rel> 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); faction.setPermittedRelations(perm, targetValue);
msg(p.txt.titleize("Perm for " + faction.describeTo(fme, true))); msg(p.txt.titleize("Perm for " + faction.describeTo(fme, true)));
msg(FPerm.getStateHeaders()); msg(FPerm.getStateHeaders());
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true)); msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));

View File

@ -4,8 +4,8 @@ import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Rel;
public class CmdSethome extends FCommand public class CmdSethome extends FCommand
{ {
@ -38,19 +38,12 @@ public class CmdSethome extends FCommand
if (faction == null) return; if (faction == null) return;
// Can the player set the home for this faction? // Can the player set the home for this faction?
if (faction == myFaction) if ( ! FPerm.SETHOME.has(sender, faction, true)) return;
{
if ( ! Permission.SETHOME_ANY.has(sender) && ! assertMinRole(Rel.OFFICER)) return;
}
else
{
if (Permission.SETHOME_ANY.has(sender, true)) return;
}
// Can the player set the faction home HERE? // Can the player set the faction home HERE?
if if
( (
! Permission.BYPASS.has(me) ! fme.hasAdminMode()
&& &&
Conf.homesMustBeInClaimedTerritory Conf.homesMustBeInClaimedTerritory
&& &&

View File

@ -7,8 +7,8 @@ import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Rel;
public class CmdUnclaim extends FCommand public class CmdUnclaim extends FCommand
{ {
@ -35,36 +35,7 @@ public class CmdUnclaim extends FCommand
FLocation flocation = new FLocation(fme); FLocation flocation = new FLocation(fme);
Faction otherFaction = Board.getFactionAt(flocation); Faction otherFaction = Board.getFactionAt(flocation);
if (fme.isAdminBypassing()) if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return;
{
Board.removeAt(flocation);
SpoutFeatures.updateTerritoryDisplayLoc(flocation);
otherFaction.msg("%s<i> unclaimed some of your land.", fme.describeTo(otherFaction, true));
msg("<i>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("<b>You don't own this land.");
return;
}
//String moneyBack = "<i>"; //String moneyBack = "<i>";
if (Econ.shouldBeUsed()) if (Econ.shouldBeUsed())

View File

@ -8,7 +8,7 @@ public class FCmdRoot extends FCommand
{ {
public CmdLeader cmdLeader = new CmdLeader(); public CmdLeader cmdLeader = new CmdLeader();
public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim(); public CmdAutoClaim cmdAutoClaim = new CmdAutoClaim();
public CmdBypass cmdBypass = new CmdBypass(); public CmdAdmin cmdBypass = new CmdAdmin();
public CmdChat cmdChat = new CmdChat(); public CmdChat cmdChat = new CmdChat();
public CmdClaim cmdClaim = new CmdClaim(); public CmdClaim cmdClaim = new CmdClaim();
public CmdConfig cmdConfig = new CmdConfig(); public CmdConfig cmdConfig = new CmdConfig();

View File

@ -387,7 +387,7 @@ public abstract class FCommand extends MCommand<P>
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost // 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) 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()) if(Conf.bankFactionPaysLandCosts && fme.hasFaction())
{ {

View File

@ -92,7 +92,7 @@ public class Econ
if (fI == null) return true; if (fI == null) return true;
// Bypassing players can do any kind of transaction // 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. // You can deposit to anywhere you feel like. It's your loss if you can't withdraw it again.
if (i == you) return true; if (i == you) return true;

View File

@ -4,11 +4,13 @@ import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockBurnEvent;
import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockListener; import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.block.BlockSpreadEvent;
import com.massivecraft.factions.Board; import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
@ -17,6 +19,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P; import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.FPerm;
@ -28,17 +31,40 @@ public class FactionsBlockListener extends BlockListener
this.p = p; 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) public static boolean playerCanBuildDestroyBlock(Player player, Block block, String action, boolean justCheck)
{ {
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
if (me.isAdminBypassing()) return true; if (me.hasAdminMode()) return true;
Location location = block.getLocation(); Location location = block.getLocation();
FLocation loc = new FLocation(location); FLocation loc = new FLocation(location);
Faction factionHere = Board.getFactionAt(loc); Faction factionHere = Board.getFactionAt(loc);
if (FPerm.PAINBUILD.has(me, location)) if ( ! FPerm.BUILD.has(me, location) && FPerm.PAINBUILD.has(me, location))
{ {
if (!justCheck) if (!justCheck)
{ {
@ -48,7 +74,7 @@ public class FactionsBlockListener extends BlockListener
return true; return true;
} }
return FPerm.BUILD.has(me, location, true); return FPerm.BUILD.has(me, loc, true);
} }
@Override @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 potentially pushing into air in another territory, we need to check it out
if (targetBlock.isEmpty() && ! FPerm.BUILD.has(pistonFaction, targetBlock.getLocation())) if (targetBlock.isEmpty() && ! FPerm.BUILD.has(pistonFaction, targetBlock.getLocation()))
{ {
event.setCancelled(true); event.setCancelled(true);

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.listeners;
import java.text.MessageFormat; import java.text.MessageFormat;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
@ -91,15 +92,15 @@ public class FactionsEntityListener extends EntityListener
{ {
if ( event.isCancelled()) return; if ( event.isCancelled()) return;
Location loc = event.getLocation(); for (Block block : event.blockList())
Faction faction = Board.getFactionAt(new FLocation(loc));
if (faction.getFlag(FFlag.EXPLOSIONS) == false)
{ {
// faction is peaceful and has explosions set to disabled Faction faction = Board.getFactionAt(new FLocation(block));
event.setCancelled(true); if (faction.getFlag(FFlag.EXPLOSIONS) == false)
return; {
// faction is peaceful and has explosions set to disabled
event.setCancelled(true);
return;
}
} }
} }

View File

@ -242,14 +242,14 @@ public class FactionsPlayerListener extends PlayerListener
public static boolean playerCanUseItemHere(Player player, Location loc, Material material, boolean justCheck) public static boolean playerCanUseItemHere(Player player, Location loc, Material material, boolean justCheck)
{ {
FPlayer me = FPlayers.i.get(player); 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; if (Conf.materialsEditTools.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false;
return true; return true;
} }
public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck)
{ {
FPlayer me = FPlayers.i.get(player); FPlayer me = FPlayers.i.get(player);
if (me.isAdminBypassing()) return true; if (me.hasAdminMode()) return true;
Location loc = block.getLocation(); Location loc = block.getLocation();
Material material = block.getType(); Material material = block.getType();
@ -350,7 +350,7 @@ public class FactionsPlayerListener extends PlayerListener
&& &&
! Conf.territoryNeutralDenyCommands.isEmpty() ! Conf.territoryNeutralDenyCommands.isEmpty()
&& &&
! me.isAdminBypassing() ! me.hasAdminMode()
) )
{ {
Iterator<String> iter = Conf.territoryNeutralDenyCommands.iterator(); Iterator<String> iter = Conf.territoryNeutralDenyCommands.iterator();
@ -378,7 +378,7 @@ public class FactionsPlayerListener extends PlayerListener
&& &&
! Conf.territoryEnemyDenyCommands.isEmpty() ! Conf.territoryEnemyDenyCommands.isEmpty()
&& &&
! me.isAdminBypassing() ! me.hasAdminMode()
) )
{ {
Iterator<String> iter = Conf.territoryEnemyDenyCommands.iterator(); Iterator<String> iter = Conf.territoryEnemyDenyCommands.iterator();

View File

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

View File

@ -7,12 +7,16 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Board; import com.massivecraft.factions.Board;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation; import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.iface.RelationParticipator;
/** /**
@ -21,13 +25,18 @@ import com.massivecraft.factions.iface.RelationParticipator;
*/ */
public enum FPerm 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), PAINBUILD("painbuild", "edit but take damage", Rel.ALLY),
DOOR("door", "use doors", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, 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),
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),
LEVER("lever", "use levers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER, Rel.ALLY), CONTAINER("container", "use containers", Rel.LEADER, Rel.OFFICER, Rel.MEMBER),
WITHDRAW("withdraw", "withdraw faction money", Rel.LEADER, Rel.OFFICER), 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; private final String nicename;
@ -63,12 +72,17 @@ public enum FPerm
{ {
str = str.toLowerCase(); str = str.toLowerCase();
if (str.startsWith("bui")) return BUILD; if (str.startsWith("bui")) return BUILD;
if (str.startsWith("p")) return PAINBUILD; if (str.startsWith("pa")) return PAINBUILD;
if (str.startsWith("d")) return DOOR; if (str.startsWith("do")) return DOOR;
if (str.startsWith("c")) return CONTAINER;
if (str.startsWith("but")) return BUTTON; if (str.startsWith("but")) return BUTTON;
if (str.startsWith("l")) return LEVER; if (str.startsWith("l")) return LEVER;
if (str.startsWith("w")) return WITHDRAW; 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; return null;
} }
@ -145,44 +159,63 @@ public enum FPerm
return ret; return ret;
} }
private static final String errorpattern = "<b>%s<b> can't %s in the territory of %s<b>."; private static final String errorpattern = "%s<b> does not allow you to %s<b>.";
public boolean has(RelationParticipator testSubject, Faction hostFaction, boolean informIfNot) public boolean has(Object testSubject, Faction hostFaction, boolean informIfNot)
{ {
//Faction factionDoer = RelationUtil.getFaction(testSubject); if (testSubject instanceof ConsoleCommandSender) return true;
//P.p.log("Testing the permission "+this.toString()+" for a "+testSubject.getClass().getSimpleName());
//P.p.log("hostFaction: "+hostFaction);
Rel rel = testSubject.getRelationTo(hostFaction);
//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); 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 fplayer = (FPlayer)rpSubject;
fplayer.msg(errorpattern, fplayer.describeTo(fplayer, true), this.getDescription(), hostFaction.describeTo(fplayer)); fplayer.msg(errorpattern, hostFaction.describeTo(fplayer, true), this.getDescription());
if (Permission.ADMIN.has(fplayer.getPlayer()))
{
fplayer.msg("<i>You can bypass by using " + P.p.cmdBase.cmdBypass.getUseageTemplate(false));
}
} }
return ret; return ret;
} }
public boolean has(RelationParticipator testSubject, Faction hostFaction) public boolean has(Object testSubject, Faction hostFaction)
{ {
return this.has(testSubject, hostFaction, false); 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); Faction factionThere = Board.getFactionAt(floc);
return this.has(testSubject, factionThere, informIfNot); 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); FLocation floc = new FLocation(loc);
return this.has(testSubject, floc, informIfNot); 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); 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); return this.has(testSubject, floc, false);
} }

View File

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