Converting the command structure

This commit is contained in:
Olof Larsson 2011-10-08 23:22:02 +02:00
parent 0ce9cce9d3
commit 227d54dc5f
58 changed files with 582 additions and 538 deletions

View File

@ -5,81 +5,88 @@ import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import org.bukkit.ChatColor;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.AsciiCompass;
import com.massivecraft.factions.util.DiscUtil;
import com.massivecraft.factions.util.TextUtil;
import com.massivecraft.factions.zcore.util.DiscUtil;
public class Board
{
private static transient File file = new File(P.p.getDataFolder(), "board.json");
private static transient HashMap<FLocation, Integer> flocationIds = new HashMap<FLocation, Integer>();
private static transient HashMap<FLocation, String> flocationIds = new HashMap<FLocation, String>();
//----------------------------------------------//
// Get and Set
//----------------------------------------------//
public static int getIdAt(FLocation flocation) {
if ( ! flocationIds.containsKey(flocation)) {
return 0;
public static String getIdAt(FLocation flocation)
{
if ( ! flocationIds.containsKey(flocation))
{
return "0";
}
return flocationIds.get(flocation);
}
public static Faction getFactionAt(FLocation flocation) {
return Faction.get(getIdAt(flocation));
public static Faction getFactionAt(FLocation flocation)
{
return Factions.i.get(getIdAt(flocation));
}
public static void setIdAt(int id, FLocation flocation) {
public static void setIdAt(String id, FLocation flocation)
{
clearOwnershipAt(flocation);
if (id == 0) {
if (id == "0")
{
removeAt(flocation);
}
flocationIds.put(flocation, id);
}
public static void setFactionAt(Faction faction, FLocation flocation) {
public static void setFactionAt(Faction faction, FLocation flocation)
{
setIdAt(faction.getId(), flocation);
}
public static void removeAt(FLocation flocation) {
public static void removeAt(FLocation flocation)
{
clearOwnershipAt(flocation);
flocationIds.remove(flocation);
}
// not to be confused with claims, ownership referring to further member-specific ownership of a claim
public static void clearOwnershipAt(FLocation flocation) {
public static void clearOwnershipAt(FLocation flocation)
{
Faction faction = getFactionAt(flocation);
if (faction != null && faction.isNormal()) {
if (faction != null && faction.isNormal())
{
faction.clearClaimOwnership(flocation);
}
}
public static void unclaimAll(int factionId) {
Faction faction = Faction.get(factionId);
if (faction != null && faction.isNormal()) {
public static void unclaimAll(String factionId)
{
Faction faction = Factions.i.get(factionId);
if (faction != null && faction.isNormal())
{
faction.clearAllClaimOwnership();
}
Iterator<Entry<FLocation, Integer>> iter = flocationIds.entrySet().iterator();
while (iter.hasNext()) {
Entry<FLocation, Integer> entry = iter.next();
if (entry.getValue().equals(factionId)) {
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
while (iter.hasNext())
{
Entry<FLocation, String> entry = iter.next();
if (entry.getValue().equals(factionId))
{
iter.remove();
}
}
@ -87,7 +94,8 @@ public class Board
// Is this coord NOT completely surrounded by coords claimed by the same faction?
// Simpler: Is there any nearby coord with a faction other than the faction here?
public static boolean isBorderLocation(FLocation flocation) {
public static boolean isBorderLocation(FLocation flocation)
{
Faction faction = getFactionAt(flocation);
FLocation a = flocation.getRelative(1, 0);
FLocation b = flocation.getRelative(-1, 0);
@ -97,7 +105,8 @@ public class Board
}
// Is this coord connected to any coord claimed by the specified faction?
public static boolean isConnectedLocation(FLocation flocation, Faction faction) {
public static boolean isConnectedLocation(FLocation flocation, Faction faction)
{
FLocation a = flocation.getRelative(1, 0);
FLocation b = flocation.getRelative(-1, 0);
FLocation c = flocation.getRelative(0, 1);
@ -110,12 +119,14 @@ public class Board
// Cleaner. Remove orphaned foreign keys
//----------------------------------------------//
public static void clean() {
Iterator<Entry<FLocation, Integer>> iter = flocationIds.entrySet().iterator();
public static void clean()
{
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
while (iter.hasNext()) {
Entry<FLocation, Integer> entry = iter.next();
if ( ! Faction.exists(entry.getValue())) {
P.log("Board cleaner removed "+entry.getValue()+" from "+entry.getKey());
Entry<FLocation, String> entry = iter.next();
if ( ! Factions.i.exists(entry.getValue()))
{
P.p.log("Board cleaner removed "+entry.getValue()+" from "+entry.getKey());
iter.remove();
}
}
@ -125,27 +136,33 @@ public class Board
// Coord count
//----------------------------------------------//
public static int getFactionCoordCount(int factionId) {
public static int getFactionCoordCount(String factionId)
{
int ret = 0;
for (int thatFactionId : flocationIds.values()) {
if(thatFactionId == factionId) {
for (String thatFactionId : flocationIds.values())
{
if(thatFactionId.equals(factionId))
{
ret += 1;
}
}
return ret;
}
public static int getFactionCoordCount(Faction faction) {
public static int getFactionCoordCount(Faction faction)
{
return getFactionCoordCount(faction.getId());
}
public static int getFactionCoordCountInWorld(Faction faction, String worldName) {
int factionId = faction.getId();
public static int getFactionCoordCountInWorld(Faction faction, String worldName)
{
String factionId = faction.getId();
int ret = 0;
Iterator<Entry<FLocation, Integer>> iter = flocationIds.entrySet().iterator();
Iterator<Entry<FLocation, String>> iter = flocationIds.entrySet().iterator();
while (iter.hasNext()) {
Entry<FLocation, Integer> entry = iter.next();
if (entry.getValue() == factionId && entry.getKey().getWorldName().equals(worldName)) {
Entry<FLocation, String> entry = iter.next();
if (entry.getValue().equals(factionId) && entry.getKey().getWorldName().equals(worldName))
{
ret += 1;
}
}
@ -161,10 +178,11 @@ public class Board
* north is in the direction of decreasing x
* east is in the direction of decreasing z
*/
public static ArrayList<String> getMap(Faction faction, FLocation flocation, double inDegrees) {
public static ArrayList<String> getMap(Faction faction, FLocation flocation, double inDegrees)
{
ArrayList<String> ret = new ArrayList<String>();
Faction factionLoc = getFactionAt(flocation);
ret.add(TextUtil.titleize("("+flocation.getCoordString()+") "+factionLoc.getTag(faction)));
ret.add(P.p.txt.titleize("("+flocation.getCoordString()+") "+factionLoc.getTag(faction)));
int halfWidth = Conf.mapWidth / 2;
int halfHeight = Conf.mapHeight / 2;
@ -172,7 +190,8 @@ public class Board
int width = halfWidth * 2 + 1;
int height = halfHeight * 2 + 1;
if (Conf.showMapFactionKey) {
if (Conf.showMapFactionKey)
{
height--;
}
@ -216,7 +235,7 @@ public class Board
}
// Get the compass
ArrayList<String> asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, Conf.colorChrome);
ArrayList<String> asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, P.p.txt.parse("<a>"));
// Add the compass
ret.set(1, asciiCompass.get(0)+ret.get(1).substring(3*3));
@ -240,18 +259,18 @@ public class Board
// Persistance
// -------------------------------------------- //
public static Map<String,Map<String,Integer>> dumpAsSaveFormat() {
Map<String,Map<String,Integer>> worldCoordIds = new HashMap<String,Map<String,Integer>>();
public static Map<String,Map<String,String>> dumpAsSaveFormat() {
Map<String,Map<String,String>> worldCoordIds = new HashMap<String,Map<String,String>>();
String worldName, coords;
Integer id;
String id;
for (Entry<FLocation, Integer> entry : flocationIds.entrySet()) {
for (Entry<FLocation, String> entry : flocationIds.entrySet()) {
worldName = entry.getKey().getWorldName();
coords = entry.getKey().getCoordString();
id = entry.getValue();
if ( ! worldCoordIds.containsKey(worldName)) {
worldCoordIds.put(worldName, new TreeMap<String,Integer>());
worldCoordIds.put(worldName, new TreeMap<String,String>());
}
worldCoordIds.get(worldName).put(coords, id);
@ -260,16 +279,20 @@ public class Board
return worldCoordIds;
}
public static void loadFromSaveFormat(Map<String,Map<String,Integer>> worldCoordIds) {
public static void loadFromSaveFormat(Map<String,Map<String,String>> worldCoordIds)
{
flocationIds.clear();
String worldName;
String[] coords;
int x, z, factionId;
int x, z;
String factionId;
for (Entry<String,Map<String,Integer>> entry : worldCoordIds.entrySet()) {
for (Entry<String,Map<String,String>> entry : worldCoordIds.entrySet())
{
worldName = entry.getKey();
for (Entry<String,Integer> entry2 : entry.getValue().entrySet()) {
for (Entry<String,String> entry2 : entry.getValue().entrySet())
{
coords = entry2.getKey().trim().split("[,\\s]+");
x = Integer.parseInt(coords[0]);
z = Integer.parseInt(coords[1]);
@ -279,37 +302,45 @@ public class Board
}
}
public static boolean save() {
public static boolean save()
{
//Factions.log("Saving board to disk");
try {
try
{
DiscUtil.write(file, P.p.gson.toJson(dumpAsSaveFormat()));
} catch (Exception e) {
}
catch (Exception e)
{
e.printStackTrace();
P.log("Failed to save the board to disk.");
P.p.log("Failed to save the board to disk.");
return false;
}
return true;
}
public static boolean load() {
P.log("Loading board from disk");
public static boolean load()
{
P.p.log("Loading board from disk");
if ( ! file.exists()) {
if ( ! loadOld())
P.log("No board to load from disk. Creating new file.");
if ( ! file.exists())
{
P.p.log("No board to load from disk. Creating new file.");
save();
return true;
}
try {
Type type = new TypeToken<Map<String,Map<String,Integer>>>(){}.getType();
Map<String,Map<String,Integer>> worldCoordIds = P.p.gson.fromJson(DiscUtil.read(file), type);
try
{
Type type = new TypeToken<Map<String,Map<String,String>>>(){}.getType();
Map<String,Map<String,String>> worldCoordIds = P.p.gson.fromJson(DiscUtil.read(file), type);
loadFromSaveFormat(worldCoordIds);
} catch (Exception e) {
}
catch (Exception e)
{
e.printStackTrace();
P.log("Failed to load the board from disk.");
P.p.log("Failed to load the board from disk.");
return false;
}

View File

@ -34,29 +34,56 @@ import com.massivecraft.factions.zcore.persist.PlayerEntity;
public class FPlayer extends PlayerEntity
{
// -------------------------------------------- //
// Fields
// -------------------------------------------- //
//private static transient TreeMap<String, FPlayer> instances = new TreeMap<String, FPlayer>(String.CASE_INSENSITIVE_ORDER);
//private static transient File file = new File(P.p.getDataFolder(), "players.json");
//private transient String playerName;
private transient FLocation lastStoodAt = new FLocation(); // Where did this player stand the last time we checked?
// FIELD: factionId
private String factionId;
public Faction getFaction() { return Factions.i.get(this.factionId); }
public String getFactionId() { return this.factionId; }
public boolean hasFaction() { return ! factionId.equals("0"); }
public void setFaction(Faction faction)
{
this.factionId = faction.getId();
SpoutFeatures.updateAppearances(this.getPlayer());
}
// FIELD: role
private Role role;
public Role getRole() { return this.role; }
public void setRole(Role role) { this.role = role; SpoutFeatures.updateAppearances(this.getPlayer()); }
// FIELD: title
private String title;
// FIELD: power
private double power;
// FIELD: lastPowerUpdateTime
private long lastPowerUpdateTime;
// FIELD: lastLoginTime
private long lastLoginTime;
// FIELD: mapAutoUpdating
private transient boolean mapAutoUpdating;
// FIELD: autoClaimEnabled
private transient boolean autoClaimEnabled;
// FIELD: autoSafeZoneEnabled
private transient boolean autoSafeZoneEnabled;
// FIELD: autoWarZoneEnabled
private transient boolean autoWarZoneEnabled;
// FIELD: loginPvpDisabled
private transient boolean loginPvpDisabled;
// FIELD: deleteMe
private transient boolean deleteMe;
// FIELD: chatMode
private ChatMode chatMode;
// -------------------------------------------- //
@ -105,37 +132,10 @@ public class FPlayer extends PlayerEntity
// Getters And Setters
// -------------------------------------------- //
public Faction getFaction()
{
return Faction.get(factionId);
}
public String getFactionId()
{
return this.factionId;
}
public void setFaction(Faction faction)
{
this.factionId = faction.getId();
SpoutFeatures.updateAppearances(this.getPlayer());
}
public boolean hasFaction()
{
return ! factionId.equals("0");
}
public Role getRole()
{
return this.role;
}
public void setRole(Role role)
{
this.role = role;
SpoutFeatures.updateAppearances(this.getPlayer());
}
public ChatMode getChatMode()
{
@ -513,7 +513,7 @@ public class FPlayer extends PlayerEntity
public boolean isInOthersTerritory()
{
int idHere = Board.getIdAt(new FLocation(this));
String idHere = Board.getIdAt(new FLocation(this));
return idHere > 0 && idHere != this.factionId;
}

View File

@ -93,7 +93,7 @@ public class P extends MPlugin
Worldguard.init(this);
}
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>(){}.getType();
//Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>(){}.getType();
// Add the commands
commands.add(new FCommandHelp());
@ -383,7 +383,7 @@ public class P extends MPlugin
// -------------------------------------------- //
// Test rights
// -------------------------------------------- //
/*
public static boolean hasPermParticipate(CommandSender sender) {
return hasPerm(sender, "factions.participate");
}
@ -460,7 +460,7 @@ public class P extends MPlugin
Player player = (Player)sender;
return P.Permissions.has(player, permNode);
}
*/
// -------------------------------------------- //
// Commands
// -------------------------------------------- //
@ -496,6 +496,7 @@ public class P extends MPlugin
sender.sendMessage(Conf.colorSystem+"Unknown faction command \""+commandName+"\". Try "+Conf.colorCommand+"/"+this.getBaseCommand()+" help");
}
*/
// -------------------------------------------- //
// Save all
// -------------------------------------------- //

View File

@ -1,319 +0,0 @@
package com.massivecraft.factions.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.TextUtil;
public class FBaseCommand {
public List<String> aliases;
public List<String> requiredParameters;
public List<String> optionalParameters;
public String helpNameAndParams;
public String helpDescription;
public CommandSender sender;
public boolean senderMustBePlayer;
public boolean senderIsConsole;
public Player player;
public FPlayer me;
public List<String> parameters;
private static boolean lock = false;
public FBaseCommand() {
aliases = new ArrayList<String>();
requiredParameters = new ArrayList<String>();
optionalParameters = new ArrayList<String>();
senderMustBePlayer = true;
senderIsConsole = false;
helpNameAndParams = "fail!";
helpDescription = "no description";
}
public List<String> getAliases() {
return aliases;
}
public void execute(CommandSender sender, List<String> parameters) {
this.sender = sender;
this.parameters = parameters;
if ( ! validateCall()) {
return;
}
if (sender instanceof Player) {
this.player = (Player)sender;
this.me = FPlayer.get(this.player);
senderIsConsole = false;
}
else {
senderIsConsole = true;
}
perform();
}
public void perform() {
}
public void sendMessage(String message) {
sender.sendMessage(Conf.colorSystem+message);
}
public void sendMessage(List<String> messages) {
for(String message : messages) {
this.sendMessage(message);
}
}
public boolean validateCall() {
if ( this.senderMustBePlayer && senderIsConsole ) {
sendMessage("This command can only be used by ingame players.");
return false;
}
if( ! hasPermission(sender)) {
sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+".");
return false;
}
// make sure player doesn't have their access to the command revoked
Iterator<String> iter = aliases.iterator();
while (iter.hasNext()) {
if (P.isCommandDisabled(sender, iter.next())) {
sendMessage("You lack the permissions to "+this.helpDescription.toLowerCase()+".");
return false;
}
}
if (parameters.size() < requiredParameters.size()) {
sendMessage("Usage: "+this.getUseageTemplate(false));
return false;
}
return true;
}
public boolean hasPermission(CommandSender sender) {
return P.hasPermParticipate(sender);
}
// -------------------------------------------- //
// Help and usage description
// -------------------------------------------- //
public String getUseageTemplate(boolean withDescription) {
String ret = "";
ret += Conf.colorCommand;
ret += P.p.getBaseCommand()+ " " +TextUtil.implode(this.getAliases(), ",")+" ";
List<String> parts = new ArrayList<String>();
for (String requiredParameter : this.requiredParameters) {
parts.add("["+requiredParameter+"]");
}
for (String optionalParameter : this.optionalParameters) {
parts.add("*["+optionalParameter+"]");
}
ret += Conf.colorParameter;
ret += TextUtil.implode(parts, " ");
if (withDescription) {
ret += " "+Conf.colorSystem + this.helpDescription;
}
return ret;
}
public String getUseageTemplate() {
return getUseageTemplate(true);
}
// -------------------------------------------- //
// Assertions
// -------------------------------------------- //
public boolean assertHasFaction() {
if ( ! me.hasFaction()) {
sendMessage("You are not member of any faction.");
return false;
}
return true;
}
public boolean assertMinRole(Role role) {
if (me.getRole().value < role.value) {
sendMessage("You must be "+role+" to "+this.helpDescription+".");
return false;
}
return true;
}
// -------------------------------------------- //
// Commonly used logic
// -------------------------------------------- //
public FPlayer findFPlayer(String playerName, boolean defaultToMe) {
FPlayer fp = FPlayer.find(playerName);
if (fp == null) {
if (defaultToMe) {
return me;
}
sendMessage("The player \""+playerName+"\" could not be found");
}
return fp;
}
public FPlayer findFPlayer(String playerName) {
return findFPlayer(playerName, false);
}
public Faction findFaction(String factionName, boolean defaultToMine) {
// First we search faction names
Faction faction = Faction.findByTag(factionName);
if (faction != null) {
return faction;
}
// Next we search player names
FPlayer fp = FPlayer.find(factionName);
if (fp != null) {
return fp.getFaction();
}
if (defaultToMine && !senderIsConsole) {
return me.getFaction();
}
sendMessage(Conf.colorSystem+"No faction or player \""+factionName+"\" was found");
return null;
}
public Faction findFaction(String factionName) {
return findFaction(factionName, false);
}
public boolean canIAdministerYou(FPlayer i, FPlayer you) {
if ( ! i.getFaction().equals(you.getFaction())) {
i.sendMessage(you.getNameAndRelevant(i)+Conf.colorSystem+" is not in the same faction as you.");
return false;
}
if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.ADMIN) ) {
return true;
}
if (you.getRole().equals(Role.ADMIN)) {
i.sendMessage(Conf.colorSystem+"Only the faction admin can do that.");
} else if (i.getRole().equals(Role.MODERATOR)) {
if ( i == you ) {
return true; //Moderators can control themselves
} else {
i.sendMessage(Conf.colorSystem+"Moderators can't control each other...");
}
} else {
i.sendMessage(Conf.colorSystem+"You must be a faction moderator to do that.");
}
return false;
}
// 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) {
if (!Econ.enabled() || this.me == null || cost == 0.0 || Conf.adminBypassPlayers.contains(me.getName())) {
return true;
}
String desc = this.helpDescription.toLowerCase();
Faction faction = me.getFaction();
// pay up
if (cost > 0.0) {
String costString = Econ.moneyString(cost);
if(Conf.bankFactionPaysCosts && me.hasFaction() ) {
if(!faction.removeMoney(cost)) {
sendMessage("It costs "+costString+" to "+desc+", which your faction can't currently afford.");
return false;
} else {
sendMessage(faction.getTag()+" has paid "+costString+" to "+desc+".");
}
} else {
if (!Econ.deductMoney(me.getName(), cost)) {
sendMessage("It costs "+costString+" to "+desc+", which you can't currently afford.");
return false;
}
sendMessage("You have paid "+costString+" to "+desc+".");
}
}
// wait... we pay you to use this command?
else {
String costString = Econ.moneyString(-cost);
if(Conf.bankFactionPaysCosts && me.hasFaction() ) {
faction.addMoney(-cost);
sendMessage(faction.getTag()+" has been paid "+costString+" to "+desc+".");
} else {
Econ.addMoney(me.getName(), -cost);
}
sendMessage("You have been paid "+costString+" to "+desc+".");
}
return true;
}
public static final List<String> aliasTrue = new ArrayList<String>(Arrays.asList("true", "yes", "y", "ok", "on", "+"));
public static final List<String> aliasFalse = new ArrayList<String>(Arrays.asList("false", "no", "n", "off", "-"));
public boolean parseBool(String str) {
return aliasTrue.contains(str.toLowerCase());
}
public void setLock(boolean newLock) {
if( newLock ) {
sendMessage("Factions is now locked");
} else {
sendMessage("Factions in now unlocked");
}
lock = newLock;
}
public boolean isLocked() {
return lock;
}
public void sendLockMessage() {
me.sendMessage("Factions is locked. Please try again later");
}
}

View File

@ -0,0 +1,318 @@
package com.massivecraft.factions.commands;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FPlayers;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.MCommand;
public abstract class FCommand extends MCommand<P>
{
//TODO: Legacy to handle
//public boolean senderIsConsole;
//private static boolean lock = false;
public FPlayer fme;
public boolean senderMustBeMember;
public boolean senderMustBeModerator;
public boolean senderMustBeAdmin;
public FCommand()
{
super(P.p);
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain)
{
if (sender instanceof Player)
{
this.fme = FPlayers.i.get((Player)sender);
}
else
{
this.fme = null;
}
super.execute(sender, args, commandChain);
}
@Override
public boolean validSenderType(CommandSender sender, boolean informSenderIfNot)
{
boolean superValid = super.validSenderType(sender, informSenderIfNot);
if ( ! superValid) return false;
if ( ! (this.senderMustBeMember || this.senderMustBeModerator || this.senderMustBeAdmin)) return true;
if ( ! (sender instanceof Player)) return false;
FPlayer fplayer = FPlayers.i.get((Player)sender);
if ( ! fplayer.hasFaction())
{
sender.sendMessage(p.txt.parse("<b>You are not member of any faction."));
return false;
}
if (this.senderMustBeModerator && ! fplayer.getRole().isAtLeast(Role.MODERATOR))
{
sender.sendMessage(p.txt.parse("<b>Only faction moderators can %s.", this.helpShort));
return false;
}
if (this.senderMustBeAdmin && ! fplayer.getRole().isAtLeast(Role.ADMIN))
{
sender.sendMessage(p.txt.parse("<b>Only faction admins can %s.", this.helpShort));
return false;
}
return true;
}
// -------------------------------------------- //
// Argument Readers
// -------------------------------------------- //
// ARG AS FPLAYER
public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg)
{
FPlayer ret = def;
String name = this.argAsString(idx);
if (name != null)
{
FPlayer fplayer = FPlayers.i.get(name);
if (fplayer != null)
{
ret = fplayer;
}
}
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The player \"<p>%s<b>\" could not be found.", name));
}
return ret;
}
public FPlayer argAsFPlayer(int idx, FPlayer def)
{
return this.argAsFPlayer(idx, def, true);
}
public FPlayer argAsFPlayer(int idx)
{
return this.argAsFPlayer(idx, null);
}
// ARG AS BEST FPLAYER MATCH
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg)
{
FPlayer ret = def;
String name = this.argAsString(idx);
if (name != null)
{
FPlayer fplayer = FPlayers.i.find(name);
if (fplayer != null)
{
ret = fplayer;
}
}
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The player \"<p>%s<b>\" could not be found.", name));
}
return ret;
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def)
{
return this.argAsBestFPlayerMatch(idx, def, true);
}
public FPlayer argAsBestFPlayerMatch(int idx)
{
return this.argAsBestFPlayerMatch(idx, null);
}
// ARG AS FACTION
public Faction argAsFaction(int idx, Faction def, boolean msg)
{
Faction ret = def;
String name = this.argAsString(idx);
if (name != null)
{
// First we search faction names
Faction faction = Factions.i.findByTag(name);
if (faction != null)
{
ret = faction;
}
// Next we search player names
FPlayer fplayer = FPlayers.i.find(name);
if (fplayer != null)
{
ret = fplayer.getFaction();
}
}
if (msg && ret == null)
{
this.sendMessage(p.txt.parse("<b>The faction or player \"<p>%s<b>\" could not be found.", name));
}
return ret;
}
public Faction argAsFaction(int idx, Faction def)
{
return this.argAsFaction(idx, def, true);
}
public Faction argAsFaction(int idx)
{
return this.argAsFaction(idx, null);
}
// -------------------------------------------- //
// Commonly used logic
// -------------------------------------------- //
public boolean canIAdministerYou(FPlayer i, FPlayer you)
{
if ( ! i.getFaction().equals(you.getFaction()))
{
i.sendMessage(p.txt.parse("%s <b>is not in the same faction as you.",you.getNameAndRelevant(i)));
return false;
}
if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.ADMIN) )
{
return true;
}
if (you.getRole().equals(Role.ADMIN))
{
i.sendMessage(p.txt.parse("<b>Only the faction admin can do that."));
}
else if (i.getRole().equals(Role.MODERATOR))
{
if ( i == you )
{
return true; //Moderators can control themselves
}
else
{
i.sendMessage(p.txt.parse("<b>Moderators can't control each other..."));
}
}
else
{
i.sendMessage(p.txt.parse("<b>You must be a faction moderator to do that."));
}
return false;
}
// 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)
{
if ( ! Econ.enabled() || this.me == null || cost == 0.0 || Conf.adminBypassPlayers.contains(me.getName()))
{
return true;
}
String desc = this.helpShort.toLowerCase();
Faction faction = fme.getFaction();
// pay up
if (cost > 0.0)
{
String costString = Econ.moneyString(cost);
if(Conf.bankFactionPaysCosts && fme.hasFaction() )
{
if(!faction.removeMoney(cost))
{
sendMessage("It costs "+costString+" to "+desc+", which your faction can't currently afford.");
return false;
}
else
{
sendMessage(faction.getTag()+" has paid "+costString+" to "+desc+".");
}
}
else
{
if (!Econ.deductMoney(me.getName(), cost))
{
sendMessage("It costs "+costString+" to "+desc+", which you can't currently afford.");
return false;
}
sendMessage("You have paid "+costString+" to "+desc+".");
}
}
// wait... we pay you to use this command?
else
{
String costString = Econ.moneyString(-cost);
if(Conf.bankFactionPaysCosts && fme.hasFaction() )
{
faction.addMoney(-cost);
sendMessage(faction.getTag()+" has been paid "+costString+" to "+desc+".");
}
else
{
Econ.addMoney(me.getName(), -cost);
}
sendMessage("You have been paid "+costString+" to "+desc+".");
}
return true;
}
// TODO: Move these messages to the locked command??
// TODO: I lost the check for this code somewhere as well :/
public void setIsLocked(boolean isLocked)
{
if( isLocked )
{
sendMessage("Factions is now locked");
}
else
{
sendMessage("Factions in now unlocked");
}
lock = isLocked;
}
public boolean isLocked()
{
return lock;
}
public void sendLockMessage()
{
me.sendMessage("Factions is locked. Please try again later");
}
}

View File

@ -5,7 +5,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Role;
public class FCommandAdmin extends FBaseCommand {
public class FCommandAdmin extends FCommand {
public FCommandAdmin() {
aliases.add("admin");

View File

@ -5,7 +5,7 @@ import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Role;
public class FCommandAutoClaim extends FBaseCommand {
public class FCommandAutoClaim extends FCommand {
public FCommandAutoClaim() {
aliases.add("autoclaim");

View File

@ -7,7 +7,7 @@ import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandAutoSafeclaim extends FBaseCommand {
public class FCommandAutoSafeclaim extends FCommand {
public FCommandAutoSafeclaim() {
aliases.add("autosafe");

View File

@ -7,7 +7,7 @@ import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandAutoWarclaim extends FBaseCommand {
public class FCommandAutoWarclaim extends FCommand {
public FCommandAutoWarclaim() {
aliases.add("autowar");

View File

@ -6,7 +6,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandBalance extends FBaseCommand {
public class FCommandBalance extends FCommand {
public FCommandBalance() {
aliases.add("balance");

View File

@ -6,7 +6,7 @@ import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
public class FCommandBypass extends FBaseCommand {
public class FCommandBypass extends FCommand {
public FCommandBypass() {
aliases.add("bypass");
@ -21,14 +21,14 @@ public class FCommandBypass extends FBaseCommand {
@Override
public void perform() {
if ( ! Conf.adminBypassPlayers.contains(player.getName())) {
Conf.adminBypassPlayers.add(player.getName());
if ( ! Conf.adminBypassPlayers.contains(me.getName())) {
Conf.adminBypassPlayers.add(me.getName());
me.sendMessage("You have enabled admin bypass mode. You will be able to build or destroy anywhere.");
P.log(player.getName() + " has ENABLED admin bypass mode.");
P.log(me.getName() + " has ENABLED admin bypass mode.");
} else {
Conf.adminBypassPlayers.remove(player.getName());
Conf.adminBypassPlayers.remove(me.getName());
me.sendMessage("You have disabled admin bypass mode.");
P.log(player.getName() + " DISABLED admin bypass mode.");
P.log(me.getName() + " DISABLED admin bypass mode.");
}
}
}

View File

@ -3,7 +3,7 @@ package com.massivecraft.factions.commands;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.struct.ChatMode;
public class FCommandChat extends FBaseCommand {
public class FCommandChat extends FCommand {
public FCommandChat() {
aliases.add("chat");

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions.commands;
public class FCommandClaim extends FBaseCommand {
public class FCommandClaim extends FCommand {
public FCommandClaim() {
aliases.add("claim");

View File

@ -15,7 +15,7 @@ import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.SpoutFeatures;
public class FCommandConfig extends FBaseCommand {
public class FCommandConfig extends FCommand {
private static HashMap<String, String> properFieldNames = new HashMap<String, String>();
@ -222,7 +222,7 @@ public class FCommandConfig extends FBaseCommand {
if (!success.isEmpty()) {
sendMessage(success);
if (sender instanceof Player) {
P.log(success + " Command was run by "+player.getName()+".");
P.log(success + " Command was run by "+me.getName()+".");
}
}
// save change to disk

View File

@ -11,7 +11,7 @@ import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Role;
public class FCommandCreate extends FBaseCommand {
public class FCommandCreate extends FCommand {
public FCommandCreate() {
aliases.add("create");

View File

@ -5,7 +5,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Role;
public class FCommandDeinvite extends FBaseCommand {
public class FCommandDeinvite extends FCommand {
public FCommandDeinvite() {
aliases.add("deinvite");

View File

@ -7,7 +7,7 @@ import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
public class FCommandDeposit extends FBaseCommand {
public class FCommandDeposit extends FCommand {
public FCommandDeposit() {
aliases.add("deposit");
@ -49,7 +49,7 @@ public class FCommandDeposit extends FBaseCommand {
faction.addMoney(amount);
sendMessage("You have deposited "+amountString+" into "+faction.getTag()+"'s bank.");
sendMessage(faction.getTag()+" now has "+Econ.moneyString(faction.getMoney()));
P.log(player.getName() + " deposited "+amountString+" into "+faction.getTag()+"'s bank.");
P.log(me.getName() + " deposited "+amountString+" into "+faction.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == faction) {

View File

@ -5,7 +5,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.TextUtil;
public class FCommandDescription extends FBaseCommand {
public class FCommandDescription extends FCommand {
public FCommandDescription() {
aliases.add("desc");

View File

@ -9,7 +9,7 @@ import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Role;
public class FCommandDisband extends FBaseCommand {
public class FCommandDisband extends FCommand {
public FCommandDisband() {
aliases.add("disband");
@ -75,7 +75,7 @@ public class FCommandDisband extends FBaseCommand {
if (amount > 0.0) {
String amountString = Econ.moneyString(amount);
sendMessage("You have been given the disbanded faction's bank, totaling "+amountString+".");
P.log(player.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+".");
P.log(me.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+".");
}
}

View File

@ -9,7 +9,7 @@ import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.util.TextUtil;
public class FCommandHelp extends FBaseCommand {
public class FCommandHelp extends FCommand {
public FCommandHelp() {
aliases.add("help");

View File

@ -12,7 +12,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
public class FCommandHome extends FBaseCommand {
public class FCommandHome extends FCommand {
public FCommandHome() {
aliases.add("home");
@ -49,12 +49,12 @@ public class FCommandHome extends FBaseCommand {
return;
}
if (!Conf.homesTeleportAllowedFromDifferentWorld && player.getWorld().getUID() != myFaction.getHome().getWorld().getUID()) {
if (!Conf.homesTeleportAllowedFromDifferentWorld && me.getWorld().getUID() != myFaction.getHome().getWorld().getUID()) {
me.sendMessage("You cannot teleport to your faction home while in a different world.");
return;
}
Faction faction = Board.getFactionAt(new FLocation(player.getLocation()));
Faction faction = Board.getFactionAt(new FLocation(me.getLocation()));
// if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby
if (
@ -62,15 +62,15 @@ public class FCommandHome extends FBaseCommand {
&& !faction.isSafeZone()
&& (!me.isInOwnTerritory() || (me.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))
) {
Location loc = player.getLocation();
Location loc = me.getLocation();
World w = loc.getWorld();
double x = loc.getX();
double y = loc.getY();
double z = loc.getZ();
for (Player p : player.getServer().getOnlinePlayers())
for (Player p : me.getServer().getOnlinePlayers())
{
if (p == null || !p.isOnline() || p.isDead() || p == player || p.getWorld() != w)
if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w)
continue;
FPlayer fp = FPlayer.get(p);
@ -97,7 +97,7 @@ public class FCommandHome extends FBaseCommand {
return;
}
player.teleport(myFaction.getHome());
me.teleport(myFaction.getHome());
}
}

View File

@ -5,7 +5,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Role;
public class FCommandInvite extends FBaseCommand {
public class FCommandInvite extends FCommand {
public FCommandInvite() {
aliases.add("invite");

View File

@ -3,7 +3,7 @@ package com.massivecraft.factions.commands;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
public class FCommandJoin extends FBaseCommand {
public class FCommandJoin extends FCommand {
public FCommandJoin() {
aliases.add("join");

View File

@ -5,7 +5,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandKick extends FBaseCommand {
public class FCommandKick extends FCommand {
public FCommandKick() {
aliases.add("kick");

View File

@ -2,7 +2,7 @@ package com.massivecraft.factions.commands;
import org.bukkit.command.CommandSender;
public class FCommandLeave extends FBaseCommand {
public class FCommandLeave extends FCommand {
public FCommandLeave() {
aliases.add("leave");

View File

@ -11,7 +11,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.util.TextUtil;
public class FCommandList extends FBaseCommand {
public class FCommandList extends FCommand {
public FCommandList() {
aliases.add("list");

View File

@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.P;
public class FCommandLock extends FBaseCommand {
public class FCommandLock extends FCommand {
public FCommandLock() {
aliases.add("lock");

View File

@ -7,7 +7,7 @@ import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FLocation;
public class FCommandMap extends FBaseCommand {
public class FCommandMap extends FCommand {
public FCommandMap() {
aliases.add("map");

View File

@ -5,7 +5,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Role;
public class FCommandMod extends FBaseCommand {
public class FCommandMod extends FCommand {
public FCommandMod() {
aliases.add("mod");

View File

@ -7,7 +7,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Role;
public class FCommandNoBoom extends FBaseCommand {
public class FCommandNoBoom extends FCommand {
public FCommandNoBoom() {
aliases.add("noboom");

View File

@ -4,7 +4,7 @@ import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Role;
public class FCommandOpen extends FBaseCommand {
public class FCommandOpen extends FCommand {
public FCommandOpen() {
aliases.add("open");

View File

@ -9,7 +9,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Role;
public class FCommandOwner extends FBaseCommand {
public class FCommandOwner extends FCommand {
public FCommandOwner() {
aliases.add("owner");
@ -21,7 +21,7 @@ public class FCommandOwner extends FBaseCommand {
@Override
public void perform() {
boolean hasBypass = P.hasPermAdminBypass(player);
boolean hasBypass = P.hasPermAdminBypass(me);
if ( ! hasBypass && ! assertHasFaction()) {
return;

View File

@ -10,7 +10,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandOwnerList extends FBaseCommand {
public class FCommandOwnerList extends FCommand {
public FCommandOwnerList() {
aliases.add("ownerlist");
@ -20,7 +20,7 @@ public class FCommandOwnerList extends FBaseCommand {
@Override
public void perform() {
boolean hasBypass = P.hasPermAdminBypass(player);
boolean hasBypass = P.hasPermAdminBypass(me);
if ( ! hasBypass && ! assertHasFaction()) {
return;

View File

@ -8,9 +8,11 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Role;
public class FCommandPay extends FBaseCommand {
public class FCommandPay extends FCommand
{
public FCommandPay() {
public FCommandPay()
{
aliases.add("pay");
helpDescription = "Pay another faction from your bank";
@ -63,7 +65,7 @@ public class FCommandPay extends FBaseCommand {
them.addMoney(amount);
sendMessage("You have paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
sendMessage(us.getTag()+" now has "+Econ.moneyString(us.getMoney()));
P.log(player.getName() + " paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
P.log(me.getName() + " paid "+amountString+" from "+us.getTag()+"'s bank to "+them.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == us || fplayer.getFaction() == them) {

View File

@ -8,7 +8,7 @@ import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.integration.SpoutFeatures;
public class FCommandPeaceful extends FBaseCommand {
public class FCommandPeaceful extends FCommand {
public FCommandPeaceful() {
aliases.add("peaceful");

View File

@ -8,7 +8,7 @@ import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
public class FCommandPermanent extends FBaseCommand {
public class FCommandPermanent extends FCommand {
public FCommandPermanent() {
aliases.add("permanent");

View File

@ -8,7 +8,7 @@ import com.massivecraft.factions.P;
import com.massivecraft.factions.FPlayer;
public class FCommandPower extends FBaseCommand {
public class FCommandPower extends FCommand {
public FCommandPower() {
aliases.add("power");
@ -30,7 +30,7 @@ public class FCommandPower extends FBaseCommand {
public void perform() {
FPlayer target;
if (parameters.size() > 0) {
if (!P.hasPermViewAnyPower(player)) {
if (!P.hasPermViewAnyPower(me)) {
me.sendMessage("You do not have the appropriate permission to view another player's power level.");
return;
}

View File

@ -8,7 +8,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandReload extends FBaseCommand {
public class FCommandReload extends FCommand {
public FCommandReload() {
aliases.add("reload");

View File

@ -7,7 +7,7 @@ import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandSafeclaim extends FBaseCommand {
public class FCommandSafeclaim extends FCommand {
public FCommandSafeclaim() {
aliases.add("safeclaim");

View File

@ -6,7 +6,7 @@ import com.massivecraft.factions.Board;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandSafeunclaimall extends FBaseCommand {
public class FCommandSafeunclaimall extends FCommand {
public FCommandSafeunclaimall() {
aliases.add("safeunclaimall");

View File

@ -4,7 +4,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.P;
public class FCommandSaveAll extends FBaseCommand {
public class FCommandSaveAll extends FCommand {
public FCommandSaveAll() {
aliases.add("saveall");

View File

@ -5,7 +5,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Role;
public class FCommandSethome extends FBaseCommand {
public class FCommandSethome extends FCommand {
public FCommandSethome() {
aliases.add("sethome");
@ -38,7 +38,7 @@ public class FCommandSethome extends FBaseCommand {
Faction myFaction = me.getFaction();
if (parameters.size() > 0) {
if (!P.hasPermAdminBypass(player)) {
if (!P.hasPermAdminBypass(me)) {
me.sendMessage("You cannot set the home of another faction without adminBypass permission.");
return;
}
@ -51,7 +51,7 @@ public class FCommandSethome extends FBaseCommand {
}
}
if (Conf.homesMustBeInClaimedTerritory && !me.isInOwnTerritory() && !P.hasPermAdminBypass(player)) {
if (Conf.homesMustBeInClaimedTerritory && !me.isInOwnTerritory() && !P.hasPermAdminBypass(me)) {
me.sendMessage("Sorry, your faction home can only be set inside your own claimed territory.");
return;
}
@ -61,7 +61,7 @@ public class FCommandSethome extends FBaseCommand {
return;
}
myFaction.setHome(player.getLocation());
myFaction.setHome(me.getLocation());
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" set the home for your faction. You can now use:");
myFaction.sendMessage(new FCommandHome().getUseageTemplate());

View File

@ -13,7 +13,7 @@ import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.TextUtil;
public class FCommandShow extends FBaseCommand {
public class FCommandShow extends FCommand {
public FCommandShow() {
aliases.add("show");

View File

@ -9,7 +9,7 @@ import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.TextUtil;
public class FCommandTag extends FBaseCommand {
public class FCommandTag extends FCommand {
public FCommandTag() {
aliases.add("tag");

View File

@ -6,7 +6,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.util.TextUtil;
public class FCommandTitle extends FBaseCommand {
public class FCommandTitle extends FCommand {
public FCommandTitle() {
aliases.add("title");
@ -54,7 +54,7 @@ public class FCommandTitle extends FBaseCommand {
myFaction.sendMessage(me.getNameAndRelevant(myFaction)+Conf.colorSystem+" changed a title: "+you.getNameAndRelevant(myFaction));
if (Conf.spoutFactionTitlesOverNames) {
SpoutFeatures.updateAppearances(player);
SpoutFeatures.updateAppearances(me);
}
}

View File

@ -8,7 +8,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Role;
public class FCommandUnclaim extends FBaseCommand {
public class FCommandUnclaim extends FCommand {
public FCommandUnclaim() {
aliases.add("unclaim");
@ -47,7 +47,7 @@ public class FCommandUnclaim extends FBaseCommand {
return;
}
if (Conf.adminBypassPlayers.contains(player.getName())) {
if (Conf.adminBypassPlayers.contains(me.getName())) {
Board.removeAt(flocation);
otherFaction.sendMessage(me.getNameAndRelevant(otherFaction)+Conf.colorSystem+" unclaimed some of your land.");
@ -81,7 +81,7 @@ public class FCommandUnclaim extends FBaseCommand {
faction.addMoney(refund);
moneyBack = " "+faction.getTag()+" received a refund of "+Econ.moneyString(refund)+".";
} else {
Econ.addMoney(player.getName(), refund);
Econ.addMoney(me.getName(), refund);
moneyBack = " They received a refund of "+Econ.moneyString(refund)+".";
}
}
@ -95,7 +95,7 @@ public class FCommandUnclaim extends FBaseCommand {
}
moneyBack = " It cost "+faction.getTag()+" "+Econ.moneyString(refund)+".";
} else {
if (!Econ.deductMoney(player.getName(), -refund)) {
if (!Econ.deductMoney(me.getName(), -refund)) {
sendMessage("Unclaiming this land will cost "+Econ.moneyString(-refund)+", which you can't currently afford.");
return;
}

View File

@ -6,7 +6,7 @@ import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Role;
public class FCommandUnclaimall extends FBaseCommand {
public class FCommandUnclaimall extends FCommand {
public FCommandUnclaimall() {
aliases.add("unclaimall");
@ -42,7 +42,7 @@ public class FCommandUnclaimall extends FBaseCommand {
faction.addMoney(refund);
moneyBack = " "+faction.getTag()+" received a refund of "+Econ.moneyString(refund)+".";
} else {
Econ.addMoney(player.getName(), refund);
Econ.addMoney(me.getName(), refund);
moneyBack = " They received a refund of "+Econ.moneyString(refund)+".";
}
}
@ -56,7 +56,7 @@ public class FCommandUnclaimall extends FBaseCommand {
}
moneyBack = " It cost "+faction.getTag()+" "+Econ.moneyString(refund)+".";
} else {
if (!Econ.deductMoney(player.getName(), -refund)) {
if (!Econ.deductMoney(me.getName(), -refund)) {
sendMessage("Unclaiming all faction land will cost "+Econ.moneyString(-refund)+", which you can't currently afford.");
return;
}

View File

@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
import com.massivecraft.factions.P;
public class FCommandVersion extends FBaseCommand {
public class FCommandVersion extends FCommand {
public FCommandVersion() {
aliases.add("version");

View File

@ -7,7 +7,7 @@ import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandWarclaim extends FBaseCommand {
public class FCommandWarclaim extends FCommand {
public FCommandWarclaim() {
aliases.add("warclaim");

View File

@ -6,7 +6,7 @@ import com.massivecraft.factions.Board;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
public class FCommandWarunclaimall extends FBaseCommand {
public class FCommandWarunclaimall extends FCommand {
public FCommandWarunclaimall() {
aliases.add("warunclaimall");

View File

@ -8,7 +8,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Role;
public class FCommandWithdraw extends FBaseCommand {
public class FCommandWithdraw extends FCommand {
public FCommandWithdraw() {
aliases.add("withdraw");
@ -55,7 +55,7 @@ public class FCommandWithdraw extends FBaseCommand {
Econ.addMoney(me.getName(), amount);
sendMessage("You have withdrawn "+amountString+" from "+faction.getTag()+"'s bank.");
sendMessage(faction.getTag()+" now has "+Econ.moneyString(faction.getMoney()));
P.log(player.getName() + " withdrew "+amountString+" from "+faction.getTag()+"'s bank.");
P.log(me.getName() + " withdrew "+amountString+" from "+faction.getTag()+"'s bank.");
for (FPlayer fplayer : FPlayer.getAllOnline()) {
if (fplayer.getFaction() == faction) {

View File

@ -10,7 +10,7 @@ import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
public class FRelationCommand extends FBaseCommand {
public class FRelationCommand extends FCommand {
public FRelationCommand() {
requiredParameters.add("faction tag");

View File

@ -18,6 +18,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.Permission;
import com.massivecraft.factions.struct.Relation;
@ -185,7 +186,7 @@ public class FactionsBlockListener extends BlockListener
if (otherFaction.isNone())
{
if (!Conf.wildernessDenyBuild || P.hasPermAdminBypass(player) || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName()))
if (!Conf.wildernessDenyBuild || Permission.ADMIN_BYPASS.has(player) || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName()))
{
return true; // This is not faction territory. Use whatever you like here.
}
@ -197,7 +198,7 @@ public class FactionsBlockListener extends BlockListener
}
else if (otherFaction.isSafeZone())
{
if (!Conf.safeZoneDenyBuild || P.hasPermManageSafeZone(player))
if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player))
{
return true;
}
@ -208,7 +209,7 @@ public class FactionsBlockListener extends BlockListener
}
else if (otherFaction.isWarZone())
{
if (!Conf.warZoneDenyBuild || P.hasPermManageWarZone(player))
if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player))
{
return true;
}
@ -253,7 +254,7 @@ public class FactionsBlockListener extends BlockListener
}
}
// Also cancel and/or cause pain if player doesn't have ownership rights for this claim
else if (rel.isMember() && ownershipFail && !P.hasPermOwnershipBypass(player))
else if (rel.isMember() && ownershipFail && ! Permission.OWNERSHIP_BYPASS.has(player))
{
if (Conf.ownedAreaPainBuild && !justCheck)
{

View File

@ -29,6 +29,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.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.MiscUtil;
@ -449,7 +450,7 @@ public class FactionsEntityListener extends EntityListener
if (otherFaction.isNone())
{
if (!Conf.wildernessDenyBuild || P.hasPermAdminBypass(player) || Conf.worldsNoWildernessProtection.contains(player.getWorld().getName()))
if (!Conf.wildernessDenyBuild || Permission.ADMIN_BYPASS.has(player) || Conf.worldsNoWildernessProtection.contains(player.getWorld().getName()))
{
return true; // This is not faction territory. Use whatever you like here.
}
@ -459,7 +460,7 @@ public class FactionsEntityListener extends EntityListener
if (otherFaction.isSafeZone())
{
if (P.hasPermManageSafeZone(player) || !Conf.safeZoneDenyBuild)
if (Permission.MANAGE_SAFE_ZONE.has(player) || !Conf.safeZoneDenyBuild)
{
return true;
}
@ -468,7 +469,7 @@ public class FactionsEntityListener extends EntityListener
}
else if (otherFaction.isWarZone())
{
if (P.hasPermManageWarZone(player) || !Conf.warZoneDenyBuild)
if (Permission.MANAGE_WAR_ZONE.has(player) || !Conf.warZoneDenyBuild)
{
return true;
}
@ -487,7 +488,7 @@ public class FactionsEntityListener extends EntityListener
return false;
}
// Also cancel if player doesn't have ownership rights for this claim
else if (rel.isMember() && ownershipFail && !P.hasPermOwnershipBypass(player))
else if (rel.isMember() && ownershipFail && !Permission.OWNERSHIP_BYPASS.has(player))
{
me.sendMessage("You can't "+action+" paintings in this territory, it is owned by: "+otherFaction.getOwnerListString(loc));
return false;

View File

@ -8,7 +8,6 @@ import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
@ -32,6 +31,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.zcore.util.TextUtil;
@ -264,7 +264,7 @@ public class FactionsPlayerListener extends PlayerListener
}
else if (me.autoSafeZoneEnabled())
{
if (!P.hasPermManageSafeZone((CommandSender)player))
if ( ! Permission.MANAGE_SAFE_ZONE.has(player))
{
me.enableAutoSafeZone(false);
}
@ -281,7 +281,7 @@ public class FactionsPlayerListener extends PlayerListener
}
else if (me.autoWarZoneEnabled())
{
if (!P.hasPermManageWarZone((CommandSender)player))
if ( ! Permission.MANAGE_WAR_ZONE.has(player))
{
me.enableAutoWarZone(false);
}
@ -358,7 +358,7 @@ public class FactionsPlayerListener extends PlayerListener
if (otherFaction.isNone())
{
if (!Conf.wildernessDenyUseage || P.hasPermAdminBypass(player) || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName()))
if (!Conf.wildernessDenyUseage || Permission.ADMIN_BYPASS.has(player) || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName()))
{
return true; // This is not faction territory. Use whatever you like here.
}
@ -371,7 +371,7 @@ public class FactionsPlayerListener extends PlayerListener
}
else if (otherFaction.isSafeZone())
{
if (!Conf.safeZoneDenyUseage || P.hasPermManageSafeZone(player))
if (!Conf.safeZoneDenyUseage || Permission.MANAGE_SAFE_ZONE.has(player))
{
return true;
}
@ -383,7 +383,7 @@ public class FactionsPlayerListener extends PlayerListener
}
else if (otherFaction.isWarZone())
{
if (!Conf.warZoneDenyUseage || P.hasPermManageWarZone(player))
if (!Conf.warZoneDenyUseage || Permission.MANAGE_WAR_ZONE.has(player))
{
return true;
}
@ -408,7 +408,7 @@ public class FactionsPlayerListener extends PlayerListener
return false;
}
// Also cancel if player doesn't have ownership rights for this claim
else if (rel.isMember() && ownershipFail && !P.hasPermOwnershipBypass(player))
else if (rel.isMember() && ownershipFail && ! Permission.OWNERSHIP_BYPASS.has(player))
{
if (!justCheck)
{
@ -469,7 +469,7 @@ public class FactionsPlayerListener extends PlayerListener
return false;
}
// Also cancel if player doesn't have ownership rights for this claim
else if (rel.isMember() && ownershipFail && !P.hasPermOwnershipBypass(player))
else if (rel.isMember() && ownershipFail && ! Permission.OWNERSHIP_BYPASS.has(player))
{
if (!justCheck)
{

View File

@ -1,9 +1,8 @@
package com.massivecraft.factions.struct;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.P;
public enum Permission
{
@ -30,7 +29,17 @@ public enum Permission
this.node = node;
}
public boolean has(CommandSender sender, boolean informSenderIfNot)
{
return P.p.perm.has(sender, this.node, informSenderIfNot);
}
public boolean has(CommandSender sender)
{
return has(sender, false);
}
/*public boolean has(CommandSender sender)
{
//return CreativeGates.p.perm.has(sender, this.node);
}
@ -49,7 +58,7 @@ public enum Permission
Player player = (Player)sender;
return Factions.Permissions.has(player, permNode);
}
}*/
}

View File

@ -26,7 +26,7 @@ public class AsciiCompass {
return String.valueOf(this.asciiChar);
}
public String toString(boolean isActive, ChatColor colorActive, ChatColor colorDefault) {
public String toString(boolean isActive, ChatColor colorActive, String colorDefault) {
return (isActive ? colorActive : colorDefault)+String.valueOf(this.asciiChar);
}
}
@ -58,7 +58,7 @@ public class AsciiCompass {
return null;
}
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, ChatColor colorDefault) {
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) {
ArrayList<String> ret = new ArrayList<String>();
String row;
@ -83,7 +83,7 @@ public class AsciiCompass {
return ret;
}
public static ArrayList<String> getAsciiCompass(double inDegrees, ChatColor colorActive, ChatColor colorDefault) {
public static ArrayList<String> getAsciiCompass(double inDegrees, ChatColor colorActive, String colorDefault) {
return getAsciiCompass(getCompassPointForDirection(inDegrees), colorActive, colorDefault);
}
}

View File

@ -38,7 +38,7 @@ public abstract class MCommand<T extends MPlugin>
// Information available on execution of the command
public CommandSender sender; // Will always be set
public Player player; // Will only be set when the sender is a player
public Player me; // Will only be set when the sender is a player
public List<String> args; // Will contain the arguments, or and empty list if there are none.
public List<MCommand<?>> commandChain; // The command chain used to execute this command
@ -68,11 +68,11 @@ public abstract class MCommand<T extends MPlugin>
this.sender = sender;
if (sender instanceof Player)
{
this.player = (Player)sender;
this.me = (Player)sender;
}
else
{
this.player = null;
this.me = null;
}
this.args = args;
this.commandChain = commandChain;
@ -255,7 +255,7 @@ public abstract class MCommand<T extends MPlugin>
// Message Sending Helpers
// -------------------------------------------- //
public void msg(String msg, boolean parseColors)
public void sendMessage(String msg, boolean parseColors)
{
if (parseColors)
{
@ -265,22 +265,22 @@ public abstract class MCommand<T extends MPlugin>
sender.sendMessage(msg);
}
public void msg(String msg)
public void sendMessage(String msg)
{
this.msg(msg, false);
this.sendMessage(msg, false);
}
public void msg(List<String> msgs, boolean parseColors)
public void sendMessage(List<String> msgs, boolean parseColors)
{
for(String msg : msgs)
{
this.msg(msg, parseColors);
this.sendMessage(msg, parseColors);
}
}
public void msg(List<String> msgs)
public void sendMessage(List<String> msgs)
{
msg(msgs, false);
sendMessage(msgs, false);
}
// -------------------------------------------- //
@ -377,7 +377,7 @@ public abstract class MCommand<T extends MPlugin>
if (msg && ret == null)
{
// TODO: Fix this injection risk!
this.msg(p.txt.tags("<b>The player \"<p>"+name+"<b>\" could not be found."));
this.sendMessage(p.txt.tags("<b>The player \"<p>"+name+"<b>\" could not be found."));
}
return ret;
@ -409,7 +409,7 @@ public abstract class MCommand<T extends MPlugin>
if (msg && ret == null)
{
// TODO: Fix this injection risk!
this.msg(p.txt.tags("<b>No player match found for \"<p>"+name+"<b>\"."));
this.sendMessage(p.txt.tags("<b>No player match found for \"<p>"+name+"<b>\"."));
}
return ret;