From b88430a628810422315b173575c83da1583105de Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 11 Mar 2012 13:36:03 -0500 Subject: [PATCH 1/2] New setting "playersWhoBypassAllProtection" (default empty), which is a list of player names that should always bypass normal faction protections such as block destruction and placement. This is primarily for use with other plugins/mods which use a fake player to take action, which shouldn't necessarily be subject to protections provided by Factions. Note that case is important; you must preserve the exact capitalization of the name. As with every other setting, you are advised to use /f config to modify it. Example: /f config playersWhoBypassAllProtection fakePluginPlayerName - add/remove the specified player name Also switched several HashSets in Conf.java to LinkedHashSets. LinkedHashSets do have slower insertion and deletion than HashSets, but importantly they have faster lookup speed (at least until you get up to several hundred entries). --- src/com/massivecraft/factions/Conf.java | 19 +++++++++++-------- .../listeners/FactionsBlockListener.java | 4 +++- .../listeners/FactionsEntityListener.java | 4 +++- .../listeners/FactionsPlayerListener.java | 13 ++++++++----- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 9ed968c6..fdf6e7ee 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -135,11 +135,11 @@ public class Conf public static int actionDeniedPainAmount = 2; // commands which will be prevented if the player is a member of a permanent faction - public static Set permanentFactionMemberDenyCommands = new HashSet(); + public static Set permanentFactionMemberDenyCommands = new LinkedHashSet(); // commands which will be prevented when in claimed territory of another faction - public static Set territoryNeutralDenyCommands = new HashSet(); - public static Set territoryEnemyDenyCommands = new HashSet(); + public static Set territoryNeutralDenyCommands = new LinkedHashSet(); + public static Set territoryEnemyDenyCommands = new LinkedHashSet(); public static double territoryShieldFactor = 0.3; @@ -211,12 +211,15 @@ public class Conf //public static boolean bankMembersCanWithdraw = false; //Have to be at least moderator to withdraw or pay money to another faction public static boolean bankFactionPaysCosts = true; //The faction pays for faction command costs, such as sethome public static boolean bankFactionPaysLandCosts = true; //The faction pays for land claiming costs. - - public static Set worldsNoClaiming = new HashSet(); - public static Set worldsNoPowerLoss = new HashSet(); - public static Set worldsIgnorePvP = new HashSet(); + + // mainly for other plugins/mods that use a fake player to take actions, which shouldn't be subject to our protections + public static Set playersWhoBypassAllProtection = new LinkedHashSet(); + + public static Set worldsNoClaiming = new LinkedHashSet(); + public static Set worldsNoPowerLoss = new LinkedHashSet(); + public static Set worldsIgnorePvP = new LinkedHashSet(); // TODO: A better solution Would be to have One wilderness faction per world. - //public static Set worldsNoWildernessProtection = new HashSet(); + //public static Set worldsNoWildernessProtection = new LinkedHashSet(); public static transient int mapHeight = 8; public static transient int mapWidth = 39; diff --git a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java index aa89f8f5..aa2174b6 100644 --- a/src/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -59,8 +59,10 @@ public class FactionsBlockListener implements Listener public static boolean playerCanBuildDestroyBlock(Player player, Block block, String action, boolean justCheck) { - FPlayer me = FPlayers.i.get(player); + String name = player.getName(); + if (Conf.playersWhoBypassAllProtection.contains(name)) return true; + FPlayer me = FPlayers.i.get(name); if (me.hasAdminMode()) return true; Location location = block.getLocation(); diff --git a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java index 281938c1..f02a744e 100644 --- a/src/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -222,7 +222,9 @@ public class FactionsEntityListener implements Listener if (attacker == null || attacker.getPlayer() == null) return true; - + + if (Conf.playersWhoBypassAllProtection.contains(attacker.getName())) return true; + if (attacker.hasLoginPvpDisabled()) { if (notify) attacker.msg("You can't hurt other players for " + Conf.noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in."); diff --git a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java index ffb299cd..85958dc0 100644 --- a/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -33,9 +33,6 @@ import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.VisualizeUtil; -import java.util.logging.Level; - - public class FactionsPlayerListener implements Listener { @@ -170,14 +167,20 @@ public class FactionsPlayerListener implements Listener // TODO: Possibly incorporate pain build... public static boolean playerCanUseItemHere(Player player, Location loc, Material material, boolean justCheck) { - FPlayer me = FPlayers.i.get(player); + String name = player.getName(); + if (Conf.playersWhoBypassAllProtection.contains(name)) return true; + + FPlayer me = FPlayers.i.get(name); if (me.hasAdminMode()) return true; if (Conf.materialsEditTools.contains(material) && ! FPerm.BUILD.has(me, loc, ! justCheck)) return false; return true; } public static boolean canPlayerUseBlock(Player player, Block block, boolean justCheck) { - FPlayer me = FPlayers.i.get(player); + String name = player.getName(); + if (Conf.playersWhoBypassAllProtection.contains(name)) return true; + + FPlayer me = FPlayers.i.get(name); if (me.hasAdminMode()) return true; Location loc = block.getLocation(); Material material = block.getType(); From fbdc0503ba2bf395d08edd71fc0f72a35aecacf3 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Sun, 11 Mar 2012 22:44:38 -0500 Subject: [PATCH 2/2] Fix for "econClaimUnconnectedFee" not working correctly --- src/com/massivecraft/factions/FPlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index e000c5f0..e4fe7ccb 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -641,7 +641,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator { double cost = Econ.calculateClaimCost(ownedLand, currentFaction.isNormal()); - if (Conf.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, currentFaction)) + if (Conf.econClaimUnconnectedFee != 0.0 && forFaction.getLandRoundedInWorld(flocation.getWorldName()) > 0 && !Board.isConnectedLocation(flocation, forFaction)) cost += Conf.econClaimUnconnectedFee; if(Conf.bankEnabled && Conf.bankFactionPaysLandCosts && this.hasFaction())