diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index ee20c206..5b5a6c63 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -48,6 +48,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.MainHand; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -725,17 +726,17 @@ public class GeneralMethods { */ public static Entity getClosestEntity(Location center, double radius) { Entity found = null; - double distance = radius * radius; + Double distance = null; for (Entity entity : GeneralMethods.getEntitiesAroundPoint(center, radius)) { - double check = center.distance(entity.getLocation()); + double check = center.distanceSquared(entity.getLocation()); - if (check < distance) { + if (distance == null || check < distance) { found = entity; distance = check; } } - + return found; } @@ -747,12 +748,12 @@ public class GeneralMethods { */ public static LivingEntity getClosestLivingEntity(Location center, double radius) { LivingEntity le = null; - double distance = radius * radius; + Double distance = null; for (Entity entity : GeneralMethods.getEntitiesAroundPoint(center, radius)) { - double check = center.distance(entity.getLocation()); + double check = center.distanceSquared(entity.getLocation()); - if (entity instanceof LivingEntity && check < distance) { + if (entity instanceof LivingEntity && (distance == null || check < distance)) { le = (LivingEntity) entity; distance = check; } @@ -962,6 +963,16 @@ public class GeneralMethods { return location.clone().subtract(new Vector(Math.cos(angle), 0, Math.sin(angle)).normalize().multiply(distance)); } + public static Location getMainHandLocation(final Player player) { + Location loc; + if (player.getMainHand() == MainHand.LEFT) { + loc = GeneralMethods.getLeftSide(player.getLocation(), .55).add(0, 1.2, 0); + } else { + loc = GeneralMethods.getRightSide(player.getLocation(), .55).add(0, 1.2, 0); + } + return loc; + } + public static Plugin getProbending() { if (hasProbending()) { return Bukkit.getServer().getPluginManager().getPlugin("Probending"); @@ -1031,8 +1042,8 @@ public class GeneralMethods { public static Entity getTargetedEntity(final Player player, final double range) { return getTargetedEntity(player, range, new ArrayList()); } - - public static Location getTargetedLocation(final Player player, final double range, final boolean ignoreTempBlocks, final Material... nonOpaque2) { + + public static Location getTargetedLocation(final Player player, final double range, final boolean ignoreTempBlocks, final boolean checkDiagonals, final Material... nonOpaque2) { final Location origin = player.getEyeLocation(); final Vector direction = origin.getDirection(); @@ -1052,6 +1063,11 @@ public class GeneralMethods { for (double i = 0; i < range; i += 0.2) { location.add(vec); + + if (checkDiagonals && checkDiagonalWall(location, vec)) { + location.subtract(vec); + break; + } final Block block = location.getBlock(); @@ -1068,12 +1084,16 @@ public class GeneralMethods { return location; } + public static Location getTargetedLocation(final Player player, final double range, final boolean ignoreTempBlocks, final Material... nonOpaque2) { + return getTargetedLocation(player, range, ignoreTempBlocks, true, nonOpaque2); + } + public static Location getTargetedLocation(final Player player, final double range, final Material... nonOpaque2) { return getTargetedLocation(player, range, false, nonOpaque2); } public static Location getTargetedLocation(final Player player, final int range) { - return getTargetedLocation(player, range, Material.AIR); + return getTargetedLocation(player, range, false); } public static Block getTopBlock(final Location loc, final int range) { diff --git a/src/com/projectkorra/projectkorra/ability/EarthAbility.java b/src/com/projectkorra/projectkorra/ability/EarthAbility.java index d0aae2fc..1617ebaf 100644 --- a/src/com/projectkorra/projectkorra/ability/EarthAbility.java +++ b/src/com/projectkorra/projectkorra/ability/EarthAbility.java @@ -563,10 +563,10 @@ public abstract class EarthAbility extends ElementalAbi if (block.equals(sourceblock)) { info.getState().update(true, false); if (RaiseEarth.blockInAllAffectedBlocks(sourceblock)) { - EarthAbility.revertBlock(sourceblock); + RaiseEarth.revertAffectedBlock(sourceblock); } if (RaiseEarth.blockInAllAffectedBlocks(block)) { - EarthAbility.revertBlock(block); + RaiseEarth.revertAffectedBlock(block); } MOVED_EARTH.remove(block); return true; @@ -595,10 +595,10 @@ public abstract class EarthAbility extends ElementalAbi } if (RaiseEarth.blockInAllAffectedBlocks(sourceblock)) { - EarthAbility.revertBlock(sourceblock); + RaiseEarth.revertAffectedBlock(sourceblock); } if (RaiseEarth.blockInAllAffectedBlocks(block)) { - EarthAbility.revertBlock(block); + RaiseEarth.revertAffectedBlock(block); } MOVED_EARTH.remove(block); } diff --git a/src/com/projectkorra/projectkorra/airbending/AirBlast.java b/src/com/projectkorra/projectkorra/airbending/AirBlast.java index 1b1c0650..13ff8fca 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBlast.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBlast.java @@ -213,72 +213,72 @@ public class AirBlast extends AirAbility { } private void affect(final Entity entity) { - final boolean isUser = entity.getUniqueId() == this.player.getUniqueId(); - - if (!isUser || this.isFromOtherOrigin) { - this.pushFactor = this.pushFactorForOthers; - final Vector velocity = entity.getVelocity(); - final double max = this.speed / this.speedFactor; - double factor = this.pushFactor; - - final Vector push = this.direction.clone(); - if (Math.abs(push.getY()) > max && !isUser) { - if (push.getY() < 0) { - push.setY(-max); - } else { - push.setY(max); - } - } - if (this.location.getWorld().equals(this.origin.getWorld())) { - factor *= 1 - this.location.distance(this.origin) / (2 * this.range); - } - - if (isUser && GeneralMethods.isSolid(this.player.getLocation().add(0, -.5, 0).getBlock())) { - factor *= .5; - } - - final double comp = velocity.dot(push.clone().normalize()); - if (comp > factor) { - velocity.multiply(.5); - velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize()))); - } else if (comp + factor * .5 > factor) { - velocity.add(push.clone().multiply(factor - comp)); - } else { - velocity.add(push.clone().multiply(factor * .5)); - } - - if (entity instanceof Player) { - if (Commands.invincible.contains(((Player) entity).getName())) { - return; - } - } - - if (Double.isNaN(velocity.length())) { + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) { return; } + } + + final boolean isUser = entity.getUniqueId() == this.player.getUniqueId(); + double knockback = this.pushFactorForOthers; - GeneralMethods.setVelocity(entity, velocity); - if (this.source != null) { - new HorizontalVelocityTracker(entity, this.player, 200l, this.source); + if (isUser) { + if (isFromOtherOrigin) { + knockback = this.pushFactor; } else { - new HorizontalVelocityTracker(entity, this.player, 200l, this); - } - - if (entity.getFireTicks() > 0) { - entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0); - } - - entity.setFireTicks(0); - breakBreathbendingHold(entity); - - if (this.source != null && (this.damage > 0 && entity instanceof LivingEntity && !entity.equals(this.player) && !this.affectedEntities.contains(entity))) { - DamageHandler.damageEntity(entity, this.damage, this.source); - this.affectedEntities.add(entity); - } else if (this.source == null && (this.damage > 0 && entity instanceof LivingEntity && !entity.equals(this.player) && !this.affectedEntities.contains(entity))) { - DamageHandler.damageEntity(entity, this.damage, this); - this.affectedEntities.add(entity); + return; } } + + final double max = this.speed / this.speedFactor; + + final Vector push = this.direction.clone(); + if (Math.abs(push.getY()) > max && !isUser) { + if (push.getY() < 0) { + push.setY(-max); + } else { + push.setY(max); + } + } + + if (this.location.getWorld().equals(this.origin.getWorld())) { + knockback *= 1 - this.location.distance(this.origin) / (2 * this.range); + } + + if (GeneralMethods.isSolid(entity.getLocation().add(0, -0.5, 0).getBlock()) && source == null) { + knockback *= 0.85; + } + + push.normalize().multiply(knockback); + + if (Math.abs(entity.getVelocity().dot(push)) > knockback && entity.getVelocity().angle(push) > Math.PI / 3) { + push.normalize().add(entity.getVelocity()).multiply(knockback); + } + + GeneralMethods.setVelocity(entity, push); + + if (this.source != null) { + new HorizontalVelocityTracker(entity, this.player, 200l, this.source); + } else { + new HorizontalVelocityTracker(entity, this.player, 200l, this); + } + + if (this.damage > 0 && entity instanceof LivingEntity && !entity.equals(this.player) && !this.affectedEntities.contains(entity)) { + if (this.source != null) { + DamageHandler.damageEntity(entity, this.damage, this.source); + } else { + DamageHandler.damageEntity(entity, this.damage, this); + } + + this.affectedEntities.add(entity); + } + + if (entity.getFireTicks() > 0) { + entity.getWorld().playEffect(entity.getLocation(), Effect.EXTINGUISH, 0); + } + + entity.setFireTicks(0); + breakBreathbendingHold(entity); } @Override diff --git a/src/com/projectkorra/projectkorra/airbending/AirBurst.java b/src/com/projectkorra/projectkorra/airbending/AirBurst.java index 6ea1c3ff..31832346 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirBurst.java +++ b/src/com/projectkorra/projectkorra/airbending/AirBurst.java @@ -325,10 +325,6 @@ public class AirBurst extends AirAbility { return this.blasts; } - public ArrayList getAffectedEntities() { - return this.affectedEntities; - } - @Override public Class getConfigType() { return AirBurstConfig.class; diff --git a/src/com/projectkorra/projectkorra/airbending/AirSuction.java b/src/com/projectkorra/projectkorra/airbending/AirSuction.java index 175715f4..1a1d40f1 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSuction.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSuction.java @@ -44,6 +44,8 @@ public class AirSuction extends AirAbility { private double radius; @Attribute(Attribute.KNOCKBACK) private double pushFactor; + @Attribute(Attribute.KNOCKBACK + "Others") + private double pushFactorForOthers; private Random random; private Location location; private Location origin; @@ -78,7 +80,8 @@ public class AirSuction extends AirAbility { this.speed = config.Speed; this.range = config.Range; this.radius = config.Radius; - this.pushFactor = config.PushFactor; + this.pushFactor = config.PushFactor_Self; + this.pushFactorForOthers = config.PushFactor_Others; this.cooldown = config.Cooldown; this.random = new Random(); this.origin = this.getTargetLocation(); @@ -203,10 +206,15 @@ public class AirSuction extends AirAbility { if ((entity.getEntityId() == this.player.getEntityId()) && !this.canAffectSelf) { continue; } - final Vector velocity = entity.getVelocity(); + + double knockback = this.pushFactor; + + if (entity.getEntityId() != player.getEntityId()) { + knockback = this.pushFactorForOthers; + } + final double max = this.speed; final Vector push = this.direction.clone(); - double factor = this.pushFactor; if (Math.abs(push.getY()) > max) { if (push.getY() < 0) { @@ -217,20 +225,16 @@ public class AirSuction extends AirAbility { } if (this.location.getWorld().equals(this.origin.getWorld())) { - factor *= 1 - this.location.distance(this.origin) / (2 * this.range); + knockback *= 1 - this.location.distance(this.origin) / (2 * this.range); + } + + push.normalize().multiply(knockback); + + if (Math.abs(entity.getVelocity().dot(push)) > knockback) { + push.normalize().add(entity.getVelocity()).multiply(knockback); } - final double comp = velocity.dot(push.clone().normalize()); - if (comp > factor) { - velocity.multiply(.5); - velocity.add(push.clone().normalize().multiply(velocity.clone().dot(push.clone().normalize()))); - } else if (comp + factor * .5 > factor) { - velocity.add(push.clone().multiply(factor - comp)); - } else { - velocity.add(push.clone().multiply(factor * .5)); - } - - GeneralMethods.setVelocity(entity, velocity); + GeneralMethods.setVelocity(entity, push.normalize().multiply(knockback)); new HorizontalVelocityTracker(entity, this.player, 200l, this); entity.setFallDistance(0); diff --git a/src/com/projectkorra/projectkorra/airbending/AirSwipe.java b/src/com/projectkorra/projectkorra/airbending/AirSwipe.java index eabf8215..c10a88fb 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirSwipe.java +++ b/src/com/projectkorra/projectkorra/airbending/AirSwipe.java @@ -78,7 +78,7 @@ public class AirSwipe extends AirAbility { } this.charging = charging; - this.origin = player.getEyeLocation(); + this.origin = GeneralMethods.getMainHandLocation(player); this.particles = config.AnimationParticleAmount; this.arc = config.Arc; this.arcIncrement = config.StepSize; diff --git a/src/com/projectkorra/projectkorra/airbending/Suffocate.java b/src/com/projectkorra/projectkorra/airbending/Suffocate.java index 776b4fcf..04cdbe6e 100644 --- a/src/com/projectkorra/projectkorra/airbending/Suffocate.java +++ b/src/com/projectkorra/projectkorra/airbending/Suffocate.java @@ -143,7 +143,6 @@ public class Suffocate extends AirAbility { } } - this.bPlayer.addCooldown(this); this.start(); } @@ -172,7 +171,7 @@ public class Suffocate extends AirAbility { if (this.player.getWorld().equals(this.targets.get(0).getWorld())) { dist = this.player.getEyeLocation().distance(this.targets.get(0).getEyeLocation()); } - final Location targetLoc = this.player.getEyeLocation().clone().add(this.player.getEyeLocation().getDirection().normalize().multiply(dist)); + final Location targetLoc = GeneralMethods.getTargetedLocation(player, dist, false, getTransparentMaterials()); final List ents = GeneralMethods.getEntitiesAroundPoint(targetLoc, this.constantAimRadius); for (int i = 0; i < this.targets.size(); i++) { @@ -337,6 +336,7 @@ public class Suffocate extends AirAbility { @Override public void remove() { super.remove(); + this.bPlayer.addCooldown(this); for (int i = 0; i < this.tasks.size(); i++) { this.tasks.get(i).cancel(); this.tasks.remove(i); diff --git a/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java b/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java index b287ee0a..29f9e70d 100644 --- a/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java +++ b/src/com/projectkorra/projectkorra/airbending/combo/AirSweep.java @@ -3,6 +3,7 @@ package com.projectkorra.projectkorra.airbending.combo; import java.util.ArrayList; import java.util.List; +import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -133,22 +134,23 @@ public class AirSweep extends AirAbility implements ComboAbility if (this.origin == null) { this.direction = this.player.getEyeLocation().getDirection().normalize(); - this.origin = this.player.getLocation().add(this.direction.clone().multiply(10)); + this.origin = GeneralMethods.getMainHandLocation(player).add(this.direction.clone().multiply(10)); } if (this.progressCounter < 8) { return; } if (this.destination == null) { - this.destination = this.player.getLocation().add(this.player.getEyeLocation().getDirection().normalize().multiply(10)); + this.destination = GeneralMethods.getMainHandLocation(player).add(GeneralMethods.getMainHandLocation(player).getDirection().normalize().multiply(10)); final Vector origToDest = GeneralMethods.getDirection(this.origin, this.destination); + final Location hand = GeneralMethods.getMainHandLocation(player); for (double i = 0; i < 30; i++) { final Location endLoc = this.origin.clone().add(origToDest.clone().multiply(i / 30)); - if (GeneralMethods.locationEqualsIgnoreDirection(this.player.getLocation(), endLoc)) { + if (GeneralMethods.locationEqualsIgnoreDirection(hand, endLoc)) { continue; } - final Vector vec = GeneralMethods.getDirection(this.player.getLocation(), endLoc); + final Vector vec = GeneralMethods.getDirection(hand, endLoc); - final FireComboStream fs = new FireComboStream(this.player, this, vec, this.player.getLocation(), this.range, this.speed); + final FireComboStream fs = new FireComboStream(this.player, this, vec, hand, this.range, this.speed); fs.setDensity(1); fs.setSpread(0F); fs.setUseNewParticles(true); @@ -193,17 +195,17 @@ public class AirSweep extends AirAbility implements ComboAbility this.remove(); return; } - if (!entity.equals(this.player) && !this.affectedEntities.contains(entity) && !(entity instanceof Player && Commands.invincible.contains(((Player) entity).getName()))) { - this.affectedEntities.add(entity); + if (!entity.equals(this.player) && !(entity instanceof Player && Commands.invincible.contains(((Player) entity).getName()))) { if (this.knockback != 0) { - final Vector force = fstream.getDirection(); - entity.setVelocity(force.multiply(this.knockback)); + final Vector force = fstream.getLocation().getDirection(); + GeneralMethods.setVelocity(entity, force.clone().multiply(this.knockback)); + new HorizontalVelocityTracker(entity, this.player, 200l, this); + entity.setFallDistance(0); } - if (this.damage != 0) { - if (entity instanceof LivingEntity) { - if (fstream.getAbility().getName().equalsIgnoreCase("AirSweep")) { - DamageHandler.damageEntity(entity, this.damage, this); - } else { + if(!this.affectedEntities.contains(entity)) { + this.affectedEntities.add(entity); + if (this.damage != 0) { + if (entity instanceof LivingEntity) { DamageHandler.damageEntity(entity, this.damage, this); } } diff --git a/src/com/projectkorra/projectkorra/command/PresetCommand.java b/src/com/projectkorra/projectkorra/command/PresetCommand.java index 9eac68ea..9da29fbf 100644 --- a/src/com/projectkorra/projectkorra/command/PresetCommand.java +++ b/src/com/projectkorra/projectkorra/command/PresetCommand.java @@ -78,41 +78,45 @@ public class PresetCommand extends PKCommand { bPlayer = BendingPlayer.getBendingPlayer(player); } - // bending preset list. - if (args.size() == 1) { - if (Arrays.asList(listaliases).contains(args.get(0)) && this.hasPermission(sender, "list")) { - boolean firstMessage = true; - - final List presets = Preset.presets.get(player.getUniqueId()); - final List presetNames = new ArrayList(); - - if (presets == null || presets.isEmpty()) { - GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noPresets); - return; - } - - for (final Preset preset : presets) { - presetNames.add(preset.getName()); - } - - for (final String s : this.getPage(presetNames, ChatColor.GOLD + "Presets: ", 1, false)) { - if (firstMessage) { - GeneralMethods.sendBrandingMessage(sender, s); - firstMessage = false; - } else { - sender.sendMessage(ChatColor.YELLOW + s); - } - } - - return; + int page = 1; + String name = null; + if (args.size() == 1 && !Arrays.asList(listaliases).contains(args.get(0))){ + this.help(sender, false); + } else if (args.size() >= 2) { + if (Arrays.asList(listaliases).contains(args.get(0))) { + page = Integer.parseInt(args.get(1)); } else { - this.help(sender, false); - return; + name = args.get(1); } } - final String name = args.get(1); - if (Arrays.asList(deletealiases).contains(args.get(0)) && this.hasPermission(sender, "delete")) { // bending preset delete name. + // bending preset list. + if (Arrays.asList(listaliases).contains(args.get(0)) && this.hasPermission(sender, "list")) { + boolean firstMessage = true; + + final List presets = Preset.presets.get(player.getUniqueId()); + final List presetNames = new ArrayList(); + + if (presets == null || presets.isEmpty()) { + GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noPresets); + return; + } + + for (final Preset preset : presets) { + presetNames.add(preset.getName()); + } + + for (final String s : this.getPage(presetNames, ChatColor.GOLD + "Presets: ", page, false)) { + if (firstMessage) { + GeneralMethods.sendBrandingMessage(sender, s); + firstMessage = false; + } else { + sender.sendMessage(ChatColor.YELLOW + s); + } + } + + return; + } else if (Arrays.asList(deletealiases).contains(args.get(0)) && this.hasPermission(sender, "delete")) { // bending preset delete name. if (!Preset.presetExists(player, name)) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noPresetName); return; diff --git a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java index 95deda30..dd9d00ce 100644 --- a/src/com/projectkorra/projectkorra/configuration/ConfigManager.java +++ b/src/com/projectkorra/projectkorra/configuration/ConfigManager.java @@ -91,4 +91,4 @@ public class ConfigManager { return null; } } -} \ No newline at end of file +} diff --git a/src/com/projectkorra/projectkorra/earthbending/Catapult.java b/src/com/projectkorra/projectkorra/earthbending/Catapult.java index 044add6b..9e624c4b 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Catapult.java +++ b/src/com/projectkorra/projectkorra/earthbending/Catapult.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.attribute.Attribute; @@ -70,6 +71,9 @@ public class Catapult extends EarthAbility { private void moveEarth(final Vector apply, final Vector direction) { for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.origin, 2)) { if (entity.getEntityId() != this.player.getEntityId()) { + if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation()) || ((entity instanceof Player) && Commands.invincible.contains(((Player) entity).getName()))) { + continue; + } entity.setVelocity(apply); } } diff --git a/src/com/projectkorra/projectkorra/earthbending/Collapse.java b/src/com/projectkorra/projectkorra/earthbending/Collapse.java index 42db5e40..a2e879ed 100644 --- a/src/com/projectkorra/projectkorra/earthbending/Collapse.java +++ b/src/com/projectkorra/projectkorra/earthbending/Collapse.java @@ -99,7 +99,7 @@ public class Collapse extends EarthAbility { thisBlock = this.block.getWorld().getBlockAt(this.location.clone().add(this.direction.clone().multiply(-i))); this.affectedBlocks.put(thisBlock, thisBlock); if (RaiseEarth.blockInAllAffectedBlocks(thisBlock)) { - EarthAbility.revertBlock(thisBlock); + RaiseEarth.revertAffectedBlock(thisBlock); } } } diff --git a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java index 43c32723..16e3cb9d 100644 --- a/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java +++ b/src/com/projectkorra/projectkorra/earthbending/EarthBlast.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -376,8 +377,12 @@ public class EarthBlast extends EarthAbility { this.firstDestination = this.location.clone(); if (this.destination.getY() - this.location.getY() > 2) { this.firstDestination.setY(this.destination.getY() - 1); - } else { + } else if (this.location.getY() > player.getEyeLocation().getY() && this.location.getBlock().getRelative(BlockFace.UP).isPassable()) { + this.firstDestination.subtract(0, 2, 0); + } else if (this.location.getBlock().getRelative(BlockFace.UP).isPassable() && this.location.getBlock().getRelative(BlockFace.UP, 2).isPassable()) { this.firstDestination.add(0, 2, 0); + } else { + this.firstDestination.add(GeneralMethods.getDirection(this.location, this.destination).normalize().setY(0)); } if (this.destination.distanceSquared(this.location) <= 1) { diff --git a/src/com/projectkorra/projectkorra/earthbending/RaiseEarth.java b/src/com/projectkorra/projectkorra/earthbending/RaiseEarth.java index d5433629..e89a2ed7 100644 --- a/src/com/projectkorra/projectkorra/earthbending/RaiseEarth.java +++ b/src/com/projectkorra/projectkorra/earthbending/RaiseEarth.java @@ -2,7 +2,6 @@ package com.projectkorra.projectkorra.earthbending; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Location; @@ -15,11 +14,10 @@ import com.projectkorra.projectkorra.attribute.Attribute; import com.projectkorra.projectkorra.configuration.configs.abilities.earth.RaiseEarthConfig; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; +import com.projectkorra.projectkorra.util.TempBlock; public class RaiseEarth extends EarthAbility { - private static final Map ALL_AFFECTED_BLOCKS = new ConcurrentHashMap<>(); - private int distance; @Attribute(Attribute.HEIGHT) private int height; @@ -104,7 +102,7 @@ public class RaiseEarth extends EarthAbility { private boolean canInstantiate() { for (final Block block : this.affectedBlocks.keySet()) { - if (!this.isEarthbendable(block) || ALL_AFFECTED_BLOCKS.containsKey(block)) { + if (!this.isEarthbendable(block) || TempBlock.isTempBlock(block)) { return false; } } @@ -143,11 +141,15 @@ public class RaiseEarth extends EarthAbility { } public static boolean blockInAllAffectedBlocks(final Block block) { - return ALL_AFFECTED_BLOCKS.containsKey(block); + for (RaiseEarth raiseEarth : getAbilities(RaiseEarth.class)) { + if (raiseEarth.affectedBlocks.contains(block)) { + return true; + } + } + return false; } public static void revertAffectedBlock(final Block block) { - ALL_AFFECTED_BLOCKS.remove(block); for (final RaiseEarth raiseEarth : getAbilities(RaiseEarth.class)) { raiseEarth.affectedBlocks.remove(block); } diff --git a/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java b/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java index e2e5eab4..f65e30c8 100644 --- a/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java +++ b/src/com/projectkorra/projectkorra/earthbending/metal/MetalClips.java @@ -18,6 +18,7 @@ import org.bukkit.entity.Zombie; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import com.projectkorra.projectkorra.command.Commands; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.MetalAbility; @@ -166,7 +167,7 @@ public class MetalClips extends MetalAbility { return; } else if (this.metalClipsCount == 3 && !this.canUse4Clips) { return; - } else if (this.targetEntity != null && GeneralMethods.isRegionProtectedFromBuild(this, this.targetEntity.getLocation())) { + } else if (this.targetEntity != null && (GeneralMethods.isRegionProtectedFromBuild(this, this.targetEntity.getLocation()) || ((targetEntity instanceof Player) && Commands.invincible.contains(((Player) targetEntity).getName())))) { return; } diff --git a/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java b/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java index 3fa43402..1b61e7a7 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java +++ b/src/com/projectkorra/projectkorra/firebending/FireBlastCharged.java @@ -217,7 +217,7 @@ public class FireBlastCharged extends FireAbility { } boolean exploded = false; - for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, 2 * this.collisionRadius)) { + for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.location, this.collisionRadius)) { if (entity.getEntityId() == this.player.getEntityId() || GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation())) { continue; } @@ -311,7 +311,9 @@ public class FireBlastCharged extends FireAbility { @Override public void remove() { super.remove(); - this.bPlayer.addCooldown(this); + if (this.charged) { + this.bPlayer.addCooldown(this); + } } @Override diff --git a/src/com/projectkorra/projectkorra/firebending/FireJet.java b/src/com/projectkorra/projectkorra/firebending/FireJet.java index 6e9d235a..3fe40aad 100644 --- a/src/com/projectkorra/projectkorra/firebending/FireJet.java +++ b/src/com/projectkorra/projectkorra/firebending/FireJet.java @@ -74,10 +74,8 @@ public class FireJet extends FireAbility { this.time = System.currentTimeMillis(); this.start(); - + this.previousGlidingState = player.isGliding(); - - this.bPlayer.addCooldown(this); } } @@ -122,6 +120,7 @@ public class FireJet extends FireAbility { } this.flightHandler.removeInstance(this.player, this.getName()); this.player.setFallDistance(0); + this.bPlayer.addCooldown(this); } @Override diff --git a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java index a8695d29..16a62b81 100644 --- a/src/com/projectkorra/projectkorra/firebending/WallOfFire.java +++ b/src/com/projectkorra/projectkorra/firebending/WallOfFire.java @@ -103,7 +103,6 @@ public class WallOfFire extends FireAbility { this.initializeBlocks(); this.start(); - this.bPlayer.addCooldown(this); } private void affect(final Entity entity) { @@ -211,6 +210,12 @@ public class WallOfFire extends FireAbility { } } + @Override + public void remove() { + super.remove(); + this.bPlayer.addCooldown(this); + } + @Override public String getName() { return "WallOfFire"; diff --git a/src/com/projectkorra/projectkorra/firebending/combo/JetBlast.java b/src/com/projectkorra/projectkorra/firebending/combo/JetBlast.java index a4421df1..5e044148 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/JetBlast.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/JetBlast.java @@ -81,7 +81,6 @@ public class JetBlast extends FireAbility implements ComboAbilit return; } - this.bPlayer.addCooldown("JetBlast", this.cooldown); this.firstTime = false; final float spread = 0F; ParticleEffect.EXPLOSION_LARGE.display(this.player.getLocation(), 1, spread, spread, spread, 0); @@ -108,6 +107,7 @@ public class JetBlast extends FireAbility implements ComboAbilit task.remove(); } super.remove(); + this.bPlayer.addCooldown("JetBlast", this.cooldown); } @Override diff --git a/src/com/projectkorra/projectkorra/firebending/combo/JetBlaze.java b/src/com/projectkorra/projectkorra/firebending/combo/JetBlaze.java index 2063e3c3..bb4dd4a7 100644 --- a/src/com/projectkorra/projectkorra/firebending/combo/JetBlaze.java +++ b/src/com/projectkorra/projectkorra/firebending/combo/JetBlaze.java @@ -90,7 +90,6 @@ public class JetBlaze extends FireAbility implements ComboAbilit this.remove(); return; } - this.bPlayer.addCooldown("JetBlaze", this.cooldown); this.firstTime = false; } else if (System.currentTimeMillis() - this.time > this.duration) { this.remove(); @@ -105,7 +104,7 @@ public class JetBlaze extends FireAbility implements ComboAbilit fs.setDensity(8); fs.setSpread(1.0F); fs.setUseNewParticles(true); - fs.setCollisionRadius(3); + fs.setCollisionRadius(2); fs.setParticleEffect(ParticleEffect.SMOKE_LARGE); fs.setDamage(this.damage); fs.setFireTicks(this.fireTicks); @@ -123,6 +122,7 @@ public class JetBlaze extends FireAbility implements ComboAbilit task.remove(); } super.remove(); + this.bPlayer.addCooldown("JetBlaze", this.cooldown); } @Override diff --git a/src/com/projectkorra/projectkorra/firebending/lightning/Lightning.java b/src/com/projectkorra/projectkorra/firebending/lightning/Lightning.java index 5eb0801e..31b84960 100644 --- a/src/com/projectkorra/projectkorra/firebending/lightning/Lightning.java +++ b/src/com/projectkorra/projectkorra/firebending/lightning/Lightning.java @@ -3,6 +3,8 @@ package com.projectkorra.projectkorra.firebending.lightning; import java.util.ArrayList; import java.util.List; +import com.projectkorra.projectkorra.ability.CoreAbility; +import com.projectkorra.projectkorra.firebending.FireJet; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -181,6 +183,9 @@ public class Lightning extends LightningAbility { } else if (!this.bPlayer.canBendIgnoreCooldowns(this)) { this.remove(); return; + } else if (CoreAbility.hasAbility(player, FireJet.class)){ + this.removeWithTasks(); + return; } this.locations.clear(); diff --git a/src/com/projectkorra/projectkorra/waterbending/SurgeWall.java b/src/com/projectkorra/projectkorra/waterbending/SurgeWall.java index b451f74a..7db0060e 100644 --- a/src/com/projectkorra/projectkorra/waterbending/SurgeWall.java +++ b/src/com/projectkorra/projectkorra/waterbending/SurgeWall.java @@ -256,12 +256,11 @@ public class SurgeWall extends WaterAbility { } final ArrayList blocks = new ArrayList(); - final Location targetLoc = GeneralMethods.getTargetedLocation(this.player, (int) this.range, Material.WATER, Material.ICE); + final Location targetLoc = GeneralMethods.getTargetedLocation(this.player, (int) this.range, false, false, Material.WATER, Material.ICE); this.location = targetLoc.clone(); final Vector eyeDir = this.player.getEyeLocation().getDirection(); Vector vector; Block block; - for (double i = 0; i <= this.getNightFactor(this.radius); i += 0.5) { for (double angle = 0; angle < 360; angle += 10) { vector = GeneralMethods.getOrthogonalVector(eyeDir.clone(), angle, i); diff --git a/src/com/projectkorra/projectkorra/waterbending/util/WaterReturn.java b/src/com/projectkorra/projectkorra/waterbending/util/WaterReturn.java index 52dd2c28..15543946 100644 --- a/src/com/projectkorra/projectkorra/waterbending/util/WaterReturn.java +++ b/src/com/projectkorra/projectkorra/waterbending/util/WaterReturn.java @@ -116,8 +116,8 @@ public class WaterReturn extends WaterAbility { private void fillBottle() { final PlayerInventory inventory = this.player.getInventory(); - if (inventory.contains(Material.GLASS_BOTTLE)) { - final int index = inventory.first(Material.GLASS_BOTTLE); + final int index = inventory.first(Material.GLASS_BOTTLE); + if (index >= 0) { final ItemStack item = inventory.getItem(index); final ItemStack water = waterBottleItem(); @@ -148,27 +148,15 @@ public class WaterReturn extends WaterAbility { return false; } - public static boolean hasWaterBottle(final Player player) { - if (hasAbility(player, WaterReturn.class) || isBending(player)) { - return false; - } - final PlayerInventory inventory = player.getInventory(); - if (inventory.contains(Material.POTION)) { - final ItemStack item = inventory.getItem(inventory.first(Material.POTION)); - final PotionMeta meta = (PotionMeta) item.getItemMeta(); - return meta.getBasePotionData().getType() == PotionType.WATER; - } - return false; - } - - public static void emptyWaterBottle(final Player player) { - final PlayerInventory inventory = player.getInventory(); + public static int firstWaterBottle(final PlayerInventory inventory) { int index = inventory.first(Material.POTION); // Check that the first one found is actually a WATER bottle. We aren't implementing potion bending just yet. - if (index != -1 && !((PotionMeta) inventory.getItem(index).getItemMeta()).getBasePotionData().getType().equals(PotionType.WATER)) { - for (int i = 0; i < inventory.getSize(); i++) { - if (inventory.getItem(i).getType() == Material.POTION) { + if (index != -1) { + int aux = index; + index = -1; + for (int i = aux; i < inventory.getSize(); i++) { + if (inventory.getItem(i) != null && inventory.getItem(i).getType() == Material.POTION && inventory.getItem(i).hasItemMeta()) { final PotionMeta meta = (PotionMeta) inventory.getItem(i).getItemMeta(); if (meta.getBasePotionData().getType().equals(PotionType.WATER)) { index = i; @@ -178,6 +166,22 @@ public class WaterReturn extends WaterAbility { } } + return index; + } + + public static boolean hasWaterBottle(final Player player) { + if (hasAbility(player, WaterReturn.class) || isBending(player)) { + return false; + } + final PlayerInventory inventory = player.getInventory(); + + return WaterReturn.firstWaterBottle(inventory) >= 0; + } + + public static void emptyWaterBottle(final Player player) { + final PlayerInventory inventory = player.getInventory(); + int index = WaterReturn.firstWaterBottle(inventory); + if (index != -1) { final ItemStack item = inventory.getItem(index); if (item.getAmount() == 1) {