From b45846be688271158c9dec5653057e577914786e Mon Sep 17 00:00:00 2001 From: MistPhizzle Date: Fri, 13 Jun 2014 16:37:34 -0400 Subject: [PATCH] Earthbending Methods Just some methods for some of the Earthbending Abilities --- .classpath | 15 +- .../ProjectKorra/Information.java | 116 +++++++++++++++ .../projectkorra/ProjectKorra/Methods.java | 133 +++++++++++++++++- 3 files changed, 251 insertions(+), 13 deletions(-) create mode 100644 src/com/projectkorra/ProjectKorra/Information.java diff --git a/.classpath b/.classpath index 490c0604..144906d6 100644 --- a/.classpath +++ b/.classpath @@ -1,18 +1,9 @@ -<<<<<<< HEAD - + + + -======= - - - - - - - - ->>>>>>> 44624cd18ebcbb8b5c2a56bf36e9d5c6a8974795 diff --git a/src/com/projectkorra/ProjectKorra/Information.java b/src/com/projectkorra/ProjectKorra/Information.java new file mode 100644 index 00000000..3f6b3710 --- /dev/null +++ b/src/com/projectkorra/ProjectKorra/Information.java @@ -0,0 +1,116 @@ +package com.projectkorra.ProjectKorra; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.entity.Player; + +public class Information { + + private Player player; + private long time; + private Block block; + private Location location; + private Material type; + private int integer; + private double value; + private byte data; + private String string; + private BlockState state; + + private static int ID = Integer.MIN_VALUE; + private int id; + + public Information() { + id = ID++; + if (ID >= Integer.MAX_VALUE) { + ID = Integer.MIN_VALUE; + } + } + + public int getID() { + return id; + } + + public void setState(BlockState state) { + this.state = state; + } + + public BlockState getState() { + return state; + } + + public void setString(String string) { + this.string = string; + } + + public String getString() { + return string; + } + + public void setPlayer(Player player) { + this.player = player; + } + + public Player getPlayer() { + return player; + } + + public void setTime(long time) { + this.time = time; + } + + public long getTime() { + return time; + } + + public void setBlock(Block block) { + this.block = block; + } + + public Block getBlock() { + return block; + } + + public void setLocation(Location location) { + this.location = location; + } + + public Location getLocation() { + return location; + } + + public void setType(Material type) { + this.type = type; + } + + public Material getType() { + return type; + } + + public void setInteger(int integer) { + this.integer = integer; + } + + public int getInteger() { + return integer; + } + + public void setDouble(double value) { + this.value = value; + } + + public double getDouble() { + return value; + } + + public void setData(byte data) { + this.data = data; + } + + public byte getData() { + return data; + } + +} \ No newline at end of file diff --git a/src/com/projectkorra/ProjectKorra/Methods.java b/src/com/projectkorra/ProjectKorra/Methods.java index 382bce85..5bedf4b7 100644 --- a/src/com/projectkorra/ProjectKorra/Methods.java +++ b/src/com/projectkorra/ProjectKorra/Methods.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -30,6 +31,7 @@ import org.bukkit.util.Vector; import com.projectkorra.ProjectKorra.Ability.AbilityModule; import com.projectkorra.ProjectKorra.Ability.AbilityModuleManager; import com.projectkorra.ProjectKorra.earthbending.EarthPassive; +import com.projectkorra.abilities.RaiseEarth.EarthColumn; public class Methods { @@ -39,6 +41,10 @@ public class Methods { Methods.plugin = plugin; } + public static ConcurrentHashMap movedearth = new ConcurrentHashMap(); + public static ConcurrentHashMap tempair = new ConcurrentHashMap(); + public static ArrayList tempnophysics = new ArrayList(); + public static boolean isBender(String player, Element element) { BendingPlayer bPlayer = getBendingPlayer(player); if (bPlayer.hasElement(element)) return true; @@ -295,7 +301,7 @@ public class Methods { if (AbilityModuleManager.firebendingabilities.contains(ability)) return ChatColor.RED; else return null; } - + public static boolean isWater(Block block) { if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER) return true; return false; @@ -450,6 +456,42 @@ public class Methods { return 1; } + public static Block getEarthSourceBlock(Player player, double range) { + Block testblock = player.getTargetBlock(getTransparentEarthbending(), + (int) range); + if (isEarthbendable(player, testblock)) + return testblock; + Location location = player.getEyeLocation(); + Vector vector = location.getDirection().clone().normalize(); + for (double i = 0; i <= range; i++) { + Block block = location.clone().add(vector.clone().multiply(i)) + .getBlock(); + // if (isRegionProtectedFromBuild(player, Abilities.RaiseEarth, + // location)) + // continue; + if (isEarthbendable(player, block)) { + return block; + } + } + return null; + } + + public static void removeRevertIndex(Block block) { + if (movedearth.containsKey(block)) { + Information info = movedearth.get(block); + if (block.getType() == Material.SANDSTONE + && info.getType() == Material.SAND) + block.setType(Material.SAND); + if (isAbilityInstalled("RaiseEarth", "orion304")) { + if (EarthColumn.blockInAllAffectedBlocks(block)) + EarthColumn.revertBlock(block); + + EarthColumn.resetBlock(block); + } + movedearth.remove(block); + } + } + public static double waterbendingNightAugment(double value, World world) { if (isNight(world)) { return plugin.getConfig().getDouble("Properties.Water.NightFactor") * value; @@ -474,6 +516,95 @@ public class Methods { return false; } + public static Location getPointOnLine(Location origin, Location target, + double distance) { + return origin.clone().add( + getDirection(origin, target).normalize().multiply(distance)); + + } + + public static void breakBlock(Block block) { + block.breakNaturally(new ItemStack(Material.AIR)); + } + + public static void moveEarthBlock(Block source, Block target) { + byte full = 0x0; + Information info; + if (movedearth.containsKey(source)) { + // verbose("Moving something already moved."); + info = movedearth.get(source); + info.setTime(System.currentTimeMillis()); + movedearth.remove(source); + movedearth.put(target, info); + } else { + // verbose("Moving something for the first time."); + info = new Information(); + info.setBlock(source); + // info.setType(source.getType()); + // info.setData(source.getData()); + info.setTime(System.currentTimeMillis()); + info.setState(source.getState()); + movedearth.put(target, info); + } + + if (isAdjacentToThreeOrMoreSources(source)) { + source.setType(Material.WATER); + source.setData(full); + } else { + source.setType(Material.AIR); + } + if (info.getState().getType() == Material.SAND) { + target.setType(Material.SANDSTONE); + } else { + target.setType(info.getState().getType()); + target.setData(info.getState().getRawData()); + } + } + + public static void addTempAirBlock(Block block) { + if (movedearth.containsKey(block)) { + Information info = movedearth.get(block); + block.setType(Material.AIR); + info.setTime(System.currentTimeMillis()); + movedearth.remove(block); + tempair.put(info.getID(), info); + } else { + Information info = new Information(); + info.setBlock(block); + // info.setType(block.getType()); + // info.setData(block.getData()); + info.setState(block.getState()); + info.setTime(System.currentTimeMillis()); + block.setType(Material.AIR); + tempair.put(info.getID(), info); + } + + } + + public static Vector getDirection(Location location, Location destination) { + double x1, y1, z1; + double x0, y0, z0; + + x1 = destination.getX(); + y1 = destination.getY(); + z1 = destination.getZ(); + + x0 = location.getX(); + y0 = location.getY(); + z0 = location.getZ(); + + return new Vector(x1 - x0, y1 - y0, z1 - z0); + + } + + public static HashSet getTransparentEarthbending() { + HashSet set = new HashSet(); + for (int i : transparentToEarthbending) { + set.add((byte) i); + } + return set; + } + public static void damageEntity(Player player, Entity entity, double damage) { if (entity instanceof LivingEntity) { ((LivingEntity) entity).damage(damage, player);