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;
}
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)));
}
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 + "]!");
}
}
Aggregations