summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEvilSeph <evilseph@gmail.com>2011-10-01 16:16:22 -0400
committerEvilSeph <evilseph@gmail.com>2011-10-02 23:04:09 -0400
commit35761eb83ed2590ba0884d77be5d6aae7bafd96f (patch)
tree3bed5f962c2d071d9ec08c21d3da76a2cffd9a35 /src
parent050bd70a5dfd09f0447c7a9d0412d9a714cae1cd (diff)
downloadbukkit-35761eb83ed2590ba0884d77be5d6aae7bafd96f.tar
bukkit-35761eb83ed2590ba0884d77be5d6aae7bafd96f.tar.gz
bukkit-35761eb83ed2590ba0884d77be5d6aae7bafd96f.tar.lz
bukkit-35761eb83ed2590ba0884d77be5d6aae7bafd96f.tar.xz
bukkit-35761eb83ed2590ba0884d77be5d6aae7bafd96f.zip
Added callback line of sight methods. Thanks xZise!
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/entity/LivingEntity.java29
-rw-r--r--src/main/java/org/bukkit/util/Callback.java19
-rw-r--r--src/main/java/org/bukkit/util/TransparentCallback.java34
3 files changed, 82 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/entity/LivingEntity.java b/src/main/java/org/bukkit/entity/LivingEntity.java
index 2bc90bef..e9661e19 100644
--- a/src/main/java/org/bukkit/entity/LivingEntity.java
+++ b/src/main/java/org/bukkit/entity/LivingEntity.java
@@ -5,6 +5,7 @@ import java.util.List;
import org.bukkit.Location;
import org.bukkit.block.Block;
+import org.bukkit.util.Callback;
/**
* Represents a living entity, such as a monster or player
@@ -51,6 +52,34 @@ public interface LivingEntity extends Entity {
* Gets all blocks along the player's line of sight
* List iterates from player's position to target inclusive
*
+ * @param callback Through every iteration it will call {@link Callback#call(Object)}. If set to/returns <code>null</code> only air is considered transparent.
+ * @param maxDistance This is the maximum distance to scan. This may be further limited by the server, but never to less than 100 blocks.
+ * @return List containing all blocks along the player's line of sight
+ */
+ public List<Block> getLineOfSight(Callback<Boolean, Block> callback, int maxDistance);
+
+ /**
+ * Gets the block that the player has targeted
+ *
+ * @param callback Through every iteration it will call {@link Callback#call(Object)}. If set to/returns <code>null</code> only air is considered transparent.
+ * @param maxDistance This is the maximum distance to scan. This may be further limited by the server, but never to less than 100 blocks.
+ * @return Block that the player has targeted
+ */
+ public Block getTargetBlock(Callback<Boolean, Block> callback, int maxDistance);
+
+ /**
+ * Gets the block that the player has targeted
+ *
+ * @param callback Through every iteration it will call {@link Callback#call(Object)}. If set to/returns <code>null</code> only air is considered transparent.
+ * @param maxDistance This is the maximum distance to scan. This may be further limited by the server, but never to less than 100 blocks.
+ * @return Block that the player has targeted
+ */
+ public List<Block> getLastTwoTargetBlocks(Callback<Boolean, Block> callback, int maxDistance);
+
+ /**
+ * Gets all blocks along the player's line of sight
+ * List iterates from player's position to target inclusive
+ *
* @param transparent HashSet containing all transparent block IDs. If set to null only air is considered transparent.
* @param maxDistance This is the maximum distance to scan. This may be further limited by the server, but never to less than 100 blocks.
* @return List containing all blocks along the player's line of sight
diff --git a/src/main/java/org/bukkit/util/Callback.java b/src/main/java/org/bukkit/util/Callback.java
new file mode 100644
index 00000000..89205329
--- /dev/null
+++ b/src/main/java/org/bukkit/util/Callback.java
@@ -0,0 +1,19 @@
+package org.bukkit.util;
+
+/**
+ * Primitive callback class, to allow specific callback handling. For example to determine if a block in sight is invisible.
+ *
+ * @param <Result> This is the type it will return.
+ * @param <Parameter> This is the type it has as parameter.
+ */
+public interface Callback<Result, Parameter> {
+
+ /**
+ * This method will be called on each step.
+ *
+ * @param parameter The parameter of this step.
+ * @return The result of the step.
+ */
+ public Result call(Parameter parameter);
+
+}
diff --git a/src/main/java/org/bukkit/util/TransparentCallback.java b/src/main/java/org/bukkit/util/TransparentCallback.java
new file mode 100644
index 00000000..28a8f0c4
--- /dev/null
+++ b/src/main/java/org/bukkit/util/TransparentCallback.java
@@ -0,0 +1,34 @@
+package org.bukkit.util;
+
+import java.util.Set;
+
+import org.bukkit.block.Block;
+
+/**
+ * Default transparent call back. This class as callback acts like the normal
+ * line of sight methods.
+ *
+ * To implement own handler override {@link TransparentCallback#call(Block)} and
+ * call it via super.
+ */
+public class TransparentCallback implements Callback<Boolean, Block> {
+
+ private final Set<Byte> transparent;
+
+ /**
+ * Creates a new callback class which returns by default for every block in
+ * the transparent list true. Otherwise false. Could be expanded by override
+ * the {@link Callback#call(Block)} method.
+ *
+ * @param transparent
+ * The list of transparent blocks.
+ */
+ public TransparentCallback(Set<Byte> transparent) {
+ this.transparent = transparent;
+ }
+
+ public Boolean call(Block parameter) {
+ return this.transparent.contains((byte) parameter.getTypeId());
+ }
+
+}