    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(false);
    436            }
    437            else if (par1Packet14BlockDig.status == 3)
    438            {
    439                this.playerEntity.dropOneItem(true);
    440            }
    441            else if (par1Packet14BlockDig.status == 5)
    442            {
    443                this.playerEntity.stopUsingItem();
    444            }
    445            else
    446            {
    447                int var3 = this.mcServer.getSpawnProtectionSize();
    448                boolean var4 = var2.provider.dimensionId != 0 || this.mcServer.getConfigurationManager().getOps().isEmpty() || this.mcServer.getConfigurationManager().areCommandsAllowed(this.playerEntity.username) || var3 <= 0 || this.mcServer.isSinglePlayer();
    449                boolean var5 = false;
    450
    451                if (par1Packet14BlockDig.status == 0)
    452                {
    453                    var5 = true;
    454                }
    455
    456                if (par1Packet14BlockDig.status == 1)
    457                {
    458                    var5 = true;
    459                }
    460
    461                if (par1Packet14BlockDig.status == 2)
    462                {
    463                    var5 = true;
    464                }
    465
    466                int var6 = par1Packet14BlockDig.xPosition;
    467                int var7 = par1Packet14BlockDig.yPosition;
    468                int var8 = par1Packet14BlockDig.zPosition;
    469
    470                if (var5)
    471                {
    472                    double var9 = this.playerEntity.posX - ((double)var6 + 0.5D);
    473                    double var11 = this.playerEntity.posY - ((double)var7 + 0.5D) + 1.5D;
    474                    double var13 = this.playerEntity.posZ - ((double)var8 + 0.5D);
    475                    double var15 = var9 * var9 + var11 * var11 + var13 * var13;
    476
    477                    double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1;
    478                    dist *= dist;
    479
    480                    if (var15 > dist)
    481                    {
    482                        return;
    483                    }
    484
    485                    if (var7 >= this.mcServer.getBuildLimit())
    486                    {
    487                        return;
    488                    }
    489                }
    490
    491                ChunkCoordinates var17 = var2.getSpawnPoint();
    492                int var10 = MathHelper.abs_int(var6 - var17.posX);
    493                int var18 = MathHelper.abs_int(var8 - var17.posZ);
    494
    495                if (var10 > var18)
    496                {
    497                    var18 = var10;
    498                }
    499
    500                if (par1Packet14BlockDig.status == 0)
    501                {
    502                    if (var18 <= var3 && !var4)
    503                    {
    504                        ForgeEventFactory.onPlayerInteract(playerEntity, Action.LEFT_CLICK_BLOCK, var6, var7, var8, 0);
    505                        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var6, var7, var8, var2));
    506                    }
    507                    else
    508                    {
    509                        this.playerEntity.theItemInWorldManager.onBlockClicked(var6, var7, var8, par1Packet14BlockDig.face);
    510                    }
    511                }
    512                else if (par1Packet14BlockDig.status == 2)
    513                {
    514                    this.playerEntity.theItemInWorldManager.uncheckedTryHarvestBlock(var6, var7, var8);
    515
    516                    if (var2.getBlockId(var6, var7, var8) != 0)
    517                    {
    518                        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var6, var7, var8, var2));
    519                    }
    520                }
    521                else if (par1Packet14BlockDig.status == 1)
    522                {
    523                    this.playerEntity.theItemInWorldManager.cancelDestroyingBlock(var6, var7, var8);
    524
    525                    if (var2.getBlockId(var6, var7, var8) != 0)
    526                    {
    527                        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var6, var7, var8, var2));
    528                    }
    529                }
    530            }
    531        }
    532
    533        public void handlePlace(Packet15Place par1Packet15Place)
    534        {
    535            WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    536            ItemStack var3 = this.playerEntity.inventory.getCurrentItem();
    537            boolean var4 = false;
    538            int var5 = par1Packet15Place.getXPosition();
    539            int var6 = par1Packet15Place.getYPosition();
    540            int var7 = par1Packet15Place.getZPosition();
    541            int var8 = par1Packet15Place.getDirection();
    542            int var9 = this.mcServer.getSpawnProtectionSize();
    543            boolean var10 = var2.provider.dimensionId != 0 || this.mcServer.getConfigurationManager().getOps().isEmpty() || this.mcServer.getConfigurationManager().areCommandsAllowed(this.playerEntity.username) || var9 <= 0 || this.mcServer.isSinglePlayer();
    544
    545            if (par1Packet15Place.getDirection() == 255)
    546            {
    547                if (var3 == null)
    548                {
    549                    return;
    550                }
    551
    552                PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(playerEntity, PlayerInteractEvent.Action.RIGHT_CLICK_AIR, 0, 0, 0, -1);
    553                if (event.useItem != Event.Result.DENY)
    554                {
    555                    this.playerEntity.theItemInWorldManager.tryUseItem(this.playerEntity, var2, var3);
    556                }
    557            }
    558            else if (par1Packet15Place.getYPosition() >= this.mcServer.getBuildLimit() - 1 && (par1Packet15Place.getDirection() == 1 || par1Packet15Place.getYPosition() >= this.mcServer.getBuildLimit()))
    559            {
    560                this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet3Chat("\u00a77Height limit for building is " + this.mcServer.getBuildLimit()));
    561                var4 = true;
    562            }
    563            else
    564            {
    565                ChunkCoordinates var11 = var2.getSpawnPoint();
    566                int var12 = MathHelper.abs_int(var5 - var11.posX);
    567                int var13 = MathHelper.abs_int(var7 - var11.posZ);
    568
    569                if (var12 > var13)
    570                {
    571                    var13 = var12;
    572                }
    573
    574                double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1;
    575                dist *= dist;
    576                if (this.hasMoved && this.playerEntity.getDistanceSq((double)var5 + 0.5D, (double)var6 + 0.5D, (double)var7 + 0.5D) < dist && (var13 > var9 || var10))
    577                {
    578                    this.playerEntity.theItemInWorldManager.activateBlockOrUseItem(this.playerEntity, var2, var3, var5, var6, var7, var8, par1Packet15Place.getXOffset(), par1Packet15Place.getYOffset(), par1Packet15Place.getZOffset());
    579                }
    580
    581                var4 = true;
    582            }
    583
    584            if (var4)
    585            {
    586                this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var5, var6, var7, var2));
    587
    588                if (var8 == 0)
    589                {
    590                    --var6;
    591                }
    592
    593                if (var8 == 1)
    594                {
    595                    ++var6;
    596                }
    597
    598                if (var8 == 2)
    599                {
    600                    --var7;
    601                }
    602
    603                if (var8 == 3)
    604                {
    605                    ++var7;
    606                }
    607
    608                if (var8 == 4)
    609                {
    610                    --var5;
    611                }
    612
    613                if (var8 == 5)
    614                {
    615                    ++var5;
    616                }
    617
    618                this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var5, var6, var7, var2));
    619            }
    620
    621            var3 = this.playerEntity.inventory.getCurrentItem();
    622
    623            if (var3 != null && var3.stackSize == 0)
    624            {
    625                this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = null;
    626                var3 = null;
    627            }
    628
    629            if (var3 == null || var3.getMaxItemUseDuration() == 0)
    630            {
    631                this.playerEntity.playerInventoryBeingManipulated = true;
    632                this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem] = ItemStack.copyItemStack(this.playerEntity.inventory.mainInventory[this.playerEntity.inventory.currentItem]);
    633                Slot var14 = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem);
    634                this.playerEntity.openContainer.updateCraftingResults();
    635                this.playerEntity.playerInventoryBeingManipulated = false;
    636
    637                if (!ItemStack.areItemStacksEqual(this.playerEntity.inventory.getCurrentItem(), par1Packet15Place.getItemStack()))
    638                {
    639                    this.sendPacketToPlayer(new Packet103SetSlot(this.playerEntity.openContainer.windowId, var14.slotNumber, this.playerEntity.inventory.getCurrentItem()));
    640                }
    641            }
    642        }
    643
    644        public void handleErrorMessage(String par1Str, Object[] par2ArrayOfObj)
    645        {
    646            logger.info(this.playerEntity.username + " lost connection: " + par1Str);
    647            this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet3Chat("\u00a7e" + this.playerEntity.username + " left the game."));
    648            this.mcServer.getConfigurationManager().playerLoggedOut(this.playerEntity);
    649            this.connectionClosed = true;
    650
    651            if (this.mcServer.isSinglePlayer() && this.playerEntity.username.equals(this.mcServer.getServerOwner()))
    652            {
    653                logger.info("Stopping singleplayer server as player logged out");
    654                this.mcServer.initiateShutdown();
    655            }
    656        }
    657
    658        /**
    659         * Default handler called for packets that don't have their own handlers in NetClientHandler; currentlly does
    660         * nothing.
    661         */
    662        public void unexpectedPacket(Packet par1Packet)
    663        {
    664            logger.warning(this.getClass() + " wasn\'t prepared to deal with a " + par1Packet.getClass());
    665            this.kickPlayerFromServer("Protocol error, unexpected packet");
    666        }
    667
    668        /**
    669         * addToSendQueue. if it is a chat packet, check before sending it
    670         */
    671        public void sendPacketToPlayer(Packet par1Packet)
    672        {
    673            if (par1Packet instanceof Packet3Chat)
    674            {
    675                Packet3Chat var2 = (Packet3Chat)par1Packet;
    676                int var3 = this.playerEntity.getChatVisibility();
    677
    678                if (var3 == 2)
    679                {
    680                    return;
    681                }
    682
    683                if (var3 == 1 && !var2.func_73475_d())
    684                {
    685                    return;
    686                }
    687            }
    688
    689            this.netManager.addToSendQueue(par1Packet);
    690        }
    691
    692        public void handleBlockItemSwitch(Packet16BlockItemSwitch par1Packet16BlockItemSwitch)
    693        {
    694            if (par1Packet16BlockItemSwitch.id >= 0 && par1Packet16BlockItemSwitch.id < InventoryPlayer.func_70451_h())
    695            {
    696                this.playerEntity.inventory.currentItem = par1Packet16BlockItemSwitch.id;
    697            }
    698            else
    699            {
    700                logger.warning(this.playerEntity.username + " tried to set an invalid carried item");
    701            }
    702        }
    703
    704        public void handleChat(Packet3Chat par1Packet3Chat)
    705        {
    706            par1Packet3Chat = FMLNetworkHandler.handleChatMessage(this, par1Packet3Chat);
    707            if (this.playerEntity.getChatVisibility() == 2)
    708            {
    709                this.sendPacketToPlayer(new Packet3Chat("Cannot send chat message."));
    710            }
    711            else
    712            {
    713                String var2 = par1Packet3Chat.message;
    714
    715                if (var2.length() > 100)
    716                {
    717                    this.kickPlayerFromServer("Chat message too long");
    718                }
    719                else
    720                {
    721                    var2 = var2.trim();
    722
    723                    for (int var3 = 0; var3 < var2.length(); ++var3)
    724                    {
    725                        if (!ChatAllowedCharacters.isAllowedCharacter(var2.charAt(var3)))
    726                        {
    727                            this.kickPlayerFromServer("Illegal characters in chat");
    728                            return;
    729                        }
    730                    }
    731
    732                    if (var2.startsWith("/"))
    733                    {
    734                        this.handleSlashCommand(var2);
    735                    }
    736                    else
    737                    {
    738                        if (this.playerEntity.getChatVisibility() == 1)
    739                        {
    740                            this.sendPacketToPlayer(new Packet3Chat("Cannot send chat message."));
    741                            return;
    742                        }
    743                        ServerChatEvent event = new ServerChatEvent(this.playerEntity, var2, "<" + this.playerEntity.username + "> " + var2);
    744                        if (MinecraftForge.EVENT_BUS.post(event))
    745                        {
    746                            return;
    747                        }
    748                        var2 = event.line;
    749                        logger.info(var2);
    750                        this.mcServer.getConfigurationManager().sendPacketToAllPlayers(new Packet3Chat(var2, false));
    751                    }
    752
    753                    this.chatSpamThresholdCount += 20;
    754
    755                    if (this.chatSpamThresholdCount > 200 && !this.mcServer.getConfigurationManager().areCommandsAllowed(this.playerEntity.username))
    756                    {
    757                        this.kickPlayerFromServer("disconnect.spam");
    758                    }
    759                }
    760            }
    761        }
    762
    763        /**
    764         * Processes a / command
    765         */
    766        private void handleSlashCommand(String par1Str)
    767        {
    768            this.mcServer.getCommandManager().executeCommand(this.playerEntity, par1Str);
    769        }
    770
    771        public void handleAnimation(Packet18Animation par1Packet18Animation)
    772        {
    773            if (par1Packet18Animation.animate == 1)
    774            {
    775                this.playerEntity.swingItem();
    776            }
    777        }
    778
    779        /**
    780         * runs registerPacket on the given Packet19EntityAction
    781         */
    782        public void handleEntityAction(Packet19EntityAction par1Packet19EntityAction)
    783        {
    784            if (par1Packet19EntityAction.state == 1)
    785            {
    786                this.playerEntity.setSneaking(true);
    787            }
    788            else if (par1Packet19EntityAction.state == 2)
    789            {
    790                this.playerEntity.setSneaking(false);
    791            }
    792            else if (par1Packet19EntityAction.state == 4)
    793            {
    794                this.playerEntity.setSprinting(true);
    795            }
    796            else if (par1Packet19EntityAction.state == 5)
    797            {
    798                this.playerEntity.setSprinting(false);
    799            }
    800            else if (par1Packet19EntityAction.state == 3)
    801            {
    802                this.playerEntity.wakeUpPlayer(false, true, true);
    803                this.hasMoved = false;
    804            }
    805        }
    806
    807        public void handleKickDisconnect(Packet255KickDisconnect par1Packet255KickDisconnect)
    808        {
    809            this.netManager.networkShutdown("disconnect.quitting", new Object[0]);
    810        }
    811
    812        /**
    813         * returns 0 for memoryMapped connections
    814         */
    815        public int packetSize()
    816        {
    817            return this.netManager.packetSize();
    818        }
    819
    820        public void handleUseEntity(Packet7UseEntity par1Packet7UseEntity)
    821        {
    822            WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    823            Entity var3 = var2.getEntityByID(par1Packet7UseEntity.targetEntity);
    824
    825            if (var3 != null)
    826            {
    827                boolean var4 = this.playerEntity.canEntityBeSeen(var3);
    828                double var5 = 36.0D;
    829
    830                if (!var4)
    831                {
    832                    var5 = 9.0D;
    833                }
    834
    835                if (this.playerEntity.getDistanceSqToEntity(var3) < var5)
    836                {
    837                    if (par1Packet7UseEntity.isLeftClick == 0)
    838                    {
    839                        this.playerEntity.interactWith(var3);
    840                    }
    841                    else if (par1Packet7UseEntity.isLeftClick == 1)
    842                    {
    843                        this.playerEntity.attackTargetEntityWithCurrentItem(var3);
    844                    }
    845                }
    846            }
    847        }
    848
    849        public void handleClientCommand(Packet205ClientCommand par1Packet205ClientCommand)
    850        {
    851            if (par1Packet205ClientCommand.forceRespawn == 1)
    852            {
    853                if (this.playerEntity.playerConqueredTheEnd)
    854                {
    855                    this.playerEntity = this.mcServer.getConfigurationManager().respawnPlayer(this.playerEntity, 0, true);
    856                }
    857                else if (this.playerEntity.getServerForPlayer().getWorldInfo().isHardcoreModeEnabled())
    858                {
    859                    if (this.mcServer.isSinglePlayer() && this.playerEntity.username.equals(this.mcServer.getServerOwner()))
    860                    {
    861                        this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!");
    862                        this.mcServer.deleteWorldAndStopServer();
    863                    }
    864                    else
    865                    {
    866                        BanEntry var2 = new BanEntry(this.playerEntity.username);
    867                        var2.setBanReason("Death in Hardcore");
    868                        this.mcServer.getConfigurationManager().getBannedPlayers().put(var2);
    869                        this.playerEntity.playerNetServerHandler.kickPlayerFromServer("You have died. Game over, man, it\'s game over!");
    870                    }
    871                }
    872                else
    873                {
    874                    if (this.playerEntity.getHealth() > 0)
    875                    {
    876                        return;
    877                    }
    878
    879                    this.playerEntity = this.mcServer.getConfigurationManager().respawnPlayer(this.playerEntity, playerEntity.dimension, false);
    880                }
    881            }
    882        }
    883
    884        /**
    885         * packet.processPacket is only called if this returns true
    886         */
    887        public boolean canProcessPackets()
    888        {
    889            return true;
    890        }
    891
    892        /**
    893         * respawns the player
    894         */
    895        public void handleRespawn(Packet9Respawn par1Packet9Respawn) {}
    896
    897        public void handleCloseWindow(Packet101CloseWindow par1Packet101CloseWindow)
    898        {
    899            this.playerEntity.closeInventory();
    900        }
    901
    902        public void handleWindowClick(Packet102WindowClick par1Packet102WindowClick)
    903        {
    904            if (this.playerEntity.openContainer.windowId == par1Packet102WindowClick.window_Id && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    905            {
    906                ItemStack var2 = this.playerEntity.openContainer.slotClick(par1Packet102WindowClick.inventorySlot, par1Packet102WindowClick.mouseClick, par1Packet102WindowClick.holdingShift, this.playerEntity);
    907
    908                if (ItemStack.areItemStacksEqual(par1Packet102WindowClick.itemStack, var2))
    909                {
    910                    this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet106Transaction(par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, true));
    911                    this.playerEntity.playerInventoryBeingManipulated = true;
    912                    this.playerEntity.openContainer.updateCraftingResults();
    913                    this.playerEntity.updateHeldItem();
    914                    this.playerEntity.playerInventoryBeingManipulated = false;
    915                }
    916                else
    917                {
    918                    this.field_72586_s.addKey(this.playerEntity.openContainer.windowId, Short.valueOf(par1Packet102WindowClick.action));
    919                    this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet106Transaction(par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, false));
    920                    this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, false);
    921                    ArrayList var3 = new ArrayList();
    922
    923                    for (int var4 = 0; var4 < this.playerEntity.openContainer.inventorySlots.size(); ++var4)
    924                    {
    925                        var3.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(var4)).getStack());
    926                    }
    927
    928                    this.playerEntity.sendContainerAndContentsToPlayer(this.playerEntity.openContainer, var3);
    929                }
    930            }
    931        }
    932
    933        public void handleEnchantItem(Packet108EnchantItem par1Packet108EnchantItem)
    934        {
    935            if (this.playerEntity.openContainer.windowId == par1Packet108EnchantItem.windowId && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    936            {
    937                this.playerEntity.openContainer.enchantItem(this.playerEntity, par1Packet108EnchantItem.enchantment);
    938                this.playerEntity.openContainer.updateCraftingResults();
    939            }
    940        }
    941
    942        /**
    943         * Handle a creative slot packet.
    944         */
    945        public void handleCreativeSetSlot(Packet107CreativeSetSlot par1Packet107CreativeSetSlot)
    946        {
    947            if (this.playerEntity.theItemInWorldManager.isCreative())
    948            {
    949                boolean var2 = par1Packet107CreativeSetSlot.slot < 0;
    950                ItemStack var3 = par1Packet107CreativeSetSlot.itemStack;
    951                boolean var4 = par1Packet107CreativeSetSlot.slot >= 1 && par1Packet107CreativeSetSlot.slot < 36 + InventoryPlayer.func_70451_h();
    952                boolean var5 = var3 == null || var3.itemID < Item.itemsList.length && var3.itemID >= 0 && Item.itemsList[var3.itemID] != null;
    953                boolean var6 = var3 == null || var3.getItemDamage() >= 0 && var3.getItemDamage() >= 0 && var3.stackSize <= 64 && var3.stackSize > 0;
    954
    955                if (var4 && var5 && var6)
    956                {
    957                    if (var3 == null)
    958                    {
    959                        this.playerEntity.inventoryContainer.putStackInSlot(par1Packet107CreativeSetSlot.slot, (ItemStack)null);
    960                    }
    961                    else
    962                    {
    963                        this.playerEntity.inventoryContainer.putStackInSlot(par1Packet107CreativeSetSlot.slot, var3);
    964                    }
    965
    966                    this.playerEntity.inventoryContainer.setPlayerIsPresent(this.playerEntity, true);
    967                }
    968                else if (var2 && var5 && var6 && this.creativeItemCreationSpamThresholdTally < 200)
    969                {
    970                    this.creativeItemCreationSpamThresholdTally += 20;
    971                    EntityItem var7 = this.playerEntity.dropPlayerItem(var3);
    972
    973                    if (var7 != null)
    974                    {
    975                        var7.func_70288_d();
    976                    }
    977                }
    978            }
    979        }
    980
    981        public void handleTransaction(Packet106Transaction par1Packet106Transaction)
    982        {
    983            Short var2 = (Short)this.field_72586_s.lookup(this.playerEntity.openContainer.windowId);
    984
    985            if (var2 != null && par1Packet106Transaction.shortWindowId == var2.shortValue() && this.playerEntity.openContainer.windowId == par1Packet106Transaction.windowId && !this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    986            {
    987                this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, true);
    988            }
    989        }
    990
    991        /**
    992         * Updates Client side signs
    993         */
    994        public void handleUpdateSign(Packet130UpdateSign par1Packet130UpdateSign)
    995        {
    996            WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    997
    998            if (var2.blockExists(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition))
    999            {
    1000                TileEntity var3 = var2.getBlockTileEntity(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition);
    1001
    1002                if (var3 instanceof TileEntitySign)
    1003                {
    1004                    TileEntitySign var4 = (TileEntitySign)var3;
    1005
    1006                    if (!var4.isEditable())
    1007                    {
    1008                        this.mcServer.logWarning("Player " + this.playerEntity.username + " just tried to change non-editable sign");
    1009                        return;
    1010                    }
    1011                }
    1012
    1013                int var6;
    1014                int var8;
    1015
    1016                for (var8 = 0; var8 < 4; ++var8)
    1017                {
    1018                    boolean var5 = true;
    1019
    1020                    if (par1Packet130UpdateSign.signLines[var8].length() > 15)
    1021                    {
    1022                        var5 = false;
    1023                    }
    1024                    else
    1025                    {
    1026                        for (var6 = 0; var6 < par1Packet130UpdateSign.signLines[var8].length(); ++var6)
    1027                        {
    1028                            if (ChatAllowedCharacters.allowedCharacters.indexOf(par1Packet130UpdateSign.signLines[var8].charAt(var6)) < 0)
    1029                            {
    1030                                var5 = false;
    1031                            }
    1032                        }
    1033                    }
    1034
    1035                    if (!var5)
    1036                    {
    1037                        par1Packet130UpdateSign.signLines[var8] = "!?";
    1038                    }
    1039                }
    1040
    1041                if (var3 instanceof TileEntitySign)
    1042                {
    1043                    var8 = par1Packet130UpdateSign.xPosition;
    1044                    int var9 = par1Packet130UpdateSign.yPosition;
    1045                    var6 = par1Packet130UpdateSign.zPosition;
    1046                    TileEntitySign var7 = (TileEntitySign)var3;
    1047                    System.arraycopy(par1Packet130UpdateSign.signLines, 0, var7.signText, 0, 4);
    1048                    var7.onInventoryChanged();
    1049                    var2.markBlockForUpdate(var8, var9, var6);
    1050                }
    1051            }
    1052        }
    1053
    1054        /**
    1055         * Handle a keep alive packet.
    1056         */
    1057        public void handleKeepAlive(Packet0KeepAlive par1Packet0KeepAlive)
    1058        {
    1059            if (par1Packet0KeepAlive.randomId == this.keepAliveRandomID)
    1060            {
    1061                int var2 = (int)(System.nanoTime() / 1000000L - this.keepAliveTimeSent);
    1062                this.playerEntity.ping = (this.playerEntity.ping * 3 + var2) / 4;
    1063            }
    1064        }
    1065
    1066        /**
    1067         * determine if it is a server handler
    1068         */
    1069        public boolean isServerHandler()
    1070        {
    1071            return true;
    1072        }
    1073
    1074        /**
    1075         * Handle a player abilities packet.
    1076         */
    1077        public void handlePlayerAbilities(Packet202PlayerAbilities par1Packet202PlayerAbilities)
    1078        {
    1079            this.playerEntity.capabilities.isFlying = par1Packet202PlayerAbilities.getFlying() && this.playerEntity.capabilities.allowFlying;
    1080        }
    1081
    1082        public void handleAutoComplete(Packet203AutoComplete par1Packet203AutoComplete)
    1083        {
    1084            StringBuilder var2 = new StringBuilder();
    1085            String var4;
    1086
    1087            for (Iterator var3 = this.mcServer.getPossibleCompletions(this.playerEntity, par1Packet203AutoComplete.getText()).iterator(); var3.hasNext(); var2.append(var4))
    1088            {
    1089                var4 = (String)var3.next();
    1090
    1091                if (var2.length() > 0)
    1092                {
    1093                    var2.append("\u0000");
    1094                }
    1095            }
    1096
    1097            this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet203AutoComplete(var2.toString()));
    1098        }
    1099
    1100        public void handleClientInfo(Packet204ClientInfo par1Packet204ClientInfo)
    1101        {
    1102            this.playerEntity.updateClientInfo(par1Packet204ClientInfo);
    1103        }
    1104
    1105        public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload)
    1106        {
    1107            FMLNetworkHandler.handlePacket250Packet(par1Packet250CustomPayload, netManager, this);
    1108        }
    1109
    1110        public void handleVanilla250Packet(Packet250CustomPayload par1Packet250CustomPayload)
    1111        {
    1112            DataInputStream var2;
    1113            ItemStack var3;
    1114            ItemStack var4;
    1115
    1116            if ("MC|BEdit".equals(par1Packet250CustomPayload.channel))
    1117            {
    1118                try
    1119                {
    1120                    var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1121                    var3 = Packet.readItemStack(var2);
    1122
    1123                    if (!ItemWritableBook.validBookTagPages(var3.getTagCompound()))
    1124                    {
    1125                        throw new IOException("Invalid book tag!");
    1126                    }
    1127
    1128                    var4 = this.playerEntity.inventory.getCurrentItem();
    1129
    1130                    if (var3 != null && var3.itemID == Item.writableBook.shiftedIndex && var3.itemID == var4.itemID)
    1131                    {
    1132                        var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages"));
    1133                    }
    1134                }
    1135                catch (Exception var12)
    1136                {
    1137                    var12.printStackTrace();
    1138                }
    1139            }
    1140            else if ("MC|BSign".equals(par1Packet250CustomPayload.channel))
    1141            {
    1142                try
    1143                {
    1144                    var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1145                    var3 = Packet.readItemStack(var2);
    1146
    1147                    if (!ItemEditableBook.validBookTagContents(var3.getTagCompound()))
    1148                    {
    1149                        throw new IOException("Invalid book tag!");
    1150                    }
    1151
    1152                    var4 = this.playerEntity.inventory.getCurrentItem();
    1153
    1154                    if (var3 != null && var3.itemID == Item.writtenBook.shiftedIndex && var4.itemID == Item.writableBook.shiftedIndex)
    1155                    {
    1156                        var4.setTagInfo("author", new NBTTagString("author", this.playerEntity.username));
    1157                        var4.setTagInfo("title", new NBTTagString("title", var3.getTagCompound().getString("title")));
    1158                        var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages"));
    1159                        var4.itemID = Item.writtenBook.shiftedIndex;
    1160                    }
    1161                }
    1162                catch (Exception var11)
    1163                {
    1164                    var11.printStackTrace();
    1165                }
    1166            }
    1167            else
    1168            {
    1169                int var14;
    1170
    1171                if ("MC|TrSel".equals(par1Packet250CustomPayload.channel))
    1172                {
    1173                    try
    1174                    {
    1175                        var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1176                        var14 = var2.readInt();
    1177                        Container var15 = this.playerEntity.openContainer;
    1178
    1179                        if (var15 instanceof ContainerMerchant)
    1180                        {
    1181                            ((ContainerMerchant)var15).setCurrentRecipeIndex(var14);
    1182                        }
    1183                    }
    1184                    catch (Exception var10)
    1185                    {
    1186                        var10.printStackTrace();
    1187                    }
    1188                }
    1189                else
    1190                {
    1191                    int var18;
    1192
    1193                    if ("MC|AdvCdm".equals(par1Packet250CustomPayload.channel))
    1194                    {
    1195                        if (!this.mcServer.isCommandBlockEnabled())
    1196                        {
    1197                            this.playerEntity.sendChatToPlayer(this.playerEntity.translateString("advMode.notEnabled", new Object[0]));
    1198                        }
    1199                        else if (this.playerEntity.canCommandSenderUseCommand(2, "") && this.playerEntity.capabilities.isCreativeMode)
    1200                        {
    1201                            try
    1202                            {
    1203                                var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1204                                var14 = var2.readInt();
    1205                                var18 = var2.readInt();
    1206                                int var5 = var2.readInt();
    1207                                String var6 = Packet.readString(var2, 256);
    1208                                TileEntity var7 = this.playerEntity.worldObj.getBlockTileEntity(var14, var18, var5);
    1209
    1210                                if (var7 != null && var7 instanceof TileEntityCommandBlock)
    1211                                {
    1212                                    ((TileEntityCommandBlock)var7).setCommand(var6);
    1213                                    this.playerEntity.worldObj.markBlockForUpdate(var14, var18, var5);
    1214                                    this.playerEntity.sendChatToPlayer("Command set: " + var6);
    1215                                }
    1216                            }
    1217                            catch (Exception var9)
    1218                            {
    1219                                var9.printStackTrace();
    1220                            }
    1221                        }
    1222                        else
    1223                        {
    1224                            this.playerEntity.sendChatToPlayer(this.playerEntity.translateString("advMode.notAllowed", new Object[0]));
    1225                        }
    1226                    }
    1227                    else if ("MC|Beacon".equals(par1Packet250CustomPayload.channel))
    1228                    {
    1229                        if (this.playerEntity.openContainer instanceof ContainerBeacon)
    1230                        {
    1231                            try
    1232                            {
    1233                                var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1234                                var14 = var2.readInt();
    1235                                var18 = var2.readInt();
    1236                                ContainerBeacon var17 = (ContainerBeacon)this.playerEntity.openContainer;
    1237                                Slot var19 = var17.getSlot(0);
    1238
    1239                                if (var19.getHasStack())
    1240                                {
    1241                                    var19.decrStackSize(1);
    1242                                    TileEntityBeacon var20 = var17.getBeacon();
    1243                                    var20.func_82128_d(var14);
    1244                                    var20.func_82127_e(var18);
    1245                                    var20.onInventoryChanged();
    1246                                }
    1247                            }
    1248                            catch (Exception var8)
    1249                            {
    1250                                var8.printStackTrace();
    1251                            }
    1252                        }
    1253                    }
    1254                    else if ("MC|ItemName".equals(par1Packet250CustomPayload.channel) && this.playerEntity.openContainer instanceof ContainerRepair)
    1255                    {
    1256                        ContainerRepair var13 = (ContainerRepair)this.playerEntity.openContainer;
    1257
    1258                        if (par1Packet250CustomPayload.data != null && par1Packet250CustomPayload.data.length >= 1)
    1259                        {
    1260                            String var16 = ChatAllowedCharacters.filerAllowedCharacters(new String(par1Packet250CustomPayload.data));
    1261
    1262                            if (var16.length() <= 30)
    1263                            {
    1264                                var13.func_82850_a(var16);
    1265                            }
    1266                        }
    1267                        else
    1268                        {
    1269                            var13.func_82850_a("");
    1270                        }
    1271                    }
    1272                }
    1273            }
    1274        }
    1275
    1276
    1277        @Override
    1278
    1279        /**
    1280         * Contains logic for handling packets containing arbitrary unique item data. Currently this is only for maps.
    1281         */
    1282        public void handleMapData(Packet131MapData par1Packet131MapData)
    1283        {
    1284            FMLNetworkHandler.handlePacket131Packet(this, par1Packet131MapData);
    1285        }
    1286
    1287        // modloader compat -- yuk!
    1288        @Override
    1289        public EntityPlayerMP getPlayer()
    1290        {
    1291            return playerEntity;
    1292        }
    1293    }