1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-12 10:20:28 +00:00

Move the /computer command into the main computercraft command

I don't think anyone has actually ended up using this, so it's unlikely
to break anything (though do tell me if this is the case). On the flip
side, this allows us to queue events on multiple computers, and means
we can provide a little more documentation.
This commit is contained in:
SquidDev 2018-11-29 11:57:52 +00:00
parent 949b71d40c
commit 7e6eb62504
3 changed files with 30 additions and 62 deletions

View File

@ -1,60 +0,0 @@
package dan200.computercraft.shared.command;
import dan200.computercraft.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;
import javax.annotation.Nonnull;
public class CommandComputer extends CommandBase
{
@Override
@Nonnull
public String getName()
{
return "computer";
}
@Override
@Nonnull
public String getUsage( @Nonnull ICommandSender sender )
{
return "computer <id> <value1> [value2]...";
}
@Override
public void execute( @Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args ) throws CommandException
{
if( args.length < 2 )
{
throw new CommandException( "Usage: /computer <id> <value1> [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;
}
}

View File

@ -9,6 +9,7 @@ import dan200.computercraft.core.tracking.Tracking;
import dan200.computercraft.core.tracking.TrackingContext;
import dan200.computercraft.core.tracking.TrackingField;
import dan200.computercraft.shared.command.framework.*;
import dan200.computercraft.shared.computer.core.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
@ -379,6 +380,35 @@ public final class CommandComputerCraft extends CommandDelegate
}
} );
root.register( new SubCommandBase(
"queue", "<id> [args...]", "Send a computer_command event to a command computer", UserLevel.ANYONE,
"Send a computer_command event to a command computer, passing through the additional arguments. " +
"This is mostly designed for map makers, acting as a more computer-friendly version of /trigger. Any " +
"player can run the command, which would most likely be done through a text component's click event."
)
{
@Override
public void execute( @Nonnull CommandContext context, @Nonnull List<String> arguments ) throws CommandException
{
if( arguments.size() < 1 ) throw new CommandException( context.getFullUsage() );
String selector = arguments.get( 0 );
Object[] rest = arguments.subList( 1, arguments.size() ).toArray();
boolean found = false;
for( ServerComputer computer : ComputerSelector.getComputers( selector ) )
{
if( computer.getFamily() != ComputerFamily.Command || !computer.isOn() ) continue;
found = true;
computer.queueEvent( "computer_command", rest );
}
if( !found )
{
throw new CommandException( "Could not find any command computers matching " + selector );
}
}
} );
return root;
}

View File

@ -10,7 +10,6 @@ import dan200.computercraft.ComputerCraft;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.pocket.IPocketUpgrade;
import dan200.computercraft.core.computer.MainThread;
import dan200.computercraft.shared.command.CommandComputer;
import dan200.computercraft.shared.command.CommandComputerCraft;
import dan200.computercraft.shared.command.ContainerViewComputer;
import dan200.computercraft.shared.common.ColourableRecipe;
@ -131,7 +130,6 @@ public abstract class ComputerCraftProxyCommon implements IComputerCraftProxy
public void initServer( MinecraftServer server )
{
CommandHandler handler = (CommandHandler) server.getCommandManager();
handler.registerCommand( new CommandComputer() );
handler.registerCommand( new CommandComputerCraft() );
}