1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-12 11:10:29 +00:00

Move CommandComputer into a child package

Means we can be a little more organised where we put the additional
commands.
This commit is contained in:
SquidDev 2017-11-15 15:57:10 +00:00
parent dd5698241b
commit 2ae6fb47e7
2 changed files with 31 additions and 14 deletions

View File

@ -22,6 +22,7 @@ import dan200.computercraft.core.apis.AddressPredicate;
import dan200.computercraft.core.filesystem.ComboMount;
import dan200.computercraft.core.filesystem.FileMount;
import dan200.computercraft.core.filesystem.JarMount;
import dan200.computercraft.shared.command.CommandComputer;
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
import dan200.computercraft.shared.computer.blocks.BlockComputer;
@ -422,7 +423,7 @@ public class ComputerCraft
@Mod.EventHandler
public void onServerStarting( FMLServerStartingEvent event )
{
event.registerServerCommand( new ComputerCommand() );
event.registerServerCommand( new CommandComputer() );
}
@Mod.EventHandler

View File

@ -1,5 +1,6 @@
package dan200.computercraft;
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;
@ -8,37 +9,52 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import org.apache.commons.lang3.ArrayUtils;
public class ComputerCommand extends CommandBase {
import javax.annotation.Nonnull;
public class CommandComputer extends CommandBase
{
@Override
public String getName() {
@Nonnull
public String getName()
{
return "computer";
}
@Override
public String getUsage(ICommandSender iCommandSender) {
@Nonnull
public String getUsage( @Nonnull ICommandSender sender )
{
return "computer <id> <value1> [value2]...";
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if( args.length < 2 ){
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 ){
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 ){
else
{
throw new CommandException( "Computer #" + args[ 0 ] + " is not a Command Computer" );
}
}
catch( NumberFormatException e )
{
throw new CommandException( "Invalid ID" );
}
}
@Override
public int getRequiredPermissionLevel(){
public int getRequiredPermissionLevel()
{
return 0;
}
}