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