2019-01-01 01:10:18 +00:00
|
|
|
/*
|
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
|
2017-12-06 15:51:02 +00:00
|
|
|
package dan200.computercraft.shared.command.framework;
|
|
|
|
|
|
|
|
import dan200.computercraft.ComputerCraft;
|
|
|
|
import net.minecraft.command.CommandException;
|
|
|
|
import net.minecraft.command.ICommand;
|
|
|
|
import net.minecraft.command.ICommandSender;
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
2019-03-29 21:21:39 +00:00
|
|
|
* {@link ICommand} which delegates to a {@link ISubCommand}.
|
2017-12-06 15:51:02 +00:00
|
|
|
*/
|
|
|
|
public class CommandDelegate implements ICommand
|
|
|
|
{
|
|
|
|
private final ISubCommand command;
|
|
|
|
|
|
|
|
public CommandDelegate( ISubCommand command )
|
|
|
|
{
|
|
|
|
this.command = command;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getName()
|
|
|
|
{
|
|
|
|
return command.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getUsage( @Nonnull ICommandSender sender )
|
|
|
|
{
|
2018-02-13 11:45:13 +00:00
|
|
|
return new CommandContext( sender.getServer(), sender, command ).getFullUsage();
|
2017-12-06 15:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public List<String> getAliases()
|
|
|
|
{
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void execute( @Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args ) throws CommandException
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
command.execute( new CommandContext( server, sender, command ), Arrays.asList( args ) );
|
|
|
|
}
|
|
|
|
catch( CommandException e )
|
|
|
|
{
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
catch( Throwable e )
|
|
|
|
{
|
|
|
|
ComputerCraft.log.error( "Unhandled exception in command", e );
|
2019-03-16 10:26:40 +00:00
|
|
|
throw new CommandException( "commands.computercraft.generic.exception", e.toString() );
|
2017-12-06 15:51:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public List<String> getTabCompletions( @Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args, @Nullable BlockPos pos )
|
|
|
|
{
|
|
|
|
return command.getCompletion( new CommandContext( server, sender, command ), Arrays.asList( args ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean checkPermission( @Nonnull MinecraftServer server, @Nonnull ICommandSender sender )
|
|
|
|
{
|
|
|
|
return command.checkPermission( new CommandContext( server, sender, command ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUsernameIndex( @Nonnull String[] args, int index )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo( @Nonnull ICommand o )
|
|
|
|
{
|
|
|
|
return getName().compareTo( o.getName() );
|
|
|
|
}
|
|
|
|
}
|