From b5d1619e75a7d535bc33a9cc6401c64befe608dc Mon Sep 17 00:00:00 2001 From: EvilSeph Date: Wed, 8 Jun 2011 17:00:30 -0400 Subject: [PATCH] More teleport changes. Thanks Zeerix! --- .../net/minecraft/server/NetworkManager.java | 28 ++++++++----------- .../net/minecraft/server/PlayerManager.java | 26 +++++++++++------ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/minecraft/server/NetworkManager.java b/src/main/java/net/minecraft/server/NetworkManager.java index 230f7a15f1..b8b5f4b4c2 100644 --- a/src/main/java/net/minecraft/server/NetworkManager.java +++ b/src/main/java/net/minecraft/server/NetworkManager.java @@ -93,38 +93,32 @@ public class NetworkManager { try { Object object; - Packet packet; + Packet packet = null; // CraftBukkit int i; int[] aint; - if (!this.n.isEmpty() && (this.f == 0 || System.currentTimeMillis() - ((Packet) this.n.get(0)).timestamp >= (long) this.f)) { - object = this.g; - synchronized (this.g) { + // CraftBukkit start - thread safety and prioitizing packets in this.n (high prioirty queue) over those in this.o (low priority queue). + object = this.g; + synchronized (this.g) { + long time = System.currentTimeMillis(); + if (!this.n.isEmpty() && (this.f == 0 || time - ((Packet) this.n.get(0)).timestamp >= (long) this.f)) { packet = (Packet) this.n.remove(0); this.x -= packet.a() + 1; - } - - Packet.a(packet, this.output); - aint = e; - i = packet.b(); - aint[i] += packet.a() + 1; - flag = true; - } - - if (this.y-- <= 0 && !this.o.isEmpty() && (this.f == 0 || System.currentTimeMillis() - ((Packet) this.o.get(0)).timestamp >= (long) this.f)) { - object = this.g; - synchronized (this.g) { + } else if (this.y-- <= 0 && !this.o.isEmpty() && (this.f == 0 || time - ((Packet) this.o.get(0)).timestamp >= (long) this.f)) { packet = (Packet) this.o.remove(0); this.x -= packet.a() + 1; + this.y = 0; } + } + if (packet != null) { Packet.a(packet, this.output); aint = e; i = packet.b(); aint[i] += packet.a() + 1; - this.y = 0; flag = true; } + // CraftBukkit end return flag; } catch (Exception exception) { diff --git a/src/main/java/net/minecraft/server/PlayerManager.java b/src/main/java/net/minecraft/server/PlayerManager.java index fe17122274..ff0aac4570 100644 --- a/src/main/java/net/minecraft/server/PlayerManager.java +++ b/src/main/java/net/minecraft/server/PlayerManager.java @@ -3,6 +3,11 @@ package net.minecraft.server; import java.util.ArrayList; import java.util.List; +// CraftBukkit start +import java.util.Collections; +import java.util.Comparator; +// CraftBukkit end + public class PlayerManager { public List a = new ArrayList(); @@ -134,14 +139,6 @@ public class PlayerManager { int i1 = i - k; int j1 = j - l; - // CraftBukkit start - if (i1 > this.f || i1 < -this.f || j1 > this.f || j1 < -this.f) { - this.removePlayer(entityplayer); - this.addPlayer(entityplayer); - return; - } - // CraftBukkit end - if (i1 != 0 || j1 != 0) { for (int k1 = i - this.f; k1 <= i + this.f; ++k1) { for (int l1 = j - this.f; l1 <= j + this.f; ++l1) { @@ -161,6 +158,19 @@ public class PlayerManager { entityplayer.d = entityplayer.locX; entityplayer.e = entityplayer.locZ; + + // CraftBukkit start - send nearest chunks first + if (i1 > 1 || i1 < -1 || j1 > 1 || j1 < -1) { + final int x = i; + final int z = j; + List chunksToSend = entityplayer.f; + Collections.sort(chunksToSend, new Comparator() { + public int compare(ChunkCoordIntPair a, ChunkCoordIntPair b) { + return Math.max(Math.abs(a.x-x), Math.abs(a.z-z)) - Math.max(Math.abs(b.x-x), Math.abs(b.z-z)); + } + }); + } + // CraftBukkit end } } }