From 1636708cef382ad0cd172421940fb39058ff28ac Mon Sep 17 00:00:00 2001 From: drtshock Date: Wed, 28 Jan 2015 10:13:23 -0600 Subject: [PATCH] Adds DTR freeze functionality from #229. --- .../java/com/massivecraft/factions/Faction.java | 4 ++++ .../factions/zcore/persist/MemoryFPlayer.java | 5 +++++ .../factions/zcore/persist/MemoryFaction.java | 14 ++++++++++++++ src/main/resources/config.yml | 8 +++++++- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 7ed6ab80..78325b37 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -111,6 +111,10 @@ public interface Faction extends EconomyParticipator { public boolean isPlayerFreeType(); + public boolean isPowerFrozen(); + + public void setLastDeath(long time); + // ------------------------------- // Relation and relation colors // ------------------------------- diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java index 9a2910f1..1d55a493 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFPlayer.java @@ -486,6 +486,8 @@ public abstract class MemoryFPlayer implements FPlayer { if (!Conf.powerRegenOffline) { return; } + } else if (hasFaction() && getFaction().isPowerFrozen()) { + return; // Don't let power regen if faction power is frozen. } long now = System.currentTimeMillis(); long millisPassed = now - this.lastPowerUpdateTime; @@ -517,6 +519,9 @@ public abstract class MemoryFPlayer implements FPlayer { public void onDeath() { this.updatePower(); this.alterPower(-Conf.powerPerDeath); + if (hasFaction()) { + getFaction().setLastDeath(System.currentTimeMillis()); + } } //----------------------------------------------// diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index b12c5ebb..9ddcb634 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -40,6 +40,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { protected Set invites = new HashSet(); protected HashMap> announcements = new HashMap>(); protected ConcurrentHashMap warps = new ConcurrentHashMap(); + protected long lastDeath; public HashMap> getAnnouncements() { return this.announcements; @@ -247,6 +248,19 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { this.powerBoost = powerBoost; } + public boolean isPowerFrozen() { + int freezeSeconds = P.p.getConfig().getInt("hcf.powerfreeze", 0); + if (freezeSeconds == 0) { + return false; + } + + return System.currentTimeMillis() - lastDeath < freezeSeconds * 1000; + } + + public void setLastDeath(long time) { + this.lastDeath = time; + } + // -------------------------------------------- // // Construct // -------------------------------------------- // diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index bd5e3caa..ae36aeb5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -182,4 +182,10 @@ hcf: # Should we allow Factions to over claim if they are raidable (above has no effect on this)? # This has always been true, allowing factions to over claim others. - overclaim: true \ No newline at end of file + overclaim: true + + # Power Freeze + # After a player dies, how long should the faction not be able to regen power? + # This resets on each death but does not accumulate. + # Set to 0 for no freeze. Time is in seconds. + powerfreeze: 0 \ No newline at end of file