ServerConfigurationManager

Login/join orchestrator: fires S01 JoinGame, S38 tab-list, S39 abilities and S41 difficulty during initializeConnectionToPlayer.

net/minecraft/server/management/ServerConfigurationManager.java

Updated 2026-09-12

Deep Analysis

Server-wide player roster, bans, whitelist and spawn lifecycle. Creates NetHandlerPlayServer on login, sends join burst, and handles respawn, dimension transfer and logout broadcast.

Key Methods in Depth (7)

initializeConnectionToPlayer

Sends login burst and places player.

initializeConnectionToPlayer builds the login burst for a new EntityPlayerMP after NBT load. It resolves the profile name, caches the profile, reads player NBT, binds world and ItemInWorldManager, and logs IP with entityId and coordinates. It sets game type, creates NetHandlerPlayServer and sends S01 JoinGame with entityId, game type, hardcore, dimension, difficulty, max players, terrain and reduced debug. It then sends MC|Brand S3F, S41 difficulty, S05 spawn, S39 abilities and S09 held change. It pushes stats, achievements and full scoreboard, broadcasts the join message and registers the player in the roster. It teleports with setPlayerLocation S08, syncs time and weather, applies resource pack and re-sends potion effects with S1D. Riding NBT is restored by spawning the mount entity.

        NetHandlerPlayServer nethandlerplayserver = new NetHandlerPlayServer(this.mcServer, netManager, playerIn);
        nethandlerplayserver.sendPacket(new S01PacketJoinGame(playerIn.getEntityId(), playerIn.theItemInWorldManager.getGameType(), worldinfo.isHardcoreModeEnabled(), worldserver.provider.getDimensionId(), worldserver.getDifficulty(), this.getMaxPlayers(), worldinfo.getTerrainType(), worldserver.getGameRules().getBoolean("reducedDebugInfo")));
        nethandlerplayserver.sendPacket(new S3FPacketCustomPayload("MC|Brand", (new PacketBuffer(Unpooled.buffer())).writeString(this.getServerInstance().getServerModName())));
        nethandlerplayserver.sendPacket(new S41PacketServerDifficulty(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
        nethandlerplayserver.sendPacket(new S05PacketSpawnPosition(blockpos));
        nethandlerplayserver.sendPacket(new S39PacketPlayerAbilities(playerIn.capabilities));
        nethandlerplayserver.sendPacket(new S09PacketHeldItemChange(playerIn.inventory.currentItem));
        playerIn.getStatFile().func_150877_d();
        playerIn.getStatFile().sendAchievements(playerIn);
        this.sendScoreboard((ServerScoreboard)worldserver.getScoreboard(), playerIn);
        this.mcServer.refreshStatusNextTick();
        ChatComponentTranslation chatcomponenttranslation;

The NetHandlerPlayServer construction binds the channel to the player entity. S01PacketJoinGame carries entityId, game type, dimension and difficulty so the client can build WorldClient. The MC|Brand S3F advertises server mod name for client display. S41, S05, S39 and S09 sync difficulty lock, spawn point, fly flags and held slot. sendScoreboard plus stats complete the burst before S08 position arrives.

allowUserToConnect

Ban, whitelist, IP and full gates.

allowUserToConnect enforces login gates in fixed order and returns a kick reason or null. First it checks profile bans via bannedPlayers, appending ban reason and formatted expiry date if present. Second it checks whitelist via canJoin, returning not white-listed when enforced and the player is neither op nor listed. Third it checks IP bans via bannedIPs with reason and expiry formatting. Fourth it checks capacity where list size at or above maxPlayers and no bypass returns server is full. Null means all gates passed and NetHandlerLoginServer may proceed to compression and LoginSuccess. The order matters because bans outrank whitelist and capacity. No packets are sent here, the caller closes with S00 using the returned string.

        {
            UserListBansEntry userlistbansentry = (UserListBansEntry)this.bannedPlayers.getEntry(profile);
            String s1 = "You are banned from this server!\nReason: " + userlistbansentry.getBanReason();

            if (userlistbansentry.getBanEndDate() != null)
            {
                s1 = s1 + "\nYour ban will be removed on " + dateFormat.format(userlistbansentry.getBanEndDate());
            }

            return s1;
        }
        else if (!this.canJoin(profile))
        {
            return "You are not white-listed on this server!";
        }
        else if (this.bannedIPs.isBanned(address))
        {
            IPBanEntry ipbanentry = this.bannedIPs.getBanEntry(address);
            String s = "Your IP address is banned from this server!\nReason: " + ipbanentry.getBanReason();

            if (ipbanentry.getBanEndDate() != null)
            {
                s = s + "\nYour ban will be removed on " + dateFormat.format(ipbanentry.getBanEndDate());
            }

            return s;
        }
        else
        {
            return this.playerEntityList.size() >= this.maxPlayers && !this.bypassesPlayerLimit(profile) ? "The server is full!" : null;
        }

The bannedPlayers entry lookup builds the profile-ban string with reason and optional expiry date. The canJoin else-if enforces whitelist after profile bans so banned players cannot bypass via listing. The bannedIPs branch mirrors the profile logic for address bans with expiry formatting. The final else encodes capacity as size at or above maxPlayers without bypass returning server is full else null. Returning null is the only success path to S02 LoginSuccess.

recreatePlayerEntity

Respawns player preserving connection.

recreatePlayerEntity respawns a dead player while reusing the NetHandlerPlayServer connection. It untracks the old entity from tracker and player manager, removes it dangerously and drops it from the roster. It copies dimension, creates a fresh ItemInWorldManager and EntityPlayerMP, then reuses the handler, clones inventory and stats, and preserves entityId and command stats. It resolves bed spawn via getBedSpawnLocation and places at plus 0.5 plus 0.1 offsets, or sends S2B state zero when the bed is invalid. It loads the chunk, lifts the player above collision up to Y 256, sends S07 Respawn, S08 location via setPlayerLocation, S05 spawn and S1F experience. It resyncs time and weather, re-adds to manager and world, restores maps and heals. No kick occurs.

        if (blockpos != null)
        {
            BlockPos blockpos1 = EntityPlayer.getBedSpawnLocation(this.mcServer.worldServerForDimension(playerIn.dimension), blockpos, flag);

            if (blockpos1 != null)
            {
                entityplayermp.setLocationAndAngles((double)((float)blockpos1.getX() + 0.5F), (double)((float)blockpos1.getY() + 0.1F), (double)((float)blockpos1.getZ() + 0.5F), 0.0F, 0.0F);
                entityplayermp.setSpawnPoint(blockpos, flag);
            }
            else
            {
                entityplayermp.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(0, 0.0F));
            }
        }

        worldserver.theChunkProviderServer.loadChunk((int)entityplayermp.posX >> 4, (int)entityplayermp.posZ >> 4);

        while (!worldserver.getCollidingBoundingBoxes(entityplayermp, entityplayermp.getEntityBoundingBox()).isEmpty() && entityplayermp.posY < 256.0D)
        {
            entityplayermp.setPosition(entityplayermp.posX, entityplayermp.posY + 1.0D, entityplayermp.posZ);
        }

        entityplayermp.playerNetServerHandler.sendPacket(new S07PacketRespawn(entityplayermp.dimension, entityplayermp.worldObj.getDifficulty(), entityplayermp.worldObj.getWorldInfo().getTerrainType(), entityplayermp.theItemInWorldManager.getGameType()));
        BlockPos blockpos2 = worldserver.getSpawnPoint();
        entityplayermp.playerNetServerHandler.setPlayerLocation(entityplayermp.posX, entityplayermp.posY, entityplayermp.posZ, entityplayermp.rotationYaw, entityplayermp.rotationPitch);

The bed null check skips spawn logic for world-spawn respawns. getBedSpawnLocation validates the bed, with plus 0.5 and plus 0.1 offsets centering the player on respawn. Invalid beds send S2B state zero to show the respawn-screen message. The chunk load plus while-collision lift to Y 256 prevents suffocation on respawn. S07 Respawn plus setPlayerLocation S08 rebuild the client world and pin the position.

transferPlayerToDimension

Moves player across dimensions.

transferPlayerToDimension moves a live player across dimensions without dropping the connection. It records the old dimension, sets the new id and sends S07 Respawn with difficulty, terrain and game type so the client rebuilds WorldClient. It removes the player dangerously, clears isDead, scales coordinates through transferEntityToWorld with factor 8.0 between overworld and nether clamped to border, or spawn point for end. It re-registers with preparePlayer, pins position with setPlayerLocation S08, rebinds ItemInWorldManager world and resyncs time and weather. It then syncs inventory and re-sends every active S1D potion effect. No kick occurs, failure leaves the player in the new world at the portal exit.

    public void transferPlayerToDimension(EntityPlayerMP playerIn, int dimension)
    {
        int i = playerIn.dimension;
        WorldServer worldserver = this.mcServer.worldServerForDimension(playerIn.dimension);
        playerIn.dimension = dimension;
        WorldServer worldserver1 = this.mcServer.worldServerForDimension(playerIn.dimension);
        playerIn.playerNetServerHandler.sendPacket(new S07PacketRespawn(playerIn.dimension, playerIn.worldObj.getDifficulty(), playerIn.worldObj.getWorldInfo().getTerrainType(), playerIn.theItemInWorldManager.getGameType()));
        worldserver.removePlayerEntityDangerously(playerIn);
        playerIn.isDead = false;
        this.transferEntityToWorld(playerIn, i, worldserver, worldserver1);
        this.preparePlayer(playerIn, worldserver);
        playerIn.playerNetServerHandler.setPlayerLocation(playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
        playerIn.theItemInWorldManager.setWorld(worldserver1);
        this.updateTimeAndWeatherForPlayer(playerIn, worldserver1);
        this.syncPlayerInventory(playerIn);

        for (PotionEffect potioneffect : playerIn.getActivePotionEffects())
        {
            playerIn.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(playerIn.getEntityId(), potioneffect));
        }
    }

Saving old dimension i preserves the source for coordinate scaling. S07PacketRespawn forces the client to swap WorldClient before the entity moves. removePlayerEntityDangerously plus isDead false detach from the old world without death drops. transferEntityToWorld applies times or divide by 8.0 clamping plus portal placement. setPlayerLocation S08, inventory sync and S1D effect loop complete the handoff so buffs survive travel.

playerLoggedIn

Joins roster and announces.

playerLoggedIn joins the roster and announces presence with S38 tab-list packets. It appends to playerEntityList and uuidToPlayerMap for lookups and duplicate detection. It broadcasts S38 ADD_PLAYER for the newcomer to all existing players via sendPacketToAllPlayers. It spawns the entity in the dimension world and registers with preparePlayer to load chunks and tracking. It then loops the full roster and sends each existing ADD_PLAYER to the newcomer so tab lists converge symmetrically. No kick or teleport occurs here, position was already set by initializeConnectionToPlayer. Duplicate logins are handled earlier by createPlayerForUser kicking the old session.

    public void playerLoggedIn(EntityPlayerMP playerIn)
    {
        this.playerEntityList.add(playerIn);
        this.uuidToPlayerMap.put(playerIn.getUniqueID(), playerIn);
        this.sendPacketToAllPlayers(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.ADD_PLAYER, new EntityPlayerMP[] {playerIn}));
        WorldServer worldserver = this.mcServer.worldServerForDimension(playerIn.dimension);
        worldserver.spawnEntityInWorld(playerIn);
        this.preparePlayer(playerIn, (WorldServer)null);

        for (int i = 0; i < this.playerEntityList.size(); ++i)
        {
            EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntityList.get(i);
            playerIn.playerNetServerHandler.sendPacket(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.ADD_PLAYER, new EntityPlayerMP[] {entityplayermp}));
        }
    }

Adding to list and uuid map makes the player visible to commands and duplicate checks. The broadcast S38 ADD_PLAYER informs all clients to create tab-list entries. spawnEntityInWorld plus preparePlayer load the chunk and start entity tracking. The loop sends the full existing roster as individual S38 ADD_PLAYER packets to the newcomer. This two-way exchange keeps tab lists consistent on join.

playerLoggedOut

Persists and removes player.

playerLoggedOut persists and removes a disconnecting player. It triggers leaveGameStat, writes NBT and stats via writePlayerData, and removes any ridden mount dangerously. It removes the player entity and its tracker entry, drops it from playerEntityList, and clears uuidToPlayerMap and stat files only if the mapped entry is identical. It broadcasts S38 REMOVE_PLAYER to remaining players so tab lists drop the entry. No packets go to the leaver because the channel is closing. The method is called from NetHandlerPlayServer onDisconnect after the quit message. Failure to remove from maps would leave ghost tab entries and block relogin.

    public void playerLoggedOut(EntityPlayerMP playerIn)
    {
        playerIn.triggerAchievement(StatList.leaveGameStat);
        this.writePlayerData(playerIn);
        WorldServer worldserver = playerIn.getServerForPlayer();

        if (playerIn.ridingEntity != null)
        {
            worldserver.removePlayerEntityDangerously(playerIn.ridingEntity);
            logger.debug("removing player mount");
        }

        worldserver.removeEntity(playerIn);
        worldserver.getPlayerManager().removePlayer(playerIn);
        this.playerEntityList.remove(playerIn);
        UUID uuid = playerIn.getUniqueID();
        EntityPlayerMP entityplayermp = (EntityPlayerMP)this.uuidToPlayerMap.get(uuid);

        if (entityplayermp == playerIn)
        {
            this.uuidToPlayerMap.remove(uuid);
            this.playerStatFiles.remove(uuid);
        }

        this.sendPacketToAllPlayers(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.REMOVE_PLAYER, new EntityPlayerMP[] {playerIn}));
    }

triggerAchievement plus writePlayerData flush stats and NBT before removal. The ridingEntity check removes horse, boat or pig mounts to avoid orphan vehicles. removeEntity plus removePlayer plus list removal detach tracking and roster membership. The identity check before map removal protects against deleting a newer duplicate login. The final S38 REMOVE_PLAYER broadcast tells clients to purge the tab entry.

updateTimeAndWeatherForPlayer

Syncs border, time and rain.

updateTimeAndWeatherForPlayer syncs border, clock and rain to one player after login, respawn or dimension change. It sends S44 WorldBorder INITIALIZE from the overworld border so the client enforces the same center and size. It sends S03 TimeUpdate with total time, day time and doDaylightCycle gamerule. If the target world isRaining it sends S2B state 1 to start rain, state 7 with rain strength and state 8 with thunder strength. Clear weather sends only border and time with no S2B. No kick or teleport occurs. Clients apply rain strength gradually to render particles and sky darkening.

    public void updateTimeAndWeatherForPlayer(EntityPlayerMP playerIn, WorldServer worldIn)
    {
        WorldBorder worldborder = this.mcServer.worldServers[0].getWorldBorder();
        playerIn.playerNetServerHandler.sendPacket(new S44PacketWorldBorder(worldborder, S44PacketWorldBorder.Action.INITIALIZE));
        playerIn.playerNetServerHandler.sendPacket(new S03PacketTimeUpdate(worldIn.getTotalWorldTime(), worldIn.getWorldTime(), worldIn.getGameRules().getBoolean("doDaylightCycle")));

        if (worldIn.isRaining())
        {
            playerIn.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(1, 0.0F));
            playerIn.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(7, worldIn.getRainStrength(1.0F)));
            playerIn.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(8, worldIn.getThunderStrength(1.0F)));
        }
    }

Fetching the overworld border ensures nether and end players share the same boundary. S44 INITIALIZE carries center, size and warning timers in one packet. S03PacketTimeUpdate carries total age, day time and daylight-cycle flag to drive the sun. The isRaining gate adds S2B 1, 7 and 8 for rain begin plus strength lerps. Without rain the client keeps clear skies from the earlier world load.

Packet Usage

PacketDirTrigger
S01sentLogin burst with entityId and gametype
S05sentSpawn point on login/respawn
S07sentRespawn or dimension change
S38sentTab-list add/remove/latency tick
S03sentTime/weather sync for player
S44sentWorldBorder init and listener fan-out

Internal State

playerEntityListOrdered online EntityPlayerMP roster
uuidToPlayerMapUUID lookup for dup-login and queries
bannedPlayers/bannedIPsBan lists checked in allowUserToConnect
maxPlayers/viewDistanceCapacity and chunk radius for PlayerManager
playerPingIndex>600 ticks triggers latency broadcast

Full Source

ServerConfigurationManager.java1080 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.server.management;
2
3
import com.google.common.collect.Lists;
4
import com.google.common.collect.Maps;
5
import com.google.common.collect.Sets;
6
import com.mojang.authlib.GameProfile;
7
import io.netty.buffer.Unpooled;
8
import java.io.File;
9
import java.net.SocketAddress;
10
import java.text.SimpleDateFormat;
11
import java.util.List;
12
import java.util.Map;
13
import java.util.Set;
14
import java.util.UUID;
15
import net.minecraft.entity.Entity;
16
import net.minecraft.entity.EntityList;
17
import net.minecraft.entity.player.EntityPlayer;
18
import net.minecraft.entity.player.EntityPlayerMP;
19
import net.minecraft.nbt.NBTTagCompound;
20
import net.minecraft.network.NetHandlerPlayServer;
21
import net.minecraft.network.NetworkManager;
22
import net.minecraft.network.Packet;
23
import net.minecraft.network.PacketBuffer;
24
import net.minecraft.network.play.server.S01PacketJoinGame;
25
import net.minecraft.network.play.server.S02PacketChat;
26
import net.minecraft.network.play.server.S03PacketTimeUpdate;
27
import net.minecraft.network.play.server.S05PacketSpawnPosition;
28
import net.minecraft.network.play.server.S07PacketRespawn;
29
import net.minecraft.network.play.server.S09PacketHeldItemChange;
30
import net.minecraft.network.play.server.S1DPacketEntityEffect;
31
import net.minecraft.network.play.server.S1FPacketSetExperience;
32
import net.minecraft.network.play.server.S2BPacketChangeGameState;
33
import net.minecraft.network.play.server.S38PacketPlayerListItem;
34
import net.minecraft.network.play.server.S39PacketPlayerAbilities;
35
import net.minecraft.network.play.server.S3EPacketTeams;
36
import net.minecraft.network.play.server.S3FPacketCustomPayload;
37
import net.minecraft.network.play.server.S41PacketServerDifficulty;
38
import net.minecraft.network.play.server.S44PacketWorldBorder;
39
import net.minecraft.potion.PotionEffect;
40
import net.minecraft.scoreboard.ScoreObjective;
41
import net.minecraft.scoreboard.ScorePlayerTeam;
42
import net.minecraft.scoreboard.ServerScoreboard;
43
import net.minecraft.scoreboard.Team;
44
import net.minecraft.server.MinecraftServer;
45
import net.minecraft.stats.StatList;
46
import net.minecraft.stats.StatisticsFile;
47
import net.minecraft.util.BlockPos;
48
import net.minecraft.util.ChatComponentTranslation;
49
import net.minecraft.util.EnumChatFormatting;
50
import net.minecraft.util.IChatComponent;
51
import net.minecraft.util.MathHelper;
52
import net.minecraft.world.World;
53
import net.minecraft.world.WorldServer;
54
import net.minecraft.world.WorldSettings;
55
import net.minecraft.world.border.IBorderListener;
56
import net.minecraft.world.border.WorldBorder;
57
import net.minecraft.world.demo.DemoWorldManager;
58
import net.minecraft.world.storage.IPlayerFileData;
59
import net.minecraft.world.storage.WorldInfo;
60
import org.apache.logging.log4j.LogManager;
61
import org.apache.logging.log4j.Logger;
62
63
public abstract class ServerConfigurationManager
64
{
65
    public static final File FILE_PLAYERBANS = new File("banned-players.json");
66
    public static final File FILE_IPBANS = new File("banned-ips.json");
67
    public static final File FILE_OPS = new File("ops.json");
68
    public static final File FILE_WHITELIST = new File("whitelist.json");
69
    private static final Logger logger = LogManager.getLogger();
70
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
71
72
    /** Reference to the MinecraftServer object. */
73
    private final MinecraftServer mcServer;
74
    private final List<EntityPlayerMP> playerEntityList = Lists.<EntityPlayerMP>newArrayList();
75
    private final Map<UUID, EntityPlayerMP> uuidToPlayerMap = Maps.<UUID, EntityPlayerMP>newHashMap();
76
    private final UserListBans bannedPlayers;
77
    private final BanList bannedIPs;
78
79
    /** A set containing the OPs. */
80
    private final UserListOps ops;
81
82
    /** The Set of all whitelisted players. */
83
    private final UserListWhitelist whiteListedPlayers;
84
    private final Map<UUID, StatisticsFile> playerStatFiles;
85
86
    /** Reference to the PlayerNBTManager object. */
87
    private IPlayerFileData playerNBTManagerObj;
88
89
    /**
90
     * Server setting to only allow OPs and whitelisted players to join the server.
91
     */
92
    private boolean whiteListEnforced;
93
94
    /** The maximum number of players that can be connected at a time. */
95
    protected int maxPlayers;
96
    private int viewDistance;
97
    private WorldSettings.GameType gameType;
98
99
    /** True if all players are allowed to use commands (cheats). */
100
    private boolean commandsAllowedForAll;
101
102
    /**
103
     * index into playerEntities of player to ping, updated every tick; currently hardcoded to max at 200 players
104
     */
105
    private int playerPingIndex;
106
107
    public ServerConfigurationManager(MinecraftServer server)
108
    {
109
        this.bannedPlayers = new UserListBans(FILE_PLAYERBANS);
110
        this.bannedIPs = new BanList(FILE_IPBANS);
111
        this.ops = new UserListOps(FILE_OPS);
112
        this.whiteListedPlayers = new UserListWhitelist(FILE_WHITELIST);
113
        this.playerStatFiles = Maps.<UUID, StatisticsFile>newHashMap();
114
        this.mcServer = server;
115
        this.bannedPlayers.setLanServer(false);
116
        this.bannedIPs.setLanServer(false);
117
        this.maxPlayers = 8;
118
    }
119
120
    public void initializeConnectionToPlayer(NetworkManager netManager, EntityPlayerMP playerIn)
121
    {
122
        GameProfile gameprofile = playerIn.getGameProfile();
123
        PlayerProfileCache playerprofilecache = this.mcServer.getPlayerProfileCache();
124
        GameProfile gameprofile1 = playerprofilecache.getProfileByUUID(gameprofile.getId());
125
        String s = gameprofile1 == null ? gameprofile.getName() : gameprofile1.getName();
126
        playerprofilecache.addEntry(gameprofile);
127
        NBTTagCompound nbttagcompound = this.readPlayerDataFromFile(playerIn);
128
        playerIn.setWorld(this.mcServer.worldServerForDimension(playerIn.dimension));
129
        playerIn.theItemInWorldManager.setWorld((WorldServer)playerIn.worldObj);
130
        String s1 = "local";
131
132
        if (netManager.getRemoteAddress() != null)
133
        {
134
            s1 = netManager.getRemoteAddress().toString();
135
        }
136
137
        logger.info(playerIn.getName() + "[" + s1 + "] logged in with entity id " + playerIn.getEntityId() + " at (" + playerIn.posX + ", " + playerIn.posY + ", " + playerIn.posZ + ")");
138
        WorldServer worldserver = this.mcServer.worldServerForDimension(playerIn.dimension);
139
        WorldInfo worldinfo = worldserver.getWorldInfo();
140
        BlockPos blockpos = worldserver.getSpawnPoint();
141
        this.setPlayerGameTypeBasedOnOther(playerIn, (EntityPlayerMP)null, worldserver);
142
        NetHandlerPlayServer nethandlerplayserver = new NetHandlerPlayServer(this.mcServer, netManager, playerIn);
143
        nethandlerplayserver.sendPacket(new S01PacketJoinGame(playerIn.getEntityId(), playerIn.theItemInWorldManager.getGameType(), worldinfo.isHardcoreModeEnabled(), worldserver.provider.getDimensionId(), worldserver.getDifficulty(), this.getMaxPlayers(), worldinfo.getTerrainType(), worldserver.getGameRules().getBoolean("reducedDebugInfo")));
144
        nethandlerplayserver.sendPacket(new S3FPacketCustomPayload("MC|Brand", (new PacketBuffer(Unpooled.buffer())).writeString(this.getServerInstance().getServerModName())));
145
        nethandlerplayserver.sendPacket(new S41PacketServerDifficulty(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
146
        nethandlerplayserver.sendPacket(new S05PacketSpawnPosition(blockpos));
147
        nethandlerplayserver.sendPacket(new S39PacketPlayerAbilities(playerIn.capabilities));
148
        nethandlerplayserver.sendPacket(new S09PacketHeldItemChange(playerIn.inventory.currentItem));
149
        playerIn.getStatFile().func_150877_d();
150
        playerIn.getStatFile().sendAchievements(playerIn);
151
        this.sendScoreboard((ServerScoreboard)worldserver.getScoreboard(), playerIn);
152
        this.mcServer.refreshStatusNextTick();
153
        ChatComponentTranslation chatcomponenttranslation;
154
155
        if (!playerIn.getName().equalsIgnoreCase(s))
156
        {
157
            chatcomponenttranslation = new ChatComponentTranslation("multiplayer.player.joined.renamed", new Object[] {playerIn.getDisplayName(), s});
158
        }
159
        else
160
        {
161
            chatcomponenttranslation = new ChatComponentTranslation("multiplayer.player.joined", new Object[] {playerIn.getDisplayName()});
162
        }
163
164
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.YELLOW);
165
        this.sendChatMsg(chatcomponenttranslation);
166
        this.playerLoggedIn(playerIn);
167
        nethandlerplayserver.setPlayerLocation(playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
168
        this.updateTimeAndWeatherForPlayer(playerIn, worldserver);
169
170
        if (this.mcServer.getResourcePackUrl().length() > 0)
171
        {
172
            playerIn.loadResourcePack(this.mcServer.getResourcePackUrl(), this.mcServer.getResourcePackHash());
173
        }
174
175
        for (PotionEffect potioneffect : playerIn.getActivePotionEffects())
176
        {
177
            nethandlerplayserver.sendPacket(new S1DPacketEntityEffect(playerIn.getEntityId(), potioneffect));
178
        }
179
180
        playerIn.addSelfToInternalCraftingInventory();
181
182
        if (nbttagcompound != null && nbttagcompound.hasKey("Riding", 10))
183
        {
184
            Entity entity = EntityList.createEntityFromNBT(nbttagcompound.getCompoundTag("Riding"), worldserver);
185
186
            if (entity != null)
187
            {
188
                entity.forceSpawn = true;
189
                worldserver.spawnEntityInWorld(entity);
190
                playerIn.mountEntity(entity);
191
                entity.forceSpawn = false;
192
            }
193
        }
194
    }
195
196
    protected void sendScoreboard(ServerScoreboard scoreboardIn, EntityPlayerMP playerIn)
197
    {
198
        Set<ScoreObjective> set = Sets.<ScoreObjective>newHashSet();
199
200
        for (ScorePlayerTeam scoreplayerteam : scoreboardIn.getTeams())
201
        {
202
            playerIn.playerNetServerHandler.sendPacket(new S3EPacketTeams(scoreplayerteam, 0));
203
        }
204
205
        for (int i = 0; i < 19; ++i)
206
        {
207
            ScoreObjective scoreobjective = scoreboardIn.getObjectiveInDisplaySlot(i);
208
209
            if (scoreobjective != null && !set.contains(scoreobjective))
210
            {
211
                for (Packet packet : scoreboardIn.func_96550_d(scoreobjective))
212
                {
213
                    playerIn.playerNetServerHandler.sendPacket(packet);
214
                }
215
216
                set.add(scoreobjective);
217
            }
218
        }
219
    }
220
221
    /**
222
     * Sets the NBT manager to the one for the WorldServer given.
223
     */
224
    public void setPlayerManager(WorldServer[] worldServers)
225
    {
226
        this.playerNBTManagerObj = worldServers[0].getSaveHandler().getPlayerNBTManager();
227
        worldServers[0].getWorldBorder().addListener(new IBorderListener()
228
        {
229
            public void onSizeChanged(WorldBorder border, double newSize)
230
            {
231
                ServerConfigurationManager.this.sendPacketToAllPlayers(new S44PacketWorldBorder(border, S44PacketWorldBorder.Action.SET_SIZE));
232
            }
233
            public void onTransitionStarted(WorldBorder border, double oldSize, double newSize, long time)
234
            {
235
                ServerConfigurationManager.this.sendPacketToAllPlayers(new S44PacketWorldBorder(border, S44PacketWorldBorder.Action.LERP_SIZE));
236
            }
237
            public void onCenterChanged(WorldBorder border, double x, double z)
238
            {
239
                ServerConfigurationManager.this.sendPacketToAllPlayers(new S44PacketWorldBorder(border, S44PacketWorldBorder.Action.SET_CENTER));
240
            }
241
            public void onWarningTimeChanged(WorldBorder border, int newTime)
242
            {
243
                ServerConfigurationManager.this.sendPacketToAllPlayers(new S44PacketWorldBorder(border, S44PacketWorldBorder.Action.SET_WARNING_TIME));
244
            }
245
            public void onWarningDistanceChanged(WorldBorder border, int newDistance)
246
            {
247
                ServerConfigurationManager.this.sendPacketToAllPlayers(new S44PacketWorldBorder(border, S44PacketWorldBorder.Action.SET_WARNING_BLOCKS));
248
            }
249
            public void onDamageAmountChanged(WorldBorder border, double newAmount)
250
            {
251
            }
252
            public void onDamageBufferChanged(WorldBorder border, double newSize)
253
            {
254
            }
255
        });
256
    }
257
258
    public void preparePlayer(EntityPlayerMP playerIn, WorldServer worldIn)
259
    {
260
        WorldServer worldserver = playerIn.getServerForPlayer();
261
262
        if (worldIn != null)
263
        {
264
            worldIn.getPlayerManager().removePlayer(playerIn);
265
        }
266
267
        worldserver.getPlayerManager().addPlayer(playerIn);
268
        worldserver.theChunkProviderServer.loadChunk((int)playerIn.posX >> 4, (int)playerIn.posZ >> 4);
269
    }
270
271
    public int getEntityViewDistance()
272
    {
273
        return PlayerManager.getFurthestViewableBlock(this.getViewDistance());
274
    }
275
276
    /**
277
     * called during player login. reads the player information from disk.
278
     */
279
    public NBTTagCompound readPlayerDataFromFile(EntityPlayerMP playerIn)
280
    {
281
        NBTTagCompound nbttagcompound = this.mcServer.worldServers[0].getWorldInfo().getPlayerNBTTagCompound();
282
        NBTTagCompound nbttagcompound1;
283
284
        if (playerIn.getName().equals(this.mcServer.getServerOwner()) && nbttagcompound != null)
285
        {
286
            playerIn.readFromNBT(nbttagcompound);
287
            nbttagcompound1 = nbttagcompound;
288
            logger.debug("loading single player");
289
        }
290
        else
291
        {
292
            nbttagcompound1 = this.playerNBTManagerObj.readPlayerData(playerIn);
293
        }
294
295
        return nbttagcompound1;
296
    }
297
298
    /**
299
     * also stores the NBTTags if this is an intergratedPlayerList
300
     */
301
    protected void writePlayerData(EntityPlayerMP playerIn)
302
    {
303
        this.playerNBTManagerObj.writePlayerData(playerIn);
304
        StatisticsFile statisticsfile = (StatisticsFile)this.playerStatFiles.get(playerIn.getUniqueID());
305
306
        if (statisticsfile != null)
307
        {
308
            statisticsfile.saveStatFile();
309
        }
310
    }
311
312
    /**
313
     * Called when a player successfully logs in. Reads player data from disk and inserts the player into the world.
314
     */
315
    public void playerLoggedIn(EntityPlayerMP playerIn)
316
    {
317
        this.playerEntityList.add(playerIn);
318
        this.uuidToPlayerMap.put(playerIn.getUniqueID(), playerIn);
319
        this.sendPacketToAllPlayers(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.ADD_PLAYER, new EntityPlayerMP[] {playerIn}));
320
        WorldServer worldserver = this.mcServer.worldServerForDimension(playerIn.dimension);
321
        worldserver.spawnEntityInWorld(playerIn);
322
        this.preparePlayer(playerIn, (WorldServer)null);
323
324
        for (int i = 0; i < this.playerEntityList.size(); ++i)
325
        {
326
            EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntityList.get(i);
327
            playerIn.playerNetServerHandler.sendPacket(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.ADD_PLAYER, new EntityPlayerMP[] {entityplayermp}));
328
        }
329
    }
330
331
    /**
332
     * using player's dimension, update their movement when in a vehicle (e.g. cart, boat)
333
     */
334
    public void serverUpdateMountedMovingPlayer(EntityPlayerMP playerIn)
335
    {
336
        playerIn.getServerForPlayer().getPlayerManager().updateMountedMovingPlayer(playerIn);
337
    }
338
339
    /**
340
     * Called when a player disconnects from the game. Writes player data to disk and removes them from the world.
341
     */
342
    public void playerLoggedOut(EntityPlayerMP playerIn)
343
    {
344
        playerIn.triggerAchievement(StatList.leaveGameStat);
345
        this.writePlayerData(playerIn);
346
        WorldServer worldserver = playerIn.getServerForPlayer();
347
348
        if (playerIn.ridingEntity != null)
349
        {
350
            worldserver.removePlayerEntityDangerously(playerIn.ridingEntity);
351
            logger.debug("removing player mount");
352
        }
353
354
        worldserver.removeEntity(playerIn);
355
        worldserver.getPlayerManager().removePlayer(playerIn);
356
        this.playerEntityList.remove(playerIn);
357
        UUID uuid = playerIn.getUniqueID();
358
        EntityPlayerMP entityplayermp = (EntityPlayerMP)this.uuidToPlayerMap.get(uuid);
359
360
        if (entityplayermp == playerIn)
361
        {
362
            this.uuidToPlayerMap.remove(uuid);
363
            this.playerStatFiles.remove(uuid);
364
        }
365
366
        this.sendPacketToAllPlayers(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.REMOVE_PLAYER, new EntityPlayerMP[] {playerIn}));
367
    }
368
369
    /**
370
     * checks ban-lists, then white-lists, then space for the server. Returns null on success, or an error message
371
     */
372
    public String allowUserToConnect(SocketAddress address, GameProfile profile)
373
    {
374
        if (this.bannedPlayers.isBanned(profile))
375
        {
376
            UserListBansEntry userlistbansentry = (UserListBansEntry)this.bannedPlayers.getEntry(profile);
377
            String s1 = "You are banned from this server!\nReason: " + userlistbansentry.getBanReason();
378
379
            if (userlistbansentry.getBanEndDate() != null)
380
            {
381
                s1 = s1 + "\nYour ban will be removed on " + dateFormat.format(userlistbansentry.getBanEndDate());
382
            }
383
384
            return s1;
385
        }
386
        else if (!this.canJoin(profile))
387
        {
388
            return "You are not white-listed on this server!";
389
        }
390
        else if (this.bannedIPs.isBanned(address))
391
        {
392
            IPBanEntry ipbanentry = this.bannedIPs.getBanEntry(address);
393
            String s = "Your IP address is banned from this server!\nReason: " + ipbanentry.getBanReason();
394
395
            if (ipbanentry.getBanEndDate() != null)
396
            {
397
                s = s + "\nYour ban will be removed on " + dateFormat.format(ipbanentry.getBanEndDate());
398
            }
399
400
            return s;
401
        }
402
        else
403
        {
404
            return this.playerEntityList.size() >= this.maxPlayers && !this.bypassesPlayerLimit(profile) ? "The server is full!" : null;
405
        }
406
    }
407
408
    /**
409
     * also checks for multiple logins across servers
410
     */
411
    public EntityPlayerMP createPlayerForUser(GameProfile profile)
412
    {
413
        UUID uuid = EntityPlayer.getUUID(profile);
414
        List<EntityPlayerMP> list = Lists.<EntityPlayerMP>newArrayList();
415
416
        for (int i = 0; i < this.playerEntityList.size(); ++i)
417
        {
418
            EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntityList.get(i);
419
420
            if (entityplayermp.getUniqueID().equals(uuid))
421
            {
422
                list.add(entityplayermp);
423
            }
424
        }
425
426
        EntityPlayerMP entityplayermp2 = (EntityPlayerMP)this.uuidToPlayerMap.get(profile.getId());
427
428
        if (entityplayermp2 != null && !list.contains(entityplayermp2))
429
        {
430
            list.add(entityplayermp2);
431
        }
432
433
        for (EntityPlayerMP entityplayermp1 : list)
434
        {
435
            entityplayermp1.playerNetServerHandler.kickPlayerFromServer("You logged in from another location");
436
        }
437
438
        ItemInWorldManager iteminworldmanager;
439
440
        if (this.mcServer.isDemo())
441
        {
442
            iteminworldmanager = new DemoWorldManager(this.mcServer.worldServerForDimension(0));
443
        }
444
        else
445
        {
446
            iteminworldmanager = new ItemInWorldManager(this.mcServer.worldServerForDimension(0));
447
        }
448
449
        return new EntityPlayerMP(this.mcServer, this.mcServer.worldServerForDimension(0), profile, iteminworldmanager);
450
    }
451
452
    /**
453
     * Called on respawn
454
     */
455
    public EntityPlayerMP recreatePlayerEntity(EntityPlayerMP playerIn, int dimension, boolean conqueredEnd)
456
    {
457
        playerIn.getServerForPlayer().getEntityTracker().removePlayerFromTrackers(playerIn);
458
        playerIn.getServerForPlayer().getEntityTracker().untrackEntity(playerIn);
459
        playerIn.getServerForPlayer().getPlayerManager().removePlayer(playerIn);
460
        this.playerEntityList.remove(playerIn);
461
        this.mcServer.worldServerForDimension(playerIn.dimension).removePlayerEntityDangerously(playerIn);
462
        BlockPos blockpos = playerIn.getBedLocation();
463
        boolean flag = playerIn.isSpawnForced();
464
        playerIn.dimension = dimension;
465
        ItemInWorldManager iteminworldmanager;
466
467
        if (this.mcServer.isDemo())
468
        {
469
            iteminworldmanager = new DemoWorldManager(this.mcServer.worldServerForDimension(playerIn.dimension));
470
        }
471
        else
472
        {
473
            iteminworldmanager = new ItemInWorldManager(this.mcServer.worldServerForDimension(playerIn.dimension));
474
        }
475
476
        EntityPlayerMP entityplayermp = new EntityPlayerMP(this.mcServer, this.mcServer.worldServerForDimension(playerIn.dimension), playerIn.getGameProfile(), iteminworldmanager);
477
        entityplayermp.playerNetServerHandler = playerIn.playerNetServerHandler;
478
        entityplayermp.clonePlayer(playerIn, conqueredEnd);
479
        entityplayermp.setEntityId(playerIn.getEntityId());
480
        entityplayermp.setCommandStats(playerIn);
481
        WorldServer worldserver = this.mcServer.worldServerForDimension(playerIn.dimension);
482
        this.setPlayerGameTypeBasedOnOther(entityplayermp, playerIn, worldserver);
483
484
        if (blockpos != null)
485
        {
486
            BlockPos blockpos1 = EntityPlayer.getBedSpawnLocation(this.mcServer.worldServerForDimension(playerIn.dimension), blockpos, flag);
487
488
            if (blockpos1 != null)
489
            {
490
                entityplayermp.setLocationAndAngles((double)((float)blockpos1.getX() + 0.5F), (double)((float)blockpos1.getY() + 0.1F), (double)((float)blockpos1.getZ() + 0.5F), 0.0F, 0.0F);
491
                entityplayermp.setSpawnPoint(blockpos, flag);
492
            }
493
            else
494
            {
495
                entityplayermp.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(0, 0.0F));
496
            }
497
        }
498
499
        worldserver.theChunkProviderServer.loadChunk((int)entityplayermp.posX >> 4, (int)entityplayermp.posZ >> 4);
500
501
        while (!worldserver.getCollidingBoundingBoxes(entityplayermp, entityplayermp.getEntityBoundingBox()).isEmpty() && entityplayermp.posY < 256.0D)
502
        {
503
            entityplayermp.setPosition(entityplayermp.posX, entityplayermp.posY + 1.0D, entityplayermp.posZ);
504
        }
505
506
        entityplayermp.playerNetServerHandler.sendPacket(new S07PacketRespawn(entityplayermp.dimension, entityplayermp.worldObj.getDifficulty(), entityplayermp.worldObj.getWorldInfo().getTerrainType(), entityplayermp.theItemInWorldManager.getGameType()));
507
        BlockPos blockpos2 = worldserver.getSpawnPoint();
508
        entityplayermp.playerNetServerHandler.setPlayerLocation(entityplayermp.posX, entityplayermp.posY, entityplayermp.posZ, entityplayermp.rotationYaw, entityplayermp.rotationPitch);
509
        entityplayermp.playerNetServerHandler.sendPacket(new S05PacketSpawnPosition(blockpos2));
510
        entityplayermp.playerNetServerHandler.sendPacket(new S1FPacketSetExperience(entityplayermp.experience, entityplayermp.experienceTotal, entityplayermp.experienceLevel));
511
        this.updateTimeAndWeatherForPlayer(entityplayermp, worldserver);
512
        worldserver.getPlayerManager().addPlayer(entityplayermp);
513
        worldserver.spawnEntityInWorld(entityplayermp);
514
        this.playerEntityList.add(entityplayermp);
515
        this.uuidToPlayerMap.put(entityplayermp.getUniqueID(), entityplayermp);
516
        entityplayermp.addSelfToInternalCraftingInventory();
517
        entityplayermp.setHealth(entityplayermp.getHealth());
518
        return entityplayermp;
519
    }
520
521
    /**
522
     * moves provided player from overworld to nether or vice versa
523
     */
524
    public void transferPlayerToDimension(EntityPlayerMP playerIn, int dimension)
525
    {
526
        int i = playerIn.dimension;
527
        WorldServer worldserver = this.mcServer.worldServerForDimension(playerIn.dimension);
528
        playerIn.dimension = dimension;
529
        WorldServer worldserver1 = this.mcServer.worldServerForDimension(playerIn.dimension);
530
        playerIn.playerNetServerHandler.sendPacket(new S07PacketRespawn(playerIn.dimension, playerIn.worldObj.getDifficulty(), playerIn.worldObj.getWorldInfo().getTerrainType(), playerIn.theItemInWorldManager.getGameType()));
531
        worldserver.removePlayerEntityDangerously(playerIn);
532
        playerIn.isDead = false;
533
        this.transferEntityToWorld(playerIn, i, worldserver, worldserver1);
534
        this.preparePlayer(playerIn, worldserver);
535
        playerIn.playerNetServerHandler.setPlayerLocation(playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
536
        playerIn.theItemInWorldManager.setWorld(worldserver1);
537
        this.updateTimeAndWeatherForPlayer(playerIn, worldserver1);
538
        this.syncPlayerInventory(playerIn);
539
540
        for (PotionEffect potioneffect : playerIn.getActivePotionEffects())
541
        {
542
            playerIn.playerNetServerHandler.sendPacket(new S1DPacketEntityEffect(playerIn.getEntityId(), potioneffect));
543
        }
544
    }
545
546
    /**
547
     * Transfers an entity from a world to another world.
548
     *  
549
     * @param oldWorldIn The world transfering from
550
     * @param toWorldIn The world transfering the entity to
551
     */
552
    public void transferEntityToWorld(Entity entityIn, int p_82448_2_, WorldServer oldWorldIn, WorldServer toWorldIn)
553
    {
554
        double d0 = entityIn.posX;
555
        double d1 = entityIn.posZ;
556
        double d2 = 8.0D;
557
        float f = entityIn.rotationYaw;
558
        oldWorldIn.theProfiler.startSection("moving");
559
560
        if (entityIn.dimension == -1)
561
        {
562
            d0 = MathHelper.clamp_double(d0 / d2, toWorldIn.getWorldBorder().minX() + 16.0D, toWorldIn.getWorldBorder().maxX() - 16.0D);
563
            d1 = MathHelper.clamp_double(d1 / d2, toWorldIn.getWorldBorder().minZ() + 16.0D, toWorldIn.getWorldBorder().maxZ() - 16.0D);
564
            entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
565
566
            if (entityIn.isEntityAlive())
567
            {
568
                oldWorldIn.updateEntityWithOptionalForce(entityIn, false);
569
            }
570
        }
571
        else if (entityIn.dimension == 0)
572
        {
573
            d0 = MathHelper.clamp_double(d0 * d2, toWorldIn.getWorldBorder().minX() + 16.0D, toWorldIn.getWorldBorder().maxX() - 16.0D);
574
            d1 = MathHelper.clamp_double(d1 * d2, toWorldIn.getWorldBorder().minZ() + 16.0D, toWorldIn.getWorldBorder().maxZ() - 16.0D);
575
            entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
576
577
            if (entityIn.isEntityAlive())
578
            {
579
                oldWorldIn.updateEntityWithOptionalForce(entityIn, false);
580
            }
581
        }
582
        else
583
        {
584
            BlockPos blockpos;
585
586
            if (p_82448_2_ == 1)
587
            {
588
                blockpos = toWorldIn.getSpawnPoint();
589
            }
590
            else
591
            {
592
                blockpos = toWorldIn.getSpawnCoordinate();
593
            }
594
595
            d0 = (double)blockpos.getX();
596
            entityIn.posY = (double)blockpos.getY();
597
            d1 = (double)blockpos.getZ();
598
            entityIn.setLocationAndAngles(d0, entityIn.posY, d1, 90.0F, 0.0F);
599
600
            if (entityIn.isEntityAlive())
601
            {
602
                oldWorldIn.updateEntityWithOptionalForce(entityIn, false);
603
            }
604
        }
605
606
        oldWorldIn.theProfiler.endSection();
607
608
        if (p_82448_2_ != 1)
609
        {
610
            oldWorldIn.theProfiler.startSection("placing");
611
            d0 = (double)MathHelper.clamp_int((int)d0, -29999872, 29999872);
612
            d1 = (double)MathHelper.clamp_int((int)d1, -29999872, 29999872);
613
614
            if (entityIn.isEntityAlive())
615
            {
616
                entityIn.setLocationAndAngles(d0, entityIn.posY, d1, entityIn.rotationYaw, entityIn.rotationPitch);
617
                toWorldIn.getDefaultTeleporter().placeInPortal(entityIn, f);
618
                toWorldIn.spawnEntityInWorld(entityIn);
619
                toWorldIn.updateEntityWithOptionalForce(entityIn, false);
620
            }
621
622
            oldWorldIn.theProfiler.endSection();
623
        }
624
625
        entityIn.setWorld(toWorldIn);
626
    }
627
628
    /**
629
     * self explanitory
630
     */
631
    public void onTick()
632
    {
633
        if (++this.playerPingIndex > 600)
634
        {
635
            this.sendPacketToAllPlayers(new S38PacketPlayerListItem(S38PacketPlayerListItem.Action.UPDATE_LATENCY, this.playerEntityList));
636
            this.playerPingIndex = 0;
637
        }
638
    }
639
640
    public void sendPacketToAllPlayers(Packet packetIn)
641
    {
642
        for (int i = 0; i < this.playerEntityList.size(); ++i)
643
        {
644
            ((EntityPlayerMP)this.playerEntityList.get(i)).playerNetServerHandler.sendPacket(packetIn);
645
        }
646
    }
647
648
    public void sendPacketToAllPlayersInDimension(Packet packetIn, int dimension)
649
    {
650
        for (int i = 0; i < this.playerEntityList.size(); ++i)
651
        {
652
            EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntityList.get(i);
653
654
            if (entityplayermp.dimension == dimension)
655
            {
656
                entityplayermp.playerNetServerHandler.sendPacket(packetIn);
657
            }
658
        }
659
    }
660
661
    public void sendMessageToAllTeamMembers(EntityPlayer player, IChatComponent message)
662
    {
663
        Team team = player.getTeam();
664
665
        if (team != null)
666
        {
667
            for (String s : team.getMembershipCollection())
668
            {
669
                EntityPlayerMP entityplayermp = this.getPlayerByUsername(s);
670
671
                if (entityplayermp != null && entityplayermp != player)
672
                {
673
                    entityplayermp.addChatMessage(message);
674
                }
675
            }
676
        }
677
    }
678
679
    public void sendMessageToTeamOrEvryPlayer(EntityPlayer player, IChatComponent message)
680
    {
681
        Team team = player.getTeam();
682
683
        if (team == null)
684
        {
685
            this.sendChatMsg(message);
686
        }
687
        else
688
        {
689
            for (int i = 0; i < this.playerEntityList.size(); ++i)
690
            {
691
                EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntityList.get(i);
692
693
                if (entityplayermp.getTeam() != team)
694
                {
695
                    entityplayermp.addChatMessage(message);
696
                }
697
            }
698
        }
699
    }
700
701
    public String func_181058_b(boolean p_181058_1_)
702
    {
703
        String s = "";
704
        List<EntityPlayerMP> list = Lists.newArrayList(this.playerEntityList);
705
706
        for (int i = 0; i < ((List)list).size(); ++i)
707
        {
708
            if (i > 0)
709
            {
710
                s = s + ", ";
711
            }
712
713
            s = s + ((EntityPlayerMP)list.get(i)).getName();
714
715
            if (p_181058_1_)
716
            {
717
                s = s + " (" + ((EntityPlayerMP)list.get(i)).getUniqueID().toString() + ")";
718
            }
719
        }
720
721
        return s;
722
    }
723
724
    /**
725
     * Returns an array of the usernames of all the connected players.
726
     */
727
    public String[] getAllUsernames()
728
    {
729
        String[] astring = new String[this.playerEntityList.size()];
730
731
        for (int i = 0; i < this.playerEntityList.size(); ++i)
732
        {
733
            astring[i] = ((EntityPlayerMP)this.playerEntityList.get(i)).getName();
734
        }
735
736
        return astring;
737
    }
738
739
    public GameProfile[] getAllProfiles()
740
    {
741
        GameProfile[] agameprofile = new GameProfile[this.playerEntityList.size()];
742
743
        for (int i = 0; i < this.playerEntityList.size(); ++i)
744
        {
745
            agameprofile[i] = ((EntityPlayerMP)this.playerEntityList.get(i)).getGameProfile();
746
        }
747
748
        return agameprofile;
749
    }
750
751
    public UserListBans getBannedPlayers()
752
    {
753
        return this.bannedPlayers;
754
    }
755
756
    public BanList getBannedIPs()
757
    {
758
        return this.bannedIPs;
759
    }
760
761
    public void addOp(GameProfile profile)
762
    {
763
        this.ops.addEntry(new UserListOpsEntry(profile, this.mcServer.getOpPermissionLevel(), this.ops.bypassesPlayerLimit(profile)));
764
    }
765
766
    public void removeOp(GameProfile profile)
767
    {
768
        this.ops.removeEntry(profile);
769
    }
770
771
    public boolean canJoin(GameProfile profile)
772
    {
773
        return !this.whiteListEnforced || this.ops.hasEntry(profile) || this.whiteListedPlayers.hasEntry(profile);
774
    }
775
776
    public boolean canSendCommands(GameProfile profile)
777
    {
778
        return this.ops.hasEntry(profile) || this.mcServer.isSinglePlayer() && this.mcServer.worldServers[0].getWorldInfo().areCommandsAllowed() && this.mcServer.getServerOwner().equalsIgnoreCase(profile.getName()) || this.commandsAllowedForAll;
779
    }
780
781
    public EntityPlayerMP getPlayerByUsername(String username)
782
    {
783
        for (EntityPlayerMP entityplayermp : this.playerEntityList)
784
        {
785
            if (entityplayermp.getName().equalsIgnoreCase(username))
786
            {
787
                return entityplayermp;
788
            }
789
        }
790
791
        return null;
792
    }
793
794
    /**
795
     * params: x,y,z,r,dimension. The packet is sent to all players within r radius of x,y,z (r^2>x^2+y^2+z^2)
796
     */
797
    public void sendToAllNear(double x, double y, double z, double radius, int dimension, Packet packetIn)
798
    {
799
        this.sendToAllNearExcept((EntityPlayer)null, x, y, z, radius, dimension, packetIn);
800
    }
801
802
    /**
803
     * params: srcPlayer,x,y,z,r,dimension. The packet is not sent to the srcPlayer, but all other players within the
804
     * search radius
805
     */
806
    public void sendToAllNearExcept(EntityPlayer p_148543_1_, double x, double y, double z, double radius, int dimension, Packet p_148543_11_)
807
    {
808
        for (int i = 0; i < this.playerEntityList.size(); ++i)
809
        {
810
            EntityPlayerMP entityplayermp = (EntityPlayerMP)this.playerEntityList.get(i);
811
812
            if (entityplayermp != p_148543_1_ && entityplayermp.dimension == dimension)
813
            {
814
                double d0 = x - entityplayermp.posX;
815
                double d1 = y - entityplayermp.posY;
816
                double d2 = z - entityplayermp.posZ;
817
818
                if (d0 * d0 + d1 * d1 + d2 * d2 < radius * radius)
819
                {
820
                    entityplayermp.playerNetServerHandler.sendPacket(p_148543_11_);
821
                }
822
            }
823
        }
824
    }
825
826
    /**
827
     * Saves all of the players' current states.
828
     */
829
    public void saveAllPlayerData()
830
    {
831
        for (int i = 0; i < this.playerEntityList.size(); ++i)
832
        {
833
            this.writePlayerData((EntityPlayerMP)this.playerEntityList.get(i));
834
        }
835
    }
836
837
    public void addWhitelistedPlayer(GameProfile profile)
838
    {
839
        this.whiteListedPlayers.addEntry(new UserListWhitelistEntry(profile));
840
    }
841
842
    public void removePlayerFromWhitelist(GameProfile profile)
843
    {
844
        this.whiteListedPlayers.removeEntry(profile);
845
    }
846
847
    public UserListWhitelist getWhitelistedPlayers()
848
    {
849
        return this.whiteListedPlayers;
850
    }
851
852
    public String[] getWhitelistedPlayerNames()
853
    {
854
        return this.whiteListedPlayers.getKeys();
855
    }
856
857
    public UserListOps getOppedPlayers()
858
    {
859
        return this.ops;
860
    }
861
862
    public String[] getOppedPlayerNames()
863
    {
864
        return this.ops.getKeys();
865
    }
866
867
    /**
868
     * Either does nothing, or calls readWhiteList.
869
     */
870
    public void loadWhiteList()
871
    {
872
    }
873
874
    /**
875
     * Updates the time and weather for the given player to those of the given world
876
     */
877
    public void updateTimeAndWeatherForPlayer(EntityPlayerMP playerIn, WorldServer worldIn)
878
    {
879
        WorldBorder worldborder = this.mcServer.worldServers[0].getWorldBorder();
880
        playerIn.playerNetServerHandler.sendPacket(new S44PacketWorldBorder(worldborder, S44PacketWorldBorder.Action.INITIALIZE));
881
        playerIn.playerNetServerHandler.sendPacket(new S03PacketTimeUpdate(worldIn.getTotalWorldTime(), worldIn.getWorldTime(), worldIn.getGameRules().getBoolean("doDaylightCycle")));
882
883
        if (worldIn.isRaining())
884
        {
885
            playerIn.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(1, 0.0F));
886
            playerIn.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(7, worldIn.getRainStrength(1.0F)));
887
            playerIn.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(8, worldIn.getThunderStrength(1.0F)));
888
        }
889
    }
890
891
    /**
892
     * sends the players inventory to himself
893
     */
894
    public void syncPlayerInventory(EntityPlayerMP playerIn)
895
    {
896
        playerIn.sendContainerToPlayer(playerIn.inventoryContainer);
897
        playerIn.setPlayerHealthUpdated();
898
        playerIn.playerNetServerHandler.sendPacket(new S09PacketHeldItemChange(playerIn.inventory.currentItem));
899
    }
900
901
    /**
902
     * Returns the number of players currently on the server.
903
     */
904
    public int getCurrentPlayerCount()
905
    {
906
        return this.playerEntityList.size();
907
    }
908
909
    /**
910
     * Returns the maximum number of players allowed on the server.
911
     */
912
    public int getMaxPlayers()
913
    {
914
        return this.maxPlayers;
915
    }
916
917
    /**
918
     * Returns an array of usernames for which player.dat exists for.
919
     */
920
    public String[] getAvailablePlayerDat()
921
    {
922
        return this.mcServer.worldServers[0].getSaveHandler().getPlayerNBTManager().getAvailablePlayerDat();
923
    }
924
925
    public void setWhiteListEnabled(boolean whitelistEnabled)
926
    {
927
        this.whiteListEnforced = whitelistEnabled;
928
    }
929
930
    public List<EntityPlayerMP> getPlayersMatchingAddress(String address)
931
    {
932
        List<EntityPlayerMP> list = Lists.<EntityPlayerMP>newArrayList();
933
934
        for (EntityPlayerMP entityplayermp : this.playerEntityList)
935
        {
936
            if (entityplayermp.getPlayerIP().equals(address))
937
            {
938
                list.add(entityplayermp);
939
            }
940
        }
941
942
        return list;
943
    }
944
945
    /**
946
     * Gets the View Distance.
947
     */
948
    public int getViewDistance()
949
    {
950
        return this.viewDistance;
951
    }
952
953
    public MinecraftServer getServerInstance()
954
    {
955
        return this.mcServer;
956
    }
957
958
    /**
959
     * On integrated servers, returns the host's player data to be written to level.dat.
960
     */
961
    public NBTTagCompound getHostPlayerData()
962
    {
963
        return null;
964
    }
965
966
    public void setGameType(WorldSettings.GameType p_152604_1_)
967
    {
968
        this.gameType = p_152604_1_;
969
    }
970
971
    private void setPlayerGameTypeBasedOnOther(EntityPlayerMP p_72381_1_, EntityPlayerMP p_72381_2_, World worldIn)
972
    {
973
        if (p_72381_2_ != null)
974
        {
975
            p_72381_1_.theItemInWorldManager.setGameType(p_72381_2_.theItemInWorldManager.getGameType());
976
        }
977
        else if (this.gameType != null)
978
        {
979
            p_72381_1_.theItemInWorldManager.setGameType(this.gameType);
980
        }
981
982
        p_72381_1_.theItemInWorldManager.initializeGameType(worldIn.getWorldInfo().getGameType());
983
    }
984
985
    /**
986
     * Sets whether all players are allowed to use commands (cheats) on the server.
987
     */
988
    public void setCommandsAllowedForAll(boolean p_72387_1_)
989
    {
990
        this.commandsAllowedForAll = p_72387_1_;
991
    }
992
993
    /**
994
     * Kicks everyone with "Server closed" as reason.
995
     */
996
    public void removeAllPlayers()
997
    {
998
        for (int i = 0; i < this.playerEntityList.size(); ++i)
999
        {
1000
            ((EntityPlayerMP)this.playerEntityList.get(i)).playerNetServerHandler.kickPlayerFromServer("Server closed");
1001
        }
1002
    }
1003
1004
    public void sendChatMsgImpl(IChatComponent component, boolean isChat)
1005
    {
1006
        this.mcServer.addChatMessage(component);
1007
        byte b0 = (byte)(isChat ? 1 : 0);
1008
        this.sendPacketToAllPlayers(new S02PacketChat(component, b0));
1009
    }
1010
1011
    /**
1012
     * Sends the given string to every player as chat message.
1013
     */
1014
    public void sendChatMsg(IChatComponent component)
1015
    {
1016
        this.sendChatMsgImpl(component, true);
1017
    }
1018
1019
    public StatisticsFile getPlayerStatsFile(EntityPlayer playerIn)
1020
    {
1021
        UUID uuid = playerIn.getUniqueID();
1022
        StatisticsFile statisticsfile = uuid == null ? null : (StatisticsFile)this.playerStatFiles.get(uuid);
1023
1024
        if (statisticsfile == null)
1025
        {
1026
            File file1 = new File(this.mcServer.worldServerForDimension(0).getSaveHandler().getWorldDirectory(), "stats");
1027
            File file2 = new File(file1, uuid.toString() + ".json");
1028
1029
            if (!file2.exists())
1030
            {
1031
                File file3 = new File(file1, playerIn.getName() + ".json");
1032
1033
                if (file3.exists() && file3.isFile())
1034
                {
1035
                    file3.renameTo(file2);
1036
                }
1037
            }
1038
1039
            statisticsfile = new StatisticsFile(this.mcServer, file2);
1040
            statisticsfile.readStatFile();
1041
            this.playerStatFiles.put(uuid, statisticsfile);
1042
        }
1043
1044
        return statisticsfile;
1045
    }
1046
1047
    public void setViewDistance(int distance)
1048
    {
1049
        this.viewDistance = distance;
1050
1051
        if (this.mcServer.worldServers != null)
1052
        {
1053
            for (WorldServer worldserver : this.mcServer.worldServers)
1054
            {
1055
                if (worldserver != null)
1056
                {
1057
                    worldserver.getPlayerManager().setPlayerViewRadius(distance);
1058
                }
1059
            }
1060
        }
1061
    }
1062
1063
    public List<EntityPlayerMP> getPlayerList()
1064
    {
1065
        return this.playerEntityList;
1066
    }
1067
1068
    /**
1069
     * Get's the EntityPlayerMP object representing the player with the UUID.
1070
     */
1071
    public EntityPlayerMP getPlayerByUUID(UUID playerUUID)
1072
    {
1073
        return (EntityPlayerMP)this.uuidToPlayerMap.get(playerUUID);
1074
    }
1075
1076
    public boolean bypassesPlayerLimit(GameProfile p_183023_1_)
1077
    {
1078
        return false;
1079
    }
1080
}

Deobfuscated MCP 1.8.9 source of ServerConfigurationManager from Marcelektro/MavenMCP-1.8.9 (net/minecraft/server/management/ServerConfigurationManager.java), stored verbatim.