From 54e2254904153ad5fbc071468560c2305e9128a8 Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Wed, 4 May 2011 22:16:26 -0400 Subject: [PATCH] Made teleporting between worlds 'smoother'. Thanks Raphfrk! --- .../java/net/minecraft/server/PlayerInstance.java | 9 ++++++--- .../org/bukkit/craftbukkit/entity/CraftPlayer.java | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraft/server/PlayerInstance.java b/src/main/java/net/minecraft/server/PlayerInstance.java index f867aa862f..eb0edeba3a 100644 --- a/src/main/java/net/minecraft/server/PlayerInstance.java +++ b/src/main/java/net/minecraft/server/PlayerInstance.java @@ -37,8 +37,11 @@ class PlayerInstance { if (this.b.contains(entityplayer)) { throw new IllegalStateException("Failed to add player. " + entityplayer + " already is in chunk " + this.chunkX + ", " + this.chunkZ); } else { - entityplayer.g.add(this.e); - entityplayer.netServerHandler.sendPacket(new Packet50PreChunk(this.e.x, this.e.z, true)); + // CraftBukkit start + if (entityplayer.g.add(this.e)) { + entityplayer.netServerHandler.sendPacket(new Packet50PreChunk(this.e.x, this.e.z, true)); + } + // CraftBukkit end this.b.add(entityplayer); entityplayer.f.add(this.e); } @@ -63,7 +66,7 @@ class PlayerInstance { } entityplayer.f.remove(this.e); - if (entityplayer.g.contains(this.e)) { + if (entityplayer.g.remove(this.e)) { // CraftBukkit - contains -> remove entityplayer.netServerHandler.sendPacket(new Packet50PreChunk(this.chunkX, this.chunkZ, false)); } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 9d1c9f5a4a..55d80dde9d 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -12,6 +12,7 @@ import net.minecraft.server.Packet54PlayNoteBlock; import net.minecraft.server.Packet6SpawnPosition; import net.minecraft.server.ServerConfigurationManager; import net.minecraft.server.WorldServer; +import net.minecraft.server.ChunkCoordIntPair; import org.bukkit.Achievement; import org.bukkit.Location; import org.bukkit.Material; @@ -194,6 +195,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { if (teleportSuccess) { manager.server.tracker.trackPlayer(entity); manager.server.tracker.untrackEntity(entity); + int cx = (int) location.getBlockX() >> 4; + int cz = (int) location.getBlockZ() >> 4; + for (int x = -10 ; x <= 10 ; x++ ) { + for (int z = -10 ; z <= 10 ; z++ ) { + ChunkCoordIntPair chunkPosition = new ChunkCoordIntPair(cx + x, cz + z); + if (entity.g.remove(chunkPosition)) { + newEntity.g.add(chunkPosition); + } + } + } oldWorld.manager.removePlayer(entity); manager.players.remove(entity); oldWorld.removeEntity(entity);