Fix memory leak in PlayerList

This commit is contained in:
md_5 2017-07-17 09:55:47 +10:00
parent c1b8cace2a
commit 49c2537fe2
2 changed files with 139 additions and 35 deletions

View File

@ -49,6 +49,15 @@
public EntityPlayer(MinecraftServer minecraftserver, WorldServer worldserver, GameProfile gameprofile, PlayerInteractManager playerinteractmanager) {
super(worldserver, gameprofile);
playerinteractmanager.player = this;
@@ -72,7 +102,7 @@
}
this.server = minecraftserver;
- this.bZ = minecraftserver.getPlayerList().a((EntityHuman) this);
+ this.bZ = minecraftserver.getPlayerList().getStatisticManager(this); // CraftBukkit
this.bY = minecraftserver.getPlayerList().h(this);
this.P = 1.0F;
this.setPositionRotation(blockposition, 0.0F, 0.0F);
@@ -81,6 +111,11 @@
this.setPosition(this.locX, this.locY + 1.0D, this.locZ);
}

View File

@ -30,7 +30,7 @@
public abstract class PlayerList {
public static final File a = new File("banned-players.json");
@@ -28,7 +51,7 @@
@@ -28,14 +51,16 @@
private static final Logger f = LogManager.getLogger();
private static final SimpleDateFormat g = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
private final MinecraftServer server;
@ -39,7 +39,18 @@
private final Map<UUID, EntityPlayer> j = Maps.newHashMap();
private final GameProfileBanList k;
private final IpBanList l;
@@ -44,7 +67,15 @@
private final OpList operators;
private final WhiteList whitelist;
- private final Map<UUID, ServerStatisticManager> o;
- private final Map<UUID, AdvancementDataPlayer> p;
+ // CraftBukkit start
+ // private final Map<UUID, ServerStatisticManager> o;
+ // private final Map<UUID, AdvancementDataPlayer> p;
+ // CraftBukkit end
public IPlayerFileData playerFileData;
private boolean hasWhitelist;
protected int maxPlayers;
@@ -44,13 +69,23 @@
private boolean u;
private int v;
@ -55,7 +66,17 @@
this.k = new GameProfileBanList(PlayerList.a);
this.l = new IpBanList(PlayerList.b);
this.operators = new OpList(PlayerList.c);
@@ -65,6 +96,12 @@
this.whitelist = new WhiteList(PlayerList.d);
- this.o = Maps.newHashMap();
- this.p = Maps.newHashMap();
+ // CraftBukkit start
+ // this.o = Maps.newHashMap();
+ // this.p = Maps.newHashMap();
+ // CraftBukkit end
this.server = minecraftserver;
this.k.a(false);
this.l.a(false);
@@ -65,6 +100,12 @@
usercache.a(gameprofile);
NBTTagCompound nbttagcompound = this.a(entityplayer);
@ -68,7 +89,7 @@
entityplayer.spawnIn(this.server.getWorldServer(entityplayer.dimension));
entityplayer.playerInteractManager.a((WorldServer) entityplayer.world);
@@ -74,7 +111,8 @@
@@ -74,7 +115,8 @@
s1 = networkmanager.getSocketAddress().toString();
}
@ -78,7 +99,7 @@
WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
WorldData worlddata = worldserver.getWorldData();
@@ -82,6 +120,7 @@
@@ -82,6 +124,7 @@
PlayerConnection playerconnection = new PlayerConnection(this.server, networkmanager, entityplayer);
playerconnection.sendPacket(new PacketPlayOutLogin(entityplayer.getId(), entityplayer.playerInteractManager.getGameMode(), worlddata.isHardcore(), worldserver.worldProvider.getDimensionManager().getDimensionID(), worldserver.getDifficulty(), this.getMaxPlayers(), worlddata.getType(), worldserver.getGameRules().getBoolean("reducedDebugInfo")));
@ -86,7 +107,7 @@
playerconnection.sendPacket(new PacketPlayOutCustomPayload("MC|Brand", (new PacketDataSerializer(Unpooled.buffer())).a(this.getServer().getServerModName())));
playerconnection.sendPacket(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
playerconnection.sendPacket(new PacketPlayOutAbilities(entityplayer.abilities));
@@ -91,17 +130,23 @@
@@ -91,17 +134,23 @@
entityplayer.F().a(entityplayer);
this.sendScoreboard((ScoreboardServer) worldserver.getScoreboard(), entityplayer);
this.server.aD();
@ -116,7 +137,7 @@
playerconnection.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
this.b(entityplayer, worldserver);
if (!this.server.getResourcePack().isEmpty()) {
@@ -153,6 +198,8 @@
@@ -153,6 +202,8 @@
}
entityplayer.syncInventory();
@ -125,7 +146,7 @@
}
public void sendScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) {
@@ -185,26 +232,27 @@
@@ -185,26 +236,27 @@
}
public void setPlayerFileData(WorldServer[] aworldserver) {
@ -158,7 +179,7 @@
}
public void b(WorldBorder worldborder, double d0) {}
@@ -237,7 +285,7 @@
@@ -237,7 +289,7 @@
@Nullable
public NBTTagCompound a(EntityPlayer entityplayer) {
@ -167,7 +188,23 @@
NBTTagCompound nbttagcompound1;
if (entityplayer.getName().equals(this.server.Q()) && nbttagcompound != null) {
@@ -267,28 +315,73 @@
@@ -253,13 +305,13 @@
protected void savePlayerFile(EntityPlayer entityplayer) {
this.playerFileData.save(entityplayer);
- ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) this.o.get(entityplayer.getUniqueID());
+ ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) entityplayer.getStatisticManager(); // CraftBukkit
if (serverstatisticmanager != null) {
serverstatisticmanager.b();
}
- AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.p.get(entityplayer.getUniqueID());
+ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancementData(); // CraftBukkit
if (advancementdataplayer != null) {
advancementdataplayer.c();
@@ -267,28 +319,73 @@
}
@ -247,8 +284,16 @@
this.savePlayerFile(entityplayer);
if (entityplayer.isPassenger()) {
Entity entity = entityplayer.getVehicle();
@@ -322,13 +415,61 @@
this.p.remove(uuid);
@@ -318,17 +415,67 @@
if (entityplayer1 == entityplayer) {
this.j.remove(uuid);
- this.o.remove(uuid);
- this.p.remove(uuid);
+ // CraftBukkit start
+ // this.o.remove(uuid);
+ // this.p.remove(uuid);
+ // CraftBukkit end
}
- this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[] { entityplayer}));
@ -312,7 +357,7 @@
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.k.get(gameprofile);
s = "You are banned from this server!\nReason: " + gameprofilebanentry.getReason();
@@ -336,10 +477,12 @@
@@ -336,10 +483,12 @@
s = s + "\nYour ban will be removed on " + PlayerList.g.format(gameprofilebanentry.getExpires());
}
@ -328,7 +373,7 @@
IpBanEntry ipbanentry = this.l.get(socketaddress);
s = "Your IP address is banned from this server!\nReason: " + ipbanentry.getReason();
@@ -347,13 +490,25 @@
@@ -347,13 +496,25 @@
s = s + "\nYour ban will be removed on " + PlayerList.g.format(ipbanentry.getExpires());
}
@ -357,7 +402,7 @@
UUID uuid = EntityHuman.a(gameprofile);
ArrayList arraylist = Lists.newArrayList();
@@ -388,17 +543,27 @@
@@ -388,17 +549,27 @@
}
return new EntityPlayer(this.server, this.server.getWorldServer(0), gameprofile, (PlayerInteractManager) object);
@ -386,7 +431,7 @@
entityplayer.dimension = i;
Object object;
@@ -409,6 +574,11 @@
@@ -409,6 +580,11 @@
}
EntityPlayer entityplayer1 = new EntityPlayer(this.server, this.server.getWorldServer(entityplayer.dimension), entityplayer.getProfile(), (PlayerInteractManager) object);
@ -398,7 +443,7 @@
entityplayer1.playerConnection = entityplayer.playerConnection;
entityplayer1.copyFrom(entityplayer, flag);
@@ -423,43 +593,163 @@
@@ -423,43 +599,163 @@
entityplayer1.addScoreboardTag(s);
}
@ -579,7 +624,7 @@
public void f(EntityPlayer entityplayer) {
GameProfile gameprofile = entityplayer.getProfile();
int i = this.isOp(gameprofile) ? this.operators.a(gameprofile) : 0;
@@ -498,12 +788,111 @@
@@ -498,12 +794,111 @@
}
public void changeWorld(Entity entity, int i, WorldServer worldserver, WorldServer worldserver1) {
@ -691,7 +736,7 @@
if (entity.dimension == -1) {
d0 = MathHelper.a(d0 / 8.0D, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D);
d1 = MathHelper.a(d1 / 8.0D, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D);
@@ -522,6 +911,8 @@
@@ -522,6 +917,8 @@
BlockPosition blockposition;
if (i == 1) {
@ -700,7 +745,7 @@
blockposition = worldserver1.getSpawn();
} else {
blockposition = worldserver1.getDimensionSpawn();
@@ -535,16 +926,27 @@
@@ -535,16 +932,27 @@
worldserver.entityJoinedWorld(entity, false);
}
}
@ -731,7 +776,7 @@
worldserver1.entityJoinedWorld(entity, false);
}
@@ -552,11 +954,23 @@
@@ -552,11 +960,23 @@
}
entity.spawnIn(worldserver1);
@ -756,7 +801,7 @@
this.v = 0;
}
@@ -569,6 +983,25 @@
@@ -569,6 +989,25 @@
}
@ -782,7 +827,7 @@
public void a(Packet<?> packet, int i) {
for (int j = 0; j < this.players.size(); ++j) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(j);
@@ -667,11 +1100,23 @@
@@ -667,11 +1106,23 @@
this.operators.add(new OpListEntry(gameprofile, this.server.q(), this.operators.b(gameprofile)));
this.b(this.a(gameprofile.getId()), i);
@ -806,7 +851,7 @@
}
private void b(EntityPlayer entityplayer, int i) {
@@ -696,7 +1141,7 @@
@@ -696,7 +1147,7 @@
}
public boolean isOp(GameProfile gameprofile) {
@ -815,7 +860,7 @@
}
@Nullable
@@ -720,6 +1165,12 @@
@@ -720,6 +1171,12 @@
for (int j = 0; j < this.players.size(); ++j) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(j);
@ -828,7 +873,7 @@
if (entityplayer != entityhuman && entityplayer.dimension == i) {
double d4 = d0 - entityplayer.locX;
double d5 = d1 - entityplayer.locY;
@@ -767,7 +1218,7 @@
@@ -767,7 +1224,7 @@
public void reloadWhitelist() {}
public void b(EntityPlayer entityplayer, WorldServer worldserver) {
@ -837,7 +882,7 @@
entityplayer.playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean("doDaylightCycle")));
@@ -775,16 +1226,21 @@
@@ -775,16 +1232,21 @@
entityplayer.playerConnection.sendPacket(new PacketPlayOutSpawnPosition(blockposition));
if (worldserver.isRaining()) {
@ -863,7 +908,7 @@
entityplayer.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(entityplayer.inventory.itemInHandIndex));
}
@@ -797,7 +1253,7 @@
@@ -797,7 +1259,7 @@
}
public String[] getSeenPlayers() {
@ -872,7 +917,7 @@
}
public boolean getHasWhitelist() {
@@ -846,17 +1302,29 @@
@@ -846,26 +1308,41 @@
}
public void u() {
@ -905,7 +950,47 @@
}
public void sendMessage(IChatBaseComponent ichatbasecomponent) {
@@ -909,8 +1377,10 @@
this.sendMessage(ichatbasecomponent, true);
}
- public ServerStatisticManager a(EntityHuman entityhuman) {
+ // CraftBukkit start
+ // PAIL: rename
+ public ServerStatisticManager getStatisticManager(EntityPlayer entityhuman) {
UUID uuid = entityhuman.getUniqueID();
- ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) this.o.get(uuid);
+ ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) entityhuman.getStatisticManager();
+ // CraftBukkit end
if (serverstatisticmanager == null) {
File file = new File(this.server.getWorldServer(0).getDataManager().getDirectory(), "stats");
@@ -881,7 +1358,7 @@
serverstatisticmanager = new ServerStatisticManager(this.server, file1);
serverstatisticmanager.a();
- this.o.put(uuid, serverstatisticmanager);
+ // this.o.put(uuid, serverstatisticmanager); // CraftBukkit
}
return serverstatisticmanager;
@@ -889,14 +1366,14 @@
public AdvancementDataPlayer h(EntityPlayer entityplayer) {
UUID uuid = entityplayer.getUniqueID();
- AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.p.get(uuid);
+ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancementData(); // CraftBukkit
if (advancementdataplayer == null) {
File file = new File(this.server.getWorldServer(0).getDataManager().getDirectory(), "advancements");
File file1 = new File(file, uuid + ".json");
advancementdataplayer = new AdvancementDataPlayer(this.server, file1, entityplayer);
- this.p.put(uuid, advancementdataplayer);
+ // this.p.put(uuid, advancementdataplayer); // CraftBukkit
}
advancementdataplayer.a(entityplayer);
@@ -909,8 +1386,10 @@
WorldServer[] aworldserver = this.server.worldServer;
int j = aworldserver.length;
@ -918,14 +1003,24 @@
if (worldserver != null) {
worldserver.getPlayerChunkMap().a(i);
@@ -941,6 +1411,11 @@
@@ -934,13 +1413,20 @@
}
public void reload() {
- Iterator iterator = this.p.values().iterator();
+ // CraftBukkit start
+ /*Iterator iterator = this.p.values().iterator();
while (iterator.hasNext()) {
AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) iterator.next();
advancementdataplayer.b();
}
+ // CraftBukkit start - trigger immediate flush of advancements
+ }*/
+
+ for (EntityPlayer player : players) {
+ player.getAdvancementData().b(player);
+ }
+ player.getAdvancementData().b();
+ player.getAdvancementData().b(player); // CraftBukkit - trigger immediate flush of advancements
}
+ // CraftBukkit end
}