diff --git a/pom.xml b/pom.xml
index c8307ffa22..da81536713 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,13 +18,13 @@
bukkit-repo
- http://artifacts.lukegb.com/artifactory/repo
+ http://repo.bukkit.org/artifactory/repo
bukkit-plugins
- http://artifacts.lukegb.com/artifactory/plugins-release
+ http://repo.bukkit.org/artifactory/plugins-release
diff --git a/src/main/java/net/minecraft/server/BlockButton.java b/src/main/java/net/minecraft/server/BlockButton.java
index 1002c9c901..f20a881878 100644
--- a/src/main/java/net/minecraft/server/BlockButton.java
+++ b/src/main/java/net/minecraft/server/BlockButton.java
@@ -167,7 +167,7 @@ public class BlockButton extends Block {
if (j1 == 0) {
return true;
} else {
- //Allow the lever to change the current
+ //Allow the button to change the current
int old = (j1 != 8) ? 1 : 0;
int current = (j1 == 8) ? 1 : 0;
BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, old, current);
@@ -243,6 +243,15 @@ public class BlockButton extends Block {
int l = world.getData(i, j, k);
if ((l & 8) != 0) {
+ // Craftbukkit start
+ CraftWorld craftWorld = ((WorldServer) world).getWorld();
+ CraftServer server = ((WorldServer) world).getServer();
+ CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k);
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 1, 0);
+ server.getPluginManager().callEvent(eventRedstone);
+ if (eventRedstone.getNewCurrent() > 0) return;
+ // Craftbukkit end
+
world.c(i, j, k, l & 7);
world.h(i, j, k, this.id);
int i1 = l & 7;
diff --git a/src/main/java/net/minecraft/server/BlockPressurePlate.java b/src/main/java/net/minecraft/server/BlockPressurePlate.java
index 90f0a74925..7fedf6cec8 100644
--- a/src/main/java/net/minecraft/server/BlockPressurePlate.java
+++ b/src/main/java/net/minecraft/server/BlockPressurePlate.java
@@ -4,7 +4,8 @@ import java.util.List;
import java.util.Random;
// CraftBukkit start
-import org.bukkit.block.BlockFace;import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.block.BlockFace;
+import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.entity.CraftLivingEntity;
@@ -115,6 +116,15 @@ public class BlockPressurePlate extends Block {
flag1 = true;
}
+ // Craftbukkit start
+ CraftWorld craftWorld = ((WorldServer) world).getWorld();
+ CraftServer server = ((WorldServer) world).getServer();
+ CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k);
+ BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, flag ? 1 : 0, flag1 ? 1 : 0);
+ server.getPluginManager().callEvent(eventRedstone);
+ flag1 = eventRedstone.getNewCurrent() > 0;
+ // Craftbukkit end
+
if (flag1 && !flag) {
world.c(i, j, k, 1);
world.h(i, j, k, this.id);
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index e37db53fe0..ef81adf90f 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map;
import java.util.Random;
+import org.bukkit.craftbukkit.CraftWorld;
+
public class Chunk {
public static boolean a;
@@ -44,7 +46,11 @@ public class Chunk {
}
// CraftBukkit start
- bukkitChunk = new org.bukkit.craftbukkit.CraftChunk( this );
+ CraftWorld cw = ((WorldServer) world).getWorld();
+ bukkitChunk = (cw == null) ? null:cw.popPreservedChunk( i, j );
+ if (bukkitChunk == null) {
+ bukkitChunk = new org.bukkit.craftbukkit.CraftChunk( this );
+ }
}
public org.bukkit.Chunk bukkitChunk;
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 53b69ef311..8b2b44bd15 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -10,15 +10,16 @@ import java.util.Set;
// CraftBukkit start
import org.bukkit.Location;
+import org.bukkit.Server;
import org.bukkit.craftbukkit.CraftChunk;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.world.ChunkLoadEvent;
+import org.bukkit.event.world.ChunkUnloadEvent;
// CraftBukkit end
public class ChunkProviderServer implements IChunkProvider {
-
public LongHashset a = new LongHashset(); // CraftBukkit
private Chunk b;
private IChunkProvider c;
@@ -39,7 +40,7 @@ public class ChunkProviderServer implements IChunkProvider {
return this.e.containsKey(i, j);
}
// CraftBukkit end
-
+
public void c(int i, int j) {
int k = i * 16 + 8 - this.g.spawnX;
int l = j * 16 + 8 - this.g.spawnZ;
@@ -197,16 +198,23 @@ public class ChunkProviderServer implements IChunkProvider {
public boolean a() {
if (!this.g.C) {
// CraftBukkit start
+ Server server = g.getServer();
while (!this.a.isEmpty()) {
long chunkcoordinates = this.a.popFirst();
Chunk chunk = e.get(chunkcoordinates);
if (chunk == null) continue;
- chunk.e();
- this.b(chunk);
- this.a(chunk);
- this.a.remove(chunkcoordinates);
- this.e.remove(chunkcoordinates);
- this.f.remove(chunk);
+
+ ChunkUnloadEvent cue = new ChunkUnloadEvent(Type.CHUNK_UNLOADED, chunk.bukkitChunk);
+ server.getPluginManager().callEvent(cue);
+ if (!cue.isCancelled()) {
+ g.getWorld().preserveChunk( (CraftChunk) chunk.bukkitChunk );
+
+ chunk.e();
+ this.b(chunk);
+ this.a(chunk);
+ this.e.remove(chunkcoordinates);
+ this.f.remove(chunk);
+ }
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/EntityCreature.java b/src/main/java/net/minecraft/server/EntityCreature.java
index c867b32caa..49b4c7a260 100644
--- a/src/main/java/net/minecraft/server/EntityCreature.java
+++ b/src/main/java/net/minecraft/server/EntityCreature.java
@@ -4,6 +4,7 @@ package net.minecraft.server;
import org.bukkit.craftbukkit.entity.CraftMonster;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftEntity;
+import org.bukkit.craftbukkit.TrigMath;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@@ -118,7 +119,7 @@ public class EntityCreature extends EntityLiving {
double d1 = vec3d.a - this.locX;
double d2 = vec3d.c - this.locZ;
double d3 = vec3d.b - (double) l1;
- float f4 = (float) (Math.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F;
+ float f4 = (float) (TrigMath.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F;
float f5 = f4 - this.yaw;
for (this.by = this.bC; f5 < -180.0F; f5 += 360.0F) {
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 2e3e71774c..66bae6e112 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -4,6 +4,7 @@ import java.util.List;
// CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.TrigMath;
import org.bukkit.craftbukkit.entity.CraftItemDrop;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
@@ -124,7 +125,7 @@ public abstract class EntityHuman extends EntityLiving {
this.as = this.at;
super.o();
float f = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ);
- float f1 = (float) Math.atan(-this.motY * 0.20000000298023224D) * 15.0F;
+ float f1 = (float) TrigMath.atan(-this.motY * 0.20000000298023224D) * 15.0F;
if (f > 0.1F) {
f = 0.1F;
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
index 366f8f1efa..c2c371db1c 100644
--- a/src/main/java/net/minecraft/server/EntityLiving.java
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
@@ -10,6 +10,7 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.craftbukkit.TrigMath;
import org.bukkit.event.Event.Type;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@@ -236,7 +237,7 @@ public abstract class EntityLiving extends Entity {
if (f > 0.05F) {
f3 = 1.0F;
f2 = f * 3.0F;
- f1 = (float) Math.atan2(d1, d0) * 180.0F / 3.1415927F - 90.0F;
+ f1 = (float) TrigMath.atan2(d1, d0) * 180.0F / 3.1415927F - 90.0F;
}
if (this.aY > 0.0F) {
diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java
index 3eb7bcc91c..e5734447b3 100644
--- a/src/main/java/net/minecraft/server/Explosion.java
+++ b/src/main/java/net/minecraft/server/Explosion.java
@@ -29,9 +29,8 @@ public class Explosion {
public Entity e;
public float f;
public Set g = new HashSet();
- // Craftbukkit start
- public boolean wasCanceled = false;
- // Craftbukkit end
+
+ public boolean wasCanceled = false; // Craftbukkit
public Explosion(World world, Entity entity, double d0, double d1, double d2, float f) {
this.i = world;
@@ -240,7 +239,7 @@ public class Explosion {
}
if (i1 > 0) {
- Block.byId[i1].a(this.i, j, k, l, this.i.getData(j, k, l), 0.3F);
+ Block.byId[i1].a(this.i, j, k, l, this.i.getData(j, k, l), event.getYield()); // Craftbukkit
this.i.e(j, k, l, 0);
Block.byId[i1].a_(this.i, j, k, l);
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 6f16c45c3a..f3c4c97d71 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -185,7 +185,7 @@ public class MinecraftServer implements ICommandListener, Runnable {
// Craftbukkit start
for (WorldServer world : worlds) {
world.a(true, (IProgressUpdate) null);
-
+
Event worldSaved = new WorldEvent( Event.Type.WORLD_SAVED, world.getWorld() );
server.getPluginManager().callEvent( worldSaved );
}
@@ -310,14 +310,14 @@ public class MinecraftServer implements ICommandListener, Runnable {
}
((CraftScheduler) server.getScheduler()).mainThreadHeartbeat(this.h);
-
+
for (WorldServer world : worlds) {
world.f();
while (world.d()) {
;
}
-
+
world.c();
}
// Craftbukkit end
@@ -366,11 +366,11 @@ public class MinecraftServer implements ICommandListener, Runnable {
// Craftbukkit start
for (WorldServer world : worlds) {
world.a(true, (IProgressUpdate) null);
-
+
Event worldSaved = new WorldEvent( Event.Type.WORLD_SAVED, world.getWorld() );
server.getPluginManager().callEvent( worldSaved );
}
-
+
this.f.d();
// Craftbukkit end
@@ -398,11 +398,11 @@ public class MinecraftServer implements ICommandListener, Runnable {
s2 = s.substring(s.indexOf(" ")).trim();
this.f.e(s2);
this.a(s1, "Opping " + s2);
- this.f.a(s2, "§eYou are now op!");
+ this.f.a(s2, "\u00A7eYou are now op!");
} else if (s.toLowerCase().startsWith("deop ")) {
s2 = s.substring(s.indexOf(" ")).trim();
this.f.f(s2);
- this.f.a(s2, "§eYou are no longer op!");
+ this.f.a(s2, "\u00A7eYou are no longer op!");
this.a(s1, "De-opping " + s2);
} else if (s.toLowerCase().startsWith("ban-ip ")) {
s2 = s.substring(s.indexOf(" ")).trim();
@@ -507,14 +507,14 @@ public class MinecraftServer implements ICommandListener, Runnable {
} else if (s.toLowerCase().startsWith("say ")) {
s = s.substring(s.indexOf(" ")).trim();
a.info("[" + s1 + "] " + s);
- this.f.a((Packet) (new Packet3Chat("§d[Server] " + s)));
+ this.f.a((Packet) (new Packet3Chat("\u00A7d[Server] " + s)));
} else if (s.toLowerCase().startsWith("tell ")) {
astring = s.split(" ");
if (astring.length >= 3) {
s = s.substring(s.indexOf(" ")).trim();
s = s.substring(s.indexOf(" ")).trim();
a.info("[" + s1 + "->" + astring[1] + "] " + s);
- s = "§7" + s1 + " whispers " + s;
+ s = "\u00A77" + s1 + " whispers " + s;
a.info(s);
if (!this.f.a(astring[1], (Packet) (new Packet3Chat(s)))) {
icommandlistener.b("There\'s no player by that name online.");
@@ -554,7 +554,7 @@ public class MinecraftServer implements ICommandListener, Runnable {
private void a(String s, String s1) {
String s2 = s + ": " + s1;
- this.f.i("§7(" + s2 + ")");
+ this.f.i("\u00A77(" + s2 + ")");
a.info(s2);
}
diff --git a/src/main/java/net/minecraft/server/NetLoginHandler.java b/src/main/java/net/minecraft/server/NetLoginHandler.java
index 6347e38968..0714d8ce1a 100644
--- a/src/main/java/net/minecraft/server/NetLoginHandler.java
+++ b/src/main/java/net/minecraft/server/NetLoginHandler.java
@@ -82,7 +82,7 @@ public class NetLoginHandler extends NetHandler {
// Craftbukkit start
netserverhandler.b((Packet) (new Packet1Login("", "", entityplayer.id, entityplayer.world.u, (byte) entityplayer.world.q.g)));
netserverhandler.b((Packet) (new Packet6SpawnPosition(entityplayer.world.spawnX, entityplayer.world.spawnY, entityplayer.world.spawnZ)));
- this.e.f.a((Packet) (new Packet3Chat("§e" + entityplayer.name + " joined the game.")));
+ this.e.f.a((Packet) (new Packet3Chat("\u00A7e" + entityplayer.name + " joined the game.")));
this.e.f.a(entityplayer);
netserverhandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
this.e.c.a(netserverhandler);
diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java
index bca70f50e9..7713d24bf7 100644
--- a/src/main/java/net/minecraft/server/NetServerHandler.java
+++ b/src/main/java/net/minecraft/server/NetServerHandler.java
@@ -17,6 +17,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.TextWrapper;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockDamageEvent;
@@ -82,7 +83,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
public void a(String s) {
// CraftBukkit start
- String leaveMessage = "§e" + this.e.name + " left the game.";
+ String leaveMessage = "\u00A7e" + this.e.name + " left the game.";
PlayerKickEvent kickEvent = new PlayerKickEvent(org.bukkit.event.Event.Type.PLAYER_KICK, server.getPlayer(this.e), s, leaveMessage);
server.getPluginManager().callEvent(kickEvent);
if (kickEvent.isCancelled()) {
@@ -550,7 +551,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
public void a(String s, Object[] aobject) {
a.info(this.e.name + " lost connection: " + s);
- this.d.f.a((Packet) (new Packet3Chat("§e" + this.e.name + " left the game.")));
+ this.d.f.a((Packet) (new Packet3Chat("\u00A7e" + this.e.name + " left the game.")));
this.d.f.c(this.e);
this.c = true;
}
@@ -593,7 +594,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
// CraftBukkit end
}
}
-
+
// CraftBukkit start
public boolean chat(String msg) {
if (msg.startsWith("/")) {
@@ -608,12 +609,14 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
if (event.isCancelled()) {
return true;
}
- // CraftBukkit end
a.info(msg);
- this.d.f.a((Packet) (new Packet3Chat(msg)));
+ for (final String line: TextWrapper.wrapText(msg)) {
+ this.d.f.a((Packet) (new Packet3Chat(line)));
+ }
+ // CraftBukkit end
}
-
+
return false;
}
// CraftBukkit end
@@ -622,7 +625,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
// CraftBukkit start
CraftPlayer player = getPlayer();
- PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_COMMAND, player, s);
+ PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_COMMAND_PREPROCESS, player, s);
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
@@ -641,6 +644,14 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
if (targetPluginFound) {
return;
}
+
+ // Legacy command handler
+ event = new PlayerChatEvent(Type.PLAYER_COMMAND, player, s);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+
s = event.getMessage();
player = (CraftPlayer) event.getPlayer();
EntityPlayer e = player.getHandle();
@@ -658,10 +669,10 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
if (astring.length >= 3) {
s = s.substring(s.indexOf(" ")).trim();
s = s.substring(s.indexOf(" ")).trim();
- s = "§7" + this.e.name + " whispers " + s;
+ s = "\u00A77" + this.e.name + " whispers " + s;
a.info(s + " to " + astring[1]);
if (!this.d.f.a(astring[1], (Packet) (new Packet3Chat(s)))) {
- this.b((Packet) (new Packet3Chat("§cThere\'s no player by that name online.")));
+ this.b((Packet) (new Packet3Chat("\u00A7cThere\'s no player by that name online.")));
}
}
} else {
@@ -718,7 +729,7 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
}
public void b(String s) {
- this.b((Packet) (new Packet3Chat("§7" + s)));
+ this.b((Packet) (new Packet3Chat("\u00A77" + s)));
}
public String c() {
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 3275e36952..9844892cd0 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -834,6 +834,8 @@ public class World implements IBlockAccess {
type = MobType.SPIDER;
} else if (entity instanceof EntityZombie) {
type = MobType.ZOMBIE;
+ } else if (entity instanceof EntitySlime) {
+ type = MobType.SLIME;
}
if (type != null) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
index db700abfad..c9469f5d21 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 weakChunk;
private final HashMap cache = new HashMap();
-
+ private WorldServer worldServer;
+ private int x;
+ private int z;
+
public CraftChunk(net.minecraft.server.Chunk chunk) {
- this.chunk = chunk;
+ this.weakChunk = new WeakReference(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(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 7be7c4586b..aca525176d 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 unloadedChunks = new HashMap();
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 0000000000..46c1c2cd3b
--- /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 0000000000..2a623bf0f7
--- /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 191212c589..9a87674107 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 69a95e1e83..d017bbd079 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 298c972455..334013a13d 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 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 d63b458e43..29defcdaaf 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;
}
}