From 87032ad4f7d4eb43845f08514f6b334a91529282 Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Thu, 26 Jun 2014 19:46:59 -0400 Subject: [PATCH] HealingWaters Waterbending finished ^^ --- .../ProjectKorra/BendingManager.java | 2 + .../ProjectKorra/ConfigManager.java | 12 ++- .../waterbending/HealingWaters.java | 99 +++++++++++++++++++ src/config.yml | 7 +- 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 src/com/projectkorra/ProjectKorra/waterbending/HealingWaters.java diff --git a/src/com/projectkorra/ProjectKorra/BendingManager.java b/src/com/projectkorra/ProjectKorra/BendingManager.java index f8b12f27..acf8daec 100644 --- a/src/com/projectkorra/ProjectKorra/BendingManager.java +++ b/src/com/projectkorra/ProjectKorra/BendingManager.java @@ -38,6 +38,7 @@ import com.projectkorra.ProjectKorra.firebending.Fireball; import com.projectkorra.ProjectKorra.firebending.Illumination; import com.projectkorra.ProjectKorra.waterbending.Bloodbending; import com.projectkorra.ProjectKorra.waterbending.FreezeMelt; +import com.projectkorra.ProjectKorra.waterbending.HealingWaters; import com.projectkorra.ProjectKorra.waterbending.IceSpike; import com.projectkorra.ProjectKorra.waterbending.IceSpike2; import com.projectkorra.ProjectKorra.waterbending.OctopusForm; @@ -103,6 +104,7 @@ public class BendingManager implements Runnable { FireBlast.progressAll(); AirSuction.progressAll(); Fireball.progressAll(); + HealingWaters.heal(Bukkit.getServer()); for (int ID: AirSwipe.instances.keySet()) { AirSwipe.progress(ID); } diff --git a/src/com/projectkorra/ProjectKorra/ConfigManager.java b/src/com/projectkorra/ProjectKorra/ConfigManager.java index ad2a1572..4663311a 100644 --- a/src/com/projectkorra/ProjectKorra/ConfigManager.java +++ b/src/com/projectkorra/ProjectKorra/ConfigManager.java @@ -136,7 +136,7 @@ public class ConfigManager { config.addDefault("Abilities.Air.AirSwipe.Push", 1); config.addDefault("Abilities.Air.AirSwipe.Arc", 20); config.addDefault("Abilities.Air.AirSwipe.Speed", 25); - + config.addDefault("Abilities.Air.Tornado.Radius", 10); config.addDefault("Abilities.Air.Tornado.Height", 25); config.addDefault("Abilities.Air.Tornado.Range", 25); @@ -155,6 +155,16 @@ public class ConfigManager { config.addDefault("Abilities.Water.Bloodbending.ThrowFactor", 2); config.addDefault("Abilities.Water.Bloodbending.Range", 10); + config.addDefault("Abilities.Water.HealingWaters.Enabled", true); + config.addDefault("Abilities.Water.HealingWaters.Description", "To use, the bender must be at least partially submerged in water. " + + "If the user is not sneaking, this ability will automatically begin " + + "working provided the user has it selected. If the user is sneaking, " + + "he/she is channeling the healing to their target in front of them. " + + "In order for this channel to be successful, the user and the target must " + + "be at least partially submerged in water."); + config.addDefault("Abilities.Water.HealingWaters.Radius", 5); + config.addDefault("Abilities.Water.HealingWaters.Interval", 750); + config.addDefault("Abilities.Water.IceSpike.Enabled", true); config.addDefault("Abilities.Water.IceSpike.Description", "This ability has many functions. Clicking while targetting ice, or an entity over some ice, " + "will raise a spike of ice up, damaging and slowing the target. Tapping sneak (shift) while" diff --git a/src/com/projectkorra/ProjectKorra/waterbending/HealingWaters.java b/src/com/projectkorra/ProjectKorra/waterbending/HealingWaters.java new file mode 100644 index 00000000..d45dccaa --- /dev/null +++ b/src/com/projectkorra/ProjectKorra/waterbending/HealingWaters.java @@ -0,0 +1,99 @@ +package com.projectkorra.ProjectKorra.waterbending; + +import java.util.ArrayList; + +import org.bukkit.Server; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.projectkorra.ProjectKorra.Methods; +import com.projectkorra.ProjectKorra.ProjectKorra; +import com.projectkorra.ProjectKorra.TempBlock; + +public class HealingWaters { + + private static final double range = ProjectKorra.plugin.getConfig().getDouble("Abilities.Water.HealingWaters.Radius"); + private static final long interval = ProjectKorra.plugin.getConfig().getLong("Abilities.Water.HealingWaters.Interval"); + + private static long time = 0; + + public static void heal(Server server) { + if (System.currentTimeMillis() - time >= interval) { + time = System.currentTimeMillis(); + for (Player player : server.getOnlinePlayers()) { + if (Methods.getBoundAbility(player) != null) { + if (Methods.getBoundAbility(player).equalsIgnoreCase("HealingWaters") && Methods.canBend(player.getName(),"HealingWaters")) { + heal(player); + } + } + } + } + } + + private static void heal(Player player) { + if (inWater(player)) { + if (player.isSneaking()) { + Entity entity = Methods.getTargetedEntity(player, range, new ArrayList()); + if (entity instanceof LivingEntity && inWater(entity)) { + giveHPToEntity((LivingEntity) entity); + } + } else { + giveHP(player); + } + } + } + + private static void giveHPToEntity(LivingEntity le) { + if (!le.isDead() && le.getHealth() < le.getMaxHealth()) { + applyHealingToEntity(le); + } + } + + private static void giveHP(Player player) { + if (!player.isDead() && player.getHealth() < 20) { + // int hp = player.getHealth(); + // if (hp < 20) { + // hp++; + // } + // player.setHealth(hp); + applyHealing(player); + } + } + + + + private static boolean inWater(Entity entity) { + Block block = entity.getLocation().getBlock(); + if (Methods.isWater(block) && !TempBlock.isTempBlock(block)) + return true; + // if (entity.getLocation().getBlock().getType() == Material.WATER + // || entity.getLocation().getBlock().getType() == + // Material.STATIONARY_WATER) && + // return true; + return false; + } + + private static void applyHealing(Player player) { +// if (!Methods.isRegionProtectedFromBuild(player, Abilities.HealingWaters, +// player.getLocation())) + player.addPotionEffect(new PotionEffect( + PotionEffectType.REGENERATION, 70, 1)); + } + + private static void applyHealingToEntity(LivingEntity le) { + le.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 70, 1)); + } + + public static String getDescription() { + return "To use, the bender must be at least partially submerged in water. " + + "If the user is not sneaking, this ability will automatically begin " + + "working provided the user has it selected. If the user is sneaking, " + + "he/she is channeling the healing to their target in front of them. " + + "In order for this channel to be successful, the user and the target must " + + "be at least partially submerged in water."; + } +} \ No newline at end of file diff --git a/src/config.yml b/src/config.yml index 4b491055..44431089 100644 --- a/src/config.yml +++ b/src/config.yml @@ -99,9 +99,14 @@ Abilities: SwimSpeedFactor: 0.7 Bloodbending: Enabled: true - Description: "This ability was made illegal for a reason. With this ability selected, sneak while targeting something and you will bloodbend that target. Bloodbent targets cannot move, bend, or attack. You are free to control their actions by looking elsewhere - they will be forced to move in that direciton. Additionally, clicking while bloodbending will launch that target off in the direction you're looking. People who are capable of bloodbending are immune to technique, and you are immune to theirs." + Description: "This ability was made illegal for a reason. With this ability selected, sneak while targeting something and you will bloodbend that target. Bloodbent targets cannot move, bend, or attack. You are free to control their actions by looking elsewhere - they will be forced to move in that direction. Additionally, clicking while bloodbending will launch that target off in the direction you're looking. People who are capable of bloodbending are immune to technique, and you are immune to theirs." ThrowFactor: 2 Range: 10 + HealingWaters: + Enabled: true + Description: "To use, the bender must be at least partially submerged in water. If the user is not sneaking, this ability will automatically begin working provided the user has it selected. If the user is sneaking, he/she is channeling the healing to their target in front of them. In order for this channel to be successful, the user and the target must be at least partially submerged in water." + Radius: 5 + Interval: 750 IceSpike: Enabled: true Description: "This ability has many functions. Clicking while targetting ice, or an entity over some ice, will raise a spike of ice up, damaging and slowing the target. Tapping sneak (default: shift) while selecting a water source will select that source that can be fired with a click. Firing this will launch a spike of ice at your target, dealing a bit of damage and slowing the target. If you sneak (shift) will not selecting a source, many ice spikes will erupt from around you, damaging and slowing those targets."