From 83767dc275421c20eda256c1865626d9dc927ca8 Mon Sep 17 00:00:00 2001 From: Mark Hughes Date: Fri, 1 Jul 2016 11:52:10 +1000 Subject: [PATCH] Adds powergain flag and worldsPowerGainDisabled config option. See #526 --- .../massivecraft/factions/entity/MConf.java | 2 ++ .../massivecraft/factions/entity/MFlag.java | 24 +++++++++++-------- .../factions/task/TaskPlayerPowerUpdate.java | 13 ++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index a87ac3d5..61ca860d 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -64,6 +64,8 @@ public class MConf extends Entity // In such case set standard to false and add "Hurr" as an exeption to worldsClaimingEnabled. public WorldExceptionSet worldsClaimingEnabled = new WorldExceptionSet(); public WorldExceptionSet worldsPowerLossEnabled = new WorldExceptionSet(); + public WorldExceptionSet worldsPowerGainEnabled = new WorldExceptionSet(); + public WorldExceptionSet worldsPvpRulesEnabled = new WorldExceptionSet(); // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/entity/MFlag.java b/src/com/massivecraft/factions/entity/MFlag.java index 1bfd2b96..42de06e6 100644 --- a/src/com/massivecraft/factions/entity/MFlag.java +++ b/src/com/massivecraft/factions/entity/MFlag.java @@ -22,6 +22,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N public final static transient String ID_MONSTERS = "monsters"; public final static transient String ID_ANIMALS = "animals"; public final static transient String ID_POWERLOSS = "powerloss"; + public final static transient String ID_POWERGAIN = "powergain"; public final static transient String ID_PVP = "pvp"; public final static transient String ID_FRIENDLYFIRE = "friendlyfire"; public final static transient String ID_EXPLOSIONS = "explosions"; @@ -37,16 +38,17 @@ public class MFlag extends Entity implements Prioritized, Registerable, N public final static transient int PRIORITY_MONSTERS = 2_000; public final static transient int PRIORITY_ANIMALS = 3_000; public final static transient int PRIORITY_POWERLOSS = 4_000; - public final static transient int PRIORITY_PVP = 5_000; - public final static transient int PRIORITY_FRIENDLYFIRE = 6_000; - public final static transient int PRIORITY_EXPLOSIONS = 7_000; - public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 8_000; - public final static transient int PRIORITY_FIRESPREAD = 9_000; - public final static transient int PRIORITY_ENDERGRIEF = 10_000; - public final static transient int PRIORITY_ZOMBIEGRIEF = 11_000; - public final static transient int PRIORITY_PERMANENT = 12_000; - public final static transient int PRIORITY_PEACEFUL = 13_000; - public final static transient int PRIORITY_INFPOWER = 14_000; + public final static transient int PRIORITY_POWERGAIN = 5_000; + public final static transient int PRIORITY_PVP = 6_000; + public final static transient int PRIORITY_FRIENDLYFIRE = 7_000; + public final static transient int PRIORITY_EXPLOSIONS = 8_000; + public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 9_000; + public final static transient int PRIORITY_FIRESPREAD = 10_000; + public final static transient int PRIORITY_ENDERGRIEF = 11_000; + public final static transient int PRIORITY_ZOMBIEGRIEF = 12_000; + public final static transient int PRIORITY_PERMANENT = 13_000; + public final static transient int PRIORITY_PEACEFUL = 14_000; + public final static transient int PRIORITY_INFPOWER = 15_000; // -------------------------------------------- // // META: CORE @@ -75,6 +77,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N getFlagMonsters(); getFlagAnimals(); getFlagPowerloss(); + getFlagPowergain(); getFlagPvp(); getFlagFriendlyire(); getFlagExplosions(); @@ -91,6 +94,7 @@ public class MFlag extends Entity implements Prioritized, Registerable, N public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); } public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); } public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); } + public static MFlag getFlagPowergain() { return getCreative(PRIORITY_POWERGAIN, ID_POWERGAIN, ID_POWERGAIN, "Can power be gained in this territory?", "Power can be gained in this territory.", "Power is NOT gained in this territory.", true, false, true); } public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); } public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); } public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); } diff --git a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java index 9d3f9d2a..ef4fa604 100644 --- a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java +++ b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java @@ -1,11 +1,16 @@ package com.massivecraft.factions.task; import org.bukkit.entity.Player; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.event.EventFactionsPowerChange; import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; import com.massivecraft.massivecore.ModuloRepeatTask; +import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.TimeUnit; @@ -44,6 +49,14 @@ public class TaskPlayerPowerUpdate extends ModuloRepeatTask if (MUtil.isntPlayer(player)) continue; if (player.isDead()) continue; + // Check the powergain flag is not disabled + Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player.getLocation())); + + if ( ! faction.getFlag(MFlag.getFlagPowergain())) return; + + // Check power gain has not been disabled in this world + if ( ! MConf.get().worldsPowerGainEnabled.contains(player)) return; + MPlayer mplayer = MPlayer.get(player); double newPower = mplayer.getPower() + mplayer.getPowerPerHour() * millis / TimeUnit.MILLIS_PER_HOUR;