summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTravis Watkins <amaranth@ubuntu.com>2012-12-07 19:49:01 -0600
committerTravis Watkins <amaranth@ubuntu.com>2012-12-07 21:15:05 -0600
commit846a22304ca741ed8a39e1d881ab1b09f842b2d6 (patch)
treec3a1a830d7fd7b9b0ed88e68102efebc24d9ff93 /src
parentc74fd4196f73382a9836850d1161a8ab5f958731 (diff)
downloadcraftbukkit-846a22304ca741ed8a39e1d881ab1b09f842b2d6.tar
craftbukkit-846a22304ca741ed8a39e1d881ab1b09f842b2d6.tar.gz
craftbukkit-846a22304ca741ed8a39e1d881ab1b09f842b2d6.tar.lz
craftbukkit-846a22304ca741ed8a39e1d881ab1b09f842b2d6.tar.xz
craftbukkit-846a22304ca741ed8a39e1d881ab1b09f842b2d6.zip
Provide a faster way to get a location. Adds BUKKIT-3120
Currently when a plugin wants to get the location of something it calls getLocation() which returns a new Location object. In some scenarios this can cause enough object creation/destruction churn to be a significant overhead. For this cases we add a method that updates a provided Location object so there is no object creation done. This allows well written code to work on several locations with only a single Location object getting created. Providing a more efficient way to set a location was also looked at but the current solution is the fastest we can provide. You are not required to create a new Location object every time you want to set something's location so, with proper design, you can set locations with only a single Location object being created.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java13
-rw-r--r--src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java13
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java13
3 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
index a5c0bed8..70e7df7e 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
@@ -48,6 +48,19 @@ public class CraftBlock implements Block {
return new Location(getWorld(), x, y, z);
}
+ public Location getLocation(Location loc) {
+ if (loc != null) {
+ loc.setWorld(getWorld());
+ loc.setX(x);
+ loc.setY(y);
+ loc.setZ(z);
+ loc.setYaw(0);
+ loc.setPitch(0);
+ }
+
+ return loc;
+ }
+
public BlockVector getVector() {
return new BlockVector(x, y, z);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
index e83eb301..05296898 100644
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockState.java
@@ -148,6 +148,19 @@ public class CraftBlockState implements BlockState {
return new Location(world, x, y, z);
}
+ public Location getLocation(Location loc) {
+ if (loc != null) {
+ loc.setWorld(world);
+ loc.setX(x);
+ loc.setY(y);
+ loc.setZ(z);
+ loc.setYaw(0);
+ loc.setPitch(0);
+ }
+
+ return loc;
+ }
+
public void setRawData(byte data) {
this.data.setData(data);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index e68edf10..503c8a9a 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -156,6 +156,19 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return new Location(getWorld(), entity.locX, entity.locY, entity.locZ, entity.yaw, entity.pitch);
}
+ public Location getLocation(Location loc) {
+ if (loc != null) {
+ loc.setWorld(getWorld());
+ loc.setX(entity.locX);
+ loc.setY(entity.locY);
+ loc.setZ(entity.locZ);
+ loc.setYaw(entity.yaw);
+ loc.setPitch(entity.pitch);
+ }
+
+ return loc;
+ }
+
public Vector getVelocity() {
return new Vector(entity.motX, entity.motY, entity.motZ);
}