diff --git a/src/com/projectkorra/ProjectKorra/ConfigManager.java b/src/com/projectkorra/ProjectKorra/ConfigManager.java index a5c5d7a1..548f3961 100644 --- a/src/com/projectkorra/ProjectKorra/ConfigManager.java +++ b/src/com/projectkorra/ProjectKorra/ConfigManager.java @@ -275,6 +275,11 @@ public class ConfigManager { config.addDefault("Abilities.Earth.Earthblast.Damage", 4); config.addDefault("Abilities.Earth.EarthBlast.Push", 0.3); + config.addDefault("Abilities.Earth.EarthGrab.Enabled", true); + config.addDefault("Abilities.Earth.EarthGrab.Description", "To use, simply left-click while targeting a creature within range. " + + "This ability will erect a circle of earth to trap the creature in."); + config.addDefault("Abilities.Earth.EarthGrab.Range", 15); + config.addDefault("Abilities.Earth.RaiseEarth.Enabled", true); config.addDefault("Abilities.Earth.RaiseEarth.Description", "To use, simply left-click on an earthbendable block. " + "A column of earth will shoot upwards from that location. " diff --git a/src/com/projectkorra/ProjectKorra/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index ee6e727b..dce1dd39 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -66,6 +66,7 @@ import com.projectkorra.ProjectKorra.earthbending.CompactColumn; import com.projectkorra.ProjectKorra.earthbending.EarthArmor; import com.projectkorra.ProjectKorra.earthbending.EarthBlast; import com.projectkorra.ProjectKorra.earthbending.EarthColumn; +import com.projectkorra.ProjectKorra.earthbending.EarthGrab; import com.projectkorra.ProjectKorra.earthbending.EarthPassive; import com.projectkorra.ProjectKorra.earthbending.EarthWall; import com.projectkorra.ProjectKorra.earthbending.Shockwave; @@ -248,6 +249,9 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("Shockwave")) { new Shockwave(player); } + if (abil.equalsIgnoreCase("EarthGrab")) { + EarthGrab.EarthGrabSelf(player); + } } if (Methods.isFireAbility(abil)) { @@ -501,6 +505,10 @@ public class PKListener implements Listener { if (abil.equalsIgnoreCase("EarthArmor")) { new EarthArmor(player); } + + if (abil.equalsIgnoreCase("EarthGrab")) { + new EarthGrab(player); + } } if (Methods.isFireAbility(abil)) { if (Methods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Fire.CanBendWithWeapons")) { diff --git a/src/com/projectkorra/ProjectKorra/earthbending/EarthGrab.java b/src/com/projectkorra/ProjectKorra/earthbending/EarthGrab.java new file mode 100644 index 00000000..f2488d4b --- /dev/null +++ b/src/com/projectkorra/ProjectKorra/earthbending/EarthGrab.java @@ -0,0 +1,149 @@ +package com.projectkorra.ProjectKorra.earthbending; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import com.projectkorra.ProjectKorra.Methods; +import com.projectkorra.ProjectKorra.ProjectKorra; + +public class EarthGrab { + + private static double range = ProjectKorra.plugin.getConfig().getDouble("Abilities.Earth.EarthGrab.Range"); + public static Map cooldowns = new HashMap(); + + public EarthGrab(Player player) { + // Methods.verbose("initiating"); + if (cooldowns.containsKey(player.getName())) { + if (cooldowns.get(player.getName()) + ProjectKorra.plugin.getConfig().getLong("Properties.GlobalCooldown") >= System.currentTimeMillis()) { + return; + } else { + cooldowns.remove(player.getName()); + } + } + + Location origin = player.getEyeLocation(); + Vector direction = origin.getDirection(); + double lowestdistance = range + 1; + Entity closestentity = null; + for (Entity entity : Methods.getEntitiesAroundPoint(origin, range)) { + if (Methods.getDistanceFromLine(direction, origin, + entity.getLocation()) <= 3 + && (entity instanceof LivingEntity) + && (entity.getEntityId() != player.getEntityId())) { + double distance = origin.distance(entity.getLocation()); + if (distance < lowestdistance) { + closestentity = entity; + lowestdistance = distance; + } + } + } + + if (closestentity != null) { + // Methods.verbose("grabbing"); + ArrayList blocks = new ArrayList(); + Location location = closestentity.getLocation(); + Location loc1 = location.clone(); + Location loc2 = location.clone(); + Location testloc, testloc2; + double factor = 3; + double factor2 = 4; + int height1 = 3; + int height2 = 2; + for (double angle = 0; angle <= 360; angle += 20) { + testloc = loc1.clone().add( + factor * Math.cos(Math.toRadians(angle)), 1, + factor * Math.sin(Math.toRadians(angle))); + testloc2 = loc2.clone().add( + factor2 * Math.cos(Math.toRadians(angle)), 1, + factor2 * Math.sin(Math.toRadians(angle))); + for (int y = 0; y < EarthColumn.standardheight - height1; y++) { + testloc = testloc.clone().add(0, -1, 0); + if (Methods.isEarthbendable(player, testloc.getBlock())) { + if (!blocks.contains(testloc.getBlock())) { + new EarthColumn(player, testloc, height1 + y - 1); + } + blocks.add(testloc.getBlock()); + break; + } + } + for (int y = 0; y < EarthColumn.standardheight - height2; y++) { + testloc2 = testloc2.clone().add(0, -1, 0); + if (Methods.isEarthbendable(player, testloc2.getBlock())) { + if (!blocks.contains(testloc2.getBlock())) { + new EarthColumn(player, testloc2, height2 + y - 1); + } + blocks.add(testloc2.getBlock()); + break; + } + } + } + + if (!blocks.isEmpty()) + cooldowns.put(player.getName(), System.currentTimeMillis()); + } + } + + public static void EarthGrabSelf(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()); + } + } + + Entity closestentity = player; + + if (closestentity != null) { + // Methods.verbose("grabbing"); + ArrayList blocks = new ArrayList(); + Location location = closestentity.getLocation(); + Location loc1 = location.clone(); + Location loc2 = location.clone(); + Location testloc, testloc2; + double factor = 3; + double factor2 = 4; + int height1 = 3; + int height2 = 2; + for (double angle = 0; angle <= 360; angle += 20) { + testloc = loc1.clone().add( + factor * Math.cos(Math.toRadians(angle)), 1, + factor * Math.sin(Math.toRadians(angle))); + testloc2 = loc2.clone().add( + factor2 * Math.cos(Math.toRadians(angle)), 1, + factor2 * Math.sin(Math.toRadians(angle))); + for (int y = 0; y < EarthColumn.standardheight - height1; y++) { + testloc = testloc.clone().add(0, -1, 0); + if (Methods.isEarthbendable(player, testloc.getBlock())) { + if (!blocks.contains(testloc.getBlock())) { + new EarthColumn(player, testloc, height1 + y - 1); + } + blocks.add(testloc.getBlock()); + break; + } + } + for (int y = 0; y < EarthColumn.standardheight - height2; y++) { + testloc2 = testloc2.clone().add(0, -1, 0); + if (Methods.isEarthbendable(player, testloc2.getBlock())) { + if (!blocks.contains(testloc2.getBlock())) { + new EarthColumn(player, testloc2, height2 + y - 1); + } + blocks.add(testloc2.getBlock()); + break; + } + } + } + + if (!blocks.isEmpty()) + cooldowns.put(player.getName(), System.currentTimeMillis()); + } + } +} \ No newline at end of file diff --git a/src/config.yml b/src/config.yml index f45e733f..a57aecf6 100644 --- a/src/config.yml +++ b/src/config.yml @@ -185,6 +185,10 @@ Abilities: Revert: true Damage: 4 Push: 0.3 + EarthGrab: + Enabled: true + Description: "To use, simply left-click while targeting a creature within range. This ability will erect a circle of earth to trap the creature in." + Range: 15 RaiseEarth: Enabled: true Description: "To use, simply left-click on an earthbendable block. A column of earth will shoot upwards from that location. Anything in the way of the column will be brought up with it, leaving talented benders the ability to trap brainless entities up there. Additionally, simply sneak (default shift) looking at an earthbendable block. A wall of earth will shoot upwards from that location. Anything in the way of the wall will be brought up with it."