summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/bukkit
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-02-21 21:27:01 +0000
committerDinnerbone <dinnerbone@dinnerbone.com>2011-02-21 21:27:01 +0000
commit67cf646014fa6336c7df4abefe85a2dec447d699 (patch)
tree7bbc19980b6a7a642c49d4cc108fcd7e39fd9e33 /src/main/java/org/bukkit
parenta59149c2083f6b2ded3d5d23aa7d78f5201a5c0a (diff)
parent30d1a5d3fd4f5a6d682646f4ee2e790433884c6a (diff)
downloadcraftbukkit-67cf646014fa6336c7df4abefe85a2dec447d699.tar
craftbukkit-67cf646014fa6336c7df4abefe85a2dec447d699.tar.gz
craftbukkit-67cf646014fa6336c7df4abefe85a2dec447d699.tar.lz
craftbukkit-67cf646014fa6336c7df4abefe85a2dec447d699.tar.xz
craftbukkit-67cf646014fa6336c7df4abefe85a2dec447d699.zip
Merge branch 'master' of github.com:Bukkit/CraftBukkit
Diffstat (limited to 'src/main/java/org/bukkit')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftChunk.java27
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftWorld.java9
-rw-r--r--src/main/java/org/bukkit/craftbukkit/TextWrapper.java60
-rw-r--r--src/main/java/org/bukkit/craftbukkit/TrigMath.java46
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java7
-rw-r--r--src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java5
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java14
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java4
8 files changed, 161 insertions, 11 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
index db700abf..c9469f5d 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
@@ -1,6 +1,7 @@
package org.bukkit.craftbukkit;
+import java.lang.ref.WeakReference;
import java.util.HashMap;
import net.minecraft.server.WorldServer;
@@ -11,27 +12,38 @@ import org.bukkit.block.Block;
import org.bukkit.craftbukkit.block.CraftBlock;
public class CraftChunk implements Chunk {
- private final net.minecraft.server.Chunk chunk;
+ private WeakReference<net.minecraft.server.Chunk> weakChunk;
private final HashMap<Integer, Block> cache = new HashMap<Integer, Block>();
-
+ private WorldServer worldServer;
+ private int x;
+ private int z;
+
public CraftChunk(net.minecraft.server.Chunk chunk) {
- this.chunk = chunk;
+ this.weakChunk = new WeakReference<net.minecraft.server.Chunk>(chunk);
+ worldServer = (WorldServer) getHandle().d;
+ x = getHandle().j;
+ z = getHandle().k;
}
public World getWorld() {
- return ((WorldServer) chunk.d).getWorld();
+ return worldServer.getWorld();
}
public net.minecraft.server.Chunk getHandle() {
- return chunk;
+ net.minecraft.server.Chunk c = weakChunk.get();
+ if (c == null) {
+ weakChunk = new WeakReference<net.minecraft.server.Chunk>(worldServer.c(x,z));
+ c = weakChunk.get();
+ }
+ return c;
}
public int getX() {
- return chunk.j;
+ return x;
}
public int getZ() {
- return chunk.k;
+ return z;
}
@Override
@@ -49,3 +61,4 @@ public class CraftChunk implements Chunk {
return block;
}
}
+
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 7be7c458..aca52517 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -28,6 +28,7 @@ public class CraftWorld implements World {
private final Environment environment;
private final CraftServer server;
private final ChunkProviderServer provider;
+ private HashMap<Integer,CraftChunk> unloadedChunks = new HashMap<Integer, CraftChunk>();
private static final Random rand = new Random();
@@ -45,6 +46,14 @@ public class CraftWorld implements World {
server.addWorld(this);
}
+ public void preserveChunk( CraftChunk chunk ) {
+ unloadedChunks.put( (chunk.getX() << 16) + chunk.getZ(), chunk );
+ }
+
+ public CraftChunk popPreservedChunk( int x, int z ) {
+ return unloadedChunks.remove( (x << 16) + z );
+ }
+
public Block getBlockAt(int x, int y, int z) {
return getChunkAt(x >> 4, z >> 4).getBlock(x & 0xF, y & 0x7F, z & 0xF);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/TextWrapper.java b/src/main/java/org/bukkit/craftbukkit/TextWrapper.java
new file mode 100644
index 00000000..46c1c2cd
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/TextWrapper.java
@@ -0,0 +1,60 @@
+package org.bukkit.craftbukkit;
+
+public class TextWrapper {
+ private static final int[] characterWidths = new int[] {
+ 1, 9, 9, 8, 8, 8, 8, 7, 9, 8, 9, 9, 8, 9, 9, 9,
+ 8, 8, 8, 8, 9, 9, 8, 9, 8, 8, 8, 8, 8, 9, 9, 9,
+ 4, 2, 5, 6, 6, 6, 6, 3, 5, 5, 5, 6, 2, 6, 2, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 2, 2, 5, 6, 5, 6,
+ 7, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 4, 6, 6,
+ 3, 6, 6, 6, 6, 6, 5, 6, 6, 2, 6, 5, 3, 6, 6, 6,
+ 6, 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 5, 2, 5, 7, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6, 3, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 4, 6,
+ 6, 3, 6, 6, 6, 6, 6, 6, 6, 7, 6, 6, 6, 2, 6, 6,
+ 8, 9, 9, 6, 6, 6, 8, 8, 6, 8, 8, 8, 8, 8, 6, 6,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 9, 9, 9, 5, 9, 9,
+ 8, 7, 7, 8, 7, 8, 8, 8, 7, 8, 8, 7, 9, 9, 6, 7,
+ 7, 7, 7, 7, 9, 6, 7, 8, 7, 6, 6, 9, 7, 6, 7, 1
+ };
+ private static final int CHAT_WINDOW_WIDTH = 318;
+
+ public static String[] wrapText(final String text) {
+ final StringBuilder out = new StringBuilder();
+ char colorChar = 'f';
+ int lineWidth = 0;
+ boolean hasColored = true;
+ for (int i = 0; i < text.length(); i++) {
+ char ch = text.charAt(i);
+ if (ch == '\u00A7' && i < text.length() - 1) {
+ i++;
+ colorChar = text.charAt(i);
+ hasColored = false;
+ continue;
+ } else if (ch >= characterWidths.length) {
+ ch = (char) (characterWidths.length - 1);
+ }
+ final int width = characterWidths[(int) ch];
+ if (lineWidth + width >= CHAT_WINDOW_WIDTH) {
+ out.append('\n');
+ if (colorChar != 'f') {
+ out.append('\u00A7');
+ out.append(colorChar);
+ }
+ out.append(ch);
+ lineWidth = width;
+ } else {
+ if (!hasColored) {
+ out.append('\u00A7');
+ out.append(colorChar);
+ hasColored = true;
+ }
+ out.append(ch);
+ lineWidth += width;
+ }
+ }
+ return out.toString().split("\n");
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/TrigMath.java b/src/main/java/org/bukkit/craftbukkit/TrigMath.java
new file mode 100644
index 00000000..2a623bf0
--- /dev/null
+++ b/src/main/java/org/bukkit/craftbukkit/TrigMath.java
@@ -0,0 +1,46 @@
+package org.bukkit.craftbukkit;
+/**
+ * Credits for this class goes to user aioobe on stackoverflow.com
+ * Source: http://stackoverflow.com/questions/4454630/j2me-calculate-the-the-distance-between-2-latitude-and-longitude
+ *
+ */
+public class TrigMath {
+
+ static final double sq2p1 = 2.414213562373095048802e0;
+ static final double sq2m1 = .414213562373095048802e0;
+ static final double p4 = .161536412982230228262e2;
+ static final double p3 = .26842548195503973794141e3;
+ static final double p2 = .11530293515404850115428136e4;
+ static final double p1 = .178040631643319697105464587e4;
+ static final double p0 = .89678597403663861959987488e3;
+ static final double q4 = .5895697050844462222791e2;
+ static final double q3 = .536265374031215315104235e3;
+ static final double q2 = .16667838148816337184521798e4;
+ static final double q1 = .207933497444540981287275926e4;
+ static final double q0 = .89678597403663861962481162e3;
+ static final double PIO2 = 1.5707963267948966135E0;
+
+ private static double mxatan(double arg) {
+ double argsq = arg * arg, value;
+ value = ((((p4 * argsq + p3) * argsq + p2) * argsq + p1) * argsq + p0);
+ value = value / (((((argsq+q4)*argsq+q3)*argsq+q2)*argsq+q1)*argsq+q0);
+ return value * arg;
+ }
+
+ private static double msatan(double arg) {
+ return arg < sq2m1 ? mxatan(arg)
+ : arg > sq2p1 ? PIO2 - mxatan(1 / arg)
+ : PIO2 / 2 + mxatan((arg - 1) / (arg + 1));
+ }
+
+ public static double atan(double arg) {
+ return arg > 0 ? msatan(arg) : -msatan(-arg);
+ }
+
+ public static double atan2(double arg1, double arg2) {
+ if (arg1 + arg2 == arg1)
+ return arg1 >= 0 ? PIO2 : -PIO2;
+ arg1 = atan(arg1 / arg2);
+ return arg2 < 0 ? arg1 <= 0 ? arg1 + Math.PI : arg1 - Math.PI : arg1;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 191212c5..9a876741 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -46,7 +46,6 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
else if (entity instanceof EntityGiantZombie) { return new CraftGiant( server, (EntityGiantZombie) entity); }
else if (entity instanceof EntitySkeleton) { return new CraftSkeleton( server, (EntitySkeleton) entity); }
else if (entity instanceof EntitySpider) { return new CraftSpider( server, (EntitySpider) entity); }
- else if (entity instanceof EntitySlime) { return new CraftSlime( server, (EntitySlime) entity); }
else { return new CraftMonster( server, (EntityMonster) entity); }
}
@@ -57,6 +56,8 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
else { return new CraftCreature( server, (EntityCreature) entity); }
}
+ // Slimes are a special (and broken) case
+ else if (entity instanceof EntitySlime) { return new CraftSlime( server, (EntitySlime) entity); }
// Flying
else if (entity instanceof EntityFlying) {
if (entity instanceof EntityGhast) { return new CraftGhast( server, (EntityGhast) entity); }
@@ -129,6 +130,10 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
public void setFireTicks(int ticks) {
entity.fireTicks = ticks;
}
+
+ public void remove() {
+ entity.dead = true;
+ }
public Entity getHandle() {
return entity;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 69a95e1e..d017bbd0 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -14,6 +14,7 @@ import net.minecraft.server.WorldServer;
import org.bukkit.Location;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.TextWrapper;
import org.bukkit.entity.Player;
public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -80,7 +81,9 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
public void sendMessage(String message) {
- entity.a.b(new Packet3Chat(message));
+ for (final String line: TextWrapper.wrapText(message)) {
+ entity.a.b(new Packet3Chat(line));
+ }
}
public String getDisplayName() {
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index 298c9724..334013a1 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -223,4 +223,18 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
public boolean isCurrentlyRunning(int taskId){
return craftThreadManager.isAlive(taskId);
}
+
+ public boolean isQueued(int taskId) {
+ synchronized (schedulerQueue) {
+ Iterator<CraftTask> itr = schedulerQueue.keySet().iterator();
+ while (itr.hasNext()) {
+ CraftTask current = itr.next();
+ if (current.getIdNumber() == taskId) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
}
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java
index d63b458e..29defcda 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftThreadManager.java
@@ -61,8 +61,8 @@ public class CraftThreadManager {
return craftWorker.isAlive();
}
}
+ // didn't find it, so it must have been removed
+ return false;
}
- // didn't find it, so it must have been removed
- return false;
}
}