    001    package net.minecraft.network;
    002
    003    import java.io.ByteArrayInputStream;
    004    import java.io.DataInputStream;
    005    import java.io.IOException;
    006    import java.util.ArrayList;
    007    import java.util.Iterator;
    008    import java.util.Random;
    009    import java.util.logging.Logger;
    010
    011    import cpw.mods.fml.common.network.FMLNetworkHandler;
    012    import net.minecraft.entity.Entity;
    013    import net.minecraft.entity.item.EntityItem;
    014    import net.minecraft.entity.player.EntityPlayerMP;
    015    import net.minecraft.entity.player.InventoryPlayer;
    016    import net.minecraft.inventory.Container;
    017    import net.minecraft.inventory.ContainerBeacon;
    018    import net.minecraft.inventory.ContainerMerchant;
    019    import net.minecraft.inventory.ContainerRepair;
    020    import net.minecraft.inventory.Slot;
    021    import net.minecraft.item.Item;
    022    import net.minecraft.item.ItemEditableBook;
    023    import net.minecraft.item.ItemStack;
    024    import net.minecraft.item.ItemWritableBook;
    025    import net.minecraft.nbt.NBTTagString;
    026    import net.minecraft.network.packet.NetHandler;
    027    import net.minecraft.network.packet.Packet;
    028    import net.minecraft.network.packet.Packet0KeepAlive;
    029    import net.minecraft.network.packet.Packet101CloseWindow;
    030    import net.minecraft.network.packet.Packet102WindowClick;
    031    import net.minecraft.network.packet.Packet103SetSlot;
    032    import net.minecraft.network.packet.Packet106Transaction;
    033    import net.minecraft.network.packet.Packet107CreativeSetSlot;
    034    import net.minecraft.network.packet.Packet108EnchantItem;
    035    import net.minecraft.network.packet.Packet10Flying;
    036    import net.minecraft.network.packet.Packet130UpdateSign;
    037    import net.minecraft.network.packet.Packet131MapData;
    038    import net.minecraft.network.packet.Packet13PlayerLookMove;
    039    import net.minecraft.network.packet.Packet14BlockDig;
    040    import net.minecraft.network.packet.Packet15Place;
    041    import net.minecraft.network.packet.Packet16BlockItemSwitch;
    042    import net.minecraft.network.packet.Packet18Animation;
    043    import net.minecraft.network.packet.Packet19EntityAction;
    044    import net.minecraft.network.packet.Packet202PlayerAbilities;
    045    import net.minecraft.network.packet.Packet203AutoComplete;
    046    import net.minecraft.network.packet.Packet204ClientInfo;
    047    import net.minecraft.network.packet.Packet205ClientCommand;
    048    import net.minecraft.network.packet.Packet250CustomPayload;
    049    import net.minecraft.network.packet.Packet255KickDisconnect;
    050    import net.minecraft.network.packet.Packet3Chat;
    051    import net.minecraft.network.packet.Packet53BlockChange;
    052    import net.minecraft.network.packet.Packet7UseEntity;
    053    import net.minecraft.network.packet.Packet9Respawn;
    054    import net.minecraft.server.MinecraftServer;
    055    import net.minecraft.server.management.BanEntry;
    056    import net.minecraft.tileentity.TileEntity;
    057    import net.minecraft.tileentity.TileEntityBeacon;
    058    import net.minecraft.tileentity.TileEntityCommandBlock;
    059    import net.minecraft.tileentity.TileEntitySign;
    060    import net.minecraft.util.AxisAlignedBB;
    061    import net.minecraft.util.ChatAllowedCharacters;
    062    import net.minecraft.util.ChunkCoordinates;
    063    import net.minecraft.util.IntHashMap;
    064    import net.minecraft.util.MathHelper;
    065    import net.minecraft.world.WorldServer;
    066
    067    import net.minecraftforge.common.MinecraftForge;
    068    import net.minecraftforge.event.Event;
    069    import net.minecraftforge.event.ForgeEventFactory;
    070    import net.minecraftforge.event.ServerChatEvent;
    071    import net.minecraftforge.event.entity.player.PlayerInteractEvent;
    072    import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
    073
    074    public class NetServerHandler extends NetHandler
    075    {
    076        /** The logging system. */
    077        public static Logger logger = Logger.getLogger("Minecraft");
    078
    079        /** The underlying network manager for this server handler. */
    080        public INetworkManager netManager;
    081
    082        /** This is set to true whenever a player disconnects from the server. */
    083        public boolean connectionClosed = false;
    084
    085        /** Reference to the MinecraftServer object. */
    086        private MinecraftServer mcServer;
    087
    088        /** Reference to the EntityPlayerMP object. */
    089        public EntityPlayerMP playerEntity;
    090
    091        /** incremented each tick */
    092        private int currentTicks;
    093
    094        /**
    095         * player is kicked if they float for over 80 ticks without flying enabled
    096         */
    097        public int ticksForFloatKick;
    098        private boolean field_72584_h;
    099        private int keepAliveRandomID;
    100        private long keepAliveTimeSent;
    101        private static Random randomGenerator = new Random();
    102        private long ticksOfLastKeepAlive;
    103        private int chatSpamThresholdCount = 0;
    104        private int creativeItemCreationSpamThresholdTally = 0;
    105
    106        /** The last known x position for this connection. */
    107        private double lastPosX;
    108
    109        /** The last known y position for this connection. */
    110        private double lastPosY;
    111
    112        /** The last known z position for this connection. */
    113        private double lastPosZ;
    114
    115        /** is true when the player has moved since his last movement packet */
    116        private boolean hasMoved = true;
    117        private IntHashMap field_72586_s = new IntHashMap();
    118
    119        public NetServerHandler(MinecraftServer par1, INetworkManager par2, EntityPlayerMP par3)
    120        {
    121            this.mcServer = par1;
    122            this.netManager = par2;
    123            par2.setNetHandler(this);
    124            this.playerEntity = par3;
    125            par3.playerNetServerHandler = this;
    126        }
    127
    128        /**
    129         * run once each game tick
    130         */
    131        public void networkTick()
    132        {
    133            this.field_72584_h = false;
    134            ++this.currentTicks;
    135            this.mcServer.theProfiler.startSection("packetflow");
    136            this.netManager.processReadPackets();
    137            this.mcServer.theProfiler.endStartSection("keepAlive");
    138
    139            if ((long)this.currentTicks - this.ticksOfLastKeepAlive > 20L)
    140            {
    141                this.ticksOfLastKeepAlive = (long)this.currentTicks;
    142                this.keepAliveTimeSent = System.nanoTime() / 1000000L;
    143                this.keepAliveRandomID = randomGenerator.nextInt();
    144                this.sendPacketToPlayer(new Packet0KeepAlive(this.keepAliveRandomID));
    145            }
    146
    147            if (this.chatSpamThresholdCount > 0)
    148            {
    149                --this.chatSpamThresholdCount;
    150            }
    151
    152            if (this.creativeItemCreationSpamThresholdTally > 0)
    153            {
    154                --this.creativeItemCreationSpamThresholdTally;
    155            }
    156
    157            this.mcServer.theProfiler.endStartSection("playerTick");
    158            this.mcServer.theProfiler.endSection();
    159        }
    160
    161        public void kickPlayerFromServer(String par1Str)
    162        {
    163            if (!this.connectionClosed)
    164            {
    165                this.playerEntity.mountEntityAndWakeUp();
    166                this.sendPacketToPlayer(new Packet255KickDisconnect(par1Str));
    167                this.netManager.serverShutdown();
    168                this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet3Chat("\u00a7e" + this.playerEntity.username + " left the game."));
    169                this.mcServer.getConfigurationManager().playerLoggedOut(this.playerEntity);
    170                this.connectionClosed = true;
    171            }
    172        }
    173
    174        public void handleFlying(Packet10Flying par1Packet10Flying)
    175        {
    176            WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    177            this.field_72584_h = true;
    178
    179            if (!this.playerEntity.playerConqueredTheEnd)
    180            {
    181                double var3;
    182
    183                if (!this.hasMoved)
    184                {
    185                    var3 = par1Packet10Flying.yPosition - this.lastPosY;
    186
    187                    if (par1Packet10Flying.xPosition == this.lastPosX && var3 * var3 < 0.01D && par1Packet10Flying.zPosition == this.lastPosZ)
    188                    {
    189                        this.hasMoved = true;
    190                    }
    191                }
    192
    193                if (this.hasMoved)
    194                {
    195                    double var5;
    196                    double var7;
    197                    double var9;
    198                    double var13;
    199
    200                    if (this.playerEntity.ridingEntity != null)
    201                    {
    202                        float var34 = this.playerEntity.rotationYaw;
    203                        float var4 = this.playerEntity.rotationPitch;
    204                        this.playerEntity.ridingEntity.updateRiderPosition();
    205                        var5 = this.playerEntity.posX;
    206                        var7 = this.playerEntity.posY;
    207                        var9 = this.playerEntity.posZ;
    208                        double var35 = 0.0D;
    209                        var13 = 0.0D;
    210
    211                        if (par1Packet10Flying.rotating)
    212                        {
    213                            var34 = par1Packet10Flying.yaw;
    214                            var4 = par1Packet10Flying.pitch;
    215                        }
    216
    217                        if (par1Packet10Flying.moving && par1Packet10Flying.yPosition == -999.0D && par1Packet10Flying.stance == -999.0D)
    218                        {
    219                            if (Math.abs(par1Packet10Flying.xPosition) > 1.0D || Math.abs(par1Packet10Flying.zPosition) > 1.0D)
    220                            {
    221                                System.err.println(this.playerEntity.username + " was caught trying to crash the server with an invalid position.");
    222                                this.kickPlayerFromServer("Nope!");
    223                                return;
    224                            }
    225
    226                            var35 = par1Packet10Flying.xPosition;
    227                            var13 = par1Packet10Flying.zPosition;
    228                        }
    229
    230                        this.playerEntity.onGround = par1Packet10Flying.onGround;
    231                        this.playerEntity.onUpdateEntity();
    232                        this.playerEntity.moveEntity(var35, 0.0D, var13);
    233                        this.playerEntity.setPositionAndRotation(var5, var7, var9, var34, var4);
    234                        this.playerEntity.motionX = var35;
    235                        this.playerEntity.motionZ = var13;
    236
    237                        if (this.playerEntity.ridingEntity != null)
    238                        {
    239                            var2.uncheckedUpdateEntity(this.playerEntity.ridingEntity, true);
    240                        }
    241
    242                        if (this.playerEntity.ridingEntity != null)
    243                        {
    244                            this.playerEntity.ridingEntity.updateRiderPosition();
    245                        }
    246
    247                        if (!this.hasMoved) //Fixes teleportation kick while riding entities
    248                        {
    249                            return;
    250                        }
    251
    252                        this.mcServer.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity);
    253                        this.lastPosX = this.playerEntity.posX;
    254                        this.lastPosY = this.playerEntity.posY;
    255                        this.lastPosZ = this.playerEntity.posZ;
    256                        var2.updateEntity(this.playerEntity);
    257                        return;
    258                    }
    259
    260                    if (this.playerEntity.isPlayerSleeping())
    261                    {
    262                        this.playerEntity.onUpdateEntity();
    263                        this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch);
    264                        var2.updateEntity(this.playerEntity);
    265                        return;
    266                    }
    267
    268                    var3 = this.playerEntity.posY;
    269                    this.lastPosX = this.playerEntity.posX;
    270                    this.lastPosY = this.playerEntity.posY;
    271                    this.lastPosZ = this.playerEntity.posZ;
    272                    var5 = this.playerEntity.posX;
    273                    var7 = this.playerEntity.posY;
    274                    var9 = this.playerEntity.posZ;
    275                    float var11 = this.playerEntity.rotationYaw;
    276                    float var12 = this.playerEntity.rotationPitch;
    277
    278                    if (par1Packet10Flying.moving && par1Packet10Flying.yPosition == -999.0D && par1Packet10Flying.stance == -999.0D)
    279                    {
    280                        par1Packet10Flying.moving = false;
    281                    }
    282
    283                    if (par1Packet10Flying.moving)
    284                    {
    285                        var5 = par1Packet10Flying.xPosition;
    286                        var7 = par1Packet10Flying.yPosition;
    287                        var9 = par1Packet10Flying.zPosition;
    288                        var13 = par1Packet10Flying.stance - par1Packet10Flying.yPosition;
    289
    290                        if (!this.playerEntity.isPlayerSleeping() && (var13 > 1.65D || var13 < 0.1D))
    291                        {
    292                            this.kickPlayerFromServer("Illegal stance");
    293                            logger.warning(this.playerEntity.username + " had an illegal stance: " + var13);
    294                            return;
    295                        }
    296
    297                        if (Math.abs(par1Packet10Flying.xPosition) > 3.2E7D || Math.abs(par1Packet10Flying.zPosition) > 3.2E7D)
    298                        {
    299                            this.kickPlayerFromServer("Illegal position");
    300                            return;
    301                        }
    302                    }
    303
    304                    if (par1Packet10Flying.rotating)
    305                    {
    306                        var11 = par1Packet10Flying.yaw;
    307                        var12 = par1Packet10Flying.pitch;
    308                    }
    309
    310                    this.playerEntity.onUpdateEntity();
    311                    this.playerEntity.ySize = 0.0F;
    312                    this.playerEntity.setPositionAndRotation(this.lastPosX, this.lastPosY, this.lastPosZ, var11, var12);
    313
    314                    if (!this.hasMoved)
    315                    {
    316                        return;
    317                    }
    318
    319                    var13 = var5 - this.playerEntity.posX;
    320                    double var15 = var7 - this.playerEntity.posY;
    321                    double var17 = var9 - this.playerEntity.posZ;
    322                    double var19 = Math.min(Math.abs(var13), Math.abs(this.playerEntity.motionX));
    323                    double var21 = Math.min(Math.abs(var15), Math.abs(this.playerEntity.motionY));
    324                    double var23 = Math.min(Math.abs(var17), Math.abs(this.playerEntity.motionZ));
    325                    double var25 = var19 * var19 + var21 * var21 + var23 * var23;
    326
    327                    if (var25 > 100.0D && (!this.mcServer.isSinglePlayer() || !this.mcServer.getServerOwner().equals(this.playerEntity.username)))
    328                    {
    329                        logger.warning(this.playerEntity.username + " moved too quickly! " + var13 + "," + var15 + "," + var17 + " (" + var19 + ", " + var21 + ", " + var23 + ")");
    330                        this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch);
    331                        return;
    332                    }
    333
    334                    float var27 = 0.0625F;
    335                    boolean var28 = var2.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)var27, (double)var27, (double)var27)).isEmpty();
    336
    337                    if (this.playerEntity.onGround && !par1Packet10Flying.onGround && var15 > 0.0D)
    338                    {
    339                        this.playerEntity.addExhaustion(0.2F);
    340                    }
    341
    342                    if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
    343                    {
    344                        return;
    345                    }
    346
    347                    this.playerEntity.moveEntity(var13, var15, var17);
    348                    this.playerEntity.onGround = par1Packet10Flying.onGround;
    349                    this.playerEntity.addMovementStat(var13, var15, var17);
    350                    double var29 = var15;
    351                    var13 = var5 - this.playerEntity.posX;
    352                    var15 = var7 - this.playerEntity.posY;
    353
    354                    if (var15 > -0.5D || var15 < 0.5D)
    355                    {
    356                        var15 = 0.0D;
    357                    }
    358
    359                    var17 = var9 - this.playerEntity.posZ;
    360                    var25 = var13 * var13 + var15 * var15 + var17 * var17;
    361                    boolean var31 = false;
    362
    363                    if (var25 > 0.0625D && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.theItemInWorldManager.isCreative())
    364                    {
    365                        var31 = true;
    366                        logger.warning(this.playerEntity.username + " moved wrongly!");
    367                    }
    368
    369                    if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
    370                    {
    371                        return;
    372                    }
    373
    374                    this.playerEntity.setPositionAndRotation(var5, var7, var9, var11, var12);
    375                    boolean var32 = var2.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)var27, (double)var27, (double)var27)).isEmpty();
    376
    377                    if (var28 && (var31 || !var32) && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.noClip)
    378                    {
    379                        this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, var11, var12);
    380                        return;
    381                    }
    382
    383                    AxisAlignedBB var33 = this.playerEntity.boundingBox.copy().expand((double)var27, (double)var27, (double)var27).addCoord(0.0D, -0.55D, 0.0D);
    384
    385                    if (!this.mcServer.isFlightAllowed() && !this.playerEntity.theItemInWorldManager.isCreative() && !var2.isAABBNonEmpty(var33)  && !this.playerEntity.capabilities.allowFlying)
    386                    {
    387                        if (var29 >= -0.03125D)
    388                        {
    389                            ++this.ticksForFloatKick;
    390
    391                            if (this.ticksForFloatKick > 80)
    392                            {
    393                                logger.warning(this.playerEntity.username + " was kicked for floating too long!");
    394                                this.kickPlayerFromServer("Flying is not enabled on this server");
    395                                return;
    396                            }
    397                        }
    398                    }
    399                    else
    400                    {
    401                        this.ticksForFloatKick = 0;
    402                    }
    403
    404                    if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
    405                    {
    406                        return;
    407                    }
    408
    409                    this.playerEntity.onGround = par1Packet10Flying.onGround;
    410                    this.mcServer.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity);
    411                    this.playerEntity.updateFlyingState(this.playerEntity.posY - var3, par1Packet10Flying.onGround);
    412                }
    413            }
    414        }
    415
    416        /**
    417         * Moves the player to the specified destination and rotation
    418         */
    419        public void setPlayerLocation(double par1, double par3, double par5, float par7, float par8)
    420        {
    421            this.hasMoved = false;
    422            this.lastPosX = par1;
    423            this.lastPosY = par3;
    424            this.lastPosZ = par5;
    425            this.playerEntity.setPositionAndRotation(par1, par3, par5, par7, par8);
    426            this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet13PlayerLookMove(par1, par3 + 1.6200000047683716D, par3, par5, par7, par8, false));
    427        }
    428
    429        public void handleBlockDig(Packet14BlockDig par1Packet14BlockDig)
    430        {
    431            WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    432
    433            if (par1Packet14BlockDig.status == 4)
    434            {
    435                this.playerEntity.dropOneItem();
    436            }
    437            else if (par1Packet14BlockDig.status == 5)
    438            {
    439                this.playerEntity.stopUsingItem();
    440            }
    441            else
    442            {
    443                boolean var3 = var2.provider.dimensionId != 0 || this.mcServer.getConfigurationManager().getOps().isEmpty() || this.mcServer.getConfigurationManager().areCommandsAllowed(this.playerEntity.username) || this.mcServer.isSinglePlayer();
    444                boolean var4 = false;
    445
    446                if (par1Packet14BlockDig.status == 0)
    447                {
    448                    var4 = true;
    449                }
    450
    451                if (par1Packet14BlockDig.status == 2)
    452                {
    453                    var4 = true;
    454                }
    455
    456                int var5 = par1Packet14BlockDig.xPosition;
    457                int var6 = par1Packet14BlockDig.yPosition;
    458                int var7 = par1Packet14BlockDig.zPosition;
    459
    460                if (var4)
    461                {
    462                    double var8 = this.playerEntity.posX - ((double)var5 + 0.5D);
    463                    double var10 = this.playerEntity.posY - ((double)var6 + 0.5D) + 1.5D;
    464                    double var12 = this.playerEntity.posZ - ((double)var7 + 0.5D);
    465                    double var14 = var8 * var8 + var10 * var10 + var12 * var12;
    466
    467                    double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1;
    468                    dist *= dist;
    469
    470                    if (var14 > dist)
    471                    {
    472                        return;
    473                    }
    474
    475                    if (var6 >= this.mcServer.getBuildLimit())
    476                    {
    477                        return;
    478                    }
    479                }
    480
    481                ChunkCoordinates var19 = var2.getSpawnPoint();
    482                int var9 = MathHelper.abs_int(var5 - var19.posX);
    483                int var20 = MathHelper.abs_int(var7 - var19.posZ);
    484
    485                if (var9 > var20)
    486                {
    487                    var20 = var9;
    488                }
    489
    490                if (par1Packet14BlockDig.status == 0)
    491                {
    492                    if (var20 <= this.mcServer.getSpawnProtectionSize() && !var3)
    493                    {
    494                        ForgeEventFactory.onPlayerInteract(playerEntity, Action.LEFT_CLICK_BLOCK, var5, var6, var7, 0);
    495                        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var5, var6, var7, var2));
    496                    }
    497                    else
    498                    {
    499                        this.playerEntity.theItemInWorldManager.onBlockClicked(var5, var6, var7, par1Packet14BlockDig.face);
    500                    }
    501                }
    502                else if (par1Packet14BlockDig.status == 2)
    503                {
    504                    this.playerEntity.theItemInWorldManager.uncheckedTryHarvestBlock(var5, var6, var7);
    505
    506                    if (var2.getBlockId(var5, var6, var7) != 0)
    507                    {
    508                        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var5, var6, var7, var2));
    509                    }
    510                }
    511                else if (par1Packet14BlockDig.status == 1)
    512                {
    513                    this.playerEntity.theItemInWorldManager.destroyBlockInWorldPartially(var5, var6, var7);
    514
    515                    if (var2.getBlockId(var5, var6, var7) != 0)
    516                    {
    517                        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var5, var6, var7, var2));
    518                    }
    519                }
    520                else if (par1Packet14BlockDig.status == 3)
    521                {
    522                    double var11 = this.playerEntity.posX - ((double)var5 + 0.5D);
    523                    double var13 = this.playerEntity.posY - ((double)var6 + 0.5D);
    524                    double var15 = this.playerEntity.posZ - ((double)var7 + 0.5D);
    525                    double var17 = var11 * var11 + var13 * var13 + var15 * var15;
    526
    527                    if (var17 < 256.0D)
    528                    {
    529                        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var5, var6, var7, var2));
    530                    }
    531                }
    532            }
    533        }
    534
    535        public void handlePlace(Packet15Place par1Packet15Place)
    536        {
    537            WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    538            ItemStack var3 = this.playerEntity.inventory.getCurrentItem();
    539            boolean var4 = false;
    540            int var5 = par1Packet15Place.getXPosition();
    541            int var6 = par1Packet15Place.getYPosition();
    542            int var7 = par1Packet15Place.getZPosition();
    543            int var8 = par1Packet15Place.getDirection();
    544            boolean var9 = var2.provider.dimensionId != 0 || this.mcServer.getConfigurationManager().getOps().isEmpty() || this.mcServer.getConfigurationManager().areCommandsAllowed(this.playerEntity.username) || this.mcServer.isSinglePlayer();
    545
    546            if (par1Packet15Place.getDirection() == 255)
    547            {
    548                if (var3 == null)
    549                {
    550                    return;
    551                }
    552
    553                PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(playerEntity, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, 0, 0, 0, -1);
    554                if (event.useItem != Event.Result.DENY)
    555                {
    556                    this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, var2, var3);
    557                }
    558            }
    559            else if (par1Packet15Place.getYPosition() >= this.mcServer.getBuildLimit() - 1 && (par1Packet15Place.getDirection() == 1 || par1Packet15Place.getYPosition() >= this.mcServer.getBuildLimit()))
    560            {
    561                this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet3Chat("\u00a77Height limit for building is " + this.mcServer.getBuildLimit()));
    562                var4 = true;
    563            }
    564            else
    565            {
    566                ChunkCoordinates var10 = var2.getSpawnPoint();
    567                int var11 = MathHelper.abs_int(var5 - var10.posX);
    568                int var12 = MathHelper.abs_int(var7 - var10.posZ);
    569
    570                if (var11 > var12)
    571                {
    572                    var12 = var11;
    573                }
    574
    575                double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1;
    576                dist *= dist;
    577                if (this.hasMoved && this.playerEntity.getDistanceSq((double)var5 + 0.5D, (double)var6 + 0.5D, (double)var7 + 0.5D) < dist && (var12 > this.mcServer.getSpawnProtectionSize() || var9))
    578                {
    579                    this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, var2, var3, var5, var6, var7, var8, par1Packet15Place.getXOffset(), par1Packet15Place.getYOffset(), par1Packet15Place.getZOffset());
    580                }
    581
    582                var4 = true;
    583            }
    584
    585            if (var4)
    586            {
    587                this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var5, var6, var7, var2));
    588
    589                if (var8 == 0)
    590                {
    591                    --var6;
    592                }
    593
    594                if (var8 == 1)
    595                {
    596                    ++var6;
    597                }
    598
    599                if (var8 == 2)
    600                {
    601                    --var7;
    602                }
    603
    604                if (var8 == 3)
    605                {
    606                    ++var7;
    607                }
    608
    609                if (var8 == 4)
    610                {
    611                    --var5;
    612                }
    613
    614                if (var8 == 5)
    615                {
    616                    ++var5;
    617                }
    618
    619                this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var5, var6, var7, var2));
    620            }
    621
    622            var3 = this.playerEntity.inventory.getCurrentItem();
    623
    624            if (var3 != null && var3.stackSize == 0)
    625            {
    626                this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null;
    627                var3 = null;
    628            }
    629
    630            if (var3 == null || var3.getMaxItemUseDuration() == 0)
    631            {
    632                this.playerEntity.playerInventoryBeingManipulated = true;
    633                this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]);
    634                Slot var13 = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem);
    635                this.playerEntity.openContainer.updateCraftingResults();
    636                this.playerEntity.playerInventoryBeingManipulated = false;
    637
    638                if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), par1Packet15Place.getItemStack()))
    639                {
    640                    this.sendPacketToPlayer(new Packet103SetSlot(this.playerEntity.openContainer.windowId, var13.slotNumber, this.playerEntity.inventory.getCurrentItem()));
    641                }
    642            }
    643        }
    644
    645        public void handleErrorMessage(String par1Str, Object[] par2ArrayOfObj)
    646        {
    647            logger.info(this.playerEntity.username + " lost connection: " + par1Str);
    648            this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet3Chat("\u00a7e" + this.playerEntity.username + " left the game."));
    649            this.mcServer.getConfigurationManager().playerLoggedOut(this.playerEntity);
    650            this.connectionClosed = true;
    651
    652            if (this.mcServer.isSinglePlayer() && this.playerEntity.username.equals(this.mcServer.getServerOwner()))
    653            {
    654                logger.info("Stopping singleplayer server as player logged out");
    655                this.mcServer.initiateShutdown();
    656            }
    657        }
    658
    659        /**
    660         * Default handler called for packets that don't have their own handlers in NetClientHandler; currentlly does
    661         * nothing.
    662         */
    663        public void unexpectedPacket(Packet par1Packet)
    664        {
    665            logger.warning(this.getClass() + " wasn\'t prepared to deal with a " + par1Packet.getClass());
    666            this.kickPlayerFromServer("Protocol error, unexpected packet");
    667        }
    668
    669        /**
    670         * addToSendQueue. if it is a chat packet, check before sending it
    671         */
    672        public void sendPacketToPlayer(Packet par1Packet)
    673        {
    674            if (par1Packet instanceof Packet3Chat)
    675            {
    676                Packet3Chat var2 = (Packet3Chat)par1Packet;
    677                int var3 = this.playerEntity.getChatVisibility();
    678
    679                if (var3 == 2)
    680                {
    681                    return;
    682                }
    683
    684                if (var3 == 1 && !var2.func_73475_d())
    685                {
    686                    return;
    687                }
    688            }
    689
    690            this.netManager.addToSendQueue(par1Packet);
    691        }
    692
    693        public void handleBlockItemSwitch(Packet16BlockItemSwitch par1Packet16BlockItemSwitch)
    694        {
    695            if (par1Packet16BlockItemSwitch.id >= 0 && par1Packet16BlockItemSwitch.id < InventoryPlayer.func_70451_h())
    696            {
    697                this.playerEntity.inventory.currentItem = par1Packet16BlockItemSwitch.id;
    698            }
    699            else
    700            {
    701                logger.warning(this.playerEntity.username + " tried to set an invalid carried item");
    702            }
    703        }
    704
    705        public void handleChat(Packet3Chat par1Packet3Chat)
    706        {
    707            par1Packet3Chat = FMLNetworkHandler.handleChatMessage(this, par1Packet3Chat);
    708            if (this.playerEntity.getChatVisibility() == 2)
    709            {
    710                this.sendPacketToPlayer(new Packet3Chat("Cannot send chat message."));
    711            }
    712            else
    713            {
    714                String var2 = par1Packet3Chat.message;
    715
    716                if (var2.length() > 100)
    717                {
    718                    this.kickPlayerFromServer("Chat message too long");
    719                }
    720                else
    721                {
    722                    var2 = var2.trim();
    723
    724                    for (int var3 = 0; var3 < var2.length(); ++var3)
    725                    {
    726                        if (!ChatAllowedCharacters.isAllowedCharacter(var2.charAt(var3)))
    727                        {
    728                            this.kickPlayerFromServer("Illegal characters in chat");
    729                            return;
    730                        }
    731                    }
    732
    733                    if (var2.startsWith("/"))
    734                    {
    735                        this.handleSlashCommand(var2);
    736                    }
    737                    else
    738                    {
    739                        if (this.playerEntity.getChatVisibility() == 1)
    740                        {
    741                            this.sendPacketToPlayer(new Packet3Chat("Cannot send chat message."));
    742                            return;
    743                        }
    744                        ServerChatEvent event = new ServerChatEvent(this.playerEntity, var2, "<" + this.playerEntity.username + "> " + var2);
    745                        if (MinecraftForge.EVENT_BUS.post(event))
    746                        {
    747                            return;
    748                        }
    749                        var2 = event.line;
    750                        logger.info(var2);
    751                        this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet3Chat(var2, false));
    752                    }
    753
    754                    this.chatSpamThresholdCount += 20;
    755
    756                    if (this.chatSpamThresholdCount > 200 && !this.mcServer.getConfigurationManager().areCommandsAllowed(this.playerEntity.username))
    757                    {
    758                        this.kickPlayerFromServer("disconnect.spam");
    759                    }
    760                }
    761            }
    762        }
    763
    764        /**
    765         * Processes a / command
    766         */
    767        private void handleSlashCommand(String par1Str)
    768        {
    769            this.mcServer.getCommandManager().executeCommand(this.playerEntity, par1Str);
    770        }
    771
    772        public void handleAnimation(Packet18Animation par1Packet18Animation)
    773        {
    774            if (par1Packet18Animation.animate == 1)
    775            {
    776                this.playerEntity.swingItem();
    777            }
    778        }
    779
    780        /**
    781         * runs registerPacket on the given Packet19EntityAction
    782         */
    783        public void handleEntityAction(Packet19EntityAction par1Packet19EntityAction)
    784        {
    785            if (par1Packet19EntityAction.state == 1)
    786            {
    787                this.playerEntity.setSneaking(true);
    788            }
    789            else if (par1Packet19EntityAction.state == 2)
    790            {
    791                this.playerEntity.setSneaking(false);
    792            }
    793            else if (par1Packet19EntityAction.state == 4)
    794            {
    795                this.playerEntity.setSprinting(true);
    796            }
    797            else if (par1Packet19EntityAction.state == 5)
    798            {
    799                this.playerEntity.setSprinting(false);
    800            }
    801            else if (par1Packet19EntityAction.state == 3)
    802            {
    803                this.playerEntity.wakeUpPlayer(false, true, true);
    804                this.hasMoved = false;
    805            }
    806        }
    807
    808        public void handleKickDisconnect(Packet255KickDisconnect par1Packet255KickDisconnect)
    809        {
    810            this.netManager.networkShutdown("disconnect.quitting", new Object[0]);
    811        }
    812
    813        /**
    814         * returns 0 for memoryMapped connections
    815         */
    816        public int packetSize()
    817        {
    818            return this.netManager.packetSize();
    819        }
    820
    821        public void handleUseEntity(Packet7UseEntity par1Packet7UseEntity)
    822        {
    823            WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    824            Entity var3 = var2.getEntityByID(par1Packet7UseEntity.targetEntity);
    825
    826            if (var3 != null)
    827            {
    828                boolean var4 = this.playerEntity.canEntityBeSeen(var3);
    829                double var5 = 36.0D;
    830
    831                if (!var4)
    832                {
    833                    var5 = 9.0D;
    834                }
    835
    836                if (this.playerEntity.getDistanceSqToEntity(var3) < var5)
    837                {
    838                    if (par1Packet7UseEntity.isLeftClick == 0)
    839                    {
    840                        this.playerEntity.interactWith(var3);
    841                    }
    842                    else if (par1Packet7UseEntity.isLeftClick == 1)
    843                    {
    844                        this.playerEntity.attackTargetEntityWithCurrentItem(var3);
    845                    }
    846                }
    847            }
    848        }
    849
    850        public void handleClientCommand(Packet205ClientCommand par1Packet205ClientCommand)
    851        {
    852            if (par1Packet205ClientCommand.forceRespawn == 1)
    853            {
    854                if (this.playerEntity.playerConqueredTheEnd)
    855                {
    856                    this.playerEntity = this.mcServer.getConfigurationManager().respawnPlayer(this.playerEntity, 0, true);
    857                }
    858                else if (this.playerEntity.getServerForPlayer().getWorldInfo().isHardcoreModeEnabled())
    859                {
    860                    if (this.mcServer.isSinglePlayer() && this.playerEntity.username.equals(this.mcServer.getServerOwner()))
    861                    {
    862                        this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!");
    863                        this.mcServer.deleteWorldAndStopServer();
    864                    }
    865                    else
    866                    {
    867                        BanEntry var2 = new BanEntry(this.playerEntity.username);
    868                        var2.setBanReason("Death in Hardcore");
    869                        this.mcServer.getConfigurationManager().getBannedPlayers().put(var2);
    870                        this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!");
    871                    }
    872                }
    873                else
    874                {
    875                    if (this.playerEntity.getHealth() > 0)
    876                    {
    877                        return;
    878                    }
    879
    880                    this.playerEntity = this.mcServer.getConfigurationManager().respawnPlayer(this.playerEntity, playerEntity.dimension, false);
    881                }
    882            }
    883        }
    884
    885        /**
    886         * packet.processPacket is only called if this returns true
    887         */
    888        public boolean canProcessPackets()
    889        {
    890            return true;
    891        }
    892
    893        /**
    894         * respawns the player
    895         */
    896        public void handleRespawn(Packet9Respawn par1Packet9Respawn) {}
    897
    898        public void handleCloseWindow(Packet101CloseWindow par1Packet101CloseWindow)
    899        {
    900            this.playerEntity.closeInventory();
    901        }
    902
    903        public void handleWindowClick(Packet102WindowClick par1Packet102WindowClick)
    904        {
    905            if (this.playerEntity.openContainer.windowId == par1Packet102WindowClick.window_Id && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    906            {
    907                ItemStack var2 = this.playerEntity.openContainer.slotClick(par1Packet102WindowClick.inventorySlot, par1Packet102WindowClick.mouseClick, par1Packet102WindowClick.holdingShift, this.playerEntity);
    908
    909                if (ItemStack.areItemStacksEqual(par1Packet102WindowClick.itemStack, var2))
    910                {
    911                    this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet106Transaction(par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, true));
    912                    this.playerEntity.playerInventoryBeingManipulated = true;
    913                    this.playerEntity.openContainer.updateCraftingResults();
    914                    this.playerEntity.updateHeldItem();
    915                    this.playerEntity.playerInventoryBeingManipulated = false;
    916                }
    917                else
    918                {
    919                    this.field_72586_s.addKey(this.playerEntity.openContainer.windowId, Short.valueOf(par1Packet102WindowClick.action));
    920                    this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet106Transaction(par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, false));
    921                    this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, false);
    922                    ArrayList var3 = new ArrayList();
    923
    924                    for (int var4 = 0; var4 < this.playerEntity.openContainer.inventorySlots.size(); ++var4)
    925                    {
    926                        var3.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(var4)).getStack());
    927                    }
    928
    929                    this.playerEntity.sendContainerAndContentsToPlayer(this.playerEntity.openContainer, var3);
    930                }
    931            }
    932        }
    933
    934        public void handleEnchantItem(Packet108EnchantItem par1Packet108EnchantItem)
    935        {
    936            if (this.playerEntity.openContainer.windowId == par1Packet108EnchantItem.windowId && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    937            {
    938                this.playerEntity.openContainer.enchantItem(this.playerEntity, par1Packet108EnchantItem.enchantment);
    939                this.playerEntity.openContainer.updateCraftingResults();
    940            }
    941        }
    942
    943        /**
    944         * Handle a creative slot packet.
    945         */
    946        public void handleCreativeSetSlot(Packet107CreativeSetSlot par1Packet107CreativeSetSlot)
    947        {
    948            if (this.playerEntity.theItemInWorldManager.isCreative())
    949            {
    950                boolean var2 = par1Packet107CreativeSetSlot.slot < 0;
    951                ItemStack var3 = par1Packet107CreativeSetSlot.itemStack;
    952                boolean var4 = par1Packet107CreativeSetSlot.slot >= 1 && par1Packet107CreativeSetSlot.slot < 36 + InventoryPlayer.func_70451_h();
    953                boolean var5 = var3 == null || var3.itemID < Item.itemsList.length && var3.itemID >= 0 && Item.itemsList[var3.itemID] != null;
    954                boolean var6 = var3 == null || var3.getItemDamage() >= 0 && var3.getItemDamage() >= 0 && var3.stackSize <= 64 && var3.stackSize > 0;
    955
    956                if (var4 && var5 && var6)
    957                {
    958                    if (var3 == null)
    959                    {
    960                        this.playerEntity.inventoryContainer.putStackInSlot(par1Packet107CreativeSetSlot.slot, (ItemStack)null);
    961                    }
    962                    else
    963                    {
    964                        this.playerEntity.inventoryContainer.putStackInSlot(par1Packet107CreativeSetSlot.slot, var3);
    965                    }
    966
    967                    this.playerEntity.inventoryContainer.setPlayerIsPresent(this.playerEntity, true);
    968                }
    969                else if (var2 && var5 && var6 && this.creativeItemCreationSpamThresholdTally < 200)
    970                {
    971                    this.creativeItemCreationSpamThresholdTally += 20;
    972                    EntityItem var7 = this.playerEntity.dropPlayerItem(var3);
    973
    974                    if (var7 != null)
    975                    {
    976                        var7.func_70288_d();
    977                    }
    978                }
    979            }
    980        }
    981
    982        public void handleTransaction(Packet106Transaction par1Packet106Transaction)
    983        {
    984            Short var2 = (Short)this.field_72586_s.lookup(this.playerEntity.openContainer.windowId);
    985
    986            if (var2 != null && par1Packet106Transaction.shortWindowId == var2.shortValue() && this.playerEntity.openContainer.windowId == par1Packet106Transaction.windowId && !this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    987            {
    988                this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, true);
    989            }
    990        }
    991
    992        /**
    993         * Updates Client side signs
    994         */
    995        public void handleUpdateSign(Packet130UpdateSign par1Packet130UpdateSign)
    996        {
    997            WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    998
    999            if (var2.blockExists(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition))
    1000            {
    1001                TileEntity var3 = var2.getBlockTileEntity(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition);
    1002
    1003                if (var3 instanceof TileEntitySign)
    1004                {
    1005                    TileEntitySign var4 = (TileEntitySign)var3;
    1006
    1007                    if (!var4.isEditable())
    1008                    {
    1009                        this.mcServer.logWarning("Player " + this.playerEntity.username + " just tried to change non-editable sign");
    1010                        return;
    1011                    }
    1012                }
    1013
    1014                int var6;
    1015                int var8;
    1016
    1017                for (var8 = 0; var8 < 4; ++var8)
    1018                {
    1019                    boolean var5 = true;
    1020
    1021                    if (par1Packet130UpdateSign.signLines[var8].length() > 15)
    1022                    {
    1023                        var5 = false;
    1024                    }
    1025                    else
    1026                    {
    1027                        for (var6 = 0; var6 < par1Packet130UpdateSign.signLines[var8].length(); ++var6)
    1028                        {
    1029                            if (ChatAllowedCharacters.allowedCharacters.indexOf(par1Packet130UpdateSign.signLines[var8].charAt(var6)) < 0)
    1030                            {
    1031                                var5 = false;
    1032                            }
    1033                        }
    1034                    }
    1035
    1036                    if (!var5)
    1037                    {
    1038                        par1Packet130UpdateSign.signLines[var8] = "!?";
    1039                    }
    1040                }
    1041
    1042                if (var3 instanceof TileEntitySign)
    1043                {
    1044                    var8 = par1Packet130UpdateSign.xPosition;
    1045                    int var9 = par1Packet130UpdateSign.yPosition;
    1046                    var6 = par1Packet130UpdateSign.zPosition;
    1047                    TileEntitySign var7 = (TileEntitySign)var3;
    1048                    System.arraycopy(par1Packet130UpdateSign.signLines, 0, var7.signText, 0, 4);
    1049                    var7.onInventoryChanged();
    1050                    var2.markBlockForUpdate(var8, var9, var6);
    1051                }
    1052            }
    1053        }
    1054
    1055        /**
    1056         * Handle a keep alive packet.
    1057         */
    1058        public void handleKeepAlive(Packet0KeepAlive par1Packet0KeepAlive)
    1059        {
    1060            if (par1Packet0KeepAlive.randomId == this.keepAliveRandomID)
    1061            {
    1062                int var2 = (int)(System.nanoTime() / 1000000L - this.keepAliveTimeSent);
    1063                this.playerEntity.ping = (this.playerEntity.ping * 3 + var2) / 4;
    1064            }
    1065        }
    1066
    1067        /**
    1068         * determine if it is a server handler
    1069         */
    1070        public boolean isServerHandler()
    1071        {
    1072            return true;
    1073        }
    1074
    1075        /**
    1076         * Handle a player abilities packet.
    1077         */
    1078        public void handlePlayerAbilities(Packet202PlayerAbilities par1Packet202PlayerAbilities)
    1079        {
    1080            this.playerEntity.capabilities.isFlying = par1Packet202PlayerAbilities.getFlying() && this.playerEntity.capabilities.allowFlying;
    1081        }
    1082
    1083        public void handleAutoComplete(Packet203AutoComplete par1Packet203AutoComplete)
    1084        {
    1085            StringBuilder var2 = new StringBuilder();
    1086            String var4;
    1087
    1088            for (Iterator var3 = this.mcServer.getPossibleCompletions(this.playerEntity, par1Packet203AutoComplete.getText()).iterator(); var3.hasNext(); var2.append(var4))
    1089            {
    1090                var4 = (String)var3.next();
    1091
    1092                if (var2.length() > 0)
    1093                {
    1094                    var2.append("\u0000");
    1095                }
    1096            }
    1097
    1098            this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet203AutoComplete(var2.toString()));
    1099        }
    1100
    1101        public void handleClientInfo(Packet204ClientInfo par1Packet204ClientInfo)
    1102        {
    1103            this.playerEntity.updateClientInfo(par1Packet204ClientInfo);
    1104        }
    1105
    1106        public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload)
    1107        {
    1108            FMLNetworkHandler.handlePacket250Packet(par1Packet250CustomPayload, netManager, this);
    1109        }
    1110
    1111        public void handleVanilla250Packet(Packet250CustomPayload par1Packet250CustomPayload)
    1112        {
    1113            DataInputStream var2;
    1114            ItemStack var3;
    1115            ItemStack var4;
    1116
    1117            if ("MC|BEdit".equals(par1Packet250CustomPayload.channel))
    1118            {
    1119                try
    1120                {
    1121                    var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1122                    var3 = Packet.readItemStack(var2);
    1123
    1124                    if (!ItemWritableBook.validBookTagPages(var3.getTagCompound()))
    1125                    {
    1126                        throw new IOException("Invalid book tag!");
    1127                    }
    1128
    1129                    var4 = this.playerEntity.inventory.getCurrentItem();
    1130
    1131                    if (var3 != null && var3.itemID == Item.writableBook.shiftedIndex && var3.itemID == var4.itemID)
    1132                    {
    1133                        var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages"));
    1134                    }
    1135                }
    1136                catch (Exception var12)
    1137                {
    1138                    var12.printStackTrace();
    1139                }
    1140            }
    1141            else if ("MC|BSign".equals(par1Packet250CustomPayload.channel))
    1142            {
    1143                try
    1144                {
    1145                    var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1146                    var3 = Packet.readItemStack(var2);
    1147
    1148                    if (!ItemEditableBook.validBookTagContents(var3.getTagCompound()))
    1149                    {
    1150                        throw new IOException("Invalid book tag!");
    1151                    }
    1152
    1153                    var4 = this.playerEntity.inventory.getCurrentItem();
    1154
    1155                    if (var3 != null && var3.itemID == Item.writtenBook.shiftedIndex && var4.itemID == Item.writableBook.shiftedIndex)
    1156                    {
    1157                        var4.setTagInfo("author", new NBTTagString("author", this.playerEntity.username));
    1158                        var4.setTagInfo("title", new NBTTagString("title", var3.getTagCompound().getString("title")));
    1159                        var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages"));
    1160                        var4.itemID = Item.writtenBook.shiftedIndex;
    1161                    }
    1162                }
    1163                catch (Exception var11)
    1164                {
    1165                    var11.printStackTrace();
    1166                }
    1167            }
    1168            else
    1169            {
    1170                int var14;
    1171
    1172                if ("MC|TrSel".equals(par1Packet250CustomPayload.channel))
    1173                {
    1174                    try
    1175                    {
    1176                        var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1177                        var14 = var2.readInt();
    1178                        Container var15 = this.playerEntity.openContainer;
    1179
    1180                        if (var15 instanceof ContainerMerchant)
    1181                        {
    1182                            ((ContainerMerchant)var15).setCurrentRecipeIndex(var14);
    1183                        }
    1184                    }
    1185                    catch (Exception var10)
    1186                    {
    1187                        var10.printStackTrace();
    1188                    }
    1189                }
    1190                else
    1191                {
    1192                    int var18;
    1193
    1194                    if ("MC|AdvCdm".equals(par1Packet250CustomPayload.channel))
    1195                    {
    1196                        if (!this.mcServer.isCommandBlockEnabled())
    1197                        {
    1198                            this.playerEntity.sendChatToPlayer(this.playerEntity.translateString("advMode.notEnabled", new Object[0]));
    1199                        }
    1200                        else if (this.playerEntity.canCommandSenderUseCommand(2, "") && this.playerEntity.capabilities.isCreativeMode)
    1201                        {
    1202                            try
    1203                            {
    1204                                var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1205                                var14 = var2.readInt();
    1206                                var18 = var2.readInt();
    1207                                int var5 = var2.readInt();
    1208                                String var6 = Packet.readString(var2, 256);
    1209                                TileEntity var7 = this.playerEntity.worldObj.getBlockTileEntity(var14, var18, var5);
    1210
    1211                                if (var7 != null && var7 instanceof TileEntityCommandBlock)
    1212                                {
    1213                                    ((TileEntityCommandBlock)var7).setCommand(var6);
    1214                                    this.playerEntity.worldObj.markBlockForUpdate(var14, var18, var5);
    1215                                    this.playerEntity.sendChatToPlayer("Command set: " + var6);
    1216                                }
    1217                            }
    1218                            catch (Exception var9)
    1219                            {
    1220                                var9.printStackTrace();
    1221                            }
    1222                        }
    1223                        else
    1224                        {
    1225                            this.playerEntity.sendChatToPlayer(this.playerEntity.translateString("advMode.notAllowed", new Object[0]));
    1226                        }
    1227                    }
    1228                    else if ("MC|Beacon".equals(par1Packet250CustomPayload.channel))
    1229                    {
    1230                        if (this.playerEntity.openContainer instanceof ContainerBeacon)
    1231                        {
    1232                            try
    1233                            {
    1234                                var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1235                                var14 = var2.readInt();
    1236                                var18 = var2.readInt();
    1237                                ContainerBeacon var17 = (ContainerBeacon)this.playerEntity.openContainer;
    1238                                Slot var19 = var17.getSlot(0);
    1239
    1240                                if (var19.getHasStack())
    1241                                {
    1242                                    var19.decrStackSize(1);
    1243                                    TileEntityBeacon var20 = var17.getBeacon();
    1244                                    var20.func_82128_d(var14);
    1245                                    var20.func_82127_e(var18);
    1246                                    var20.onInventoryChanged();
    1247                                }
    1248                            }
    1249                            catch (Exception var8)
    1250                            {
    1251                                var8.printStackTrace();
    1252                            }
    1253                        }
    1254                    }
    1255                    else if ("MC|ItemName".equals(par1Packet250CustomPayload.channel) && this.playerEntity.openContainer instanceof ContainerRepair)
    1256                    {
    1257                        ContainerRepair var13 = (ContainerRepair)this.playerEntity.openContainer;
    1258
    1259                        if (par1Packet250CustomPayload.data != null && par1Packet250CustomPayload.data.length >= 1)
    1260                        {
    1261                            String var16 = ChatAllowedCharacters.filerAllowedCharacters(new String(par1Packet250CustomPayload.data));
    1262
    1263                            if (var16.length() <= 30)
    1264                            {
    1265                                var13.func_82850_a(var16);
    1266                            }
    1267                        }
    1268                        else
    1269                        {
    1270                            var13.func_82850_a("");
    1271                        }
    1272                    }
    1273                }
    1274            }
    1275        }
    1276
    1277
    1278        @Override
    1279
    1280        /**
    1281         * Contains logic for handling packets containing arbitrary unique item data. Currently this is only for maps.
    1282         */
    1283        public void handleMapData(Packet131MapData par1Packet131MapData)
    1284        {
    1285            FMLNetworkHandler.handlePacket131Packet(this, par1Packet131MapData);
    1286        }
    1287
    1288        // modloader compat -- yuk!
    1289        @Override
    1290        public EntityPlayerMP getPlayer()
    1291        {
    1292            return playerEntity;
    1293        }
    1294    }