diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index b5fa9504..2508d047 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -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 flocationIds = new HashMap(); + private static transient HashMap flocationIds = new HashMap(); //----------------------------------------------// // 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> iter = flocationIds.entrySet().iterator(); - while (iter.hasNext()) { - Entry entry = iter.next(); - if (entry.getValue().equals(factionId)) { + Iterator> iter = flocationIds.entrySet().iterator(); + while (iter.hasNext()) + { + Entry 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> iter = flocationIds.entrySet().iterator(); + public static void clean() + { + Iterator> iter = flocationIds.entrySet().iterator(); while (iter.hasNext()) { - Entry entry = iter.next(); - if ( ! Faction.exists(entry.getValue())) { - P.log("Board cleaner removed "+entry.getValue()+" from "+entry.getKey()); + Entry 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> iter = flocationIds.entrySet().iterator(); + Iterator> iter = flocationIds.entrySet().iterator(); while (iter.hasNext()) { - Entry entry = iter.next(); - if (entry.getValue() == factionId && entry.getKey().getWorldName().equals(worldName)) { + Entry 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 getMap(Faction faction, FLocation flocation, double inDegrees) { + public static ArrayList getMap(Faction faction, FLocation flocation, double inDegrees) + { ArrayList ret = new ArrayList(); 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 asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, Conf.colorChrome); + ArrayList asciiCompass = AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, P.p.txt.parse("")); // 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> dumpAsSaveFormat() { - Map> worldCoordIds = new HashMap>(); + public static Map> dumpAsSaveFormat() { + Map> worldCoordIds = new HashMap>(); String worldName, coords; - Integer id; + String id; - for (Entry entry : flocationIds.entrySet()) { + for (Entry entry : flocationIds.entrySet()) { worldName = entry.getKey().getWorldName(); coords = entry.getKey().getCoordString(); id = entry.getValue(); if ( ! worldCoordIds.containsKey(worldName)) { - worldCoordIds.put(worldName, new TreeMap()); + worldCoordIds.put(worldName, new TreeMap()); } worldCoordIds.get(worldName).put(coords, id); @@ -260,16 +279,20 @@ public class Board return worldCoordIds; } - public static void loadFromSaveFormat(Map> worldCoordIds) { + public static void loadFromSaveFormat(Map> worldCoordIds) + { flocationIds.clear(); String worldName; String[] coords; - int x, z, factionId; + int x, z; + String factionId; - for (Entry> entry : worldCoordIds.entrySet()) { + for (Entry> entry : worldCoordIds.entrySet()) + { worldName = entry.getKey(); - for (Entry entry2 : entry.getValue().entrySet()) { + for (Entry 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>>(){}.getType(); - Map> worldCoordIds = P.p.gson.fromJson(DiscUtil.read(file), type); + try + { + Type type = new TypeToken>>(){}.getType(); + Map> 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; } diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index cd60d21c..d273a5b6 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -33,30 +33,57 @@ import com.massivecraft.factions.zcore.persist.PlayerEntity; */ public class FPlayer extends PlayerEntity -{ - - // -------------------------------------------- // - // Fields - // -------------------------------------------- // - - //private static transient TreeMap instances = new TreeMap(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; } diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index d2739bf7..17615585 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -93,7 +93,7 @@ public class P extends MPlugin Worldguard.init(this); } - Type mapFLocToStringSetType = new TypeToken>>(){}.getType(); + //Type mapFLocToStringSetType = new TypeToken>>(){}.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 // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/commands/FBaseCommand.java b/src/com/massivecraft/factions/commands/FBaseCommand.java deleted file mode 100644 index b008b5d9..00000000 --- a/src/com/massivecraft/factions/commands/FBaseCommand.java +++ /dev/null @@ -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 aliases; - public List requiredParameters; - public List optionalParameters; - - public String helpNameAndParams; - public String helpDescription; - - public CommandSender sender; - public boolean senderMustBePlayer; - public boolean senderIsConsole; - public Player player; - public FPlayer me; - - public List parameters; - - private static boolean lock = false; - - public FBaseCommand() { - aliases = new ArrayList(); - requiredParameters = new ArrayList(); - optionalParameters = new ArrayList(); - - senderMustBePlayer = true; - senderIsConsole = false; - - helpNameAndParams = "fail!"; - helpDescription = "no description"; - } - - public List getAliases() { - return aliases; - } - - public void execute(CommandSender sender, List 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 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 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 parts = new ArrayList(); - - 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 aliasTrue = new ArrayList(Arrays.asList("true", "yes", "y", "ok", "on", "+")); - public static final List aliasFalse = new ArrayList(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"); - } -} diff --git a/src/com/massivecraft/factions/commands/FCommand.java b/src/com/massivecraft/factions/commands/FCommand.java new file mode 100644 index 00000000..894c75fa --- /dev/null +++ b/src/com/massivecraft/factions/commands/FCommand.java @@ -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

+{ + //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 args, List> 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("You are not member of any faction.")); + return false; + } + + if (this.senderMustBeModerator && ! fplayer.getRole().isAtLeast(Role.MODERATOR)) + { + sender.sendMessage(p.txt.parse("Only faction moderators can %s.", this.helpShort)); + return false; + } + + if (this.senderMustBeAdmin && ! fplayer.getRole().isAtLeast(Role.ADMIN)) + { + sender.sendMessage(p.txt.parse("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("The player \"

%s\" 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("The player \"

%s\" 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("The faction or player \"

%s\" 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 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("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("Moderators can't control each other...")); + } + } + else + { + i.sendMessage(p.txt.parse("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"); + } +} diff --git a/src/com/massivecraft/factions/commands/FCommandAdmin.java b/src/com/massivecraft/factions/commands/FCommandAdmin.java index c2451172..d73ace4b 100644 --- a/src/com/massivecraft/factions/commands/FCommandAdmin.java +++ b/src/com/massivecraft/factions/commands/FCommandAdmin.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandAutoClaim.java b/src/com/massivecraft/factions/commands/FCommandAutoClaim.java index b4045766..ca423034 100644 --- a/src/com/massivecraft/factions/commands/FCommandAutoClaim.java +++ b/src/com/massivecraft/factions/commands/FCommandAutoClaim.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandAutoSafeclaim.java b/src/com/massivecraft/factions/commands/FCommandAutoSafeclaim.java index 4f309389..6dce2c2c 100644 --- a/src/com/massivecraft/factions/commands/FCommandAutoSafeclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandAutoSafeclaim.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandAutoWarclaim.java b/src/com/massivecraft/factions/commands/FCommandAutoWarclaim.java index bd3b1388..c713899d 100644 --- a/src/com/massivecraft/factions/commands/FCommandAutoWarclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandAutoWarclaim.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandBalance.java b/src/com/massivecraft/factions/commands/FCommandBalance.java index 79af8df2..c9029335 100644 --- a/src/com/massivecraft/factions/commands/FCommandBalance.java +++ b/src/com/massivecraft/factions/commands/FCommandBalance.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandBypass.java b/src/com/massivecraft/factions/commands/FCommandBypass.java index bb35c511..9e2a0e2c 100644 --- a/src/com/massivecraft/factions/commands/FCommandBypass.java +++ b/src/com/massivecraft/factions/commands/FCommandBypass.java @@ -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."); } } } diff --git a/src/com/massivecraft/factions/commands/FCommandChat.java b/src/com/massivecraft/factions/commands/FCommandChat.java index 8f9d708c..e2ff60f1 100644 --- a/src/com/massivecraft/factions/commands/FCommandChat.java +++ b/src/com/massivecraft/factions/commands/FCommandChat.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandClaim.java b/src/com/massivecraft/factions/commands/FCommandClaim.java index 6324fd65..ba282d85 100644 --- a/src/com/massivecraft/factions/commands/FCommandClaim.java +++ b/src/com/massivecraft/factions/commands/FCommandClaim.java @@ -1,6 +1,6 @@ package com.massivecraft.factions.commands; -public class FCommandClaim extends FBaseCommand { +public class FCommandClaim extends FCommand { public FCommandClaim() { aliases.add("claim"); diff --git a/src/com/massivecraft/factions/commands/FCommandConfig.java b/src/com/massivecraft/factions/commands/FCommandConfig.java index 7ba1ace7..5b4574d3 100644 --- a/src/com/massivecraft/factions/commands/FCommandConfig.java +++ b/src/com/massivecraft/factions/commands/FCommandConfig.java @@ -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 properFieldNames = new HashMap(); @@ -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 diff --git a/src/com/massivecraft/factions/commands/FCommandCreate.java b/src/com/massivecraft/factions/commands/FCommandCreate.java index 5cac75a9..d2dd72ef 100644 --- a/src/com/massivecraft/factions/commands/FCommandCreate.java +++ b/src/com/massivecraft/factions/commands/FCommandCreate.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandDeinvite.java b/src/com/massivecraft/factions/commands/FCommandDeinvite.java index a7e93df2..065ff54d 100644 --- a/src/com/massivecraft/factions/commands/FCommandDeinvite.java +++ b/src/com/massivecraft/factions/commands/FCommandDeinvite.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandDeposit.java b/src/com/massivecraft/factions/commands/FCommandDeposit.java index 43546e00..4e1a45a3 100644 --- a/src/com/massivecraft/factions/commands/FCommandDeposit.java +++ b/src/com/massivecraft/factions/commands/FCommandDeposit.java @@ -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) { diff --git a/src/com/massivecraft/factions/commands/FCommandDescription.java b/src/com/massivecraft/factions/commands/FCommandDescription.java index c45049e5..4a85e3bf 100644 --- a/src/com/massivecraft/factions/commands/FCommandDescription.java +++ b/src/com/massivecraft/factions/commands/FCommandDescription.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandDisband.java b/src/com/massivecraft/factions/commands/FCommandDisband.java index 72d78841..c5b75dcd 100644 --- a/src/com/massivecraft/factions/commands/FCommandDisband.java +++ b/src/com/massivecraft/factions/commands/FCommandDisband.java @@ -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()+"."); } } diff --git a/src/com/massivecraft/factions/commands/FCommandHelp.java b/src/com/massivecraft/factions/commands/FCommandHelp.java index 291918b1..43adbbc1 100644 --- a/src/com/massivecraft/factions/commands/FCommandHelp.java +++ b/src/com/massivecraft/factions/commands/FCommandHelp.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandHome.java b/src/com/massivecraft/factions/commands/FCommandHome.java index a3483c22..e462921b 100644 --- a/src/com/massivecraft/factions/commands/FCommandHome.java +++ b/src/com/massivecraft/factions/commands/FCommandHome.java @@ -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()); } } diff --git a/src/com/massivecraft/factions/commands/FCommandInvite.java b/src/com/massivecraft/factions/commands/FCommandInvite.java index 3b17c6dc..ccb9ce0f 100644 --- a/src/com/massivecraft/factions/commands/FCommandInvite.java +++ b/src/com/massivecraft/factions/commands/FCommandInvite.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandJoin.java b/src/com/massivecraft/factions/commands/FCommandJoin.java index 338f31b2..4591486b 100644 --- a/src/com/massivecraft/factions/commands/FCommandJoin.java +++ b/src/com/massivecraft/factions/commands/FCommandJoin.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandKick.java b/src/com/massivecraft/factions/commands/FCommandKick.java index b68f4fb4..f4342f02 100644 --- a/src/com/massivecraft/factions/commands/FCommandKick.java +++ b/src/com/massivecraft/factions/commands/FCommandKick.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandLeave.java b/src/com/massivecraft/factions/commands/FCommandLeave.java index a8d6dab2..70c3c8d9 100644 --- a/src/com/massivecraft/factions/commands/FCommandLeave.java +++ b/src/com/massivecraft/factions/commands/FCommandLeave.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandList.java b/src/com/massivecraft/factions/commands/FCommandList.java index e789d541..f2559027 100644 --- a/src/com/massivecraft/factions/commands/FCommandList.java +++ b/src/com/massivecraft/factions/commands/FCommandList.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandLock.java b/src/com/massivecraft/factions/commands/FCommandLock.java index 5bfcd172..08676453 100644 --- a/src/com/massivecraft/factions/commands/FCommandLock.java +++ b/src/com/massivecraft/factions/commands/FCommandLock.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandMap.java b/src/com/massivecraft/factions/commands/FCommandMap.java index 71b95612..e6a0e4d9 100644 --- a/src/com/massivecraft/factions/commands/FCommandMap.java +++ b/src/com/massivecraft/factions/commands/FCommandMap.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandMod.java b/src/com/massivecraft/factions/commands/FCommandMod.java index 44b26dce..2622aa40 100644 --- a/src/com/massivecraft/factions/commands/FCommandMod.java +++ b/src/com/massivecraft/factions/commands/FCommandMod.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandNoBoom.java b/src/com/massivecraft/factions/commands/FCommandNoBoom.java index 645cfa91..28099534 100644 --- a/src/com/massivecraft/factions/commands/FCommandNoBoom.java +++ b/src/com/massivecraft/factions/commands/FCommandNoBoom.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandOpen.java b/src/com/massivecraft/factions/commands/FCommandOpen.java index 5a378f70..5aad8a8f 100644 --- a/src/com/massivecraft/factions/commands/FCommandOpen.java +++ b/src/com/massivecraft/factions/commands/FCommandOpen.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandOwner.java b/src/com/massivecraft/factions/commands/FCommandOwner.java index d36d0fd2..2c81c329 100644 --- a/src/com/massivecraft/factions/commands/FCommandOwner.java +++ b/src/com/massivecraft/factions/commands/FCommandOwner.java @@ -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; diff --git a/src/com/massivecraft/factions/commands/FCommandOwnerList.java b/src/com/massivecraft/factions/commands/FCommandOwnerList.java index f71f0ad3..8e8cb1f4 100644 --- a/src/com/massivecraft/factions/commands/FCommandOwnerList.java +++ b/src/com/massivecraft/factions/commands/FCommandOwnerList.java @@ -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; diff --git a/src/com/massivecraft/factions/commands/FCommandPay.java b/src/com/massivecraft/factions/commands/FCommandPay.java index 808b7d8a..0119d976 100644 --- a/src/com/massivecraft/factions/commands/FCommandPay.java +++ b/src/com/massivecraft/factions/commands/FCommandPay.java @@ -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) { diff --git a/src/com/massivecraft/factions/commands/FCommandPeaceful.java b/src/com/massivecraft/factions/commands/FCommandPeaceful.java index dda5c80f..96be4d83 100644 --- a/src/com/massivecraft/factions/commands/FCommandPeaceful.java +++ b/src/com/massivecraft/factions/commands/FCommandPeaceful.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandPermanent.java b/src/com/massivecraft/factions/commands/FCommandPermanent.java index 460525c4..032a8665 100644 --- a/src/com/massivecraft/factions/commands/FCommandPermanent.java +++ b/src/com/massivecraft/factions/commands/FCommandPermanent.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandPower.java b/src/com/massivecraft/factions/commands/FCommandPower.java index da53504a..42505099 100644 --- a/src/com/massivecraft/factions/commands/FCommandPower.java +++ b/src/com/massivecraft/factions/commands/FCommandPower.java @@ -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; } diff --git a/src/com/massivecraft/factions/commands/FCommandReload.java b/src/com/massivecraft/factions/commands/FCommandReload.java index a6c3cb02..51399144 100644 --- a/src/com/massivecraft/factions/commands/FCommandReload.java +++ b/src/com/massivecraft/factions/commands/FCommandReload.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandSafeclaim.java b/src/com/massivecraft/factions/commands/FCommandSafeclaim.java index b650fc0e..d2fc0062 100644 --- a/src/com/massivecraft/factions/commands/FCommandSafeclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandSafeclaim.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandSafeunclaimall.java b/src/com/massivecraft/factions/commands/FCommandSafeunclaimall.java index a70b3429..55c5c486 100644 --- a/src/com/massivecraft/factions/commands/FCommandSafeunclaimall.java +++ b/src/com/massivecraft/factions/commands/FCommandSafeunclaimall.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandSaveAll.java b/src/com/massivecraft/factions/commands/FCommandSaveAll.java index d5a494ba..f15ff337 100644 --- a/src/com/massivecraft/factions/commands/FCommandSaveAll.java +++ b/src/com/massivecraft/factions/commands/FCommandSaveAll.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandSethome.java b/src/com/massivecraft/factions/commands/FCommandSethome.java index 0882b1b8..d44a4bbd 100644 --- a/src/com/massivecraft/factions/commands/FCommandSethome.java +++ b/src/com/massivecraft/factions/commands/FCommandSethome.java @@ -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()); diff --git a/src/com/massivecraft/factions/commands/FCommandShow.java b/src/com/massivecraft/factions/commands/FCommandShow.java index b6d99e1c..d3557f85 100644 --- a/src/com/massivecraft/factions/commands/FCommandShow.java +++ b/src/com/massivecraft/factions/commands/FCommandShow.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandTag.java b/src/com/massivecraft/factions/commands/FCommandTag.java index e66a1cfa..d34286ea 100644 --- a/src/com/massivecraft/factions/commands/FCommandTag.java +++ b/src/com/massivecraft/factions/commands/FCommandTag.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandTitle.java b/src/com/massivecraft/factions/commands/FCommandTitle.java index cdf74f02..ebbe23cc 100644 --- a/src/com/massivecraft/factions/commands/FCommandTitle.java +++ b/src/com/massivecraft/factions/commands/FCommandTitle.java @@ -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); } } diff --git a/src/com/massivecraft/factions/commands/FCommandUnclaim.java b/src/com/massivecraft/factions/commands/FCommandUnclaim.java index 673a690a..c390e47c 100644 --- a/src/com/massivecraft/factions/commands/FCommandUnclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandUnclaim.java @@ -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; } diff --git a/src/com/massivecraft/factions/commands/FCommandUnclaimall.java b/src/com/massivecraft/factions/commands/FCommandUnclaimall.java index 3420c707..b86c0384 100644 --- a/src/com/massivecraft/factions/commands/FCommandUnclaimall.java +++ b/src/com/massivecraft/factions/commands/FCommandUnclaimall.java @@ -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; } diff --git a/src/com/massivecraft/factions/commands/FCommandVersion.java b/src/com/massivecraft/factions/commands/FCommandVersion.java index 80219901..967ba166 100644 --- a/src/com/massivecraft/factions/commands/FCommandVersion.java +++ b/src/com/massivecraft/factions/commands/FCommandVersion.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandWarclaim.java b/src/com/massivecraft/factions/commands/FCommandWarclaim.java index aaa6e3d3..923e0cfe 100644 --- a/src/com/massivecraft/factions/commands/FCommandWarclaim.java +++ b/src/com/massivecraft/factions/commands/FCommandWarclaim.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandWarunclaimall.java b/src/com/massivecraft/factions/commands/FCommandWarunclaimall.java index 165a1bed..fe4e051b 100644 --- a/src/com/massivecraft/factions/commands/FCommandWarunclaimall.java +++ b/src/com/massivecraft/factions/commands/FCommandWarunclaimall.java @@ -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"); diff --git a/src/com/massivecraft/factions/commands/FCommandWithdraw.java b/src/com/massivecraft/factions/commands/FCommandWithdraw.java index eaf73e22..d36d5a78 100644 --- a/src/com/massivecraft/factions/commands/FCommandWithdraw.java +++ b/src/com/massivecraft/factions/commands/FCommandWithdraw.java @@ -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) { diff --git a/src/com/massivecraft/factions/commands/FRelationCommand.java b/src/com/massivecraft/factions/commands/FRelationCommand.java index d0a90bda..c9403cd3 100644 --- a/src/com/massivecraft/factions/commands/FRelationCommand.java +++ b/src/com/massivecraft/factions/commands/FRelationCommand.java @@ -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"); diff --git a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java index 9db1b330..25be4506 100644 --- a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -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) { diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index 5dcf8619..8c0e1aca 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -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; diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 1e517e27..362b3408 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -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) { diff --git a/src/com/massivecraft/factions/struct/Permission.java b/src/com/massivecraft/factions/struct/Permission.java index b8a610fa..9b8262e9 100644 --- a/src/com/massivecraft/factions/struct/Permission.java +++ b/src/com/massivecraft/factions/struct/Permission.java @@ -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); - } + }*/ } diff --git a/src/com/massivecraft/factions/util/AsciiCompass.java b/src/com/massivecraft/factions/util/AsciiCompass.java index 66cf7dbf..1dda05f1 100644 --- a/src/com/massivecraft/factions/util/AsciiCompass.java +++ b/src/com/massivecraft/factions/util/AsciiCompass.java @@ -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 getAsciiCompass(Point point, ChatColor colorActive, ChatColor colorDefault) { + public static ArrayList getAsciiCompass(Point point, ChatColor colorActive, String colorDefault) { ArrayList ret = new ArrayList(); String row; @@ -83,7 +83,7 @@ public class AsciiCompass { return ret; } - public static ArrayList getAsciiCompass(double inDegrees, ChatColor colorActive, ChatColor colorDefault) { + public static ArrayList getAsciiCompass(double inDegrees, ChatColor colorActive, String colorDefault) { return getAsciiCompass(getCompassPointForDirection(inDegrees), colorActive, colorDefault); } } diff --git a/src/com/massivecraft/factions/zcore/MCommand.java b/src/com/massivecraft/factions/zcore/MCommand.java index 9c731b3c..c2bdfb2f 100644 --- a/src/com/massivecraft/factions/zcore/MCommand.java +++ b/src/com/massivecraft/factions/zcore/MCommand.java @@ -38,7 +38,7 @@ public abstract class MCommand // 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 args; // Will contain the arguments, or and empty list if there are none. public List> commandChain; // The command chain used to execute this command @@ -68,11 +68,11 @@ public abstract class MCommand 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 // 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 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 msgs, boolean parseColors) + public void sendMessage(List msgs, boolean parseColors) { for(String msg : msgs) { - this.msg(msg, parseColors); + this.sendMessage(msg, parseColors); } } - public void msg(List msgs) + public void sendMessage(List msgs) { - msg(msgs, false); + sendMessage(msgs, false); } // -------------------------------------------- // @@ -377,7 +377,7 @@ public abstract class MCommand if (msg && ret == null) { // TODO: Fix this injection risk! - this.msg(p.txt.tags("The player \"

"+name+"\" could not be found.")); + this.sendMessage(p.txt.tags("The player \"

"+name+"\" could not be found.")); } return ret; @@ -409,7 +409,7 @@ public abstract class MCommand if (msg && ret == null) { // TODO: Fix this injection risk! - this.msg(p.txt.tags("No player match found for \"

"+name+"\".")); + this.sendMessage(p.txt.tags("No player match found for \"

"+name+"\".")); } return ret;