001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import net.minecraft.server.MinecraftServer;
006    
007    public class TileEntityCommandBlock extends TileEntity implements ICommandSender
008    {
009        private String field_82354_a = "";
010    
011        public void func_82352_b(String par1Str)
012        {
013            this.field_82354_a = par1Str;
014            this.onInventoryChanged();
015        }
016    
017        @SideOnly(Side.CLIENT)
018    
019        /**
020         * Return the command this command block is set to execute.
021         */
022        public String getCommand()
023        {
024            return this.field_82354_a;
025        }
026    
027        /**
028         * Execute the command, called when the command block is powered.
029         */
030        public void executeCommandOnPowered(World par1World)
031        {
032            if (!par1World.isRemote)
033            {
034                MinecraftServer var2 = MinecraftServer.getServer();
035    
036                if (var2 != null && var2.isCommandBlockEnabled())
037                {
038                    ICommandManager var3 = var2.getCommandManager();
039                    var3.executeCommand(this, this.field_82354_a);
040                }
041            }
042        }
043    
044        /**
045         * Gets the name of this command sender (usually username, but possibly "Rcon")
046         */
047        public String getCommandSenderName()
048        {
049            return "@";
050        }
051    
052        public void sendChatToPlayer(String par1Str) {}
053    
054        /**
055         * Returns true if the command sender is allowed to use the given command.
056         */
057        public boolean canCommandSenderUseCommand(int par1, String par2Str)
058        {
059            return par1 <= 2;
060        }
061    
062        /**
063         * Translates and formats the given string key with the given arguments.
064         */
065        public String translateString(String par1Str, Object ... par2ArrayOfObj)
066        {
067            return par1Str;
068        }
069    
070        /**
071         * Writes a tile entity to NBT.
072         */
073        public void writeToNBT(NBTTagCompound par1NBTTagCompound)
074        {
075            super.writeToNBT(par1NBTTagCompound);
076            par1NBTTagCompound.setString("Command", this.field_82354_a);
077        }
078    
079        /**
080         * Reads a tile entity from NBT.
081         */
082        public void readFromNBT(NBTTagCompound par1NBTTagCompound)
083        {
084            super.readFromNBT(par1NBTTagCompound);
085            this.field_82354_a = par1NBTTagCompound.getString("Command");
086        }
087    
088        /**
089         * Return the coordinates for this player as ChunkCoordinates.
090         */
091        public ChunkCoordinates getPlayerCoordinates()
092        {
093            return new ChunkCoordinates(this.xCoord, this.yCoord, this.zCoord);
094        }
095    
096        /**
097         * Overriden in a sign to provide the text.
098         */
099        public Packet getDescriptionPacket()
100        {
101            NBTTagCompound var1 = new NBTTagCompound();
102            this.writeToNBT(var1);
103            return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 2, var1);
104        }
105    }