Search in sources :

Example 61 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project watson by totemo.

the class ClientCommandManager method executeCommand.

// --------------------------------------------------------------------------
/**
 * @see net.minecraft.src.ICommandManager#executeCommand(net.minecraft.src.ICommandSender,
 *      java.lang.String)
 *
 *      The JavaDocs for the interface don't currently describe the exact
 *      meaning of the return value. Looking at the code for
 *      {@link net.minecraft.src.CommandHandler} it contains a loop that
 *      applies a command for all players who match a particular name pattern.
 *      The returned value is the number of times that the command was
 *      successfully executed by that loop. Therefore in the case of this
 *      class, it returns 1 on success and 0 on error.
 */
@Override
public int executeCommand(ICommandSender sender, String commandLine) {
    try {
        String[] tokens = getTokens(commandLine);
        String verb = tokens[0];
        ICommand command = getCommand(verb);
        if (command == null) {
            throw new CommandNotFoundException();
        }
        tokens = Arrays.copyOfRange(tokens, 1, tokens.length);
        if (command.canCommandSenderUseCommand(sender)) {
            command.processCommand(sender, tokens);
            return 1;
        } else {
            sendError(sender, new ChatComponentTranslation("commands.generic.permission", new Object[0]));
        }
    } catch (WrongUsageException ex) {
        sendError(sender, new ChatComponentTranslation("commands.generic.usage", new Object[] { new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()) }));
    } catch (CommandException ex) {
        sendError(sender, new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()));
    } catch (Throwable throwable) {
        sendError(sender, new ChatComponentTranslation("commands.generic.exception", new Object[0]));
        Log.exception(Level.WARNING, "error processing command", throwable);
    }
    return 0;
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) ICommand(net.minecraft.command.ICommand) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) CommandException(net.minecraft.command.CommandException) CommandNotFoundException(net.minecraft.command.CommandNotFoundException)

Example 62 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project RecurrentComplex by Ivorforce.

the class CommandSearchStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    List<ToDoubleFunction<String>> ranks = new ArrayList<>();
    consider(ranks, parameters.get(0), Parameter::varargsList, (s, t) -> StructureSearch.searchRank(t, StructureSearch.keywords(StructureRegistry.INSTANCE.id(s), s)));
    consider(ranks, parameters.get("containing"), e -> RCP.expression(e, new BlockExpression(RecurrentComplex.specialRegistry)), StructureSearch::containedBlocks);
    consider(ranks, parameters.get("biome"), MCP::biome, StructureSearch::biome);
    consider(ranks, parameters.get("dimension"), MCP.dimension(server, sender), StructureSearch::dimension);
    consider(ranks, parameters.get("maze"), p -> p, StructureSearch::maze);
    consider(ranks, parameters.get("list"), p -> p, StructureSearch::list);
    consider(ranks, parameters.get("author"), p -> p, StructureSearch::author);
    boolean all = parameters.has("all");
    if (ranks.stream().noneMatch(Objects::nonNull))
        throw new WrongUsageException(getUsage(sender));
    postResultMessage("Results: ", sender, RCTextStyle::structure, search(all ? StructureRegistry.INSTANCE.ids() : StructureRegistry.INSTANCE.activeIDs(), name -> ranks.stream().filter(Objects::nonNull).mapToDouble(f -> f.applyAsDouble(name)).reduce(1, (a, b) -> a * b)));
}
Also used : BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) java.util(java.util) MCE(ivorius.mcopts.commands.parameters.expect.MCE) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) TextComponentBase(net.minecraft.util.text.TextComponentBase) RCConfig(ivorius.reccomplex.RCConfig) Function(java.util.function.Function) ServerTranslations(ivorius.mcopts.translation.ServerTranslations) ITextComponent(net.minecraft.util.text.ITextComponent) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Nonnull(javax.annotation.Nonnull) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) Collectors(java.util.stream.Collectors) MCP(ivorius.mcopts.commands.parameters.MCP) TextComponentString(net.minecraft.util.text.TextComponentString) ToDoubleBiFunction(java.util.function.ToDoubleBiFunction) RCP(ivorius.reccomplex.commands.parameters.RCP) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) WrongUsageException(net.minecraft.command.WrongUsageException) ToDoubleFunction(java.util.function.ToDoubleFunction) Doubles(com.google.common.primitives.Doubles) Parameter(ivorius.mcopts.commands.parameters.Parameter) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) WrongUsageException(net.minecraft.command.WrongUsageException) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) Parameter(ivorius.mcopts.commands.parameters.Parameter) MCP(ivorius.mcopts.commands.parameters.MCP) ToDoubleFunction(java.util.function.ToDoubleFunction)

Example 63 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project ICBM-Classic by BuiltBrokenModding.

the class CommandUtils method getWorld.

/**
 * Gets the world from user input
 *
 * @param sender - user running the command
 * @param value  - user inputted dimension ID
 * @param alt    - value to use for ~
 * @return world if found
 * @throws WrongUsageException - if input is invalid or world was not found
 */
public static World getWorld(ICommandSender sender, String value, World alt) throws WrongUsageException {
    if (value.equals("~")) {
        if (!(sender instanceof MinecraftServer)) {
            return alt;
        }
        throw new WrongUsageException("'~' can't be used from console");
    }
    try {
        // Parse dim ID from user input
        final int dim = Integer.parseInt(value);
        // Get world using ID
        final World world = DimensionManager.getWorld(dim);
        if (world == null) {
            throw new WrongUsageException("Dimension with ID[" + value + "] was not found!");
        }
        return world;
    } catch (NumberFormatException e) {
        throw new WrongUsageException("Invalid dimension ID[" + value + "]!");
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

WrongUsageException (net.minecraft.command.WrongUsageException)63 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)28 CommandException (net.minecraft.command.CommandException)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 ItemStack (net.minecraft.item.ItemStack)11 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 ChatComponentText (net.minecraft.util.ChatComponentText)7 BlockPos (net.minecraft.util.math.BlockPos)6 MinecraftServer (net.minecraft.server.MinecraftServer)5 Entity (net.minecraft.entity.Entity)4 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)4 World (net.minecraft.world.World)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 Affinity (am2.api.spell.enums.Affinity)2 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 Color (java.awt.Color)2 File (java.io.File)2 List (java.util.List)2 SpaceStationWorldData (micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData)2 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)2