From 094486676a63eee1b0e27fdacd81928b6c1a762e Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 22 Jun 2011 20:10:42 -0500 Subject: [PATCH] Added conf.json option "noPVPDamageToOthersForXSecondsAfterLogin" (defaults to 3 seconds) which keeps players from being able to do PvP damage for a few seconds after logging in (to counteract the exploitable 3-second PvP protection given to players when they log in); Fix for "claimsMustBeConnected" bug which prevented factions from making their initial first claim --- src/org/mcteam/factions/Conf.java | 1 + src/org/mcteam/factions/FPlayer.java | 18 +++++++++++++++++- .../listeners/FactionsEntityListener.java | 5 +++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/org/mcteam/factions/Conf.java b/src/org/mcteam/factions/Conf.java index f6043f68..e79525c5 100644 --- a/src/org/mcteam/factions/Conf.java +++ b/src/org/mcteam/factions/Conf.java @@ -67,6 +67,7 @@ public class Conf { public static double homesTeleportAllowedEnemyDistance = 32; public static boolean disablePVPForFactionlessPlayers = false; + public static int noPVPDamageToOthersForXSecondsAfterLogin = 3; public static boolean claimsMustBeConnected = false; diff --git a/src/org/mcteam/factions/FPlayer.java b/src/org/mcteam/factions/FPlayer.java index 091fdef4..f9588161 100644 --- a/src/org/mcteam/factions/FPlayer.java +++ b/src/org/mcteam/factions/FPlayer.java @@ -47,6 +47,7 @@ public class FPlayer { private transient boolean autoClaimEnabled; private transient boolean autoSafeZoneEnabled; private transient boolean autoWarZoneEnabled; + private transient boolean loginPvpDisabled; private boolean factionChatting; // -------------------------------------------- // @@ -63,6 +64,7 @@ public class FPlayer { this.autoClaimEnabled = false; this.autoSafeZoneEnabled = false; this.autoWarZoneEnabled = false; + this.loginPvpDisabled = (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) ? true : false; } public void resetFactionData() { @@ -177,6 +179,9 @@ public class FPlayer { public void setLastLoginTime(long lastLoginTime) { this.lastLoginTime = lastLoginTime; this.lastPowerUpdateTime = lastLoginTime; + if (Conf.noPVPDamageToOthersForXSecondsAfterLogin > 0) { + this.loginPvpDisabled = true; + } } public boolean isMapAutoUpdating() { @@ -186,6 +191,17 @@ public class FPlayer { public void setMapAutoUpdating(boolean mapAutoUpdating) { this.mapAutoUpdating = mapAutoUpdating; } + + public boolean hasLoginPvpDisabled() { + if (!loginPvpDisabled) { + return false; + } + if (this.lastLoginTime + (Conf.noPVPDamageToOthersForXSecondsAfterLogin * 1000) < System.currentTimeMillis()) { + this.loginPvpDisabled = false; + return false; + } + return true; + } public FLocation getLastStoodAt() { return this.lastStoodAt; @@ -490,7 +506,7 @@ public class FPlayer { return false; } - if (Conf.claimsMustBeConnected && !Board.isConnectedLocation(flocation, myFaction)) { + if (Conf.claimsMustBeConnected && myFaction.getLandRounded() > 0 && !Board.isConnectedLocation(flocation, myFaction)) { sendMessage("You can only claim additional land which is connected to your first claim!"); return false; } diff --git a/src/org/mcteam/factions/listeners/FactionsEntityListener.java b/src/org/mcteam/factions/listeners/FactionsEntityListener.java index ad1e8ddc..53b54956 100644 --- a/src/org/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/org/mcteam/factions/listeners/FactionsEntityListener.java @@ -169,6 +169,11 @@ public class FactionsEntityListener extends EntityListener { return false; } + if (attacker.hasLoginPvpDisabled()) { + attacker.sendMessage("You can't hurt other players for " + Conf.noPVPDamageToOthersForXSecondsAfterLogin + " seconds after logging in."); + return false; + } + Faction locFaction = Board.getFactionAt(new FLocation(attacker)); // so we know from above that the defender isn't in a safezone... what about the attacker, sneaky dog that he might be?