blob: e774dc9967dd89931d36f6d5e4ab00264c0bf240 [file] [log] [blame] [raw]
package li.cil.oc.server.component
import li.cil.oc.api.network.{Component, Message, Visibility}
import net.minecraft.tileentity.TileEntityCommandBlock
class CommandBlock(entity: TileEntityCommandBlock) extends Component {
val name = "command_block"
val visibility = Visibility.Network
componentVisibility = visibility
override def receive(message: Message) = super.receive(message).orElse {
message.data match {
case Array() if message.name == "command.value" =>
result(entity.getCommand)
case Array(value: Array[Byte]) if message.name == "command.value=" =>
entity.setCommand(new String(value, "UTF-8"))
entity.worldObj.markBlockForUpdate(entity.xCoord, entity.yCoord, entity.zCoord)
result(true)
case Array() if message.name == "command.run" =>
entity.setCommandSenderName(message.source.address.get)
result(entity.executeCommandOnPowered(entity.worldObj) != 0)
case _ => None
}
}
}