From 1909e0e7640a75b2ca9e1d82461a23a819acf5ae Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Mon, 7 Jul 2014 22:52:33 -0400 Subject: [PATCH] Make Avatar State less broken Avatar State is now highly configurable: You can now turn potion effects on / off as well as configure the power of the effect (the potion level). --- .../ProjectKorra/Ability/AvatarState.java | 56 +++++++++++++++---- .../ProjectKorra/ConfigManager.java | 7 +++ src/config.yml | 14 +++++ 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/com/projectkorra/ProjectKorra/Ability/AvatarState.java b/src/com/projectkorra/ProjectKorra/Ability/AvatarState.java index 1677c7c9..39b56f6d 100644 --- a/src/com/projectkorra/ProjectKorra/Ability/AvatarState.java +++ b/src/com/projectkorra/ProjectKorra/Ability/AvatarState.java @@ -1,18 +1,34 @@ package com.projectkorra.ProjectKorra.Ability; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import com.projectkorra.ProjectKorra.Flight; import com.projectkorra.ProjectKorra.Methods; +import com.projectkorra.ProjectKorra.ProjectKorra; public class AvatarState { public static ConcurrentHashMap instances = new ConcurrentHashMap(); + public static Map cooldowns = new HashMap(); + + public static FileConfiguration config = ProjectKorra.plugin.getConfig(); + private static final long cooldown = ProjectKorra.plugin.getConfig().getLong("Abilities.AvatarState.Cooldown"); + private static boolean regenEnabled = config.getBoolean("Abilities.AvatarState.PotionEffects.Regeneration.Enabled"); + private static int regenPower = config.getInt("Abilities.AvatarState.PotionEffects.Regeneration.Power") - 1; + private static boolean speedEnabled = config.getBoolean("Abilities.AvatarState.PotionEffects.Speed..Enabled"); + private static int speedPower = config.getInt("Abilities.AvatarState.Potioneffects.Speed.Power") - 1; + private static boolean resistanceEnabled = config.getBoolean("Abilities.AvatarState.PotionEffects.DamageResistance.Enabled"); + private static int resistancePower = config.getInt("Abilities.AvatarState.PotionEffects.DamageResistance.Power") - 1; + private static boolean fireResistanceEnabled = config.getBoolean("Abilities.AvatarState.PotionEffects.FireResistance.Enabled"); + private static int fireResistancePower = config.getInt("Abilities.AvatarState.PotionEffects.FireResistance.Power") - 1; private static final double factor = 5; @@ -24,9 +40,19 @@ public class AvatarState { this.player = player; if (instances.containsKey(player)) { instances.remove(player); - } else { - new Flight(player); - instances.put(player, this); + return; + } + if (cooldowns.containsKey(player.getName())) { + if (cooldowns.get(player.getName()) + cooldown >= System.currentTimeMillis()) { + return; + } else { + cooldowns.remove(player.getName()); + } + } + new Flight(player); + instances.put(player, this); + if (cooldown != 0) { + cooldowns.put(player.getName(), System.currentTimeMillis()); } } @@ -51,14 +77,22 @@ public class AvatarState { private void addPotionEffects() { int duration = 70; - player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, - duration, 3)); - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, - duration, 2)); - player.addPotionEffect(new PotionEffect( - PotionEffectType.DAMAGE_RESISTANCE, duration, 2)); - player.addPotionEffect(new PotionEffect( - PotionEffectType.FIRE_RESISTANCE, duration, 2)); + if (regenEnabled) { + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, + duration, regenPower)); + } + if (speedEnabled) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, + duration, speedPower)); + } + if (resistanceEnabled) { + player.addPotionEffect(new PotionEffect( + PotionEffectType.DAMAGE_RESISTANCE, duration, resistancePower)); + } + if (fireResistanceEnabled) { + player.addPotionEffect(new PotionEffect( + PotionEffectType.FIRE_RESISTANCE, duration, fireResistancePower)); + } } public static boolean isAvatarState(Player player) { diff --git a/src/com/projectkorra/ProjectKorra/ConfigManager.java b/src/com/projectkorra/ProjectKorra/ConfigManager.java index b86b2d2f..48babf6c 100644 --- a/src/com/projectkorra/ProjectKorra/ConfigManager.java +++ b/src/com/projectkorra/ProjectKorra/ConfigManager.java @@ -80,6 +80,13 @@ public class ConfigManager { + "are incredibly amplified in this state. Additionally, AirShield and FireJet become toggle-able " + "abilities and last until you deactivate them or the Avatar State. Click again with the Avatar " + "State selected to deactivate it."); + config.addDefault("Abilities.AvatarState.PotionEffects.Regeneration.Enabled", true); + config.addDefault("Abilities.AvatarState.PotionEffects.Regeneration.Power", 3); + config.addDefault("Abilities.AvatarState.PotionEffects.Speed.Enabled", true); + config.addDefault("Abilities.AvatarState.PotionEffects.Speed.Power", 3); + config.addDefault("Abilities.AvatarState.PotionEffects.DamageResistance.Enabled", true); + config.addDefault("Abilities.AvatarState.PotionEffects.FireResistance.Enabled", true); + config.addDefault("Abilities.AvatarState.PotionEffects.FireResistance.Power", 3); plugin.getConfig().addDefault("Abilities.Air.Passive.Factor", 0.3); plugin.getConfig().addDefault("Abilities.Air.Passive.Speed", 2); diff --git a/src/config.yml b/src/config.yml index 6d386c47..535c9cbf 100644 --- a/src/config.yml +++ b/src/config.yml @@ -58,6 +58,20 @@ Abilities: AvatarState: Enabled: true Description: "The signature ability of the Avatar, this is a toggle. Click to activate to become nearly unstoppable. While in the Avatar State, the user takes severely reduced damage from all sources, regenreates health rapidly, and is granted extreme speed. Nearly all abilities are incredibly amplified in this state. Additionally, AirShield and FireJet become toggle-able abilities and last until you deactivate them or the Avatar State. Click again with the Avatar State selected to deactivate it." + Cooldown: 720000 + PotionEffects: + Regeneration: + Enabled: true + Power: 3 + Speed: + Enabled: true + Power: 3 + DamageResistance: + Enabled: true + Power: 3 + FireResistance: + Enabled: true + Power: 3 Air: Passive: Factor: 0.3