Fix potential issues with the Minecraft FakePlayer lingering around after world unloads.

This commit is contained in:
LexManos 2018-12-07 22:03:32 -08:00 committed by tterrag
parent 65cfef1b2e
commit 592b957b77
2 changed files with 12 additions and 0 deletions

View file

@ -19,12 +19,15 @@
package net.minecraftforge.common.util;
import javax.annotation.Nullable;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.client.CPacketClientSettings;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerInteractionManager;
import net.minecraft.stats.Stat;
import net.minecraft.util.DamageSource;
@ -52,4 +55,5 @@ public class FakePlayer extends EntityPlayerMP
@Override public void tick(){ return; }
@Override public Entity changeDimension(DimensionType dim, ITeleporter teleporter){ return this; }
@Override public void handleClientSettings(CPacketClientSettings pkt){ return; }
@Override @Nullable public MinecraftServer getServer() { return FMLCommonHandler.instance().getMinecraftServerInstance(); }
}

View file

@ -68,5 +68,13 @@ public class FakePlayerFactory
public static void unloadWorld(WorldServer world)
{
fakePlayers.entrySet().removeIf(entry -> entry.getValue().world == world);
if (MINECRAFT_PLAYER != null && MINECRAFT_PLAYER.get() != null && MINECRAFT_PLAYER.get().world == world) // This shouldn't be strictly necessary, but lets be aggressive.
{
FakePlayer mc = MINECRAFT_PLAYER.get();
if (mc != null && mc.world == world)
{
MINECRAFT_PLAYER = null;
}
}
}
}