com.mojang.brigadier.exceptions.SimpleCommandExceptionType Java Examples

The following examples show how to use com.mojang.brigadier.exceptions.SimpleCommandExceptionType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomCommandExecutor.java    From 1.13-Command-API with Apache License 2.0 6 votes vote down vote up
private int executeNormalExecutor(CommandSender sender, Object[] args) throws WrapperCommandSyntaxException {
	if(sender instanceof Player && ex.stream().anyMatch(o -> o.getType() == ExecutorType.PLAYER)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.PLAYER).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof Entity && ex.stream().anyMatch(o -> o.getType() == ExecutorType.ENTITY)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.ENTITY).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ConsoleCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.CONSOLE)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.CONSOLE).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof BlockCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.BLOCK)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.BLOCK).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ProxiedCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.PROXY)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.PROXY).findFirst().get().executeWith(sender, args);
	} else if(ex.stream().anyMatch(o -> o.getType() == ExecutorType.ALL)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.ALL).findFirst().get().executeWith(sender, args);
	} else {
		throw new WrapperCommandSyntaxException(
			new SimpleCommandExceptionType(
				new LiteralMessage("This command has no implementations for " + sender.getClass().getSimpleName().toLowerCase())
			).create()
		); 
	}
}
 
Example #2
Source File: CustomCommandExecutor.java    From 1.13-Command-API with Apache License 2.0 6 votes vote down vote up
private int executeResultingExecutor(CommandSender sender, Object[] args) throws WrapperCommandSyntaxException {
	if(sender instanceof Player && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.PLAYER)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.PLAYER).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof Entity && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.ENTITY)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.ENTITY).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ConsoleCommandSender && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.CONSOLE)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.CONSOLE).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof BlockCommandSender && rEx.stream().anyMatch(o -> o.getType() == ExecutorType.BLOCK)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.BLOCK).findFirst().get().executeWith(sender, args);
	} else if(sender instanceof ProxiedCommandSender && ex.stream().anyMatch(o -> o.getType() == ExecutorType.PROXY)) {
		return ex.stream().filter(o -> o.getType() == ExecutorType.PROXY).findFirst().get().executeWith(sender, args);
	} else if(rEx.stream().anyMatch(o -> o.getType() == ExecutorType.ALL)) {
		return rEx.stream().filter(o -> o.getType() == ExecutorType.ALL).findFirst().get().executeWith(sender, args);
	} else {
		throw new WrapperCommandSyntaxException(
			new SimpleCommandExceptionType(
				new LiteralMessage("This command has no implementations for " + sender.getClass().getSimpleName().toLowerCase())
			).create()
		); 
	}
}
 
Example #3
Source File: SpawnCommand.java    From fabric-carpet with MIT License 5 votes vote down vote up
private static EntityCategory getCategory(String string) throws CommandSyntaxException
{
    if (!Arrays.stream(EntityCategory.values()).map(EntityCategory::getName).collect(Collectors.toSet()).contains(string))
    {
        throw new SimpleCommandExceptionType(Messenger.c("r Wrong mob type: "+string+" should be "+ Arrays.stream(EntityCategory.values()).map(EntityCategory::getName).collect(Collectors.joining(", ")))).create();
    }
    return EntityCategory.valueOf(string.toUpperCase());
}
 
Example #4
Source File: SettingsManager.java    From fabric-carpet with MIT License 5 votes vote down vote up
private ParsedRule<?> contextRule(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException
{
    String ruleName = StringArgumentType.getString(ctx, "rule");
    ParsedRule<?> rule = getRule(ruleName);
    if (rule == null)
        throw new SimpleCommandExceptionType(Messenger.c("rb "+ tr("ui.unknown_rule","Unknown rule")+": "+ruleName)).create();
    return rule;
}
 
Example #5
Source File: IExecutorNormal.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the command executor with the provided command sender and the provided arguments.
 * @param sender the command sender for this command
 * @param args the arguments provided to this command
 * @return 1 if the command succeeds, 0 if the command fails
 * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command
 */
@SuppressWarnings("unchecked")
default int executeWith(CommandSender sender, Object[] args) throws WrapperCommandSyntaxException {
	Class<?> type = this.getClass().getDeclaredMethods()[0].getParameterTypes()[0];
	if(type.isInstance(sender)) {
		this.run((T) type.cast(sender), args);
		return 1;
	} else {
		throw new WrapperCommandSyntaxException(
			new SimpleCommandExceptionType(
				new LiteralMessage("You must be a " + type.getSimpleName().toLowerCase() + " to run this command")
			).create()
		);
	}
}
 
Example #6
Source File: IExecutorResulting.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the command executor with the provided command sender and the provided arguments.
 * @param sender the command sender for this command
 * @param args the arguments provided to this command
 * @return the value returned by this command if the command succeeds, 0 if the command fails
 * @throws WrapperCommandSyntaxException if an error occurs during the execution of this command
 */
@SuppressWarnings("unchecked")
default int executeWith(CommandSender sender, Object[] args) throws WrapperCommandSyntaxException {
	Class<?> type = this.getClass().getDeclaredMethods()[0].getParameterTypes()[0];
	if(type.isInstance(sender)) {
		return this.run((T) type.cast(sender), args);
	} else {
		throw new WrapperCommandSyntaxException(
			new SimpleCommandExceptionType(
				new LiteralMessage("You must be a " + type.getSimpleName().toLowerCase() + " to run this command")
			).create()
		);
	}
}
 
Example #7
Source File: CustomArgument.java    From 1.13-Command-API with Apache License 2.0 5 votes vote down vote up
public CommandSyntaxException toCommandSyntax(String result, CommandContext<?> cmdCtx) {
	if(errorMessage == null) {
		//Deal with MessageBuilder
		String errorMsg = errorMessageBuilder.toString().replace("%input%", result).replace("%finput%", cmdCtx.getInput());
		return new SimpleCommandExceptionType(() -> {return errorMsg;}).create();
	} else {
		//Deal with String
		return new SimpleCommandExceptionType(new LiteralMessage(errorMessage)).create();
	}
}
 
Example #8
Source File: CommandAPI.java    From 1.13-Command-API with Apache License 2.0 2 votes vote down vote up
/**
 * Forces a command to return a success value of 0
 * @param message Description of the error message
 * @throws WrapperCommandSyntaxException
 */
public static void fail(String message) throws WrapperCommandSyntaxException {
	throw new WrapperCommandSyntaxException(new SimpleCommandExceptionType(new LiteralMessage(message)).create());
}