    001package net.minecraft.network;
    002
    003import java.io.ByteArrayInputStream;
    004import java.io.DataInputStream;
    005import java.io.IOException;
    006import java.util.ArrayList;
    007import java.util.Iterator;
    008import java.util.Random;
    009import java.util.logging.Logger;
    010
    011import cpw.mods.fml.common.network.FMLNetworkHandler;
    012import net.minecraft.entity.Entity;
    013import net.minecraft.entity.item.EntityItem;
    014import net.minecraft.entity.player.EntityPlayerMP;
    015import net.minecraft.entity.player.InventoryPlayer;
    016import net.minecraft.inventory.Container;
    017import net.minecraft.inventory.ContainerBeacon;
    018import net.minecraft.inventory.ContainerMerchant;
    019import net.minecraft.inventory.ContainerRepair;
    020import net.minecraft.inventory.Slot;
    021import net.minecraft.item.Item;
    022import net.minecraft.item.ItemEditableBook;
    023import net.minecraft.item.ItemStack;
    024import net.minecraft.item.ItemWritableBook;
    025import net.minecraft.nbt.NBTTagString;
    026import net.minecraft.network.packet.NetHandler;
    027import net.minecraft.network.packet.Packet;
    028import net.minecraft.network.packet.Packet0KeepAlive;
    029import net.minecraft.network.packet.Packet101CloseWindow;
    030import net.minecraft.network.packet.Packet102WindowClick;
    031import net.minecraft.network.packet.Packet103SetSlot;
    032import net.minecraft.network.packet.Packet106Transaction;
    033import net.minecraft.network.packet.Packet107CreativeSetSlot;
    034import net.minecraft.network.packet.Packet108EnchantItem;
    035import net.minecraft.network.packet.Packet10Flying;
    036import net.minecraft.network.packet.Packet130UpdateSign;
    037import net.minecraft.network.packet.Packet131MapData;
    038import net.minecraft.network.packet.Packet13PlayerLookMove;
    039import net.minecraft.network.packet.Packet14BlockDig;
    040import net.minecraft.network.packet.Packet15Place;
    041import net.minecraft.network.packet.Packet16BlockItemSwitch;
    042import net.minecraft.network.packet.Packet18Animation;
    043import net.minecraft.network.packet.Packet19EntityAction;
    044import net.minecraft.network.packet.Packet202PlayerAbilities;
    045import net.minecraft.network.packet.Packet203AutoComplete;
    046import net.minecraft.network.packet.Packet204ClientInfo;
    047import net.minecraft.network.packet.Packet205ClientCommand;
    048import net.minecraft.network.packet.Packet250CustomPayload;
    049import net.minecraft.network.packet.Packet255KickDisconnect;
    050import net.minecraft.network.packet.Packet3Chat;
    051import net.minecraft.network.packet.Packet53BlockChange;
    052import net.minecraft.network.packet.Packet7UseEntity;
    053import net.minecraft.network.packet.Packet9Respawn;
    054import net.minecraft.server.MinecraftServer;
    055import net.minecraft.server.management.BanEntry;
    056import net.minecraft.tileentity.TileEntity;
    057import net.minecraft.tileentity.TileEntityBeacon;
    058import net.minecraft.tileentity.TileEntityCommandBlock;
    059import net.minecraft.tileentity.TileEntitySign;
    060import net.minecraft.util.AxisAlignedBB;
    061import net.minecraft.util.ChatAllowedCharacters;
    062import net.minecraft.util.ChunkCoordinates;
    063import net.minecraft.util.IntHashMap;
    064import net.minecraft.util.MathHelper;
    065import net.minecraft.world.WorldServer;
    066
    067import net.minecraftforge.common.MinecraftForge;
    068import net.minecraftforge.event.Event;
    069import net.minecraftforge.event.ForgeEventFactory;
    070import net.minecraftforge.event.ServerChatEvent;
    071import net.minecraftforge.event.entity.player.PlayerInteractEvent;
    072import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
    073
    074public 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                //Change min->max, fixes movement speed check
    323                double var19 = Math.max(Math.abs(var13), Math.abs(this.playerEntity.motionX));
    324                double var21 = Math.max(Math.abs(var15), Math.abs(this.playerEntity.motionY));
    325                double var23 = Math.max(Math.abs(var17), Math.abs(this.playerEntity.motionZ));
    326                double var25 = var19 * var19 + var21 * var21 + var23 * var23;
    327
    328                if (var25 > 100.0D && (!this.mcServer.isSinglePlayer() || !this.mcServer.getServerOwner().equals(this.playerEntity.username)))
    329                {
    330                    logger.warning(this.playerEntity.username + " moved too quickly! " + var13 + "," + var15 + "," + var17 + " (" + var19 + ", " + var21 + ", " + var23 + ")");
    331                    this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, this.playerEntity.rotationYaw, this.playerEntity.rotationPitch);
    332                    return;
    333                }
    334
    335                float var27 = 0.0625F;
    336                boolean var28 = var2.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)var27, (double)var27, (double)var27)).isEmpty();
    337
    338                if (this.playerEntity.onGround && !par1Packet10Flying.onGround && var15 > 0.0D)
    339                {
    340                    this.playerEntity.addExhaustion(0.2F);
    341                }
    342
    343                if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
    344                {
    345                    return;
    346                }
    347
    348                this.playerEntity.moveEntity(var13, var15, var17);
    349                this.playerEntity.onGround = par1Packet10Flying.onGround;
    350                this.playerEntity.addMovementStat(var13, var15, var17);
    351                double var29 = var15;
    352                var13 = var5 - this.playerEntity.posX;
    353                var15 = var7 - this.playerEntity.posY;
    354
    355                if (var15 > -0.5D || var15 < 0.5D)
    356                {
    357                    var15 = 0.0D;
    358                }
    359
    360                var17 = var9 - this.playerEntity.posZ;
    361                var25 = var13 * var13 + var15 * var15 + var17 * var17;
    362                boolean var31 = false;
    363
    364                if (var25 > 0.0625D && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.theItemInWorldManager.isCreative())
    365                {
    366                    var31 = true;
    367                    logger.warning(this.playerEntity.username + " moved wrongly!");
    368                }
    369
    370                if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
    371                {
    372                    return;
    373                }
    374
    375                this.playerEntity.setPositionAndRotation(var5, var7, var9, var11, var12);
    376                boolean var32 = var2.getCollidingBoundingBoxes(this.playerEntity, this.playerEntity.boundingBox.copy().contract((double)var27, (double)var27, (double)var27)).isEmpty();
    377
    378                if (var28 && (var31 || !var32) && !this.playerEntity.isPlayerSleeping() && !this.playerEntity.noClip)
    379                {
    380                    this.setPlayerLocation(this.lastPosX, this.lastPosY, this.lastPosZ, var11, var12);
    381                    return;
    382                }
    383
    384                AxisAlignedBB var33 = this.playerEntity.boundingBox.copy().expand((double)var27, (double)var27, (double)var27).addCoord(0.0D, -0.55D, 0.0D);
    385
    386                if (!this.mcServer.isFlightAllowed() && !this.playerEntity.theItemInWorldManager.isCreative() && !var2.isAABBNonEmpty(var33)  && !this.playerEntity.capabilities.allowFlying)
    387                {
    388                    if (var29 >= -0.03125D)
    389                    {
    390                        ++this.ticksForFloatKick;
    391
    392                        if (this.ticksForFloatKick > 80)
    393                        {
    394                            logger.warning(this.playerEntity.username + " was kicked for floating too long!");
    395                            this.kickPlayerFromServer("Flying is not enabled on this server");
    396                            return;
    397                        }
    398                    }
    399                }
    400                else
    401                {
    402                    this.ticksForFloatKick = 0;
    403                }
    404
    405                if (!this.hasMoved) //Fixes "Moved Too Fast" kick when being teleported while moving
    406                {
    407                    return;
    408                }
    409
    410                this.playerEntity.onGround = par1Packet10Flying.onGround;
    411                this.mcServer.getConfigurationManager().serverUpdateMountedMovingPlayer(this.playerEntity);
    412                this.playerEntity.updateFlyingState(this.playerEntity.posY - var3, par1Packet10Flying.onGround);
    413            }
    414        }
    415    }
    416
    417    /**
    418     * Moves the player to the specified destination and rotation
    419     */
    420    public void setPlayerLocation(double par1, double par3, double par5, float par7, float par8)
    421    {
    422        this.hasMoved = false;
    423        this.lastPosX = par1;
    424        this.lastPosY = par3;
    425        this.lastPosZ = par5;
    426        this.playerEntity.setPositionAndRotation(par1, par3, par5, par7, par8);
    427        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet13PlayerLookMove(par1, par3 + 1.6200000047683716D, par3, par5, par7, par8, false));
    428    }
    429
    430    public void handleBlockDig(Packet14BlockDig par1Packet14BlockDig)
    431    {
    432        WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    433
    434        if (par1Packet14BlockDig.status == 4)
    435        {
    436            this.playerEntity.dropOneItem(false);
    437        }
    438        else if (par1Packet14BlockDig.status == 3)
    439        {
    440            this.playerEntity.dropOneItem(true);
    441        }
    442        else if (par1Packet14BlockDig.status == 5)
    443        {
    444            this.playerEntity.stopUsingItem();
    445        }
    446        else
    447        {
    448            int var3 = this.mcServer.getSpawnProtectionSize();
    449            boolean var4 = var2.provider.dimensionId != 0 || this.mcServer.getConfigurationManager().getOps().isEmpty() || this.mcServer.getConfigurationManager().areCommandsAllowed(this.playerEntity.username) || var3 <= 0 || this.mcServer.isSinglePlayer();
    450            boolean var5 = false;
    451
    452            if (par1Packet14BlockDig.status == 0)
    453            {
    454                var5 = true;
    455            }
    456
    457            if (par1Packet14BlockDig.status == 1)
    458            {
    459                var5 = true;
    460            }
    461
    462            if (par1Packet14BlockDig.status == 2)
    463            {
    464                var5 = true;
    465            }
    466
    467            int var6 = par1Packet14BlockDig.xPosition;
    468            int var7 = par1Packet14BlockDig.yPosition;
    469            int var8 = par1Packet14BlockDig.zPosition;
    470
    471            if (var5)
    472            {
    473                double var9 = this.playerEntity.posX - ((double)var6 + 0.5D);
    474                double var11 = this.playerEntity.posY - ((double)var7 + 0.5D) + 1.5D;
    475                double var13 = this.playerEntity.posZ - ((double)var8 + 0.5D);
    476                double var15 = var9 * var9 + var11 * var11 + var13 * var13;
    477
    478                double dist = playerEntity.theItemInWorldManager.getBlockReachDistance() + 1;
    479                dist *= dist;
    480
    481                if (var15 > dist)
    482                {
    483                    return;
    484                }
    485
    486                if (var7 >= this.mcServer.getBuildLimit())
    487                {
    488                    return;
    489                }
    490            }
    491
    492            ChunkCoordinates var17 = var2.getSpawnPoint();
    493            int var10 = MathHelper.abs_int(var6 - var17.posX);
    494            int var18 = MathHelper.abs_int(var8 - var17.posZ);
    495
    496            if (var10 > var18)
    497            {
    498                var18 = var10;
    499            }
    500
    501            if (par1Packet14BlockDig.status == 0)
    502            {
    503                if (var18 <= var3 && !var4)
    504                {
    505                    ForgeEventFactory.onPlayerInteract(playerEntity, Action.LEFT_CLICK_BLOCK, var6, var7, var8, 0);
    506                    this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var6, var7, var8, var2));
    507                }
    508                else
    509                {
    510                    this.playerEntity.theItemInWorldManager.onBlockClicked(var6, var7, var8, par1Packet14BlockDig.face);
    511                }
    512            }
    513            else if (par1Packet14BlockDig.status == 2)
    514            {
    515                this.playerEntity.theItemInWorldManager.uncheckedTryHarvestBlock(var6, var7, var8);
    516
    517                if (var2.getBlockId(var6, var7, var8) != 0)
    518                {
    519                    this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var6, var7, var8, var2));
    520                }
    521            }
    522            else if (par1Packet14BlockDig.status == 1)
    523            {
    524                this.playerEntity.theItemInWorldManager.cancelDestroyingBlock(var6, var7, var8);
    525
    526                if (var2.getBlockId(var6, var7, var8) != 0)
    527                {
    528                    this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet53BlockChange(var6, var7, var8, var2));
    529                }
    530            }
    531        }
    532    }
    533
    534    public void handlePlace(Packet15Place par1Packet15Place)
    535    {
    536        WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    537        ItemStack var3 = this.playerEntity.inventory.getCurrentItem();
    538        boolean var4 = false;
    539        int var5 = par1Packet15Place.getXPosition();
    540        int var6 = par1Packet15Place.getYPosition();
    541        int var7 = par1Packet15Place.getZPosition();
    542        int var8 = par1Packet15Place.getDirection();
    543        int var9 = this.mcServer.getSpawnProtectionSize();
    544        boolean var10 = var2.provider.dimensionId != 0 || this.mcServer.getConfigurationManager().getOps().isEmpty() || this.mcServer.getConfigurationManager().areCommandsAllowed(this.playerEntity.username) || var9 <= 0 || 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 var11 = var2.getSpawnPoint();
    567            int var12 = MathHelper.abs_int(var5 - var11.posX);
    568            int var13 = MathHelper.abs_int(var7 - var11.posZ);
    569
    570            if (var12 > var13)
    571            {
    572                var13 = var12;
    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 && (var13 > var9 || var10))
    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 var14 = this.playerEntity.openContainer.getSlotFromInventory(this.playerEntity.inventory, this.playerEntity.inventory.currentItem);
    635            this.playerEntity.openContainer.detectAndSendChanges();
    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, var14.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.getIsServer())
    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.getHotbarSize())
    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     * If this returns false, all packets will be queued for the main thread to handle, even if they would otherwise be
    887     * processed asynchronously. Used to avoid processing packets on the client before the world has been downloaded
    888     * (which happens on the main thread)
    889     */
    890    public boolean canProcessPacketsAsync()
    891    {
    892        return true;
    893    }
    894
    895    /**
    896     * respawns the player
    897     */
    898    public void handleRespawn(Packet9Respawn par1Packet9Respawn) {}
    899
    900    public void handleCloseWindow(Packet101CloseWindow par1Packet101CloseWindow)
    901    {
    902        this.playerEntity.closeInventory();
    903    }
    904
    905    public void handleWindowClick(Packet102WindowClick par1Packet102WindowClick)
    906    {
    907        if (this.playerEntity.openContainer.windowId == par1Packet102WindowClick.window_Id && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    908        {
    909            ItemStack var2 = this.playerEntity.openContainer.slotClick(par1Packet102WindowClick.inventorySlot, par1Packet102WindowClick.mouseClick, par1Packet102WindowClick.holdingShift, this.playerEntity);
    910
    911            if (ItemStack.areItemStacksEqual(par1Packet102WindowClick.itemStack, var2))
    912            {
    913                this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet106Transaction(par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, true));
    914                this.playerEntity.playerInventoryBeingManipulated = true;
    915                this.playerEntity.openContainer.detectAndSendChanges();
    916                this.playerEntity.updateHeldItem();
    917                this.playerEntity.playerInventoryBeingManipulated = false;
    918            }
    919            else
    920            {
    921                this.field_72586_s.addKey(this.playerEntity.openContainer.windowId, Short.valueOf(par1Packet102WindowClick.action));
    922                this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet106Transaction(par1Packet102WindowClick.window_Id, par1Packet102WindowClick.action, false));
    923                this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, false);
    924                ArrayList var3 = new ArrayList();
    925
    926                for (int var4 = 0; var4 < this.playerEntity.openContainer.inventorySlots.size(); ++var4)
    927                {
    928                    var3.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(var4)).getStack());
    929                }
    930
    931                this.playerEntity.sendContainerAndContentsToPlayer(this.playerEntity.openContainer, var3);
    932            }
    933        }
    934    }
    935
    936    public void handleEnchantItem(Packet108EnchantItem par1Packet108EnchantItem)
    937    {
    938        if (this.playerEntity.openContainer.windowId == par1Packet108EnchantItem.windowId && this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    939        {
    940            this.playerEntity.openContainer.enchantItem(this.playerEntity, par1Packet108EnchantItem.enchantment);
    941            this.playerEntity.openContainer.detectAndSendChanges();
    942        }
    943    }
    944
    945    /**
    946     * Handle a creative slot packet.
    947     */
    948    public void handleCreativeSetSlot(Packet107CreativeSetSlot par1Packet107CreativeSetSlot)
    949    {
    950        if (this.playerEntity.theItemInWorldManager.isCreative())
    951        {
    952            boolean var2 = par1Packet107CreativeSetSlot.slot < 0;
    953            ItemStack var3 = par1Packet107CreativeSetSlot.itemStack;
    954            boolean var4 = par1Packet107CreativeSetSlot.slot >= 1 && par1Packet107CreativeSetSlot.slot < 36 + InventoryPlayer.getHotbarSize();
    955            boolean var5 = var3 == null || var3.itemID < Item.itemsList.length && var3.itemID >= 0 && Item.itemsList[var3.itemID] != null;
    956            boolean var6 = var3 == null || var3.getItemDamage() >= 0 && var3.getItemDamage() >= 0 && var3.stackSize <= 64 && var3.stackSize > 0;
    957
    958            if (var4 && var5 && var6)
    959            {
    960                if (var3 == null)
    961                {
    962                    this.playerEntity.inventoryContainer.putStackInSlot(par1Packet107CreativeSetSlot.slot, (ItemStack)null);
    963                }
    964                else
    965                {
    966                    this.playerEntity.inventoryContainer.putStackInSlot(par1Packet107CreativeSetSlot.slot, var3);
    967                }
    968
    969                this.playerEntity.inventoryContainer.setPlayerIsPresent(this.playerEntity, true);
    970            }
    971            else if (var2 && var5 && var6 && this.creativeItemCreationSpamThresholdTally < 200)
    972            {
    973                this.creativeItemCreationSpamThresholdTally += 20;
    974                EntityItem var7 = this.playerEntity.dropPlayerItem(var3);
    975
    976                if (var7 != null)
    977                {
    978                    var7.func_70288_d();
    979                }
    980            }
    981        }
    982    }
    983
    984    public void handleTransaction(Packet106Transaction par1Packet106Transaction)
    985    {
    986        Short var2 = (Short)this.field_72586_s.lookup(this.playerEntity.openContainer.windowId);
    987
    988        if (var2 != null && par1Packet106Transaction.shortWindowId == var2.shortValue() && this.playerEntity.openContainer.windowId == par1Packet106Transaction.windowId && !this.playerEntity.openContainer.isPlayerNotUsingContainer(this.playerEntity))
    989        {
    990            this.playerEntity.openContainer.setPlayerIsPresent(this.playerEntity, true);
    991        }
    992    }
    993
    994    /**
    995     * Updates Client side signs
    996     */
    997    public void handleUpdateSign(Packet130UpdateSign par1Packet130UpdateSign)
    998    {
    999        WorldServer var2 = this.mcServer.worldServerForDimension(this.playerEntity.dimension);
    1000
    1001        if (var2.blockExists(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition))
    1002        {
    1003            TileEntity var3 = var2.getBlockTileEntity(par1Packet130UpdateSign.xPosition, par1Packet130UpdateSign.yPosition, par1Packet130UpdateSign.zPosition);
    1004
    1005            if (var3 instanceof TileEntitySign)
    1006            {
    1007                TileEntitySign var4 = (TileEntitySign)var3;
    1008
    1009                if (!var4.isEditable())
    1010                {
    1011                    this.mcServer.logWarning("Player " + this.playerEntity.username + " just tried to change non-editable sign");
    1012                    return;
    1013                }
    1014            }
    1015
    1016            int var6;
    1017            int var8;
    1018
    1019            for (var8 = 0; var8 < 4; ++var8)
    1020            {
    1021                boolean var5 = true;
    1022
    1023                if (par1Packet130UpdateSign.signLines[var8].length() > 15)
    1024                {
    1025                    var5 = false;
    1026                }
    1027                else
    1028                {
    1029                    for (var6 = 0; var6 < par1Packet130UpdateSign.signLines[var8].length(); ++var6)
    1030                    {
    1031                        if (ChatAllowedCharacters.allowedCharacters.indexOf(par1Packet130UpdateSign.signLines[var8].charAt(var6)) < 0)
    1032                        {
    1033                            var5 = false;
    1034                        }
    1035                    }
    1036                }
    1037
    1038                if (!var5)
    1039                {
    1040                    par1Packet130UpdateSign.signLines[var8] = "!?";
    1041                }
    1042            }
    1043
    1044            if (var3 instanceof TileEntitySign)
    1045            {
    1046                var8 = par1Packet130UpdateSign.xPosition;
    1047                int var9 = par1Packet130UpdateSign.yPosition;
    1048                var6 = par1Packet130UpdateSign.zPosition;
    1049                TileEntitySign var7 = (TileEntitySign)var3;
    1050                System.arraycopy(par1Packet130UpdateSign.signLines, 0, var7.signText, 0, 4);
    1051                var7.onInventoryChanged();
    1052                var2.markBlockForUpdate(var8, var9, var6);
    1053            }
    1054        }
    1055    }
    1056
    1057    /**
    1058     * Handle a keep alive packet.
    1059     */
    1060    public void handleKeepAlive(Packet0KeepAlive par1Packet0KeepAlive)
    1061    {
    1062        if (par1Packet0KeepAlive.randomId == this.keepAliveRandomID)
    1063        {
    1064            int var2 = (int)(System.nanoTime() / 1000000L - this.keepAliveTimeSent);
    1065            this.playerEntity.ping = (this.playerEntity.ping * 3 + var2) / 4;
    1066        }
    1067    }
    1068
    1069    /**
    1070     * determine if it is a server handler
    1071     */
    1072    public boolean isServerHandler()
    1073    {
    1074        return true;
    1075    }
    1076
    1077    /**
    1078     * Handle a player abilities packet.
    1079     */
    1080    public void handlePlayerAbilities(Packet202PlayerAbilities par1Packet202PlayerAbilities)
    1081    {
    1082        this.playerEntity.capabilities.isFlying = par1Packet202PlayerAbilities.getFlying() && this.playerEntity.capabilities.allowFlying;
    1083    }
    1084
    1085    public void handleAutoComplete(Packet203AutoComplete par1Packet203AutoComplete)
    1086    {
    1087        StringBuilder var2 = new StringBuilder();
    1088        String var4;
    1089
    1090        for (Iterator var3 = this.mcServer.getPossibleCompletions(this.playerEntity, par1Packet203AutoComplete.getText()).iterator(); var3.hasNext(); var2.append(var4))
    1091        {
    1092            var4 = (String)var3.next();
    1093
    1094            if (var2.length() > 0)
    1095            {
    1096                var2.append("\u0000");
    1097            }
    1098        }
    1099
    1100        this.playerEntity.playerNetServerHandler.sendPacketToPlayer(new Packet203AutoComplete(var2.toString()));
    1101    }
    1102
    1103    public void handleClientInfo(Packet204ClientInfo par1Packet204ClientInfo)
    1104    {
    1105        this.playerEntity.updateClientInfo(par1Packet204ClientInfo);
    1106    }
    1107
    1108    public void handleCustomPayload(Packet250CustomPayload par1Packet250CustomPayload)
    1109    {
    1110        FMLNetworkHandler.handlePacket250Packet(par1Packet250CustomPayload, netManager, this);
    1111    }
    1112
    1113    public void handleVanilla250Packet(Packet250CustomPayload par1Packet250CustomPayload)
    1114    {
    1115        DataInputStream var2;
    1116        ItemStack var3;
    1117        ItemStack var4;
    1118
    1119        if ("MC|BEdit".equals(par1Packet250CustomPayload.channel))
    1120        {
    1121            try
    1122            {
    1123                var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1124                var3 = Packet.readItemStack(var2);
    1125
    1126                if (!ItemWritableBook.validBookTagPages(var3.getTagCompound()))
    1127                {
    1128                    throw new IOException("Invalid book tag!");
    1129                }
    1130
    1131                var4 = this.playerEntity.inventory.getCurrentItem();
    1132
    1133                if (var3 != null && var3.itemID == Item.writableBook.itemID && var3.itemID == var4.itemID)
    1134                {
    1135                    var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages"));
    1136                }
    1137            }
    1138            catch (Exception var12)
    1139            {
    1140                var12.printStackTrace();
    1141            }
    1142        }
    1143        else if ("MC|BSign".equals(par1Packet250CustomPayload.channel))
    1144        {
    1145            try
    1146            {
    1147                var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1148                var3 = Packet.readItemStack(var2);
    1149
    1150                if (!ItemEditableBook.validBookTagContents(var3.getTagCompound()))
    1151                {
    1152                    throw new IOException("Invalid book tag!");
    1153                }
    1154
    1155                var4 = this.playerEntity.inventory.getCurrentItem();
    1156
    1157                if (var3 != null && var3.itemID == Item.writtenBook.itemID && var4.itemID == Item.writableBook.itemID)
    1158                {
    1159                    var4.setTagInfo("author", new NBTTagString("author", this.playerEntity.username));
    1160                    var4.setTagInfo("title", new NBTTagString("title", var3.getTagCompound().getString("title")));
    1161                    var4.setTagInfo("pages", var3.getTagCompound().getTagList("pages"));
    1162                    var4.itemID = Item.writtenBook.itemID;
    1163                }
    1164            }
    1165            catch (Exception var11)
    1166            {
    1167                var11.printStackTrace();
    1168            }
    1169        }
    1170        else
    1171        {
    1172            int var14;
    1173
    1174            if ("MC|TrSel".equals(par1Packet250CustomPayload.channel))
    1175            {
    1176                try
    1177                {
    1178                    var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1179                    var14 = var2.readInt();
    1180                    Container var15 = this.playerEntity.openContainer;
    1181
    1182                    if (var15 instanceof ContainerMerchant)
    1183                    {
    1184                        ((ContainerMerchant)var15).setCurrentRecipeIndex(var14);
    1185                    }
    1186                }
    1187                catch (Exception var10)
    1188                {
    1189                    var10.printStackTrace();
    1190                }
    1191            }
    1192            else
    1193            {
    1194                int var18;
    1195
    1196                if ("MC|AdvCdm".equals(par1Packet250CustomPayload.channel))
    1197                {
    1198                    if (!this.mcServer.isCommandBlockEnabled())
    1199                    {
    1200                        this.playerEntity.sendChatToPlayer(this.playerEntity.translateString("advMode.notEnabled", new Object[0]));
    1201                    }
    1202                    else if (this.playerEntity.canCommandSenderUseCommand(2, "") && this.playerEntity.capabilities.isCreativeMode)
    1203                    {
    1204                        try
    1205                        {
    1206                            var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1207                            var14 = var2.readInt();
    1208                            var18 = var2.readInt();
    1209                            int var5 = var2.readInt();
    1210                            String var6 = Packet.readString(var2, 256);
    1211                            TileEntity var7 = this.playerEntity.worldObj.getBlockTileEntity(var14, var18, var5);
    1212
    1213                            if (var7 != null && var7 instanceof TileEntityCommandBlock)
    1214                            {
    1215                                ((TileEntityCommandBlock)var7).setCommand(var6);
    1216                                this.playerEntity.worldObj.markBlockForUpdate(var14, var18, var5);
    1217                                this.playerEntity.sendChatToPlayer("Command set: " + var6);
    1218                            }
    1219                        }
    1220                        catch (Exception var9)
    1221                        {
    1222                            var9.printStackTrace();
    1223                        }
    1224                    }
    1225                    else
    1226                    {
    1227                        this.playerEntity.sendChatToPlayer(this.playerEntity.translateString("advMode.notAllowed", new Object[0]));
    1228                    }
    1229                }
    1230                else if ("MC|Beacon".equals(par1Packet250CustomPayload.channel))
    1231                {
    1232                    if (this.playerEntity.openContainer instanceof ContainerBeacon)
    1233                    {
    1234                        try
    1235                        {
    1236                            var2 = new DataInputStream(new ByteArrayInputStream(par1Packet250CustomPayload.data));
    1237                            var14 = var2.readInt();
    1238                            var18 = var2.readInt();
    1239                            ContainerBeacon var17 = (ContainerBeacon)this.playerEntity.openContainer;
    1240                            Slot var19 = var17.getSlot(0);
    1241
    1242                            if (var19.getHasStack())
    1243                            {
    1244                                var19.decrStackSize(1);
    1245                                TileEntityBeacon var20 = var17.getBeacon();
    1246                                var20.func_82128_d(var14);
    1247                                var20.func_82127_e(var18);
    1248                                var20.onInventoryChanged();
    1249                            }
    1250                        }
    1251                        catch (Exception var8)
    1252                        {
    1253                            var8.printStackTrace();
    1254                        }
    1255                    }
    1256                }
    1257                else if ("MC|ItemName".equals(par1Packet250CustomPayload.channel) && this.playerEntity.openContainer instanceof ContainerRepair)
    1258                {
    1259                    ContainerRepair var13 = (ContainerRepair)this.playerEntity.openContainer;
    1260
    1261                    if (par1Packet250CustomPayload.data != null && par1Packet250CustomPayload.data.length >= 1)
    1262                    {
    1263                        String var16 = ChatAllowedCharacters.filerAllowedCharacters(new String(par1Packet250CustomPayload.data));
    1264
    1265                        if (var16.length() <= 30)
    1266                        {
    1267                            var13.updateItemName(var16);
    1268                        }
    1269                    }
    1270                    else
    1271                    {
    1272                        var13.updateItemName("");
    1273                    }
    1274                }
    1275            }
    1276        }
    1277    }
    1278
    1279
    1280    @Override
    1281
    1282    /**
    1283     * Contains logic for handling packets containing arbitrary unique item data. Currently this is only for maps.
    1284     */
    1285    public void handleMapData(Packet131MapData par1Packet131MapData)
    1286    {
    1287        FMLNetworkHandler.handlePacket131Packet(this, par1Packet131MapData);
    1288    }
    1289
    1290    // modloader compat -- yuk!
    1291    @Override
    1292    public EntityPlayerMP getPlayer()
    1293    {
    1294        return playerEntity;
    1295    }
    1296}