1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-07-01 09:32:54 +00:00
SquidDev 173ea72001 Turn inspections up to 11
OK, so let's get this out of the way, there's some actual changes mixed
in here too. I'm really sorry:
 - Turtles can now not be renamed with unnamed item tags (previously it
   would clear the name, this seemed a little unideal).
 - commands.getBlock(s)Data will also include NBT.

Now, onto the horror story which is these inspection changes:
 - Make a lot of methods static
 - Typo fixes
 - Make utility classes final + private constructor
 - Lots of reformatting (ifs -> ternary, invert control flow, etc...)
 - ???
 - Profit!

I'm so going to regret this - can pretty much guarantee this is going to
break something.
2019-03-29 21:26:21 +00:00

98 lines
2.6 KiB
Java

/*
* 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
*/
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;
/**
* {@link ICommand} which delegates to a {@link ISubCommand}.
*/
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 )
{
return new CommandContext( sender.getServer(), sender, command ).getFullUsage();
}
@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 );
throw new CommandException( "commands.computercraft.generic.exception", e.toString() );
}
}
@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() );
}
}