NetHandlerPlayServer .java

net.minecraft.network.NetHandlerPlayServer (class): members: chatSpamThresholdCount, kickPlayerFromServer, lastSentPingPacket, floatingTickCount, lastPosX.

net.minecraft.networkclass1,461 linescommon61.3 KB

Implements

API Surface (33)

void update()
NetworkManager getNetworkManager()
void kickPlayerFromServer(String reason)
void operationComplete(Future <? super Void > p_operationComplete_1_)
void run()
void processInput(C0CPacketInput packetIn)
void processPlayer(C03PacketPlayer packetIn)
void setPlayerLocation(double x, double y, double z, float yaw, float pitch)
void setPlayerLocation(double x, double y, double z, float yaw, float pitch, Set<S08PacketPlayerPosLook.EnumFlags> relativeSet)
void processPlayerDigging(C07PacketPlayerDigging packetIn)
void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn)
void handleSpectate(C18PacketSpectate packetIn)
void handleResourcePackStatus(C19PacketResourcePackStatus packetIn)
void onDisconnect(IChatComponent reason)
void sendPacket(final Packet packetIn)
String call()
void processHeldItemChange(C09PacketHeldItemChange packetIn)
void processChatMessage(C01PacketChatMessage packetIn)
void handleAnimation(C0APacketAnimation packetIn)
void processEntityAction(C0BPacketEntityAction packetIn)
void processUseEntity(C02PacketUseEntity packetIn)
void processClientStatus(C16PacketClientStatus packetIn)
void processCloseWindow(C0DPacketCloseWindow packetIn)
void processClickWindow(C0EPacketClickWindow packetIn)
void processEnchantItem(C11PacketEnchantItem packetIn)
void processCreativeInventoryAction(C10PacketCreativeInventoryAction packetIn)
void processConfirmTransaction(C0FPacketConfirmTransaction packetIn)
void processUpdateSign(C12PacketUpdateSign packetIn)
void processKeepAlive(C00PacketKeepAlive packetIn)
void processPlayerAbilities(C13PacketPlayerAbilities packetIn)
void processTabComplete(C14PacketTabComplete packetIn)
void processClientSettings(C15PacketClientSettings packetIn)
void processVanilla250Packet(C17PacketCustomPayload packetIn)

Fields & Constants (18)

logger
netManager
serverController
playerEntity
networkTickCount
field_175090_f
floatingTickCount
field_147366_g
field_147378_h
lastPingTime
lastSentPingPacket
chatSpamThresholdCount
itemDropThreshold
field_147372_n
lastPosX
lastPosY
lastPosZ
hasMoved

String literals (46)

"keepAlive"
"You have been idle for too long!"
"Invalid move packet received"
"Illegal position"
" moved too quickly! "
" moved wrongly!"
" was kicked for floating too long!"
"Flying is not enabled on this server"
"Invalid player action"
"build.tooHigh"
" lost connection: "
"multiplayer.player.left"
"Sending packet"
"Packet being sent"
"Packet class"
" tried to set an invalid carried item"
"chat.cannotSend"
"Illegal characters in chat"
"chat.type.text"
"disconnect.spam"
"Invalid client command!"
"Attempting to attack an invalid entity"
"Player "
" tried to attack an invalid entity"

Code Graph: Dependencies (80)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

NetHandlerPlayServer.java1461 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.network;
2
3
import com.google.common.collect.Lists;
4
import com.google.common.primitives.Doubles;
5
import com.google.common.primitives.Floats;
6
import com.google.common.util.concurrent.Futures;
7
import io.netty.buffer.ByteBuf;
8
import io.netty.buffer.Unpooled;
9
import io.netty.util.concurrent.Future;
10
import io.netty.util.concurrent.GenericFutureListener;
11
import java.io.IOException;
12
import java.util.Collections;
13
import java.util.Date;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.concurrent.Callable;
17
import net.minecraft.block.material.Material;
18
import net.minecraft.command.server.CommandBlockLogic;
19
import net.minecraft.crash.CrashReport;
20
import net.minecraft.crash.CrashReportCategory;
21
import net.minecraft.entity.Entity;
22
import net.minecraft.entity.EntityMinecartCommandBlock;
23
import net.minecraft.entity.item.EntityItem;
24
import net.minecraft.entity.item.EntityXPOrb;
25
import net.minecraft.entity.passive.EntityHorse;
26
import net.minecraft.entity.player.EntityPlayer;
27
import net.minecraft.entity.player.EntityPlayerMP;
28
import net.minecraft.entity.player.InventoryPlayer;
29
import net.minecraft.entity.projectile.EntityArrow;
30
import net.minecraft.init.Items;
31
import net.minecraft.inventory.Container;
32
import net.minecraft.inventory.ContainerBeacon;
33
import net.minecraft.inventory.ContainerMerchant;
34
import net.minecraft.inventory.ContainerRepair;
35
import net.minecraft.inventory.IInventory;
36
import net.minecraft.inventory.Slot;
37
import net.minecraft.item.ItemEditableBook;
38
import net.minecraft.item.ItemStack;
39
import net.minecraft.item.ItemWritableBook;
40
import net.minecraft.nbt.NBTTagCompound;
41
import net.minecraft.nbt.NBTTagString;
42
import net.minecraft.network.play.INetHandlerPlayServer;
43
import net.minecraft.network.play.client.C00PacketKeepAlive;
44
import net.minecraft.network.play.client.C01PacketChatMessage;
45
import net.minecraft.network.play.client.C02PacketUseEntity;
46
import net.minecraft.network.play.client.C03PacketPlayer;
47
import net.minecraft.network.play.client.C07PacketPlayerDigging;
48
import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement;
49
import net.minecraft.network.play.client.C09PacketHeldItemChange;
50
import net.minecraft.network.play.client.C0APacketAnimation;
51
import net.minecraft.network.play.client.C0BPacketEntityAction;
52
import net.minecraft.network.play.client.C0CPacketInput;
53
import net.minecraft.network.play.client.C0DPacketCloseWindow;
54
import net.minecraft.network.play.client.C0EPacketClickWindow;
55
import net.minecraft.network.play.client.C0FPacketConfirmTransaction;
56
import net.minecraft.network.play.client.C10PacketCreativeInventoryAction;
57
import net.minecraft.network.play.client.C11PacketEnchantItem;
58
import net.minecraft.network.play.client.C12PacketUpdateSign;
59
import net.minecraft.network.play.client.C13PacketPlayerAbilities;
60
import net.minecraft.network.play.client.C14PacketTabComplete;
61
import net.minecraft.network.play.client.C15PacketClientSettings;
62
import net.minecraft.network.play.client.C16PacketClientStatus;
63
import net.minecraft.network.play.client.C17PacketCustomPayload;
64
import net.minecraft.network.play.client.C18PacketSpectate;
65
import net.minecraft.network.play.client.C19PacketResourcePackStatus;
66
import net.minecraft.network.play.server.S00PacketKeepAlive;
67
import net.minecraft.network.play.server.S02PacketChat;
68
import net.minecraft.network.play.server.S07PacketRespawn;
69
import net.minecraft.network.play.server.S08PacketPlayerPosLook;
70
import net.minecraft.network.play.server.S18PacketEntityTeleport;
71
import net.minecraft.network.play.server.S23PacketBlockChange;
72
import net.minecraft.network.play.server.S2FPacketSetSlot;
73
import net.minecraft.network.play.server.S32PacketConfirmTransaction;
74
import net.minecraft.network.play.server.S3APacketTabComplete;
75
import net.minecraft.network.play.server.S40PacketDisconnect;
76
import net.minecraft.server.MinecraftServer;
77
import net.minecraft.server.management.UserListBansEntry;
78
import net.minecraft.stats.AchievementList;
79
import net.minecraft.tileentity.TileEntity;
80
import net.minecraft.tileentity.TileEntityCommandBlock;
81
import net.minecraft.tileentity.TileEntitySign;
82
import net.minecraft.util.AxisAlignedBB;
83
import net.minecraft.util.BlockPos;
84
import net.minecraft.util.ChatAllowedCharacters;
85
import net.minecraft.util.ChatComponentText;
86
import net.minecraft.util.ChatComponentTranslation;
87
import net.minecraft.util.EnumChatFormatting;
88
import net.minecraft.util.EnumFacing;
89
import net.minecraft.util.IChatComponent;
90
import net.minecraft.util.ITickable;
91
import net.minecraft.util.IntHashMap;
92
import net.minecraft.util.ReportedException;
93
import net.minecraft.world.WorldServer;
94
import org.apache.commons.lang3.StringUtils;
95
import org.apache.logging.log4j.LogManager;
96
import org.apache.logging.log4j.Logger;
97
98
public class NetHandlerPlayServer implements INetHandlerPlayServer, ITickable
99
{
100
    private static final Logger logger = LogManager.getLogger();
101
    public final NetworkManager netManager;
102
    private final MinecraftServer serverController;
103
    public EntityPlayerMP playerEntity;
104
    private int networkTickCount;
105
    private int field_175090_f;
106
107
    /**
108
     * Used to keep track of how the player is floating while gamerules should prevent that. Surpassing 80 ticks means
109
     * kick
110
     */
111
    private int floatingTickCount;
112
    private boolean field_147366_g;
113
    private int field_147378_h;
114
    private long lastPingTime;
115
    private long lastSentPingPacket;
116
117
    /**
118
     * Incremented by 20 each time a user sends a chat message, decreased by one every tick. Non-ops kicked when over
119
     * 200
120
     */
121
    private int chatSpamThresholdCount;
122
    private int itemDropThreshold;
123
    private IntHashMap<Short> field_147372_n = new IntHashMap();
124
    private double lastPosX;
125
    private double lastPosY;
126
    private double lastPosZ;
127
    private boolean hasMoved = true;
128
129
    public NetHandlerPlayServer(MinecraftServer server, NetworkManager networkManagerIn, EntityPlayerMP playerIn)
130
    {
131
        this.serverController = server;
132
        this.netManager = networkManagerIn;
133
        networkManagerIn.setNetHandler(this);
134
        this.playerEntity = playerIn;
135
        playerIn.playerNetServerHandler = this;
136
    }
137
138
    /**
139
     * Like the old updateEntity(), except more generic.
140
     */
141
    public void update()
142
    {
143
        this.field_147366_g = false;
144
        ++this.networkTickCount;
145
        this.serverController.theProfiler.startSection("keepAlive");
146
147
        if ((long)this.networkTickCount - this.lastSentPingPacket > 40L)
148
        {
149
            this.lastSentPingPacket = (long)this.networkTickCount;
150
            this.lastPingTime = this.currentTimeMillis();
151
            this.field_147378_h = (int)this.lastPingTime;
152
            this.sendPacket(new S00PacketKeepAlive(this.field_147378_h));
153
        }
154
155
        this.serverController.theProfiler.endSection();
156
157
        if (this.chatSpamThresholdCount > 0)
158
        {
159
            --this.chatSpamThresholdCount;
160
        }
161
162
        if (this.itemDropThreshold > 0)
163
        {
164
            --this.itemDropThreshold;
165
        }
166
167
        if (this.playerEntity.getLastActiveTime() > 0L && this.serverController.getMaxPlayerIdleMinutes() > 0 && MinecraftServer.getCurrentTimeMillis() - this.playerEntity.getLastActiveTime() > (long)(this.serverController.getMaxPlayerIdleMinutes() * 1000 * 60))
168
        {
169
            this.kickPlayerFromServer("You have been idle for too long!");
170
        }
171
    }
172
173
    public NetworkManager getNetworkManager()
174
    {
175
        return this.netManager;
176
    }
177
178
    /**
179
     * Kick a player from the server with a reason
180
     */
181
    public void kickPlayerFromServer(String reason)
182
    {
183
        final ChatComponentText chatcomponenttext = new ChatComponentText(reason);
184
        this.netManager.sendPacket(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener < Future <? super Void >> ()
185
        {
186
            public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
187
            {
188
                NetHandlerPlayServer.this.netManager.closeChannel(chatcomponenttext);
189
            }
190
        }, new GenericFutureListener[0]);
191
        this.netManager.disableAutoRead();
192
        Futures.getUnchecked(this.serverController.addScheduledTask(new Runnable()
193
        {
194
            public void run()
195
            {
196
                NetHandlerPlayServer.this.netManager.checkDisconnected();
197
            }
198
        }));
199
    }
200
201
    /**
202
     * Processes player movement input. Includes walking, strafing, jumping, sneaking; excludes riding and toggling
203
     * flying/sprinting
204
     */
205
    public void processInput(C0CPacketInput packetIn)
206
    {
207
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
208
        this.playerEntity.setEntityActionState(packetIn.getStrafeSpeed(), packetIn.getForwardSpeed(), packetIn.isJumping(), packetIn.isSneaking());
209
    }
210
211
    private boolean func_183006_b(C03PacketPlayer p_183006_1_)
212
    {
213
        return !Doubles.isFinite(p_183006_1_.getPositionX()) || !Doubles.isFinite(p_183006_1_.getPositionY()) || !Doubles.isFinite(p_183006_1_.getPositionZ()) || !Floats.isFinite(p_183006_1_.getPitch()) || !Floats.isFinite(p_183006_1_.getYaw());
214
    }
215
216
    /**
217
     * Processes clients perspective on player positioning and/or orientation
218
     */
219
    public void processPlayer(C03PacketPlayer packetIn)
220
    {
221
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
222
223
        if (this.func_183006_b(packetIn))
224
        {
225
            this.kickPlayerFromServer("Invalid move packet received");
226
        }
227
        else
228
        {
229
            WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
230
            this.field_147366_g = true;
231
232
            if (!this.playerEntity.playerConqueredTheEnd)
233
            {
234
                double d0 = this.playerEntity.posX;
235
                double d1 = this.playerEntity.posY;
236
                double d2 = this.playerEntity.posZ;
237
                double d3 = 0.0D;
238
                double d4 = packetIn.getPositionX() - this.lastPosX;
239
                double d5 = packetIn.getPositionY() - this.lastPosY;
240
                double d6 = packetIn.getPositionZ() - this.lastPosZ;
241
242
                if (packetIn.isMoving())
243
                {
244
                    d3 = d4 * d4 + d5 * d5 + d6 * d6;
245
246
                    if (!this.hasMoved && d3 < 0.25D)
247
                    {
248
                        this.hasMoved = true;
249
                    }
250
                }
251
252
                if (this.hasMoved)
253
                {
254
                    this.field_175090_f = this.networkTickCount;
255
256
                    if (this.playerEntity.ridingEntity != null)
257
                    {
258
                        float f4 = this.playerEntity.rotationYaw;
259
                        float f = this.playerEntity.rotationPitch;
260
                        this.playerEntity.ridingEntity.updateRiderPosition();
261
                        double d16 = this.playerEntity.posX;
262
                        double d17 = this.playerEntity.posY;
263
                        double d18 = this.playerEntity.posZ;
264
265
                        if (packetIn.getRotating())
266
                        {
267
                            f4 = packetIn.getYaw();
268
                            f = packetIn.getPitch();
269
                        }
270
271
                        this.playerEntity.onGround = packetIn.isOnGround();
272
                        this.playerEntity.onUpdateEntity();
273
                        this.playerEntity.setPositionAndRotation(d16, d17, d18, f4, f);
274
275
                        if (this.playerEntity.ridingEntity != null)
276
                        {
277
                            this.playerEntity.ridingEntity.updateRiderPosition();
278
                        }
279
280
                        this.serverController.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity);
281
282
                        if (this.playerEntity.ridingEntity != null)
283
                        {
284
                            if (d3 > 4.0D)
285
                            {
286
                                Entity entity = this.playerEntity.ridingEntity;
287
                                this.playerEntity.playerNetServerHandler.sendPacket(new S18PacketEntityTeleport(entity));
288
                                this.setPlayerLocation(this.playerEntity.posX, this.playerEntity.posY, this.playerEntity.posZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch);
289
                            }
290
291
                            this.playerEntity.ridingEntity.isAirBorne = true;
292
                        }
293
294
                        if (this.hasMoved)
295
                        {
296
                            this.lastPosX = this.playerEntity.posX;
297
                            this.lastPosY = this.playerEntity.posY;
298
                            this.lastPosZ = this.playerEntity.posZ;
299
                        }
300
301
                        worldserver.updateEntity(this.playerEntity);
302
                        return;
303
                    }
304
305
                    if (this.playerEntity.isPlayerSleeping())
306
                    {
307
                        this.playerEntity.onUpdateEntity();
308
                        this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch);
309
                        worldserver.updateEntity(this.playerEntity);
310
                        return;
311
                    }
312
313
                    double d7 = this.playerEntity.posY;
314
                    this.lastPosX = this.playerEntity.posX;
315
                    this.lastPosY = this.playerEntity.posY;
316
                    this.lastPosZ = this.playerEntity.posZ;
317
                    double d8 = this.playerEntity.posX;
318
                    double d9 = this.playerEntity.posY;
319
                    double d10 = this.playerEntity.posZ;
320
                    float f1 = this.playerEntity.rotationYaw;
321
                    float f2 = this.playerEntity.rotationPitch;
322
323
                    if (packetIn.isMoving() && packetIn.getPositionY() == -999.0D)
324
                    {
325
                        packetIn.setMoving(false);
326
                    }
327
328
                    if (packetIn.isMoving())
329
                    {
330
                        d8 = packetIn.getPositionX();
331
                        d9 = packetIn.getPositionY();
332
                        d10 = packetIn.getPositionZ();
333
334
                        if (Math.abs(packetIn.getPositionX()) > 3.0E7D || Math.abs(packetIn.getPositionZ()) > 3.0E7D)
335
                        {
336
                            this.kickPlayerFromServer("Illegal position");
337
                            return;
338
                        }
339
                    }
340
341
                    if (packetIn.getRotating())
342
                    {
343
                        f1 = packetIn.getYaw();
344
                        f2 = packetIn.getPitch();
345
                    }
346
347
                    this.playerEntity.onUpdateEntity();
348
                    this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, f1, f2);
349
350
                    if (!this.hasMoved)
351
                    {
352
                        return;
353
                    }
354
355
                    double d11 = d8 - this.playerEntity.posX;
356
                    double d12 = d9 - this.playerEntity.posY;
357
                    double d13 = d10 - this.playerEntity.posZ;
358
                    double d14 = this.playerEntity.motionX * this.playerEntity.motionX + this.playerEntity.motionY * this.playerEntity.motionY + this.playerEntity.motionZ * this.playerEntity.motionZ;
359
                    double d15 = d11 * d11 + d12 * d12 + d13 * d13;
360
361
                    if (d15 - d14 > 100.0D && (!this.serverController.isSinglePlayer() || !this.serverController.getServerOwner().equals(this.playerEntity.getName())))
362
                    {
363
                        logger.warn(this.playerEntity.getName() + " moved too quickly! " + d11 + "," + d12 + "," + d13 + " (" + d11 + ", " + d12 + ", " + d13 + ")");
364
                        this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch);
365
                        return;
366
                    }
367
368
                    float f3 = 0.0625F;
369
                    boolean flag = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.getEntityBoundingBox().contract((double)f3, (double)f3, (double)f3)).isEmpty();
370
371
                    if (this.playerEntity.onGround && !packetIn.isOnGround() && d12 > 0.0D)
372
                    {
373
                        this.playerEntity.jump();
374
                    }
375
376
                    this.playerEntity.moveEntity(d11, d12, d13);
377
                    this.playerEntity.onGround = packetIn.isOnGround();
378
                    d11 = d8 - this.playerEntity.posX;
379
                    d12 = d9 - this.playerEntity.posY;
380
381
                    if (d12 > -0.5D || d12 < 0.5D)
382
                    {
383
                        d12 = 0.0D;
384
                    }
385
386
                    d13 = d10 - this.playerEntity.posZ;
387
                    d15 = d11 * d11 + d12 * d12 + d13 * d13;
388
                    boolean flag1 = false;
389
390
                    if (d15 > 0.0625D && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.theItemInWorldManager.isCreative())
391
                    {
392
                        flag1 = true;
393
                        logger.warn(this.playerEntity.getName() + " moved wrongly!");
394
                    }
395
396
                    this.playerEntity.setPositionAndRotation(d8, d9, d10, f1, f2);
397
                    this.playerEntity.addMovementStat(this.playerEntity.posX - d0, this.playerEntity.posY - d1, this.playerEntity.posZ - d2);
398
399
                    if (!this.playerEntity.noClip)
400
                    {
401
                        boolean flag2 = worldserver.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.getEntityBoundingBox().contract((double)f3, (double)f3, (double)f3)).isEmpty();
402
403
                        if (flag && (flag1 || !flag2) && !this.playerEntity.isPlayerSleeping())
404
                        {
405
                            this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, f1, f2);
406
                            return;
407
                        }
408
                    }
409
410
                    AxisAlignedBB axisalignedbb = this.playerEntity.getEntityBoundingBox().expand((double)f3, (double)f3, (double)f3).addCoord(0.0D, -0.55D, 0.0D);
411
412
                    if (!this.serverController.isFlightAllowed() && !this.playerEntity.capabilities.allowFlying && !worldserver.checkBlockCollision(axisalignedbb))
413
                    {
414
                        if (d12 >= -0.03125D)
415
                        {
416
                            ++this.floatingTickCount;
417
418
                            if (this.floatingTickCount > 80)
419
                            {
420
                                logger.warn(this.playerEntity.getName() + " was kicked for floating too long!");
421
                                this.kickPlayerFromServer("Flying is not enabled on this server");
422
                                return;
423
                            }
424
                        }
425
                    }
426
                    else
427
                    {
428
                        this.floatingTickCount = 0;
429
                    }
430
431
                    this.playerEntity.onGround = packetIn.isOnGround();
432
                    this.serverController.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity);
433
                    this.playerEntity.handleFalling(this.playerEntity.posY - d7, packetIn.isOnGround());
434
                }
435
                else if (this.networkTickCount - this.field_175090_f > 20)
436
                {
437
                    this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch);
438
                }
439
            }
440
        }
441
    }
442
443
    public void setPlayerLocation(double x, double y, double z, float yaw, float pitch)
444
    {
445
        this.setPlayerLocation(x, y, z, yaw, pitch, Collections.<S08PacketPlayerPosLook.EnumFlags>emptySet());
446
    }
447
448
    public void setPlayerLocation(double x, double y, double z, float yaw, float pitch, Set<S08PacketPlayerPosLook.EnumFlags> relativeSet)
449
    {
450
        this.hasMoved = false;
451
        this.lastPosX = x;
452
        this.lastPosY = y;
453
        this.lastPosZ = z;
454
455
        if (relativeSet.contains(S08PacketPlayerPosLook.EnumFlags.X))
456
        {
457
            this.lastPosX += this.playerEntity.posX;
458
        }
459
460
        if (relativeSet.contains(S08PacketPlayerPosLook.EnumFlags.Y))
461
        {
462
            this.lastPosY += this.playerEntity.posY;
463
        }
464
465
        if (relativeSet.contains(S08PacketPlayerPosLook.EnumFlags.Z))
466
        {
467
            this.lastPosZ += this.playerEntity.posZ;
468
        }
469
470
        float f = yaw;
471
        float f1 = pitch;
472
473
        if (relativeSet.contains(S08PacketPlayerPosLook.EnumFlags.Y_ROT))
474
        {
475
            f = yaw + this.playerEntity.rotationYaw;
476
        }
477
478
        if (relativeSet.contains(S08PacketPlayerPosLook.EnumFlags.X_ROT))
479
        {
480
            f1 = pitch + this.playerEntity.rotationPitch;
481
        }
482
483
        this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, f, f1);
484
        this.playerEntity.playerNetServerHandler.sendPacket(new S08PacketPlayerPosLook(x, y, z, yaw, pitch, relativeSet));
485
    }
486
487
    /**
488
     * Processes the player initiating/stopping digging on a particular spot, as well as a player dropping items?. (0:
489
     * initiated, 1: reinitiated, 2? , 3-4 drop item (respectively without or with player control), 5: stopped; x,y,z,
490
     * side clicked on;)
491
     */
492
    public void processPlayerDigging(C07PacketPlayerDigging packetIn)
493
    {
494
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
495
        WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
496
        BlockPos blockpos = packetIn.getPosition();
497
        this.playerEntity.markPlayerActive();
498
499
        switch (packetIn.getStatus())
500
        {
501
            case DROP_ITEM:
502
                if (!this.playerEntity.isSpectator())
503
                {
504
                    this.playerEntity.dropOneItem(false);
505
                }
506
507
                return;
508
509
            case DROP_ALL_ITEMS:
510
                if (!this.playerEntity.isSpectator())
511
                {
512
                    this.playerEntity.dropOneItem(true);
513
                }
514
515
                return;
516
517
            case RELEASE_USE_ITEM:
518
                this.playerEntity.stopUsingItem();
519
                return;
520
521
            case START_DESTROY_BLOCK:
522
            case ABORT_DESTROY_BLOCK:
523
            case STOP_DESTROY_BLOCK:
524
                double d0 = this.playerEntity.posX - ((double)blockpos.getX() + 0.5D);
525
                double d1 = this.playerEntity.posY - ((double)blockpos.getY() + 0.5D) + 1.5D;
526
                double d2 = this.playerEntity.posZ - ((double)blockpos.getZ() + 0.5D);
527
                double d3 = d0 * d0 + d1 * d1 + d2 * d2;
528
529
                if (d3 > 36.0D)
530
                {
531
                    return;
532
                }
533
                else if (blockpos.getY() >= this.serverController.getBuildLimit())
534
                {
535
                    return;
536
                }
537
                else
538
                {
539
                    if (packetIn.getStatus() == C07PacketPlayerDigging.Action.START_DESTROY_BLOCK)
540
                    {
541
                        if (!this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos))
542
                        {
543
                            this.playerEntity.theItemInWorldManager.onBlockClicked(blockpos, packetIn.getFacing());
544
                        }
545
                        else
546
                        {
547
                            this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos));
548
                        }
549
                    }
550
                    else
551
                    {
552
                        if (packetIn.getStatus() == C07PacketPlayerDigging.Action.STOP_DESTROY_BLOCK)
553
                        {
554
                            this.playerEntity.theItemInWorldManager.blockRemoving(blockpos);
555
                        }
556
                        else if (packetIn.getStatus() == C07PacketPlayerDigging.Action.ABORT_DESTROY_BLOCK)
557
                        {
558
                            this.playerEntity.theItemInWorldManager.cancelDestroyingBlock();
559
                        }
560
561
                        if (worldserver.getBlockState(blockpos).getBlock().getMaterial() != Material.air)
562
                        {
563
                            this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos));
564
                        }
565
                    }
566
567
                    return;
568
                }
569
570
            default:
571
                throw new IllegalArgumentException("Invalid player action");
572
        }
573
    }
574
575
    /**
576
     * Processes block placement and block activation (anvil, furnace, etc.)
577
     */
578
    public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement packetIn)
579
    {
580
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
581
        WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
582
        ItemStack itemstack = this.playerEntity.inventory.getCurrentItem();
583
        boolean flag = false;
584
        BlockPos blockpos = packetIn.getPosition();
585
        EnumFacing enumfacing = EnumFacing.getFront(packetIn.getPlacedBlockDirection());
586
        this.playerEntity.markPlayerActive();
587
588
        if (packetIn.getPlacedBlockDirection() == 255)
589
        {
590
            if (itemstack == null)
591
            {
592
                return;
593
            }
594
595
            this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, worldserver, itemstack);
596
        }
597
        else if (blockpos.getY() < this.serverController.getBuildLimit() - 1 || enumfacing != EnumFacing.UP && blockpos.getY() < this.serverController.getBuildLimit())
598
        {
599
            if (this.hasMoved && this.playerEntity.getDistanceSq((double)blockpos.getX() + 0.5D, (double)blockpos.getY() + 0.5D, (double)blockpos.getZ() + 0.5D) < 64.0D && !this.serverController.isBlockProtected(worldserver, blockpos, this.playerEntity) && worldserver.getWorldBorder().contains(blockpos))
600
            {
601
                this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, worldserver, itemstack, blockpos, enumfacing, packetIn.getPlacedBlockOffsetX(), packetIn.getPlacedBlockOffsetY(), packetIn.getPlacedBlockOffsetZ());
602
            }
603
604
            flag = true;
605
        }
606
        else
607
        {
608
            ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("build.tooHigh", new Object[] {Integer.valueOf(this.serverController.getBuildLimit())});
609
            chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
610
            this.playerEntity.playerNetServerHandler.sendPacket(new S02PacketChat(chatcomponenttranslation));
611
            flag = true;
612
        }
613
614
        if (flag)
615
        {
616
            this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos));
617
            this.playerEntity.playerNetServerHandler.sendPacket(new S23PacketBlockChange(worldserver, blockpos.offset(enumfacing)));
618
        }
619
620
        itemstack = this.playerEntity.inventory.getCurrentItem();
621
622
        if (itemstack != null && itemstack.stackSize == 0)
623
        {
624
            this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null;
625
            itemstack = null;
626
        }
627
628
        if (itemstack == null || itemstack.getMaxItemUseDuration() == 0)
629
        {
630
            this.playerEntity.isChangingQuantityOnly = true;
631
            this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]);
632
            Slot slot = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem);
633
            this.playerEntity.openContainer.detectAndSendChanges();
634
            this.playerEntity.isChangingQuantityOnly = false;
635
636
            if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), packetIn.getStack()))
637
            {
638
                this.sendPacket(new S2FPacketSetSlot(this.playerEntity.openContainer.windowId, slot.slotNumber, this.playerEntity.inventory.getCurrentItem()));
639
            }
640
        }
641
    }
642
643
    public void handleSpectate(C18PacketSpectate packetIn)
644
    {
645
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
646
647
        if (this.playerEntity.isSpectator())
648
        {
649
            Entity entity = null;
650
651
            for (WorldServer worldserver : this.serverController.worldServers)
652
            {
653
                if (worldserver != null)
654
                {
655
                    entity = packetIn.getEntity(worldserver);
656
657
                    if (entity != null)
658
                    {
659
                        break;
660
                    }
661
                }
662
            }
663
664
            if (entity != null)
665
            {
666
                this.playerEntity.setSpectatingEntity(this.playerEntity);
667
                this.playerEntity.mountEntity((Entity)null);
668
669
                if (entity.worldObj != this.playerEntity.worldObj)
670
                {
671
                    WorldServer worldserver1 = this.playerEntity.getServerForPlayer();
672
                    WorldServer worldserver2 = (WorldServer)entity.worldObj;
673
                    this.playerEntity.dimension = entity.dimension;
674
                    this.sendPacket(new S07PacketRespawn(this.playerEntity.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), this.playerEntity.theItemInWorldManager.getGameType()));
675
                    worldserver1.removePlayerEntityDangerously(this.playerEntity);
676
                    this.playerEntity.isDead = false;
677
                    this.playerEntity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
678
679
                    if (this.playerEntity.isEntityAlive())
680
                    {
681
                        worldserver1.updateEntityWithOptionalForce(this.playerEntity, false);
682
                        worldserver2.spawnEntityInWorld(this.playerEntity);
683
                        worldserver2.updateEntityWithOptionalForce(this.playerEntity, false);
684
                    }
685
686
                    this.playerEntity.setWorld(worldserver2);
687
                    this.serverController.getConfigurationManager().preparePlayer(this.playerEntity, worldserver1);
688
                    this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
689
                    this.playerEntity.theItemInWorldManager.setWorld(worldserver2);
690
                    this.serverController.getConfigurationManager().updateTimeAndWeatherForPlayer(this.playerEntity, worldserver2);
691
                    this.serverController.getConfigurationManager().syncPlayerInventory(this.playerEntity);
692
                }
693
                else
694
                {
695
                    this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
696
                }
697
            }
698
        }
699
    }
700
701
    public void handleResourcePackStatus(C19PacketResourcePackStatus packetIn)
702
    {
703
    }
704
705
    /**
706
     * Invoked when disconnecting, the parameter is a ChatComponent describing the reason for termination
707
     */
708
    public void onDisconnect(IChatComponent reason)
709
    {
710
        logger.info(this.playerEntity.getName() + " lost connection: " + reason);
711
        this.serverController.refreshStatusNextTick();
712
        ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("multiplayer.player.left", new Object[] {this.playerEntity.getDisplayName()});
713
        chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.YELLOW);
714
        this.serverController.getConfigurationManager().sendChatMsg(chatcomponenttranslation);
715
        this.playerEntity.mountEntityAndWakeUp();
716
        this.serverController.getConfigurationManager().playerLoggedOut(this.playerEntity);
717
718
        if (this.serverController.isSinglePlayer() && this.playerEntity.getName().equals(this.serverController.getServerOwner()))
719
        {
720
            logger.info("Stopping singleplayer server as player logged out");
721
            this.serverController.initiateShutdown();
722
        }
723
    }
724
725
    public void sendPacket(final Packet packetIn)
726
    {
727
        if (packetIn instanceof S02PacketChat)
728
        {
729
            S02PacketChat s02packetchat = (S02PacketChat)packetIn;
730
            EntityPlayer.EnumChatVisibility entityplayer$enumchatvisibility = this.playerEntity.getChatVisibility();
731
732
            if (entityplayer$enumchatvisibility == EntityPlayer.EnumChatVisibility.HIDDEN)
733
            {
734
                return;
735
            }
736
737
            if (entityplayer$enumchatvisibility == EntityPlayer.EnumChatVisibility.SYSTEM && !s02packetchat.isChat())
738
            {
739
                return;
740
            }
741
        }
742
743
        try
744
        {
745
            this.netManager.sendPacket(packetIn);
746
        }
747
        catch (Throwable throwable)
748
        {
749
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Sending packet");
750
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Packet being sent");
751
            crashreportcategory.addCrashSectionCallable("Packet class", new Callable<String>()
752
            {
753
                public String call() throws Exception
754
                {
755
                    return packetIn.getClass().getCanonicalName();
756
                }
757
            });
758
            throw new ReportedException(crashreport);
759
        }
760
    }
761
762
    /**
763
     * Updates which quickbar slot is selected
764
     */
765
    public void processHeldItemChange(C09PacketHeldItemChange packetIn)
766
    {
767
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
768
769
        if (packetIn.getSlotId() >= 0 && packetIn.getSlotId() < InventoryPlayer.getHotbarSize())
770
        {
771
            this.playerEntity.inventory.currentItem = packetIn.getSlotId();
772
            this.playerEntity.markPlayerActive();
773
        }
774
        else
775
        {
776
            logger.warn(this.playerEntity.getName() + " tried to set an invalid carried item");
777
        }
778
    }
779
780
    /**
781
     * Process chat messages (broadcast back to clients) and commands (executes)
782
     */
783
    public void processChatMessage(C01PacketChatMessage packetIn)
784
    {
785
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
786
787
        if (this.playerEntity.getChatVisibility() == EntityPlayer.EnumChatVisibility.HIDDEN)
788
        {
789
            ChatComponentTranslation chatcomponenttranslation = new ChatComponentTranslation("chat.cannotSend", new Object[0]);
790
            chatcomponenttranslation.getChatStyle().setColor(EnumChatFormatting.RED);
791
            this.sendPacket(new S02PacketChat(chatcomponenttranslation));
792
        }
793
        else
794
        {
795
            this.playerEntity.markPlayerActive();
796
            String s = packetIn.getMessage();
797
            s = StringUtils.normalizeSpace(s);
798
799
            for (int i = 0; i < s.length(); ++i)
800
            {
801
                if (!ChatAllowedCharacters.isAllowedCharacter(s.charAt(i)))
802
                {
803
                    this.kickPlayerFromServer("Illegal characters in chat");
804
                    return;
805
                }
806
            }
807
808
            if (s.startsWith("/"))
809
            {
810
                this.handleSlashCommand(s);
811
            }
812
            else
813
            {
814
                IChatComponent ichatcomponent = new ChatComponentTranslation("chat.type.text", new Object[] {this.playerEntity.getDisplayName(), s});
815
                this.serverController.getConfigurationManager().sendChatMsgImpl(ichatcomponent, false);
816
            }
817
818
            this.chatSpamThresholdCount += 20;
819
820
            if (this.chatSpamThresholdCount > 200 && !this.serverController.getConfigurationManager().canSendCommands(this.playerEntity.getGameProfile()))
821
            {
822
                this.kickPlayerFromServer("disconnect.spam");
823
            }
824
        }
825
    }
826
827
    /**
828
     * Handle commands that start with a /
829
     */
830
    private void handleSlashCommand(String command)
831
    {
832
        this.serverController.getCommandManager().executeCommand(this.playerEntity, command);
833
    }
834
835
    public void handleAnimation(C0APacketAnimation packetIn)
836
    {
837
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
838
        this.playerEntity.markPlayerActive();
839
        this.playerEntity.swingItem();
840
    }
841
842
    /**
843
     * Processes a range of action-types: sneaking, sprinting, waking from sleep, opening the inventory or setting jump
844
     * height of the horse the player is riding
845
     */
846
    public void processEntityAction(C0BPacketEntityAction packetIn)
847
    {
848
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
849
        this.playerEntity.markPlayerActive();
850
851
        switch (packetIn.getAction())
852
        {
853
            case START_SNEAKING:
854
                this.playerEntity.setSneaking(true);
855
                break;
856
857
            case STOP_SNEAKING:
858
                this.playerEntity.setSneaking(false);
859
                break;
860
861
            case START_SPRINTING:
862
                this.playerEntity.setSprinting(true);
863
                break;
864
865
            case STOP_SPRINTING:
866
                this.playerEntity.setSprinting(false);
867
                break;
868
869
            case STOP_SLEEPING:
870
                this.playerEntity.wakeUpPlayer(false, true, true);
871
                this.hasMoved = false;
872
                break;
873
874
            case RIDING_JUMP:
875
                if (this.playerEntity.ridingEntity instanceof EntityHorse)
876
                {
877
                    ((EntityHorse)this.playerEntity.ridingEntity).setJumpPower(packetIn.getAuxData());
878
                }
879
880
                break;
881
882
            case OPEN_INVENTORY:
883
                if (this.playerEntity.ridingEntity instanceof EntityHorse)
884
                {
885
                    ((EntityHorse)this.playerEntity.ridingEntity).openGUI(this.playerEntity);
886
                }
887
888
                break;
889
890
            default:
891
                throw new IllegalArgumentException("Invalid client command!");
892
        }
893
    }
894
895
    /**
896
     * Processes interactions ((un)leashing, opening command block GUI) and attacks on an entity with players currently
897
     * equipped item
898
     */
899
    public void processUseEntity(C02PacketUseEntity packetIn)
900
    {
901
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
902
        WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
903
        Entity entity = packetIn.getEntityFromWorld(worldserver);
904
        this.playerEntity.markPlayerActive();
905
906
        if (entity != null)
907
        {
908
            boolean flag = this.playerEntity.canEntityBeSeen(entity);
909
            double d0 = 36.0D;
910
911
            if (!flag)
912
            {
913
                d0 = 9.0D;
914
            }
915
916
            if (this.playerEntity.getDistanceSqToEntity(entity) < d0)
917
            {
918
                if (packetIn.getAction() == C02PacketUseEntity.Action.INTERACT)
919
                {
920
                    this.playerEntity.interactWith(entity);
921
                }
922
                else if (packetIn.getAction() == C02PacketUseEntity.Action.INTERACT_AT)
923
                {
924
                    entity.interactAt(this.playerEntity, packetIn.getHitVec());
925
                }
926
                else if (packetIn.getAction() == C02PacketUseEntity.Action.ATTACK)
927
                {
928
                    if (entity instanceof EntityItem || entity instanceof EntityXPOrb || entity instanceof EntityArrow || entity == this.playerEntity)
929
                    {
930
                        this.kickPlayerFromServer("Attempting to attack an invalid entity");
931
                        this.serverController.logWarning("Player " + this.playerEntity.getName() + " tried to attack an invalid entity");
932
                        return;
933
                    }
934
935
                    this.playerEntity.attackTargetEntityWithCurrentItem(entity);
936
                }
937
            }
938
        }
939
    }
940
941
    /**
942
     * Processes the client status updates: respawn attempt from player, opening statistics or achievements, or
943
     * acquiring 'open inventory' achievement
944
     */
945
    public void processClientStatus(C16PacketClientStatus packetIn)
946
    {
947
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
948
        this.playerEntity.markPlayerActive();
949
        C16PacketClientStatus.EnumState c16packetclientstatus$enumstate = packetIn.getStatus();
950
951
        switch (c16packetclientstatus$enumstate)
952
        {
953
            case PERFORM_RESPAWN:
954
                if (this.playerEntity.playerConqueredTheEnd)
955
                {
956
                    this.playerEntity = this.serverController.getConfigurationManager().recreatePlayerEntity(this.playerEntity, 0, true);
957
                }
958
                else if (this.playerEntity.getServerForPlayer().getWorldInfo().isHardcoreModeEnabled())
959
                {
960
                    if (this.serverController.isSinglePlayer() && this.playerEntity.getName().equals(this.serverController.getServerOwner()))
961
                    {
962
                        this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!");
963
                        this.serverController.deleteWorldAndStopServer();
964
                    }
965
                    else
966
                    {
967
                        UserListBansEntry userlistbansentry = new UserListBansEntry(this.playerEntity.getGameProfile(), (Date)null, "(You just lost the game)", (Date)null, "Death in Hardcore");
968
                        this.serverController.getConfigurationManager().getBannedPlayers().addEntry(userlistbansentry);
969
                        this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!");
970
                    }
971
                }
972
                else
973
                {
974
                    if (this.playerEntity.getHealth() > 0.0F)
975
                    {
976
                        return;
977
                    }
978
979
                    this.playerEntity = this.serverController.getConfigurationManager().recreatePlayerEntity(this.playerEntity, 0, false);
980
                }
981
982
                break;
983
984
            case REQUEST_STATS:
985
                this.playerEntity.getStatFile().func_150876_a(this.playerEntity);
986
                break;
987
988
            case OPEN_INVENTORY_ACHIEVEMENT:
989
                this.playerEntity.triggerAchievement(AchievementList.openInventory);
990
        }
991
    }
992
993
    /**
994
     * Processes the client closing windows (container)
995
     */
996
    public void processCloseWindow(C0DPacketCloseWindow packetIn)
997
    {
998
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
999
        this.playerEntity.closeContainer();
1000
    }
1001
1002
    /**
1003
     * Executes a container/inventory slot manipulation as indicated by the packet. Sends the serverside result if they
1004
     * didn't match the indicated result and prevents further manipulation by the player until he confirms that it has
1005
     * the same open container/inventory
1006
     */
1007
    public void processClickWindow(C0EPacketClickWindow packetIn)
1008
    {
1009
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1010
        this.playerEntity.markPlayerActive();
1011
1012
        if (this.playerEntity.openContainer.windowId == packetIn.getWindowId() && this.playerEntity.openContainer.getCanCraft(this.playerEntity))
1013
        {
1014
            if (this.playerEntity.isSpectator())
1015
            {
1016
                List<ItemStack> list = Lists.<ItemStack>newArrayList();
1017
1018
                for (int i = 0; i < this.playerEntity.openContainer.inventorySlots.size(); ++i)
1019
                {
1020
                    list.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(i)).getStack());
1021
                }
1022
1023
                this.playerEntity.updateCraftingInventory(this.playerEntity.openContainer, list);
1024
            }
1025
            else
1026
            {
1027
                ItemStack itemstack = this.playerEntity.openContainer.slotClick(packetIn.getSlotId(), packetIn.getUsedButton(), packetIn.getMode(), this.playerEntity);
1028
1029
                if (ItemStack.areItemStacksEqual(packetIn.getClickedItem(), itemstack))
1030
                {
1031
                    this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), true));
1032
                    this.playerEntity.isChangingQuantityOnly = true;
1033
                    this.playerEntity.openContainer.detectAndSendChanges();
1034
                    this.playerEntity.updateHeldItem();
1035
                    this.playerEntity.isChangingQuantityOnly = false;
1036
                }
1037
                else
1038
                {
1039
                    this.field_147372_n.addKey(this.playerEntity.openContainer.windowId, Short.valueOf(packetIn.getActionNumber()));
1040
                    this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), false));
1041
                    this.playerEntity.openContainer.setCanCraft(this.playerEntity, false);
1042
                    List<ItemStack> list1 = Lists.<ItemStack>newArrayList();
1043
1044
                    for (int j = 0; j < this.playerEntity.openContainer.inventorySlots.size(); ++j)
1045
                    {
1046
                        list1.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(j)).getStack());
1047
                    }
1048
1049
                    this.playerEntity.updateCraftingInventory(this.playerEntity.openContainer, list1);
1050
                }
1051
            }
1052
        }
1053
    }
1054
1055
    /**
1056
     * Enchants the item identified by the packet given some convoluted conditions (matching window, which
1057
     * should/shouldn't be in use?)
1058
     */
1059
    public void processEnchantItem(C11PacketEnchantItem packetIn)
1060
    {
1061
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1062
        this.playerEntity.markPlayerActive();
1063
1064
        if (this.playerEntity.openContainer.windowId == packetIn.getWindowId() && this.playerEntity.openContainer.getCanCraft(this.playerEntity) && !this.playerEntity.isSpectator())
1065
        {
1066
            this.playerEntity.openContainer.enchantItem(this.playerEntity, packetIn.getButton());
1067
            this.playerEntity.openContainer.detectAndSendChanges();
1068
        }
1069
    }
1070
1071
    /**
1072
     * Update the server with an ItemStack in a slot.
1073
     */
1074
    public void processCreativeInventoryAction(C10PacketCreativeInventoryAction packetIn)
1075
    {
1076
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1077
1078
        if (this.playerEntity.theItemInWorldManager.isCreative())
1079
        {
1080
            boolean flag = packetIn.getSlotId() < 0;
1081
            ItemStack itemstack = packetIn.getStack();
1082
1083
            if (itemstack != null && itemstack.hasTagCompound() && itemstack.getTagCompound().hasKey("BlockEntityTag", 10))
1084
            {
1085
                NBTTagCompound nbttagcompound = itemstack.getTagCompound().getCompoundTag("BlockEntityTag");
1086
1087
                if (nbttagcompound.hasKey("x") && nbttagcompound.hasKey("y") && nbttagcompound.hasKey("z"))
1088
                {
1089
                    BlockPos blockpos = new BlockPos(nbttagcompound.getInteger("x"), nbttagcompound.getInteger("y"), nbttagcompound.getInteger("z"));
1090
                    TileEntity tileentity = this.playerEntity.worldObj.getTileEntity(blockpos);
1091
1092
                    if (tileentity != null)
1093
                    {
1094
                        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
1095
                        tileentity.writeToNBT(nbttagcompound1);
1096
                        nbttagcompound1.removeTag("x");
1097
                        nbttagcompound1.removeTag("y");
1098
                        nbttagcompound1.removeTag("z");
1099
                        itemstack.setTagInfo("BlockEntityTag", nbttagcompound1);
1100
                    }
1101
                }
1102
            }
1103
1104
            boolean flag1 = packetIn.getSlotId() >= 1 && packetIn.getSlotId() < 36 + InventoryPlayer.getHotbarSize();
1105
            boolean flag2 = itemstack == null || itemstack.getItem() != null;
1106
            boolean flag3 = itemstack == null || itemstack.getMetadata() >= 0 && itemstack.stackSize <= 64 && itemstack.stackSize > 0;
1107
1108
            if (flag1 && flag2 && flag3)
1109
            {
1110
                if (itemstack == null)
1111
                {
1112
                    this.playerEntity.inventoryContainer.putStackInSlot(packetIn.getSlotId(), (ItemStack)null);
1113
                }
1114
                else
1115
                {
1116
                    this.playerEntity.inventoryContainer.putStackInSlot(packetIn.getSlotId(), itemstack);
1117
                }
1118
1119
                this.playerEntity.inventoryContainer.setCanCraft(this.playerEntity, true);
1120
            }
1121
            else if (flag && flag2 && flag3 && this.itemDropThreshold < 200)
1122
            {
1123
                this.itemDropThreshold += 20;
1124
                EntityItem entityitem = this.playerEntity.dropPlayerItemWithRandomChoice(itemstack, true);
1125
1126
                if (entityitem != null)
1127
                {
1128
                    entityitem.setAgeToCreativeDespawnTime();
1129
                }
1130
            }
1131
        }
1132
    }
1133
1134
    /**
1135
     * Received in response to the server requesting to confirm that the client-side open container matches the servers'
1136
     * after a mismatched container-slot manipulation. It will unlock the player's ability to manipulate the container
1137
     * contents
1138
     */
1139
    public void processConfirmTransaction(C0FPacketConfirmTransaction packetIn)
1140
    {
1141
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1142
        Short oshort = (Short)this.field_147372_n.lookup(this.playerEntity.openContainer.windowId);
1143
1144
        if (oshort != null && packetIn.getUid() == oshort.shortValue() && this.playerEntity.openContainer.windowId == packetIn.getWindowId() && !this.playerEntity.openContainer.getCanCraft(this.playerEntity) && !this.playerEntity.isSpectator())
1145
        {
1146
            this.playerEntity.openContainer.setCanCraft(this.playerEntity, true);
1147
        }
1148
    }
1149
1150
    public void processUpdateSign(C12PacketUpdateSign packetIn)
1151
    {
1152
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1153
        this.playerEntity.markPlayerActive();
1154
        WorldServer worldserver = this.serverController.worldServerForDimension(this.playerEntity.dimension);
1155
        BlockPos blockpos = packetIn.getPosition();
1156
1157
        if (worldserver.isBlockLoaded(blockpos))
1158
        {
1159
            TileEntity tileentity = worldserver.getTileEntity(blockpos);
1160
1161
            if (!(tileentity instanceof TileEntitySign))
1162
            {
1163
                return;
1164
            }
1165
1166
            TileEntitySign tileentitysign = (TileEntitySign)tileentity;
1167
1168
            if (!tileentitysign.getIsEditable() || tileentitysign.getPlayer() != this.playerEntity)
1169
            {
1170
                this.serverController.logWarning("Player " + this.playerEntity.getName() + " just tried to change non-editable sign");
1171
                return;
1172
            }
1173
1174
            IChatComponent[] aichatcomponent = packetIn.getLines();
1175
1176
            for (int i = 0; i < aichatcomponent.length; ++i)
1177
            {
1178
                tileentitysign.signText[i] = new ChatComponentText(EnumChatFormatting.getTextWithoutFormattingCodes(aichatcomponent[i].getUnformattedText()));
1179
            }
1180
1181
            tileentitysign.markDirty();
1182
            worldserver.markBlockForUpdate(blockpos);
1183
        }
1184
    }
1185
1186
    /**
1187
     * Updates a players' ping statistics
1188
     */
1189
    public void processKeepAlive(C00PacketKeepAlive packetIn)
1190
    {
1191
        if (packetIn.getKey() == this.field_147378_h)
1192
        {
1193
            int i = (int)(this.currentTimeMillis() - this.lastPingTime);
1194
            this.playerEntity.ping = (this.playerEntity.ping * 3 + i) / 4;
1195
        }
1196
    }
1197
1198
    private long currentTimeMillis()
1199
    {
1200
        return System.nanoTime() / 1000000L;
1201
    }
1202
1203
    /**
1204
     * Processes a player starting/stopping flying
1205
     */
1206
    public void processPlayerAbilities(C13PacketPlayerAbilities packetIn)
1207
    {
1208
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1209
        this.playerEntity.capabilities.isFlying = packetIn.isFlying() && this.playerEntity.capabilities.allowFlying;
1210
    }
1211
1212
    /**
1213
     * Retrieves possible tab completions for the requested command string and sends them to the client
1214
     */
1215
    public void processTabComplete(C14PacketTabComplete packetIn)
1216
    {
1217
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1218
        List<String> list = Lists.<String>newArrayList();
1219
1220
        for (String s : this.serverController.getTabCompletions(this.playerEntity, packetIn.getMessage(), packetIn.getTargetBlock()))
1221
        {
1222
            list.add(s);
1223
        }
1224
1225
        this.playerEntity.playerNetServerHandler.sendPacket(new S3APacketTabComplete((String[])list.toArray(new String[list.size()])));
1226
    }
1227
1228
    /**
1229
     * Updates serverside copy of client settings: language, render distance, chat visibility, chat colours, difficulty,
1230
     * and whether to show the cape
1231
     */
1232
    public void processClientSettings(C15PacketClientSettings packetIn)
1233
    {
1234
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1235
        this.playerEntity.handleClientSettings(packetIn);
1236
    }
1237
1238
    /**
1239
     * Synchronizes serverside and clientside book contents and signing
1240
     */
1241
    public void processVanilla250Packet(C17PacketCustomPayload packetIn)
1242
    {
1243
        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerForPlayer());
1244
1245
        if ("MC|BEdit".equals(packetIn.getChannelName()))
1246
        {
1247
            PacketBuffer packetbuffer3 = new PacketBuffer(Unpooled.wrappedBuffer((ByteBuf)packetIn.getBufferData()));
1248
1249
            try
1250
            {
1251
                ItemStack itemstack1 = packetbuffer3.readItemStackFromBuffer();
1252
1253
                if (itemstack1 != null)
1254
                {
1255
                    if (!ItemWritableBook.isNBTValid(itemstack1.getTagCompound()))
1256
                    {
1257
                        throw new IOException("Invalid book tag!");
1258
                    }
1259
1260
                    ItemStack itemstack3 = this.playerEntity.inventory.getCurrentItem();
1261
1262
                    if (itemstack3 == null)
1263
                    {
1264
                        return;
1265
                    }
1266
1267
                    if (itemstack1.getItem() == Items.writable_book && itemstack1.getItem() == itemstack3.getItem())
1268
                    {
1269
                        itemstack3.setTagInfo("pages", itemstack1.getTagCompound().getTagList("pages", 8));
1270
                    }
1271
1272
                    return;
1273
                }
1274
            }
1275
            catch (Exception exception3)
1276
            {
1277
                logger.error((String)"Couldn\'t handle book info", (Throwable)exception3);
1278
                return;
1279
            }
1280
            finally
1281
            {
1282
                packetbuffer3.release();
1283
            }
1284
1285
            return;
1286
        }
1287
        else if ("MC|BSign".equals(packetIn.getChannelName()))
1288
        {
1289
            PacketBuffer packetbuffer2 = new PacketBuffer(Unpooled.wrappedBuffer((ByteBuf)packetIn.getBufferData()));
1290
1291
            try
1292
            {
1293
                ItemStack itemstack = packetbuffer2.readItemStackFromBuffer();
1294
1295
                if (itemstack != null)
1296
                {
1297
                    if (!ItemEditableBook.validBookTagContents(itemstack.getTagCompound()))
1298
                    {
1299
                        throw new IOException("Invalid book tag!");
1300
                    }
1301
1302
                    ItemStack itemstack2 = this.playerEntity.inventory.getCurrentItem();
1303
1304
                    if (itemstack2 == null)
1305
                    {
1306
                        return;
1307
                    }
1308
1309
                    if (itemstack.getItem() == Items.written_book && itemstack2.getItem() == Items.writable_book)
1310
                    {
1311
                        itemstack2.setTagInfo("author", new NBTTagString(this.playerEntity.getName()));
1312
                        itemstack2.setTagInfo("title", new NBTTagString(itemstack.getTagCompound().getString("title")));
1313
                        itemstack2.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8));
1314
                        itemstack2.setItem(Items.written_book);
1315
                    }
1316
1317
                    return;
1318
                }
1319
            }
1320
            catch (Exception exception4)
1321
            {
1322
                logger.error((String)"Couldn\'t sign book", (Throwable)exception4);
1323
                return;
1324
            }
1325
            finally
1326
            {
1327
                packetbuffer2.release();
1328
            }
1329
1330
            return;
1331
        }
1332
        else if ("MC|TrSel".equals(packetIn.getChannelName()))
1333
        {
1334
            try
1335
            {
1336
                int i = packetIn.getBufferData().readInt();
1337
                Container container = this.playerEntity.openContainer;
1338
1339
                if (container instanceof ContainerMerchant)
1340
                {
1341
                    ((ContainerMerchant)container).setCurrentRecipeIndex(i);
1342
                }
1343
            }
1344
            catch (Exception exception2)
1345
            {
1346
                logger.error((String)"Couldn\'t select trade", (Throwable)exception2);
1347
            }
1348
        }
1349
        else if ("MC|AdvCdm".equals(packetIn.getChannelName()))
1350
        {
1351
            if (!this.serverController.isCommandBlockEnabled())
1352
            {
1353
                this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.notEnabled", new Object[0]));
1354
            }
1355
            else if (this.playerEntity.canCommandSenderUseCommand(2, "") && this.playerEntity.capabilities.isCreativeMode)
1356
            {
1357
                PacketBuffer packetbuffer = packetIn.getBufferData();
1358
1359
                try
1360
                {
1361
                    int j = packetbuffer.readByte();
1362
                    CommandBlockLogic commandblocklogic = null;
1363
1364
                    if (j == 0)
1365
                    {
1366
                        TileEntity tileentity = this.playerEntity.worldObj.getTileEntity(new BlockPos(packetbuffer.readInt(), packetbuffer.readInt(), packetbuffer.readInt()));
1367
1368
                        if (tileentity instanceof TileEntityCommandBlock)
1369
                        {
1370
                            commandblocklogic = ((TileEntityCommandBlock)tileentity).getCommandBlockLogic();
1371
                        }
1372
                    }
1373
                    else if (j == 1)
1374
                    {
1375
                        Entity entity = this.playerEntity.worldObj.getEntityByID(packetbuffer.readInt());
1376
1377
                        if (entity instanceof EntityMinecartCommandBlock)
1378
                        {
1379
                            commandblocklogic = ((EntityMinecartCommandBlock)entity).getCommandBlockLogic();
1380
                        }
1381
                    }
1382
1383
                    String s1 = packetbuffer.readStringFromBuffer(packetbuffer.readableBytes());
1384
                    boolean flag = packetbuffer.readBoolean();
1385
1386
                    if (commandblocklogic != null)
1387
                    {
1388
                        commandblocklogic.setCommand(s1);
1389
                        commandblocklogic.setTrackOutput(flag);
1390
1391
                        if (!flag)
1392
                        {
1393
                            commandblocklogic.setLastOutput((IChatComponent)null);
1394
                        }
1395
1396
                        commandblocklogic.updateCommand();
1397
                        this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.setCommand.success", new Object[] {s1}));
1398
                    }
1399
                }
1400
                catch (Exception exception1)
1401
                {
1402
                    logger.error((String)"Couldn\'t set command block", (Throwable)exception1);
1403
                }
1404
                finally
1405
                {
1406
                    packetbuffer.release();
1407
                }
1408
            }
1409
            else
1410
            {
1411
                this.playerEntity.addChatMessage(new ChatComponentTranslation("advMode.notAllowed", new Object[0]));
1412
            }
1413
        }
1414
        else if ("MC|Beacon".equals(packetIn.getChannelName()))
1415
        {
1416
            if (this.playerEntity.openContainer instanceof ContainerBeacon)
1417
            {
1418
                try
1419
                {
1420
                    PacketBuffer packetbuffer1 = packetIn.getBufferData();
1421
                    int k = packetbuffer1.readInt();
1422
                    int l = packetbuffer1.readInt();
1423
                    ContainerBeacon containerbeacon = (ContainerBeacon)this.playerEntity.openContainer;
1424
                    Slot slot = containerbeacon.getSlot(0);
1425
1426
                    if (slot.getHasStack())
1427
                    {
1428
                        slot.decrStackSize(1);
1429
                        IInventory iinventory = containerbeacon.func_180611_e();
1430
                        iinventory.setField(1, k);
1431
                        iinventory.setField(2, l);
1432
                        iinventory.markDirty();
1433
                    }
1434
                }
1435
                catch (Exception exception)
1436
                {
1437
                    logger.error((String)"Couldn\'t set beacon", (Throwable)exception);
1438
                }
1439
            }
1440
        }
1441
        else if ("MC|ItemName".equals(packetIn.getChannelName()) && this.playerEntity.openContainer instanceof ContainerRepair)
1442
        {
1443
            ContainerRepair containerrepair = (ContainerRepair)this.playerEntity.openContainer;
1444
1445
            if (packetIn.getBufferData() != null && packetIn.getBufferData().readableBytes() >= 1)
1446
            {
1447
                String s = ChatAllowedCharacters.filterAllowedCharacters(packetIn.getBufferData().readStringFromBuffer(32767));
1448
1449
                if (s.length() <= 30)
1450
                {
1451
                    containerrepair.updateItemName(s);
1452
                }
1453
            }
1454
            else
1455
            {
1456
                containerrepair.updateItemName("");
1457
            }
1458
        }
1459
    }
1460
}
1461

Deobfuscated MCP 1.8.9 source of NetHandlerPlayServer from Marcelektro/MavenMCP-1.8.9 (net/minecraft/network/NetHandlerPlayServer.java), stored verbatim.