Added back functionallity for levers and buttons, also added more wood

types.
This commit is contained in:
jedk1 2015-06-29 18:52:27 +01:00
parent f366764cdb
commit 168a47b503

View file

@ -1,374 +1,419 @@
package com.projectkorra.ProjectKorra.airbending; package com.projectkorra.ProjectKorra.airbending;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap; import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Effect;
import org.bukkit.Location; import org.bukkit.Effect;
import org.bukkit.Material; import org.bukkit.Location;
import org.bukkit.Sound; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.Sound;
import org.bukkit.block.BlockFace; import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.LivingEntity;
import org.bukkit.util.Vector; import org.bukkit.entity.Player;
import org.bukkit.material.Button;
import com.projectkorra.ProjectKorra.BendingPlayer; import org.bukkit.material.Lever;
import com.projectkorra.ProjectKorra.Commands; import org.bukkit.scheduler.BukkitRunnable;
import com.projectkorra.ProjectKorra.Flight; import org.bukkit.util.Vector;
import com.projectkorra.ProjectKorra.GeneralMethods;
import com.projectkorra.ProjectKorra.ProjectKorra; import com.projectkorra.ProjectKorra.BendingPlayer;
import com.projectkorra.ProjectKorra.Ability.AvatarState; import com.projectkorra.ProjectKorra.Commands;
import com.projectkorra.ProjectKorra.Objects.HorizontalVelocityTracker; import com.projectkorra.ProjectKorra.Flight;
import com.projectkorra.ProjectKorra.GeneralMethods;
public class AirBlast { import com.projectkorra.ProjectKorra.ProjectKorra;
import com.projectkorra.ProjectKorra.Ability.AvatarState;
private static FileConfiguration config = ProjectKorra.plugin.getConfig(); import com.projectkorra.ProjectKorra.Objects.HorizontalVelocityTracker;
public static ConcurrentHashMap<Integer, AirBlast> instances = new ConcurrentHashMap<Integer, AirBlast>(); public class AirBlast {
private static ConcurrentHashMap<Player, Location> origins = new ConcurrentHashMap<Player, Location>();
private static FileConfiguration config = ProjectKorra.plugin.getConfig();
private static int ID = Integer.MIN_VALUE;
static final int maxticks = 10000; public static ConcurrentHashMap<Integer, AirBlast> instances = new ConcurrentHashMap<Integer, AirBlast>();
private static ConcurrentHashMap<Player, Location> origins = new ConcurrentHashMap<Player, Location>();
public static double speed = config.getDouble("Abilities.Air.AirBlast.Speed");
public static double defaultrange = config.getDouble("Abilities.Air.AirBlast.Range"); private static int ID = Integer.MIN_VALUE;
public static double affectingradius = config.getDouble("Abilities.Air.AirBlast.Radius"); static final int maxticks = 10000;
public static double defaultpushfactor = config.getDouble("Abilities.Air.AirBlast.Push");
private static double originselectrange = 10; public static double speed = config.getDouble("Abilities.Air.AirBlast.Speed");
static final double maxspeed = 1. / defaultpushfactor; public static double defaultrange = config.getDouble("Abilities.Air.AirBlast.Range");
// public static long interval = 2000; public static double affectingradius = config.getDouble("Abilities.Air.AirBlast.Radius");
public static byte full = 0x0; public static double defaultpushfactor = config.getDouble("Abilities.Air.AirBlast.Push");
private static double originselectrange = 10;
public Location location; static final double maxspeed = 1. / defaultpushfactor;
private Location origin; // public static long interval = 2000;
private Vector direction; public static byte full = 0x0;
private Player player;
private int id; public Location location;
private double speedfactor; private Location origin;
private double range = defaultrange; private Vector direction;
private double pushfactor = defaultpushfactor; private Player player;
private double damage = 0; private int id;
private boolean otherorigin = false; private double speedfactor;
private int ticks = 0; private double range = defaultrange;
private boolean showParticles = true; private double pushfactor = defaultpushfactor;
private double damage = 0;
private ArrayList<Block> affectedlevers = new ArrayList<Block>(); private boolean otherorigin = false;
private ArrayList<Entity> affectedentities = new ArrayList<Entity>(); private int ticks = 0;
private boolean showParticles = true;
@SuppressWarnings("unused")
private AirBurst source = null; private ArrayList<Block> affectedlevers = new ArrayList<Block>();
private ArrayList<Entity> affectedentities = new ArrayList<Entity>();
public AirBlast(Player player) { @SuppressWarnings("unused")
private AirBurst source = null;
BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName());
if (bPlayer.isOnCooldown("AirBlast")) return; public AirBlast(Player player) {
if (player.getEyeLocation().getBlock().isLiquid()) { BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName());
return;
} if (bPlayer.isOnCooldown("AirBlast")) return;
this.player = player;
if (origins.containsKey(player)) { if (player.getEyeLocation().getBlock().isLiquid()) {
otherorigin = true; return;
origin = origins.get(player); }
origins.remove(player); this.player = player;
Entity entity = GeneralMethods.getTargetedEntity(player, range, new ArrayList<Entity>()); if (origins.containsKey(player)) {
if (entity != null) { otherorigin = true;
direction = GeneralMethods.getDirection(origin, entity.getLocation()).normalize(); origin = origins.get(player);
} else { origins.remove(player);
direction = GeneralMethods.getDirection(origin, GeneralMethods.getTargetedLocation(player, range)).normalize(); Entity entity = GeneralMethods.getTargetedEntity(player, range, new ArrayList<Entity>());
} if (entity != null) {
} else { direction = GeneralMethods.getDirection(origin, entity.getLocation()).normalize();
origin = player.getEyeLocation(); } else {
direction = player.getEyeLocation().getDirection().normalize(); direction = GeneralMethods.getDirection(origin, GeneralMethods.getTargetedLocation(player, range)).normalize();
} }
location = origin.clone(); } else {
id = ID; origin = player.getEyeLocation();
instances.put(id, this); direction = player.getEyeLocation().getDirection().normalize();
bPlayer.addCooldown("AirBlast", GeneralMethods.getGlobalCooldown()); }
location = origin.clone();
if (ID == Integer.MAX_VALUE) id = ID;
ID = Integer.MIN_VALUE; instances.put(id, this);
ID++; bPlayer.addCooldown("AirBlast", GeneralMethods.getGlobalCooldown());
// time = System.currentTimeMillis();
// timers.put(player, System.currentTimeMillis()); if (ID == Integer.MAX_VALUE)
} ID = Integer.MIN_VALUE;
ID++;
public AirBlast(Location location, Vector direction, Player player, double factorpush, AirBurst burst) { // time = System.currentTimeMillis();
if (location.getBlock().isLiquid()) { // timers.put(player, System.currentTimeMillis());
return; }
}
public AirBlast(Location location, Vector direction, Player player, double factorpush, AirBurst burst) {
source = burst; if (location.getBlock().isLiquid()) {
return;
this.player = player; }
origin = location.clone();
this.direction = direction.clone(); source = burst;
this.location = location.clone();
id = ID; this.player = player;
pushfactor *= factorpush; origin = location.clone();
instances.put(id, this); this.direction = direction.clone();
if (ID == Integer.MAX_VALUE) this.location = location.clone();
ID = Integer.MIN_VALUE; id = ID;
ID++; pushfactor *= factorpush;
} instances.put(id, this);
if (ID == Integer.MAX_VALUE)
public static void setOrigin(Player player) { ID = Integer.MIN_VALUE;
Location location = GeneralMethods.getTargetedLocation(player, originselectrange, GeneralMethods.nonOpaque); ID++;
if (location.getBlock().isLiquid() || GeneralMethods.isSolid(location.getBlock())) }
return;
public static void setOrigin(Player player) {
if (GeneralMethods.isRegionProtectedFromBuild(player, "AirBlast", location)) Location location = GeneralMethods.getTargetedLocation(player, originselectrange, GeneralMethods.nonOpaque);
return; if (location.getBlock().isLiquid() || GeneralMethods.isSolid(location.getBlock()))
return;
if (origins.containsKey(player)) {
origins.replace(player, location); if (GeneralMethods.isRegionProtectedFromBuild(player, "AirBlast", location))
} else { return;
origins.put(player, location);
} if (origins.containsKey(player)) {
} origins.replace(player, location);
} else {
@SuppressWarnings("deprecation") origins.put(player, location);
public boolean progress() { }
if (player.isDead() || !player.isOnline()) { }
instances.remove(id);
return false; @SuppressWarnings("deprecation")
} public boolean progress() {
if (player.isDead() || !player.isOnline()) {
if (GeneralMethods.isRegionProtectedFromBuild(player, "AirBlast", location)) { instances.remove(id);
instances.remove(id); return false;
return false; }
}
if (GeneralMethods.isRegionProtectedFromBuild(player, "AirBlast", location)) {
speedfactor = speed * (ProjectKorra.time_step / 1000.); instances.remove(id);
return false;
ticks++; }
if (ticks > maxticks) { speedfactor = speed * (ProjectKorra.time_step / 1000.);
instances.remove(id);
return false; ticks++;
}
Block block = location.getBlock(); if (ticks > maxticks) {
for (Block testblock : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) { instances.remove(id);
if (testblock.getType() == Material.FIRE) { return false;
testblock.setType(Material.AIR); }
testblock.getWorld().playEffect(testblock.getLocation(), Effect.EXTINGUISH, 0); Block block = location.getBlock();
} for (Block testblock : GeneralMethods.getBlocksAroundPoint(location, affectingradius)) {
if (testblock.getType() == Material.FIRE) {
if (block.getType() == Material.WOODEN_DOOR) { testblock.setType(Material.AIR);
if (block.getData() >= 8) { testblock.getWorld().playEffect(testblock.getLocation(), Effect.EXTINGUISH, 0);
block = block.getRelative(BlockFace.DOWN); }
}
Material doorTypes[] = {Material.WOODEN_DOOR, Material.SPRUCE_DOOR,
if (block.getData() < 4) { Material.BIRCH_DOOR, Material.JUNGLE_DOOR, Material.ACACIA_DOOR, Material.DARK_OAK_DOOR};
block.setData((byte) (block.getData() + 4)); if (Arrays.asList(doorTypes).contains(block.getType())) {
block.getWorld().playSound(block.getLocation(), Sound.DOOR_CLOSE, 10, 1); if (block.getData() >= 8) {
} else { block = block.getRelative(BlockFace.DOWN);
block.setData((byte) (block.getData() - 4)); }
block.getWorld().playSound(block.getLocation(), Sound.DOOR_OPEN, 10, 1);
} if (block.getData() < 4) {
} block.setData((byte) (block.getData() + 4));
if (((block.getType() == Material.LEVER) || (block.getType() == Material.STONE_BUTTON)) block.getWorld().playSound(block.getLocation(), Sound.DOOR_CLOSE, 10, 1);
&& !affectedlevers.contains(block)) { } else {
// BlockState state = block.getState(); block.setData((byte) (block.getData() - 4));
// Lever lever = (Lever) (state.getData()); block.getWorld().playSound(block.getLocation(), Sound.DOOR_OPEN, 10, 1);
// lever.setPowered(!lever.isPowered()); }
// state.setData(lever); }
// state.update(true, true); if ((block.getType() == Material.LEVER)
// && !affectedlevers.contains(block)) {
// Block relative = block.getRelative(((Attachable) block // BlockState state = block.getState();
// .getState().getData()).getFacing(), -1); // Lever lever = (Lever) (state.getData());
// relative.getState().update(true, true); // lever.setPowered(!lever.isPowered());
// // state.setData(lever);
// for (Block block2 : Methods.getBlocksAroundPoint( // state.update(true, true);
// relative.getLocation(), 2)) //
// block2.getState().update(true, true); // Block relative = block.getRelative(((Attachable) block
// .getState().getData()).getFacing(), -1);
affectedlevers.add(block); // relative.getState().update(true, true);
} //
} // for (Block block2 : Methods.getBlocksAroundPoint(
if ((GeneralMethods.isSolid(block) || block.isLiquid()) && !affectedlevers.contains(block)) { // relative.getLocation(), 2))
if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) { // block2.getState().update(true, true);
if (block.getData() == full) {
block.setType(Material.OBSIDIAN); Lever lever = new Lever(Material.LEVER, block.getData());
} else { lever.setPowered(!lever.isPowered());
block.setType(Material.COBBLESTONE); block.setData(lever.getData());
}
} affectedlevers.add(block);
instances.remove(id);
return false; } else if ((block.getType() == Material.STONE_BUTTON)
} && !affectedlevers.contains(block)) {
/* final Button button = new Button(Material.STONE_BUTTON, block.getData());
* If a player presses shift and AirBlasts straight down then button.setPowered(!button.isPowered());
* the AirBlast's location gets messed up and reading the distance block.setData(button.getData());
* returns Double.NaN. If we don't remove this instance then
* the AirBlast will never be removed. final Block btBlock = block;
*/
double dist = location.distance(origin); new BukkitRunnable() {
if (Double.isNaN(dist) || dist > range) { public void run() {
instances.remove(id); button.setPowered(!button.isPowered());
return false; btBlock.setData(button.getData());
} }
}.runTaskLater(ProjectKorra.plugin, 10);
for (Entity entity : GeneralMethods.getEntitiesAroundPoint(location, affectingradius)) {
affect(entity); affectedlevers.add(block);
} } else if ((block.getType() == Material.WOOD_BUTTON)
&& !affectedlevers.contains(block)) {
advanceLocation();
final Button button = new Button(Material.WOOD_BUTTON, block.getData());
return true; button.setPowered(!button.isPowered());
} block.setData(button.getData());
private void advanceLocation() { final Block btBlock = block;
if (showParticles)
AirMethods.playAirbendingParticles(location, 10); new BukkitRunnable() {
if (GeneralMethods.rand.nextInt(4) == 0) { public void run() {
AirMethods.playAirbendingSound(location); button.setPowered(!button.isPowered());
} btBlock.setData(button.getData());
location = location.add(direction.clone().multiply(speedfactor)); }
} }.runTaskLater(ProjectKorra.plugin, 15);
private void affect(Entity entity) { affectedlevers.add(block);
boolean isUser = entity.getEntityId() == player.getEntityId(); }
}
if (!isUser || otherorigin) { if ((GeneralMethods.isSolid(block) || block.isLiquid()) && !affectedlevers.contains(block)) {
Vector velocity = entity.getVelocity(); if (block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) {
// double mag = Math.abs(velocity.getY()); if (block.getData() == full) {
double max = maxspeed; block.setType(Material.OBSIDIAN);
double factor = pushfactor; } else {
if (AvatarState.isAvatarState(player)) { block.setType(Material.COBBLESTONE);
max = AvatarState.getValue(maxspeed); }
factor = AvatarState.getValue(factor); }
} instances.remove(id);
return false;
Vector push = direction.clone(); }
if (Math.abs(push.getY()) > max && !isUser) {
if (push.getY() < 0) /*
push.setY(-max); * If a player presses shift and AirBlasts straight down then
else * the AirBlast's location gets messed up and reading the distance
push.setY(max); * returns Double.NaN. If we don't remove this instance then
} * the AirBlast will never be removed.
*/
factor *= 1 - location.distance(origin) / (2 * range); double dist = location.distance(origin);
if (Double.isNaN(dist) || dist > range) {
if (isUser && GeneralMethods.isSolid(player.getLocation().add(0, -.5, 0).getBlock())) { instances.remove(id);
factor *= .5; return false;
} }
double comp = velocity.dot(push.clone().normalize()); for (Entity entity : GeneralMethods.getEntitiesAroundPoint(location, affectingradius)) {
if (comp > factor) { affect(entity);
velocity.multiply(.5); }
velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize())));
} else if (comp + factor * .5 > factor) { advanceLocation();
velocity.add(push.clone().multiply(factor - comp));
} else { return true;
velocity.add(push.clone().multiply(factor * .5)); }
}
private void advanceLocation() {
if (entity instanceof Player) { if (showParticles)
if (Commands.invincible.contains(((Player) entity).getName())) return; AirMethods.playAirbendingParticles(location, 10);
} if (GeneralMethods.rand.nextInt(4) == 0) {
AirMethods.playAirbendingSound(location);
if(Double.isNaN(velocity.length())) }
return; location = location.add(direction.clone().multiply(speedfactor));
}
GeneralMethods.setVelocity(entity, velocity);
new HorizontalVelocityTracker(entity, player, 200l); private void affect(Entity entity) {
entity.setFallDistance(0); boolean isUser = entity.getEntityId() == player.getEntityId();
if (!isUser && entity instanceof Player) {
new Flight((Player) entity, player); if (!isUser || otherorigin) {
} Vector velocity = entity.getVelocity();
if (entity.getFireTicks() > 0) // double mag = Math.abs(velocity.getY());
entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0); double max = maxspeed;
entity.setFireTicks(0); double factor = pushfactor;
AirMethods.breakBreathbendingHold(entity); if (AvatarState.isAvatarState(player)) {
max = AvatarState.getValue(maxspeed);
if (damage > 0 && entity instanceof LivingEntity && !entity.equals(player) && !affectedentities.contains(entity)) { factor = AvatarState.getValue(factor);
GeneralMethods.damageEntity(player, entity, damage); }
affectedentities.add(entity);
} Vector push = direction.clone();
} if (Math.abs(push.getY()) > max && !isUser) {
} if (push.getY() < 0)
push.setY(-max);
public void setDamage(double dmg) { else
this.damage = dmg; push.setY(max);
} }
public void setShowParticles(boolean show) { factor *= 1 - location.distance(origin) / (2 * range);
this.showParticles = show;
} if (isUser && GeneralMethods.isSolid(player.getLocation().add(0, -.5, 0).getBlock())) {
factor *= .5;
public boolean getShowParticles() { }
return this.showParticles;
} double comp = velocity.dot(push.clone().normalize());
if (comp > factor) {
public static void progressAll() { velocity.multiply(.5);
for (int id : instances.keySet()) velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize())));
instances.get(id).progress(); } else if (comp + factor * .5 > factor) {
for (Player player : origins.keySet()) { velocity.add(push.clone().multiply(factor - comp));
playOriginEffect(player); } else {
} velocity.add(push.clone().multiply(factor * .5));
} }
private static void playOriginEffect(Player player) { if (entity instanceof Player) {
if (!origins.containsKey(player)) if (Commands.invincible.contains(((Player) entity).getName())) return;
return; }
Location origin = origins.get(player);
if (!origin.getWorld().equals(player.getWorld())) { if(Double.isNaN(velocity.length()))
origins.remove(player); return;
return;
} GeneralMethods.setVelocity(entity, velocity);
new HorizontalVelocityTracker(entity, player, 200l);
if (GeneralMethods.getBoundAbility(player) == null) { entity.setFallDistance(0);
origins.remove(player); if (!isUser && entity instanceof Player) {
return; new Flight((Player) entity, player);
} }
if (entity.getFireTicks() > 0)
if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBlast") || !GeneralMethods.canBend(player.getName(), "AirBlast")) { entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0);
origins.remove(player); entity.setFireTicks(0);
return; AirMethods.breakBreathbendingHold(entity);
}
if (damage > 0 && entity instanceof LivingEntity && !entity.equals(player) && !affectedentities.contains(entity)) {
if (origin.distance(player.getEyeLocation()) > originselectrange) { GeneralMethods.damageEntity(player, entity, damage);
origins.remove(player); affectedentities.add(entity);
return; }
} }
}
AirMethods.playAirbendingParticles(origin, 10);
// origin.getWorld().playEffect(origin, Effect.SMOKE, 4, public void setDamage(double dmg) {
// (int) originselectrange); this.damage = dmg;
} }
public static void removeAll() { public void setShowParticles(boolean show) {
for (int id : instances.keySet()) { this.showParticles = show;
instances.remove(id); }
}
} public boolean getShowParticles() {
return this.showParticles;
public Player getPlayer() { }
return player;
} public static void progressAll() {
for (int id : instances.keySet())
public double getRange() { instances.get(id).progress();
return range; for (Player player : origins.keySet()) {
} playOriginEffect(player);
}
public void setRange(double range) { }
this.range = range;
} private static void playOriginEffect(Player player) {
if (!origins.containsKey(player))
public double getPushfactor() { return;
return pushfactor; Location origin = origins.get(player);
} if (!origin.getWorld().equals(player.getWorld())) {
origins.remove(player);
public void setPushfactor(double pushfactor) { return;
this.pushfactor = pushfactor; }
}
if (GeneralMethods.getBoundAbility(player) == null) {
origins.remove(player);
return;
}
if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirBlast") || !GeneralMethods.canBend(player.getName(), "AirBlast")) {
origins.remove(player);
return;
}
if (origin.distance(player.getEyeLocation()) > originselectrange) {
origins.remove(player);
return;
}
AirMethods.playAirbendingParticles(origin, 10);
// origin.getWorld().playEffect(origin, Effect.SMOKE, 4,
// (int) originselectrange);
}
public static void removeAll() {
for (int id : instances.keySet()) {
instances.remove(id);
}
}
public Player getPlayer() {
return player;
}
public double getRange() {
return range;
}
public void setRange(double range) {
this.range = range;
}
public double getPushfactor() {
return pushfactor;
}
public void setPushfactor(double pushfactor) {
this.pushfactor = pushfactor;
}
} }