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