diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/net/minecraft/server/Packet51MapChunk.java | 95 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java | 29 |
2 files changed, 124 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/Packet51MapChunk.java b/src/main/java/net/minecraft/server/Packet51MapChunk.java new file mode 100644 index 00000000..a46d050f --- /dev/null +++ b/src/main/java/net/minecraft/server/Packet51MapChunk.java @@ -0,0 +1,95 @@ +package net.minecraft.server; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.zip.DataFormatException; +import java.util.zip.Deflater; +import java.util.zip.Inflater; + +public class Packet51MapChunk extends Packet { + + public int a; + public int b; + public int c; + public int d; + public int e; + public int f; + public byte[] g; + private int h; + + public Packet51MapChunk() { + this.k = true; + } + + // CraftBukkit - start + public Packet51MapChunk(int i, int j, int k, int l, int i1, int j1, World world) { + this(i, j, k, l, i1, j1, world.c(i, j, k, l, i1, j1)); + } + + public Packet51MapChunk(int i, int j, int k, int l, int i1, int j1, byte[] data) { + // CraftBukkit - end + this.k = true; + this.a = i; + this.b = j; + this.c = k; + this.d = l; + this.e = i1; + this.f = j1; + byte[] abyte = data; // CraftBukkit - uses data from above constructor + Deflater deflater = new Deflater(1); + + try { + deflater.setInput(abyte); + deflater.finish(); + this.g = new byte[l * i1 * j1 * 5 / 2]; + this.h = deflater.deflate(this.g); + } finally { + deflater.end(); + } + } + + public void a(DataInputStream datainputstream) throws IOException { // CraftBukkit - throws IOEXception + this.a = datainputstream.readInt(); + this.b = datainputstream.readShort(); + this.c = datainputstream.readInt(); + this.d = datainputstream.read() + 1; + this.e = datainputstream.read() + 1; + this.f = datainputstream.read() + 1; + this.h = datainputstream.readInt(); + byte[] abyte = new byte[this.h]; + + datainputstream.readFully(abyte); + this.g = new byte[this.d * this.e * this.f * 5 / 2]; + Inflater inflater = new Inflater(); + + inflater.setInput(abyte); + + try { + inflater.inflate(this.g); + } catch (DataFormatException dataformatexception) { + throw new IOException("Bad compressed data format"); + } finally { + inflater.end(); + } + } + + public void a(DataOutputStream dataoutputstream) throws IOException { // CraftBukkit - throws IOException + dataoutputstream.writeInt(this.a); + dataoutputstream.writeShort(this.b); + dataoutputstream.writeInt(this.c); + dataoutputstream.write(this.d - 1); + dataoutputstream.write(this.e - 1); + dataoutputstream.write(this.f - 1); + dataoutputstream.writeInt(this.h); + dataoutputstream.write(this.g, 0, this.h); + } + + public void a(NetHandler nethandler) { + nethandler.a(this); + } + + public int a() { + return 17 + this.h; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index a9084f9f..ef9822e9 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -2,11 +2,13 @@ package org.bukkit.craftbukkit.entity; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.zip.Deflater; import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityPlayer; import net.minecraft.server.ItemInWorldManager; import net.minecraft.server.Packet200Statistic; import net.minecraft.server.Packet3Chat; +import net.minecraft.server.Packet51MapChunk; import net.minecraft.server.Packet53BlockChange; import net.minecraft.server.Packet54PlayNoteBlock; import net.minecraft.server.Packet6SpawnPosition; @@ -164,6 +166,33 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().netServerHandler.sendPacket(packet); } + public boolean sendChunkChange(Location loc, int sx, int sy, int sz, byte[] data) { + int x = loc.getBlockX(); + int y = loc.getBlockY(); + int z = loc.getBlockZ(); + + int cx = x >> 4; + int cz = z >> 4; + + if (sx <= 0 || sy <= 0 || sz <= 0) { + return false; + } + + if ((x + sx - 1) >> 4 != cx || (z + sz - 1) >> 4 != cz || y < 0 || y + sy > 128) { + return false; + } + + if (data.length != (sx * sy * sz * 5) / 2) { + return false; + } + + Packet51MapChunk packet = new Packet51MapChunk(x, y, z, sx, sy, sz, data); + + getHandle().netServerHandler.sendPacket(packet); + + return true; + } + @Override public boolean teleport(Location location) { WorldServer oldWorld = ((CraftWorld)getWorld()).getHandle(); |