1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-06-03 23:24:11 +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.ComboMount;
import dan200.computercraft.core.filesystem.FileMount; import dan200.computercraft.core.filesystem.FileMount;
import dan200.computercraft.core.filesystem.JarMount; import dan200.computercraft.core.filesystem.JarMount;
import dan200.computercraft.shared.command.CommandComputer;
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider; import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
import dan200.computercraft.shared.computer.blocks.BlockCommandComputer; import dan200.computercraft.shared.computer.blocks.BlockCommandComputer;
import dan200.computercraft.shared.computer.blocks.BlockComputer; import dan200.computercraft.shared.computer.blocks.BlockComputer;
@ -422,7 +423,7 @@ public class ComputerCraft
@Mod.EventHandler @Mod.EventHandler
public void onServerStarting( FMLServerStartingEvent event ) public void onServerStarting( FMLServerStartingEvent event )
{ {
event.registerServerCommand( new ComputerCommand() ); event.registerServerCommand( new CommandComputer() );
} }
@Mod.EventHandler @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.ComputerFamily;
import dan200.computercraft.shared.computer.core.ServerComputer; import dan200.computercraft.shared.computer.core.ServerComputer;
import net.minecraft.command.CommandBase; import net.minecraft.command.CommandBase;
@ -8,37 +9,52 @@ import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
public class ComputerCommand extends CommandBase { import javax.annotation.Nonnull;
public class CommandComputer extends CommandBase
{
@Override @Override
public String getName() { @Nonnull
public String getName()
{
return "computer"; return "computer";
} }
@Override @Override
public String getUsage(ICommandSender iCommandSender) { @Nonnull
public String getUsage( @Nonnull ICommandSender sender )
{
return "computer <id> <value1> [value2]..."; return "computer <id> <value1> [value2]...";
} }
@Override @Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { public void execute( @Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args ) throws CommandException
if( args.length < 2 ){ {
if( args.length < 2 )
{
throw new CommandException( "Usage: /computer <id> <value1> [value2]..." ); throw new CommandException( "Usage: /computer <id> <value1> [value2]..." );
} }
try { try
ServerComputer computer = ComputerCraft.serverComputerRegistry.lookup(Integer.valueOf(args[0])); {
if( computer != null && computer.getFamily() == ComputerFamily.Command ){ ServerComputer computer = ComputerCraft.serverComputerRegistry.lookup( Integer.valueOf( args[ 0 ] ) );
if( computer != null && computer.getFamily() == ComputerFamily.Command )
{
computer.queueEvent( "computer_command", ArrayUtils.remove( args, 0 ) ); 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" ); throw new CommandException( "Invalid ID" );
} }
} }
@Override @Override
public int getRequiredPermissionLevel(){ public int getRequiredPermissionLevel()
{
return 0; return 0;
} }
} }