Fix player leak from entity tracker and item frames

3005a20c5c
This commit is contained in:
Jedediah Smith 2015-12-22 21:55:00 -06:00 committed by Zach Brown
parent ff621fcb04
commit 0265f4eaef

View file

@ -1,22 +1,28 @@
From 5b6d3af20b71d1941643519ce0e037432d264c17 Mon Sep 17 00:00:00 2001 From 601b8ccd9ffc815477f336e6c54610f478726e44 Mon Sep 17 00:00:00 2001
From: Jedediah Smith <jedediah@silencegreys.com> From: Jedediah Smith <jedediah@silencegreys.com>
Date: Fri, 3 Apr 2015 17:26:21 -0400 Date: Fri, 3 Apr 2015 17:26:21 -0400
Subject: [PATCH] Send absolute position the first time an entity is seen Subject: [PATCH] Send absolute position the first time an entity is seen
diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java diff --git a/src/main/java/net/minecraft/server/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
index f0149bf..b77de55 100644 index f0149bf..1fc2388 100644
--- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java --- a/src/main/java/net/minecraft/server/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java +++ b/src/main/java/net/minecraft/server/EntityTrackerEntry.java
@@ -40,6 +40,7 @@ public class EntityTrackerEntry { @@ -39,7 +39,12 @@ public class EntityTrackerEntry {
private boolean x;
private boolean y; private boolean y;
public boolean n; public boolean n;
public Set<EntityPlayer> trackedPlayers = Sets.newHashSet(); - public Set<EntityPlayer> trackedPlayers = Sets.newHashSet();
+ public Set<EntityPlayer> freshViewers = Sets.newHashSet(); // PaperSpigot + // PaperSpigot start
+ // Replace trackedPlayers Set with a Map. The value is true until the player receives
+ // their first update (which is forced to have absolute coordinates), false afterward.
+ public java.util.Map<EntityPlayer, Boolean> trackedPlayerMap = new java.util.HashMap<EntityPlayer, Boolean>();
+ public Set<EntityPlayer> trackedPlayers = trackedPlayerMap.keySet();
+ // PaperSpigot end
public EntityTrackerEntry(Entity entity, int i, int j, boolean flag) { public EntityTrackerEntry(Entity entity, int i, int j, boolean flag) {
this.tracker = entity; this.tracker = entity;
@@ -121,20 +122,20 @@ public class EntityTrackerEntry { @@ -121,20 +126,20 @@ public class EntityTrackerEntry {
boolean flag = Math.abs(j1) >= 4 || Math.abs(k1) >= 4 || Math.abs(l1) >= 4 || this.m % 60 == 0; boolean flag = Math.abs(j1) >= 4 || Math.abs(k1) >= 4 || Math.abs(l1) >= 4 || this.m % 60 == 0;
boolean flag1 = Math.abs(l - this.yRot) >= 4 || Math.abs(i1 - this.xRot) >= 4; boolean flag1 = Math.abs(l - this.yRot) >= 4 || Math.abs(i1 - this.xRot) >= 4;
@ -26,7 +32,7 @@ index f0149bf..b77de55 100644
- this.yLoc = j; - this.yLoc = j;
- this.zLoc = k; - this.zLoc = k;
- } - }
+ if (this.m > 0 || this.tracker instanceof EntityArrow) { // PaperSpigot - Move up + if (this.m > 0 || this.tracker instanceof EntityArrow) { // PaperSpigot - Moved up
+ // CraftBukkit start - Code moved from below + // CraftBukkit start - Code moved from below
+ if (flag) { + if (flag) {
+ this.xLoc = i; + this.xLoc = i;
@ -49,7 +55,7 @@ index f0149bf..b77de55 100644
if (j1 >= -128 && j1 < 128 && k1 >= -128 && k1 < 128 && l1 >= -128 && l1 < 128 && this.v <= 400 && !this.x && this.y == this.tracker.onGround) { if (j1 >= -128 && j1 < 128 && k1 >= -128 && k1 < 128 && l1 >= -128 && l1 < 128 && this.v <= 400 && !this.x && this.y == this.tracker.onGround) {
if ((!flag || !flag1) && !(this.tracker instanceof EntityArrow)) { if ((!flag || !flag1) && !(this.tracker instanceof EntityArrow)) {
if (flag) { if (flag) {
@@ -173,7 +174,24 @@ public class EntityTrackerEntry { @@ -173,7 +178,26 @@ public class EntityTrackerEntry {
} }
if (object != null) { if (object != null) {
@ -59,30 +65,33 @@ index f0149bf..b77de55 100644
+ if (object instanceof PacketPlayOutEntityTeleport) { + if (object instanceof PacketPlayOutEntityTeleport) {
+ this.broadcast((Packet) object); + this.broadcast((Packet) object);
+ } else { + } else {
+ PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport(this.tracker.getId(), i, j, k, (byte) l, (byte) i1, this.tracker.onGround); + PacketPlayOutEntityTeleport teleportPacket = null;
+ +
+ for (EntityPlayer viewer : (Set<EntityPlayer>) this.trackedPlayers) { + for (java.util.Map.Entry<EntityPlayer, Boolean> viewer : trackedPlayerMap.entrySet()) {
+ if (this.freshViewers.contains(viewer)) { + if (viewer.getValue()) {
+ viewer.playerConnection.sendPacket(teleportPacket); + viewer.setValue(false);
+ if (teleportPacket == null) {
+ teleportPacket = new PacketPlayOutEntityTeleport(this.tracker.getId(), i, j, k, (byte) l, (byte) i1, this.tracker.onGround);
+ }
+ viewer.getKey().playerConnection.sendPacket(teleportPacket);
+ } else { + } else {
+ viewer.playerConnection.sendPacket((Packet) object); + viewer.getKey().playerConnection.sendPacket((Packet) object);
+ } + }
+ } + }
+ } + }
+
+ this.freshViewers.clear();
+ // PaperSpigot end + // PaperSpigot end
} }
this.b(); this.b();
@@ -324,6 +342,7 @@ public class EntityTrackerEntry { @@ -324,7 +348,7 @@ public class EntityTrackerEntry {
entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId())); entityplayer.removeQueue.remove(Integer.valueOf(this.tracker.getId()));
// CraftBukkit end // CraftBukkit end
+ this.freshViewers.add(entityplayer); // PaperSpigot - this.trackedPlayers.add(entityplayer);
this.trackedPlayers.add(entityplayer); + this.trackedPlayerMap.put(entityplayer, true); // PaperBukkit
Packet packet = this.c(); Packet packet = this.c();
entityplayer.playerConnection.sendPacket(packet);
-- --
2.5.2 2.6.4