From ec0eec5863191009dda11e1068d81e21895ac2d6 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 18 Feb 2011 19:45:58 -0800 Subject: [PATCH 01/13] Added slime as a detected entity. --- src/main/java/net/minecraft/server/World.java | 2 ++ 1 file changed, 2 insertions(+) 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) { From acd034445239325d60c3211ed71ee5e71c997ce0 Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 18 Feb 2011 20:02:20 -0800 Subject: [PATCH 02/13] Added Entity.remove() which marks an entity for removal. --- .../java/org/bukkit/craftbukkit/entity/CraftEntity.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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; From d4b67c5549dec7c27b39a27c81299e218b79826f Mon Sep 17 00:00:00 2001 From: sk89q Date: Sat, 19 Feb 2011 01:40:32 -0800 Subject: [PATCH 03/13] Lowered the priority of the old command handler event. A number of plugins were using this event incorrectly. A new event, the command preprocesser event, has replaced the previous function of the original command event. --- .../java/net/minecraft/server/NetServerHandler.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index bca70f50e9..ebd28b2bf4 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -622,7 +622,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 +641,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(); From ca4076077eb8514b2e5bbeb315058b12169e7b81 Mon Sep 17 00:00:00 2001 From: Tahg Date: Sat, 19 Feb 2011 10:55:47 -0500 Subject: [PATCH 04/13] fixed buttons, plates added yield to explosion added event for chunk unloading --- .../net/minecraft/server/BlockButton.java | 10 ++++++- .../minecraft/server/BlockPressurePlate.java | 12 +++++++- .../minecraft/server/ChunkProviderServer.java | 28 ++++++++++++------- .../java/net/minecraft/server/Explosion.java | 2 +- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/minecraft/server/BlockButton.java b/src/main/java/net/minecraft/server/BlockButton.java index 1002c9c901..c79766c4ae 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,14 @@ 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/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java index 53b69ef311..87beef5755 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -10,15 +10,17 @@ 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 class ChunkProviderServer implements IChunkProvider +{ public LongHashset a = new LongHashset(); // CraftBukkit private Chunk b; private IChunkProvider c; @@ -39,7 +41,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 +199,22 @@ 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); + if (chunk == null) { + continue; + } + ChunkUnloadEvent cue = new ChunkUnloadEvent(Type.CHUNK_UNLOADED, chunk.bukkitChunk); + server.getPluginManager().callEvent(cue); + if (!cue.isCancelled()) { + 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/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index 3eb7bcc91c..c59cebf1bd 100644 --- a/src/main/java/net/minecraft/server/Explosion.java +++ b/src/main/java/net/minecraft/server/Explosion.java @@ -240,7 +240,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()); //Modified by Craftbukkit this.i.e(j, k, l, 0); Block.byId[i1].a_(this.i, j, k, l); } From 6e3ee31336dcec939139cc97cab11d98fb99145d Mon Sep 17 00:00:00 2001 From: Erik Broes Date: Sun, 20 Feb 2011 17:09:02 +0100 Subject: [PATCH 05/13] Prevent Blocks from getting lost when a chunk reloads --- src/main/java/net/minecraft/server/Chunk.java | 5 ++++- .../java/net/minecraft/server/ChunkProviderServer.java | 2 ++ src/main/java/org/bukkit/craftbukkit/CraftChunk.java | 6 +++++- src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 10 ++++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java index e37db53fe0..592e34086b 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -44,7 +44,10 @@ public class Chunk { } // CraftBukkit start - bukkitChunk = new org.bukkit.craftbukkit.CraftChunk( this ); + bukkitChunk = ((WorldServer) world).getWorld().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 87beef5755..e6b4be5efd 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -209,6 +209,8 @@ public class ChunkProviderServer implements IChunkProvider 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); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index db700abfad..592e12033e 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java @@ -11,7 +11,7 @@ import org.bukkit.block.Block; import org.bukkit.craftbukkit.block.CraftBlock; public class CraftChunk implements Chunk { - private final net.minecraft.server.Chunk chunk; + private net.minecraft.server.Chunk chunk; private final HashMap cache = new HashMap(); public CraftChunk(net.minecraft.server.Chunk chunk) { @@ -48,4 +48,8 @@ public class CraftChunk implements Chunk { } return block; } + + public void breakLink() { + this.chunk = null; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 7be7c4586b..2f3fe70563 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,15 @@ public class CraftWorld implements World { server.addWorld(this); } + public void preserveChunk( CraftChunk chunk ) { + chunk.breakLink(); + 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); } From 09026095b69a25c59fd5b360442c7fa0bd390f4f Mon Sep 17 00:00:00 2001 From: Erik Broes Date: Sun, 20 Feb 2011 17:40:40 +0100 Subject: [PATCH 06/13] Minor cleaning of code --- src/main/java/net/minecraft/server/BlockButton.java | 3 ++- .../java/net/minecraft/server/ChunkProviderServer.java | 8 +++----- src/main/java/net/minecraft/server/Explosion.java | 7 +++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/minecraft/server/BlockButton.java b/src/main/java/net/minecraft/server/BlockButton.java index c79766c4ae..f20a881878 100644 --- a/src/main/java/net/minecraft/server/BlockButton.java +++ b/src/main/java/net/minecraft/server/BlockButton.java @@ -249,8 +249,9 @@ public class BlockButton extends Block { CraftBlock block = (CraftBlock) craftWorld.getBlockAt(i, j, k); BlockRedstoneEvent eventRedstone = new BlockRedstoneEvent(block, 1, 0); server.getPluginManager().callEvent(eventRedstone); - if(eventRedstone.getNewCurrent() > 0) return; + 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/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java index e6b4be5efd..8b2b44bd15 100644 --- a/src/main/java/net/minecraft/server/ChunkProviderServer.java +++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java @@ -19,8 +19,7 @@ import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; // CraftBukkit end -public class ChunkProviderServer implements IChunkProvider -{ +public class ChunkProviderServer implements IChunkProvider { public LongHashset a = new LongHashset(); // CraftBukkit private Chunk b; private IChunkProvider c; @@ -203,9 +202,8 @@ public class ChunkProviderServer implements IChunkProvider while (!this.a.isEmpty()) { long chunkcoordinates = this.a.popFirst(); Chunk chunk = e.get(chunkcoordinates); - if (chunk == null) { - continue; - } + if (chunk == null) continue; + ChunkUnloadEvent cue = new ChunkUnloadEvent(Type.CHUNK_UNLOADED, chunk.bukkitChunk); server.getPluginManager().callEvent(cue); if (!cue.isCancelled()) { diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java index c59cebf1bd..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), event.getYield()); //Modified by Craftbukkit + 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); } From 5121ebb65d6128b4c775c09943122d5b2f344e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Flemstr=C3=B6m?= Date: Sun, 20 Feb 2011 13:38:27 +0100 Subject: [PATCH 07/13] Fixed issue with color markers in messages sent to the client. This fix eliminates crashes related to color markers being at end-of-line, and also makes colors persist across line breaks. - The broadcast message is split up in multiple packets, one per line - Color markers are reorganized, so that color 'sticks across lines' - The wrapping method calculates the *rendered* line length. Thus, if the user has a weird font, it might look weird. --- .../minecraft/server/NetServerHandler.java | 11 ++-- .../org/bukkit/craftbukkit/TextWrapper.java | 60 +++++++++++++++++++ .../craftbukkit/entity/CraftPlayer.java | 5 +- 3 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/TextWrapper.java diff --git a/src/main/java/net/minecraft/server/NetServerHandler.java b/src/main/java/net/minecraft/server/NetServerHandler.java index ebd28b2bf4..ec91edfa79 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; @@ -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 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/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() { From 4f249b585cc01777619884598c35c55c8861b369 Mon Sep 17 00:00:00 2001 From: Daniel Chesters Date: Sat, 19 Feb 2011 21:29:51 +0100 Subject: [PATCH 08/13] Fix encoding in net.minecraft.server files. --- .../net/minecraft/server/MinecraftServer.java | 20 +++++++++---------- .../net/minecraft/server/NetLoginHandler.java | 2 +- .../minecraft/server/NetServerHandler.java | 10 +++++----- 3 files changed, 16 insertions(+), 16 deletions(-) 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 ec91edfa79..7713d24bf7 100644 --- a/src/main/java/net/minecraft/server/NetServerHandler.java +++ b/src/main/java/net/minecraft/server/NetServerHandler.java @@ -83,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()) { @@ -551,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; } @@ -669,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 { @@ -729,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() { From cec04a7360ef0baf7dfdc3cc2af2be02c54403c9 Mon Sep 17 00:00:00 2001 From: VictorD Date: Sun, 20 Feb 2011 23:16:05 +0100 Subject: [PATCH 09/13] Added null pointer check and switched to a faster arctan method --- .../java/org/bukkit/craftbukkit/TrigMath.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/org/bukkit/craftbukkit/TrigMath.java 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..0d207b37da --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/TrigMath.java @@ -0,0 +1,45 @@ +package org.bukkit.craftbukkit; +/** + * Got this code from a post by user aioobe on stackoverflow.com + * + */ +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 From bf9a55049e6be249856d07b1bda99552b0f902f7 Mon Sep 17 00:00:00 2001 From: VictorD Date: Sun, 20 Feb 2011 23:22:28 +0100 Subject: [PATCH 10/13] Second part of NPE and arctan update :3 --- src/main/java/net/minecraft/server/Chunk.java | 5 ++- .../net/minecraft/server/EntityCreature.java | 3 +- .../net/minecraft/server/EntityHuman.java | 3 +- .../net/minecraft/server/EntityLiving.java | 3 +- .../org/bukkit/craftbukkit/CraftChunk.java | 31 ++++++++++++------- .../org/bukkit/craftbukkit/CraftWorld.java | 5 ++- .../java/org/bukkit/craftbukkit/TrigMath.java | 3 +- 7 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java index 592e34086b..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,8 @@ public class Chunk { } // CraftBukkit start - bukkitChunk = ((WorldServer) world).getWorld().popPreservedChunk( i, j ); + CraftWorld cw = ((WorldServer) world).getWorld(); + bukkitChunk = (cw == null) ? null:cw.popPreservedChunk( i, j ); if (bukkitChunk == null) { bukkitChunk = new org.bukkit.craftbukkit.CraftChunk( this ); } 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/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java index 592e12033e..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 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 @@ -48,8 +60,5 @@ public class CraftChunk implements Chunk { } return block; } - - public void breakLink() { - this.chunk = null; - } } + diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 2f3fe70563..aca525176d 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -47,12 +47,11 @@ public class CraftWorld implements World { } public void preserveChunk( CraftChunk chunk ) { - chunk.breakLink(); - unloadedChunks.put( chunk.getX() << 16 + chunk.getZ(), chunk ); + unloadedChunks.put( (chunk.getX() << 16) + chunk.getZ(), chunk ); } public CraftChunk popPreservedChunk( int x, int z ) { - return unloadedChunks.remove( x << 16 + z ); + return unloadedChunks.remove( (x << 16) + z ); } public Block getBlockAt(int x, int y, int z) { diff --git a/src/main/java/org/bukkit/craftbukkit/TrigMath.java b/src/main/java/org/bukkit/craftbukkit/TrigMath.java index 0d207b37da..2a623bf0f7 100644 --- a/src/main/java/org/bukkit/craftbukkit/TrigMath.java +++ b/src/main/java/org/bukkit/craftbukkit/TrigMath.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit; /** - * Got this code from a post by user aioobe on stackoverflow.com + * 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 { From 6335a5af76f6035dcd02ee97b8069c40048af903 Mon Sep 17 00:00:00 2001 From: Luke GB Date: Mon, 21 Feb 2011 00:37:09 +0100 Subject: [PATCH 11/13] Modify URI to repo.bukkit.org --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 6269c1e633d6736cacc75c0a55f56fbf182fea88 Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Mon, 21 Feb 2011 12:28:35 +1100 Subject: [PATCH 12/13] implementation of isQueued() --- .../craftbukkit/scheduler/CraftScheduler.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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; + } + } + } From 30d1a5d3fd4f5a6d682646f4ee2e790433884c6a Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Mon, 21 Feb 2011 12:30:45 +1100 Subject: [PATCH 13/13] returning if a thread is not alive should happen before any changes to the list of workers, hence the return statement should be in the synchronized block. --- .../org/bukkit/craftbukkit/scheduler/CraftThreadManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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; } }