From d941a74564a1ec268c8e43b8ca1d6002a206d5f5 Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Wed, 25 Jun 2014 23:12:42 -0400 Subject: [PATCH] Illumination --- .../ProjectKorra/BendingManager.java | 2 + .../ProjectKorra/ConfigManager.java | 13 +- .../projectkorra/ProjectKorra/PKListener.java | 4 + .../firebending/Illumination.java | 128 ++++++++++++++++++ src/config.yml | 4 + 5 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 src/com/projectkorra/ProjectKorra/firebending/Illumination.java diff --git a/src/com/projectkorra/ProjectKorra/BendingManager.java b/src/com/projectkorra/ProjectKorra/BendingManager.java index fb5e45ca..42198e8f 100644 --- a/src/com/projectkorra/ProjectKorra/BendingManager.java +++ b/src/com/projectkorra/ProjectKorra/BendingManager.java @@ -28,6 +28,7 @@ import com.projectkorra.ProjectKorra.firebending.Cook; import com.projectkorra.ProjectKorra.firebending.FireJet; import com.projectkorra.ProjectKorra.firebending.FirePassive; import com.projectkorra.ProjectKorra.firebending.FireStream; +import com.projectkorra.ProjectKorra.firebending.Illumination; import com.projectkorra.ProjectKorra.waterbending.Bloodbending; import com.projectkorra.ProjectKorra.waterbending.FreezeMelt; import com.projectkorra.ProjectKorra.waterbending.OctopusForm; @@ -83,6 +84,7 @@ public class BendingManager implements Runnable { FreezeMelt.handleFrozenBlocks(); OctopusForm.progressAll(); AirBubble.handleBubbles(Bukkit.getServer()); + Illumination.manage(Bukkit.getServer()); for (int ID: Tornado.instances.keySet()) { Tornado.progress(ID); } diff --git a/src/com/projectkorra/ProjectKorra/ConfigManager.java b/src/com/projectkorra/ProjectKorra/ConfigManager.java index 90d008a2..d2d40032 100644 --- a/src/com/projectkorra/ProjectKorra/ConfigManager.java +++ b/src/com/projectkorra/ProjectKorra/ConfigManager.java @@ -76,6 +76,7 @@ public class ConfigManager { config.addDefault("Abilities.Air.AirBubble.Enabled", true); config.addDefault("Abilities.Air.AirBubble.Description", "To use, the bender must merely have the ability selected. All water around the user in a small bubble will vanish, replacing itself once the user either gets too far away or selects a different ability."); config.addDefault("Abilities.Air.AirBubble.Radius", 7); + config.addDefault("Abilities.Air.AirBurst.Enabled", true); config.addDefault("Abilities.Air.AirBurst.Description", "AirBurst is one of the most powerful abilities in the airbender's arsenal. " + "To use, press and hold sneak to charge your burst. " @@ -135,7 +136,7 @@ public class ConfigManager { + "While channeling, the water will form itself around you and has a chance to block incoming attacks. " + "Additionally, you can click while channeling to attack things near you, dealing damage and knocking them back. " + "Releasing shift at any time will dissipate the form."); - + config.addDefault("Abilities.Water.PhaseChange.Enabled", true); config.addDefault("Abilities.Water.PhaseChange.Description", "To use, simply left-click. " + "Any water you are looking at within range will instantly freeze over into solid ice. " @@ -154,7 +155,7 @@ public class ConfigManager { config.addDefault("Abilities.Water.WaterBubble.Enabled", true); config.addDefault("Abilities.Water.WaterBubble.Description","To use, the bender must merely have the ability selected. All water around the user in a small bubble will vanish, replacing itself once the user either gets too far away or selects a different ability."); config.addDefault("Abilities.Water.WaterBubble.Radius", 7); - + config.addDefault("Abilities.Water.WaterSpout.Enabled", true); config.addDefault("Abilities.Water.WaterSpout.Description", "To use this ability, click while over or in water. " + "You will spout water up from beneath you to experience controlled levitation. " @@ -225,6 +226,14 @@ public class ConfigManager { config.addDefault("Abilities.Fire.HeatControl.Melt.Range", 15); config.addDefault("Abilities.Fire.HeatControl.Melt.Radius", 5); + config.addDefault("Abilities.Fire.Illumination.Enabled", true); + config.addDefault("Abilities.Fire.Illumination.Description", "This ability gives firebenders a means of illuminating the area. It is a toggle - clicking " + + "will create a torch that follows you around. The torch will only appear on objects that are " + + "ignitable and can hold a torch (e.g. not leaves or ice). If you get too far away from the torch, " + + "it will disappear, but will reappear when you get on another ignitable block. Clicking again " + + "dismisses this torch."); + config.addDefault("Abilities.Fire.Illumination.Range", 5); + plugin.getConfig().addDefault("Abilities.Chi.Passive.FallReductionFactor", 0.5); plugin.getConfig().addDefault("Abilities.Chi.Passive.Speed", 1); plugin.getConfig().addDefault("Abilities.Chi.Passive.Jump", 2); diff --git a/src/com/projectkorra/ProjectKorra/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index eaf24ef5..01a5e32b 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -62,6 +62,7 @@ import com.projectkorra.ProjectKorra.firebending.Enflamed; import com.projectkorra.ProjectKorra.firebending.Extinguish; import com.projectkorra.ProjectKorra.firebending.FireJet; import com.projectkorra.ProjectKorra.firebending.FireStream; +import com.projectkorra.ProjectKorra.firebending.Illumination; import com.projectkorra.ProjectKorra.waterbending.Bloodbending; import com.projectkorra.ProjectKorra.waterbending.FreezeMelt; import com.projectkorra.ProjectKorra.waterbending.Melt; @@ -396,6 +397,9 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("HeatControl")) { new Extinguish(player); } + if (abil.equalsIgnoreCase("Illumination")) { + new Illumination(player); + } } } } diff --git a/src/com/projectkorra/ProjectKorra/firebending/Illumination.java b/src/com/projectkorra/ProjectKorra/firebending/Illumination.java new file mode 100644 index 00000000..16c743d3 --- /dev/null +++ b/src/com/projectkorra/ProjectKorra/firebending/Illumination.java @@ -0,0 +1,128 @@ +package com.projectkorra.ProjectKorra.firebending; + +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.Material; +import org.bukkit.Server; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; + +import com.projectkorra.ProjectKorra.Methods; +import com.projectkorra.ProjectKorra.ProjectKorra; + +public class Illumination { + + public static ConcurrentHashMap instances = new ConcurrentHashMap(); + public static ConcurrentHashMap blocks = new ConcurrentHashMap(); + public static ConcurrentHashMap cooldowns = new ConcurrentHashMap(); + + private static final int range = ProjectKorra.plugin.getConfig().getInt("Abilities.Fire.Illumination.Range"); + + private Player player; + private Block block; + private Material normaltype; + private byte normaldata; + + public Illumination(Player player) { + if (cooldowns.containsKey(player.getName())) { + if (cooldowns.get(player.getName()) + ProjectKorra.plugin.getConfig().getLong("Properties.GlobalCooldown") >= System.currentTimeMillis()) { + return; + } else { + cooldowns.remove(player.getName()); + } + } + + if (instances.containsKey(player)) { + instances.get(player).revert(); + instances.remove(player); + } else { + this.player = player; + set(); + instances.put(player, this); + cooldowns.put(player.getName(), System.currentTimeMillis()); + } + } + + private void set() { + Block standingblock = player.getLocation().getBlock(); + Block standblock = standingblock.getRelative(BlockFace.DOWN); + if ((FireStream.isIgnitable(player, standingblock) && standblock + .getType() != Material.LEAVES) + && block == null + && !blocks.containsKey(standblock)) { + block = standingblock; + normaltype = block.getType(); + normaldata = block.getData(); + block.setType(Material.TORCH); + blocks.put(block, player); + } else if ((FireStream.isIgnitable(player, standingblock) && standblock + .getType() != Material.LEAVES) + && !block.equals(standblock) + && !blocks.containsKey(standblock) && Methods.isSolid(standblock)) { + revert(); + block = standingblock; + normaltype = block.getType(); + normaldata = block.getData(); + block.setType(Material.TORCH); + blocks.put(block, player); + } else if (block == null) { + return; + } else if (player.getWorld() != block.getWorld()) { + revert(); + } else if (player.getLocation().distance(block.getLocation()) > Methods + .firebendingDayAugment(range, player.getWorld())) { + revert(); + } + } + + private void revert() { + if (block != null) { + blocks.remove(block); + block.setType(normaltype); + block.setData(normaldata); + } + } + + public static void revert(Block block) { + Player player = blocks.get(block); + instances.get(player).revert(); + } + + public static void manage(Server server) { + for (Player player : server.getOnlinePlayers()) { + if (instances.containsKey(player)) { + if (!Methods.canBend(player.getName(), "Illumination")) { + instances.get(player).revert(); + instances.remove(player); + } else { + instances.get(player).set(); + } + } + } + + for (Player player : instances.keySet()) { + if (!player.isOnline() || player.isDead()) { + instances.get(player).revert(); + instances.remove(player); + } + } + } + + public static void removeAll() { + for (Player player : instances.keySet()) { + instances.get(player).revert(); + instances.remove(player); + } + + } + + public static String getDescription() { + return "This ability gives firebenders a means of illuminating the area. It is a toggle - clicking " + + "will create a torch that follows you around. The torch will only appear on objects that are " + + "ignitable and can hold a torch (e.g. not leaves or ice). If you get too far away from the torch, " + + "it will disappear, but will reappear when you get on another ignitable block. Clicking again " + + "dismisses this torch."; + } + +} \ No newline at end of file diff --git a/src/config.yml b/src/config.yml index 2df65c97..1415690d 100644 --- a/src/config.yml +++ b/src/config.yml @@ -147,6 +147,10 @@ Abilities: Melt: Range: 15 Radius: 5 + Illumination: + Enabled: true + Description: "This ability gives firebenders a means of illuminating the area. It is a toggle - clicking will create a torch that follows you around. The torch will only appear on objects that are ignitable and can hold a torch (e.g. not leaves or ice). If you get too far away from the torch, it will disappear, but will reappear when you get on another ignitable block. Clicking again dismisses this torch." + Range: 5 Chi: Passive: FallReductionFactor: 0.5