diff --git a/src/main/java/dan200/computercraft/ComputerCommand.java b/src/main/java/dan200/computercraft/ComputerCommand.java new file mode 100644 index 000000000..4892576fa --- /dev/null +++ b/src/main/java/dan200/computercraft/ComputerCommand.java @@ -0,0 +1,44 @@ +package dan200.computercraft; + +import dan200.computercraft.shared.computer.core.ComputerFamily; +import dan200.computercraft.shared.computer.core.ServerComputer; +import net.minecraft.command.CommandBase; +import net.minecraft.command.CommandException; +import net.minecraft.command.ICommandSender; +import net.minecraft.server.MinecraftServer; +import org.apache.commons.lang3.ArrayUtils; + +public class ComputerCommand extends CommandBase { + + @Override + public String getName() { + return "computer"; + } + + @Override + public String getUsage(ICommandSender iCommandSender) { + return "computer [value2]..."; + } + + @Override + public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + if( args.length < 2 ){ + throw new CommandException( "Usage: /computer [value2]..." ); + } + try { + ServerComputer computer = ComputerCraft.serverComputerRegistry.lookup(Integer.valueOf(args[0])); + if( computer != null && computer.getFamily() == ComputerFamily.Command ){ + computer.queueEvent( "computer_command", ArrayUtils.remove( args, 0 ) ); + }else{ + throw new CommandException( "Computer #" + args[0] + " is not a Command Computer" ); + } + }catch( NumberFormatException e ){ + throw new CommandException( "Invalid ID" ); + } + } + + @Override + public int getRequiredPermissionLevel(){ + return 0; + } +} diff --git a/src/main/java/dan200/computercraft/ComputerCraft.java b/src/main/java/dan200/computercraft/ComputerCraft.java index d5e744312..88b413c39 100644 --- a/src/main/java/dan200/computercraft/ComputerCraft.java +++ b/src/main/java/dan200/computercraft/ComputerCraft.java @@ -400,6 +400,7 @@ public class ComputerCraft @Mod.EventHandler public void onServerStarting( FMLServerStartingEvent event ) { + event.registerServerCommand( new ComputerCommand() ); } @Mod.EventHandler diff --git a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java index 508d5c9e8..dd92b319f 100644 --- a/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java +++ b/src/main/java/dan200/computercraft/shared/computer/core/ServerComputer.java @@ -39,6 +39,7 @@ public class ServerComputer extends ServerTerminal private World m_world; private BlockPos m_position; + private final ComputerFamily m_family; private final Computer m_computer; private NBTTagCompound m_userData; private boolean m_changed; @@ -54,6 +55,7 @@ public class ServerComputer extends ServerTerminal m_world = world; m_position = null; + m_family = family; m_computer = new Computer( this, getTerminal(), computerID ); m_computer.setLabel( label ); m_userData = null; @@ -63,6 +65,10 @@ public class ServerComputer extends ServerTerminal m_ticksSincePing = 0; } + public ComputerFamily getFamily(){ + return m_family; + } + public World getWorld() { return m_world;