WaterSpout

This commit is contained in:
MistPhizzle 2014-06-24 21:36:27 -04:00
parent 44bf1c361f
commit 142b4b34eb
6 changed files with 296 additions and 33 deletions

View file

@ -26,6 +26,7 @@ import com.projectkorra.ProjectKorra.firebending.FireStream;
import com.projectkorra.ProjectKorra.waterbending.Bloodbending;
import com.projectkorra.ProjectKorra.waterbending.Plantbending;
import com.projectkorra.ProjectKorra.waterbending.WaterPassive;
import com.projectkorra.ProjectKorra.waterbending.WaterSpout;
public class BendingManager implements Runnable {
@ -69,7 +70,7 @@ public class BendingManager implements Runnable {
FireJet.progressAll();
AirScooter.progressAll();
AirSpout.spoutAll();
WaterSpout.handleSpouts(Bukkit.getServer());
for (int ID: Tornado.instances.keySet()) {
Tornado.progress(ID);
}

View file

@ -51,11 +51,11 @@ public class ConfigManager {
plugin.getConfig().addDefault("Abilities.AvatarState.Enabled", true);
plugin.getConfig().addDefault("Abilities.AvatarState.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, regenerates 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.");
+ "nearly unstoppable. While in the Avatar State, the user takes severely reduced damage from "
+ "all sources, regenerates 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.");
plugin.getConfig().addDefault("Abilities.Air.Passive.Factor", 0.3);
plugin.getConfig().addDefault("Abilities.Air.Passive.Speed", 2);
@ -126,9 +126,16 @@ public class ConfigManager {
config.addDefault("Abilities.Water.Bloodbending.ThrowFactor", 2);
config.addDefault("Abilities.Water.Bloodbending.Range", 10);
plugin.getConfig().addDefault("Abilities.Water.Plantbending.RegrowTime", 180000);
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. "
+ "This ability is a toggle, so you can activate it then use other abilities and it "
+ "will remain on. If you try to spout over an area with no water, snow or ice, "
+ "the spout will dissipate and you will fall. Click again with this ability selected to deactivate it.");
config.addDefault("Abilities.Water.WaterSpout.Height", 20);
plugin.getConfig().addDefault("Abilities.Earth.Passive.Duration", 2500);
config.addDefault("Abilities.Fire.FireJet.Enabled", true);

View file

@ -12,6 +12,7 @@ import com.projectkorra.ProjectKorra.airbending.AirSpout;
import com.projectkorra.ProjectKorra.airbending.Tornado;
import com.projectkorra.ProjectKorra.firebending.FireJet;
import com.projectkorra.ProjectKorra.waterbending.Bloodbending;
import com.projectkorra.ProjectKorra.waterbending.WaterSpout;
public class Flight {

View file

@ -56,6 +56,7 @@ import com.projectkorra.ProjectKorra.firebending.FireStream;
import com.projectkorra.ProjectKorra.waterbending.Bloodbending;
import com.projectkorra.ProjectKorra.waterbending.WaterCore;
import com.projectkorra.ProjectKorra.waterbending.WaterPassive;
import com.projectkorra.ProjectKorra.waterbending.WaterSpout;
public class PKListener implements Listener {
@ -160,6 +161,9 @@ public class PKListener implements Listener {
if (abil.equalsIgnoreCase("Bloodbending")) {
new Bloodbending(player);
}
if (abil.equalsIgnoreCase("WaterSpout")) {
new WaterSpout(player);
}
}
}
}

View file

@ -0,0 +1,246 @@
package com.projectkorra.ProjectKorra.waterbending;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import com.projectkorra.ProjectKorra.Flight;
import com.projectkorra.ProjectKorra.Methods;
import com.projectkorra.ProjectKorra.ProjectKorra;
import com.projectkorra.ProjectKorra.TempBlock;
public class WaterSpout {
public static ConcurrentHashMap<Player, WaterSpout> instances = new ConcurrentHashMap<Player, WaterSpout>();
public static ConcurrentHashMap<Block, Block> affectedblocks = new ConcurrentHashMap<Block, Block>();
public static ConcurrentHashMap<Block, Block> newaffectedblocks = new ConcurrentHashMap<Block, Block>();
public static ConcurrentHashMap<Block, Block> baseblocks = new ConcurrentHashMap<Block, Block>();
private static final int defaultheight = ProjectKorra.plugin.getConfig().getInt("Abilities.Water.WaterSpout.Height");
// private static final double threshold = .05;
// private static final byte half = 0x4;
private static final byte full = 0x0;
private Player player;
private Block base;
private TempBlock baseblock;
public WaterSpout(Player player) {
// if (BendingPlayer.getBendingPlayer(player).isOnCooldown(
// Abilities.WaterSpout))
// return;
if (instances.containsKey(player)) {
instances.get(player).remove();
return;
}
this.player = player;
new Flight(player);
player.setAllowFlight(true);
instances.put(player, this);
spout(player);
}
private void remove() {
revertBaseBlock(player);
instances.remove(player);
}
public static void handleSpouts(Server server) {
// affectedblocks.clear();
newaffectedblocks.clear();
for (Player player : instances.keySet()) {
if (!player.isOnline() || player.isDead()) {
instances.get(player).remove();
} else if (Methods.canBend(player.getName(), "WaterSpout")) {
spout(player);
} else {
instances.get(player).remove();
}
}
for (Block block : affectedblocks.keySet()) {
if (!newaffectedblocks.containsKey(block)) {
remove(block);
}
}
// for (Block block : affectedblocks.keySet()) {
// boolean remove = true;
// for (Player player : instances.keySet()) {
// if (Methods.hasAbility(player, Abilities.WaterSpout)
// && Methods.canBend(player, Abilities.WaterSpout)
// && player.getWorld() == block.getWorld()) {
// Location loc1 = player.getLocation().clone();
// loc1.setY(0);
// Location loc2 = block.getLocation().clone();
// loc2.setY(0);
// if (loc1.distance(loc2) < 1)
// remove = false;
// }
// }
// if (remove)
// remove(block);
// }
}
private static void remove(Block block) {
affectedblocks.remove(block);
TempBlock.revertBlock(block, Material.AIR);
// block.setType(Material.AIR);
// block.setData(half);
}
public static void spout(Player player) {
WaterSpout spout = instances.get(player);
player.setFallDistance(0);
player.setSprinting(false);
// if (player.getVelocity().length() > threshold) {
// // Methods.verbose("Too fast!");
// player.setVelocity(player.getVelocity().clone().normalize()
// .multiply(threshold * .5));
// }
player.removePotionEffect(PotionEffectType.SPEED);
Location location = player.getLocation().clone().add(0, .2, 0);
Block block = location.clone().getBlock();
int height = spoutableWaterHeight(location, player);
// Methods.verbose(height + " " + WaterSpout.height + " "
// + affectedblocks.size());
if (height != -1) {
location = spout.base.getLocation();
for (int i = 1; i <= height; i++) {
block = location.clone().add(0, i, 0).getBlock();
if (!TempBlock.isTempBlock(block)) {
new TempBlock(block, Material.WATER, full);
}
// block.setType(Material.WATER);
// block.setData(full);
if (!affectedblocks.containsKey(block)) {
affectedblocks.put(block, block);
}
newaffectedblocks.put(block, block);
}
if (player.getLocation().getBlockY() > block.getY()) {
player.setFlying(false);
} else {
new Flight(player);
player.setAllowFlight(true);
player.setFlying(true);
}
} else {
instances.get(player).remove();
}
}
private static int spoutableWaterHeight(Location location, Player player) {
WaterSpout spout = instances.get(player);
int height = defaultheight;
if (Methods.isNight(player.getWorld()))
height = (int) Methods.waterbendingNightAugment((double) height,
player.getWorld());
int maxheight = (int) ((double) defaultheight * ProjectKorra.plugin.getConfig().getDouble("Properties.Water.NightFactor")) + 5;
Block blocki;
for (int i = 0; i < maxheight; i++) {
blocki = location.clone().add(0, -i, 0).getBlock();
// if (Methods.isRegionProtectedFromBuild(player, Abilities.WaterSpout,
// blocki.getLocation()))
// return -1;
if (!affectedblocks.contains(blocki)) {
if (blocki.getType() == Material.WATER
|| blocki.getType() == Material.STATIONARY_WATER) {
if (!TempBlock.isTempBlock(blocki)) {
revertBaseBlock(player);
}
spout.base = blocki;
if (i > height)
return height;
return i;
}
if (blocki.getType() == Material.ICE
|| blocki.getType() == Material.SNOW
|| blocki.getType() == Material.SNOW_BLOCK) {
if (!TempBlock.isTempBlock(blocki)) {
revertBaseBlock(player);
instances.get(player).baseblock = new TempBlock(blocki,
Material.WATER, full);
}
// blocki.setType(Material.WATER);
// blocki.setData(full);
spout.base = blocki;
if (i > height)
return height;
return i;
}
if ((blocki.getType() != Material.AIR && (!Methods
.isPlant(blocki) || !Methods.canPlantbend(player)))) {
revertBaseBlock(player);
return -1;
}
}
}
revertBaseBlock(player);
return -1;
}
public static void revertBaseBlock(Player player) {
if (instances.containsKey(player)) {
if (instances.get(player).baseblock != null) {
instances.get(player).baseblock.revertBlock();
instances.get(player).baseblock = null;
}
}
}
public static void removeAll() {
for (Player player : instances.keySet()) {
instances.get(player).remove();
}
for (Block block : affectedblocks.keySet()) {
// block.setType(Material.AIR);
TempBlock.revertBlock(block, Material.AIR);
affectedblocks.remove(block);
}
}
public static ArrayList<Player> getPlayers() {
ArrayList<Player> players = new ArrayList<Player>();
for (Player player : instances.keySet())
players.add(player);
return players;
}
public static void removeSpouts(Location loc0, double radius,
Player sourceplayer) {
for (Player player : instances.keySet()) {
if (!player.equals(sourceplayer)) {
Location loc1 = player.getLocation().getBlock().getLocation();
loc0 = loc0.getBlock().getLocation();
double dx = loc1.getX() - loc0.getX();
double dy = loc1.getY() - loc0.getY();
double dz = loc1.getZ() - loc0.getZ();
double distance = Math.sqrt(dx * dx + dz * dz);
if (distance <= radius && dy > 0 && dy < defaultheight)
instances.get(player).remove();
}
}
}
public static String getDescription() {
return "To use this ability, click while over or in water. "
+ "You will spout water up from beneath you to experience controlled levitation. "
+ "This ability is a toggle, so you can activate it then use other abilities and it "
+ "will remain on. If you try to spout over an area with no water, snow or ice, "
+ "the spout will dissipate and you will fall. Click again with this ability selected to deactivate it.";
}
}

View file

@ -80,6 +80,10 @@ Abilities:
Range: 10
Plantbending:
RegrowTime: 180000
WaterSpout:
Enabled: true
Description: "To use this ability, click while over or in water. You will spout water up from beneath you to experience controlled levitation. This ability is a toggle, so you can activate it then use other abilities and it will remain on. If you try to spout over an area with no water, snow, or ice, the spout will dissipate and you will fall. Click again with this ability selected to deactivate it."
Height: 20
Earth:
Passive:
Duration: 2500