diff --git a/src/com/projectkorra/projectkorra/ProjectKorra.java b/src/com/projectkorra/projectkorra/ProjectKorra.java index ae230225..3c5573ad 100644 --- a/src/com/projectkorra/projectkorra/ProjectKorra.java +++ b/src/com/projectkorra/projectkorra/ProjectKorra.java @@ -1,13 +1,5 @@ package com.projectkorra.projectkorra; -import java.io.File; -import java.io.IOException; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - import com.bekvon.bukkit.residence.protection.FlagPermissions; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.util.ComboManager; @@ -21,11 +13,20 @@ import com.projectkorra.projectkorra.firebending.FirebendingManager; import com.projectkorra.projectkorra.object.Preset; import com.projectkorra.projectkorra.storage.DBConnection; import com.projectkorra.projectkorra.util.MetricsLite; +import com.projectkorra.projectkorra.util.PassiveHandler; import com.projectkorra.projectkorra.util.RevertChecker; import com.projectkorra.projectkorra.util.Updater; import com.projectkorra.projectkorra.util.logging.PKLogHandler; import com.projectkorra.projectkorra.waterbending.WaterbendingManager; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.io.IOException; +import java.util.logging.Logger; + public class ProjectKorra extends JavaPlugin { public static ProjectKorra plugin; @@ -78,6 +79,7 @@ public class ProjectKorra extends JavaPlugin { getServer().getScheduler().scheduleSyncRepeatingTask(this, new EarthbendingManager(this), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new FirebendingManager(this), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1); + getServer().getScheduler().scheduleSyncRepeatingTask(this, new PassiveHandler(), 0, 1); getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200); for (Player player : Bukkit.getOnlinePlayers()) { diff --git a/src/com/projectkorra/projectkorra/airbending/AirPassive.java b/src/com/projectkorra/projectkorra/airbending/AirPassive.java index eca629af..fe8b39ed 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirPassive.java +++ b/src/com/projectkorra/projectkorra/airbending/AirPassive.java @@ -1,74 +1,11 @@ package com.projectkorra.projectkorra.airbending; -import java.util.concurrent.ConcurrentHashMap; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.Element; -import com.projectkorra.projectkorra.chiblocking.ChiPassive; import com.projectkorra.projectkorra.configuration.ConfigManager; public class AirPassive { - - private static final ConcurrentHashMap FOOD = new ConcurrentHashMap<>(); - - public static float getExhaustion(Player player, float level) { - if (!FOOD.keySet().contains(player)) { - FOOD.put(player, level); - return level; - } else { - float oldlevel = FOOD.get(player); - if (level < oldlevel) { - level = 0; - } else { - double factor = getFactor(); - level = (float) ((level - oldlevel) * factor + oldlevel); - } - FOOD.replace(player, level); - return level; - } - } - - public static void handlePassive() { - int speedPower = 0; - int jumpPower = 0; - - for (Player player : Bukkit.getOnlinePlayers()) { - BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer == null) { - continue; - } - - if (bPlayer.canBendPassive(Element.AIR)) { - if (bPlayer.canBendPassive(Element.CHI)) { - if (ChiPassive.getJumpPower() > getJumpPower()) { - jumpPower = ChiPassive.getJumpPower(); - } else { - jumpPower = getJumpPower(); - } - - if (ChiPassive.getSpeedPower() > getSpeedPower()) { - speedPower = ChiPassive.getSpeedPower(); - } else { - speedPower = getSpeedPower(); - } - } - player.setExhaustion(getExhaustion(player, player.getExhaustion())); - - if (player.isSprinting()) { - if (!player.hasPotionEffect(PotionEffectType.SPEED)) { - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, speedPower)); - } - if (!player.hasPotionEffect(PotionEffectType.JUMP)) { - player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, jumpPower)); - } - } - } - } + + public static double getExhaustionFactor() { + return getFactor(); } public static double getFactor() { diff --git a/src/com/projectkorra/projectkorra/airbending/AirbendingManager.java b/src/com/projectkorra/projectkorra/airbending/AirbendingManager.java index 3fc97ef7..d18e3859 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirbendingManager.java +++ b/src/com/projectkorra/projectkorra/airbending/AirbendingManager.java @@ -13,7 +13,6 @@ public class AirbendingManager implements Runnable { @Override public void run() { AirBlast.progressOrigins(); - AirPassive.handlePassive(); AirBubble.handleBubbles(); AirSuction.progressOrigins(); } diff --git a/src/com/projectkorra/projectkorra/chiblocking/ChiPassive.java b/src/com/projectkorra/projectkorra/chiblocking/ChiPassive.java index 8a49bce0..feabc64c 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/ChiPassive.java +++ b/src/com/projectkorra/projectkorra/chiblocking/ChiPassive.java @@ -1,18 +1,14 @@ package com.projectkorra.projectkorra.chiblocking; import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.ability.ChiAbility; import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.airbending.AirPassive; import com.projectkorra.projectkorra.airbending.Suffocate; import com.projectkorra.projectkorra.configuration.ConfigManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; public class ChiPassive { @@ -64,44 +60,10 @@ public class ChiPassive { }, getTicks()); } - public static void handlePassive() { - int speedPower = 0; - int jumpPower = 0; - - for (Player player : Bukkit.getOnlinePlayers()) { - BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer == null) { - continue; - } - - if (bPlayer.canBendPassive(Element.CHI)) { - if (bPlayer.canBendPassive(Element.AIR)) { - if (AirPassive.getJumpPower() > getJumpPower()) { - jumpPower = AirPassive.getJumpPower(); - } else { - jumpPower = getJumpPower(); - } - - if (AirPassive.getSpeedPower() > getSpeedPower()) { - speedPower = AirPassive.getSpeedPower(); - } else { - speedPower = getSpeedPower(); - } - } - ChiAbility stance = bPlayer.getStance(); - - if (player.isSprinting() && !(stance instanceof AcrobatStance)) { - if (!player.hasPotionEffect(PotionEffectType.SPEED)) { - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, speedPower)); - } - if (!player.hasPotionEffect(PotionEffectType.JUMP)) { - player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 60, jumpPower)); - } - } - } - } + public static double getExhaustionFactor() { + return ConfigManager.getConfig().getDouble("Abilities.Chi.Passive.ExhaustionFactor"); } - + public static double getFallReductionFactor() { return ConfigManager.getConfig().getDouble("Abilities.Chi.Passive.FallReductionFactor"); } diff --git a/src/com/projectkorra/projectkorra/chiblocking/ChiblockingManager.java b/src/com/projectkorra/projectkorra/chiblocking/ChiblockingManager.java index 4741754c..dbfba89a 100644 --- a/src/com/projectkorra/projectkorra/chiblocking/ChiblockingManager.java +++ b/src/com/projectkorra/projectkorra/chiblocking/ChiblockingManager.java @@ -3,7 +3,9 @@ package com.projectkorra.projectkorra.chiblocking; import com.projectkorra.projectkorra.ProjectKorra; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.util.Vector; public class ChiblockingManager implements Runnable { public ProjectKorra plugin; @@ -11,13 +13,15 @@ public class ChiblockingManager implements Runnable { public ChiblockingManager(ProjectKorra plugin) { this.plugin = plugin; } - + @Override public void run() { - ChiPassive.handlePassive(); for (Player player : Bukkit.getOnlinePlayers()) { Smokescreen.removeFromHashMap(player); if (Paralyze.isParalyzed(player)) { + if (player.getLocation().subtract(0, 0.1, 0).getBlock().getType().equals(Material.AIR)) { + player.setVelocity(new Vector(0, -0.4, 0)); + } player.setFallDistance(0F); } } diff --git a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java index c612d321..f05700b2 100644 --- a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java +++ b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java @@ -785,7 +785,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.WaterCombo.IceBullet.Cooldown", 10000); config.addDefault("Abilities.Earth.Passive.Duration", 2500); - config.addDefault("Properties.Earth.Passive.SandRunSpeed", 0); + config.addDefault("Abilities.Earth.Passive.SandRunSpeed", 2); config.addDefault("Abilities.Earth.Catapult.Enabled", true); config.addDefault("Abilities.Earth.Catapult.Length", 6); @@ -1052,6 +1052,7 @@ public class ConfigManager { config.addDefault("Abilities.Fire.FireCombo.JetBlaze.Cooldown", 6000); config.addDefault("Abilities.Fire.FireCombo.JetBlaze.FireTicks", 2.5); + config.addDefault("Abilities.Chi.Passive.ExhaustionFactor", 0.3); config.addDefault("Abilities.Chi.Passive.FallReductionFactor", 0.5); config.addDefault("Abilities.Chi.Passive.Speed", 1); config.addDefault("Abilities.Chi.Passive.Jump", 1); diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthPassive.java b/src/com/projectkorra/projectkorra/earthbending/EarthPassive.java index e49ba579..0e6a46da 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthPassive.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthPassive.java @@ -15,8 +15,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; import org.bukkit.material.MaterialData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import java.util.HashSet; import java.util.concurrent.ConcurrentHashMap; @@ -95,23 +93,6 @@ public class EarthPassive { } } - public static void sandSpeed() { - for (Player player : Bukkit.getOnlinePlayers()) { - BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - - if (bPlayer != null) { - if (bPlayer.canSandbend() && bPlayer.hasElement(Element.EARTH) - && !bPlayer.canBendPassive(Element.AIR) && !bPlayer.canBendPassive(Element.CHI)) { - if (player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.SAND - || player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.SANDSTONE - || player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.RED_SANDSTONE) { - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 60, getSandRunSpeed())); - } - } - } - } - } - @SuppressWarnings("deprecation") public static void handleMetalPassives() { for (Player player : Bukkit.getOnlinePlayers()) { @@ -203,6 +184,6 @@ public class EarthPassive { } public static int getSandRunSpeed() { - return ConfigManager.getConfig().getInt("Properties.Earth.Passive.SandRunSpeed"); + return ConfigManager.getConfig().getInt("Abilities.Earth.Passive.SandRunSpeed"); } } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java b/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java index 9e493581..edabc7d1 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthbendingManager.java @@ -16,7 +16,6 @@ public class EarthbendingManager implements Runnable { public void run() { EarthPassive.revertSands(); EarthPassive.handleMetalPassives(); - EarthPassive.sandSpeed(); RevertChecker.revertEarthBlocks(); Shockwave.progressAll(); Tremorsense.manage(Bukkit.getServer()); diff --git a/src/com/projectkorra/projectkorra/util/PassiveHandler.java b/src/com/projectkorra/projectkorra/util/PassiveHandler.java new file mode 100644 index 00000000..af8f7282 --- /dev/null +++ b/src/com/projectkorra/projectkorra/util/PassiveHandler.java @@ -0,0 +1,154 @@ +package com.projectkorra.projectkorra.util; + +import com.projectkorra.projectkorra.BendingPlayer; +import com.projectkorra.projectkorra.Element; +import com.projectkorra.projectkorra.Element.SubElement; +import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.airbending.AirPassive; +import com.projectkorra.projectkorra.chiblocking.AcrobatStance; +import com.projectkorra.projectkorra.chiblocking.ChiPassive; +import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.earthbending.EarthPassive; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.concurrent.ConcurrentHashMap; + +public class PassiveHandler implements Runnable{ + + private static final ConcurrentHashMap FOOD = new ConcurrentHashMap<>(); + + public static float getExhaustion(Player player, float level, double factor) { + if (!FOOD.keySet().contains(player)) { + FOOD.put(player, level); + return level; + } else { + float oldlevel = FOOD.get(player); + if (level < oldlevel) { + level = 0; + } else { + level = (float) ((level - oldlevel) * factor + oldlevel); + } + FOOD.replace(player, level); + return level; + } + } + + public static void handleSpeedPassives() { + int air = AirPassive.getSpeedPower(); + int chi = ChiPassive.getSpeedPower(); + int earth = EarthPassive.getSandRunSpeed(); + + for (Player player : Bukkit.getOnlinePlayers()) { + if (ConfigManager.defaultConfig.get().getStringList("Properties.DisabledWorlds").contains(player.getWorld().getName())) { + return; + } + + boolean sandbender = true; + BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); + + if (bPlayer == null) continue; + if (!bPlayer.hasElement(Element.EARTH)) sandbender = false; + if (!bPlayer.hasSubElement(SubElement.SAND)) sandbender = false; + if (!bPlayer.hasElement(Element.AIR)) air = 0; + if (!bPlayer.hasElement(Element.CHI)) chi = 0; + + int max = 0; + + if (sandbender && (player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.SAND + || player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.SANDSTONE + || player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.RED_SANDSTONE)) { + if (CoreAbility.hasAbility(player, AcrobatStance.class)) { + AcrobatStance abil = CoreAbility.getAbility(player, AcrobatStance.class); + max = Math.max(air, chi); + max = Math.max(max, abil.getSpeed()); + max = Math.max(max, earth); + } else { + max = Math.max(air, chi); + max = Math.max(max, earth); + } + } else { + if (CoreAbility.hasAbility(player, AcrobatStance.class)) { + AcrobatStance abil = CoreAbility.getAbility(player, AcrobatStance.class); + max = Math.max(air, chi); + max = Math.max(max, abil.getSpeed()); + } else { + max = Math.max(air, chi); + } + } + + if (max == 0) continue; + if (player.isSprinting()) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 3, max-1)); + } + } + } + + public static void handleJumpPassives() { + int air = AirPassive.getJumpPower(); + int chi = ChiPassive.getJumpPower(); + + for (Player player : Bukkit.getOnlinePlayers()) { + if (ConfigManager.defaultConfig.get().getStringList("Properties.DisabledWorlds").contains(player.getWorld().getName())) { + return; + } + + BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); + + if (bPlayer == null) continue; + if (!bPlayer.hasElement(Element.AIR)) air = 0; + if (!bPlayer.hasElement(Element.CHI)) chi = 0; + int max = 0; + if (CoreAbility.hasAbility(player, AcrobatStance.class)) { + AcrobatStance abil = CoreAbility.getAbility(player, AcrobatStance.class); + max = Math.max(air, chi); + max = Math.max(max, abil.getSpeed()); + } else { + max = Math.max(air, chi); + if (max == 0) { + continue; + } + } + + if (player.isSprinting()) { + player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 3, max-1), false); + } + } + } + + public static void handleExhaustionPassives() { + double air = AirPassive.getExhaustionFactor(); + double chi = ChiPassive.getExhaustionFactor(); + + for (Player player : Bukkit.getOnlinePlayers()) { + if (ConfigManager.defaultConfig.get().getStringList("Properties.DisabledWorlds").contains(player.getWorld().getName())) { + return; + } + + BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); + + if (bPlayer == null) continue; + + if (!bPlayer.hasElement(Element.AIR)) air = 0; + if (!bPlayer.hasElement(Element.CHI)) chi = 0; + + double max = Math.max(air, chi); + if (max == 0) continue; + else { + player.setExhaustion(getExhaustion(player, player.getExhaustion(), max)); + } + } + } + + @Override + public void run() { + handleSpeedPassives(); + handleJumpPassives(); + handleExhaustionPassives(); + } +}