本文整理汇总了Java中org.spongepowered.api.command.args.CommandElement类的典型用法代码示例。如果您正苦于以下问题:Java CommandElement类的具体用法?Java CommandElement怎么用?Java CommandElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandElement类属于org.spongepowered.api.command.args包,在下文中一共展示了CommandElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BaseCommand
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
protected BaseCommand(
SurvivalGamesCommand parentCommand,
String name,
CommandElement arguments,
Map<List<String>, CommandCallable> children) {
this.parentCommand = parentCommand;
this.aliases = Collections.singletonList(checkNotNull(name, "name"));
this.arguments = checkNotNull(arguments, "arguments");
this.children = checkNotNull(children, "children");
children.forEach(
(aliasList, element) -> {
checkNotNull(aliasList, "aliasList");
checkNotNull(element, "childCommand");
aliasList.forEach(alias -> checkNotNull(alias, "alias"));
});
}
示例2: getCommandElements
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
protected List<CommandElement> getCommandElements(Method method) {
List<CommandElement> commandElements = new ArrayList<>(method.getParameterCount());
for (MethodArg arg : getMethodArgs(method)) {
Optional<CommandElement> optCommandElement = getCommandElement(arg.name, arg.type, arg.vararg);
if (!optCommandElement.isPresent())
throw new IllegalArgumentException("@Command method " + method.toString() + " parameter unsupported type: " + arg.type);
CommandElement commandElement = optCommandElement.get();
if (arg.optional)
commandElement = GenericArguments.optional(commandElement);
if (arg.vararg)
if (String.class.equals(arg.type))
commandElement = GenericArguments.remainingJoinedStrings(Text.of(arg.name));
else
throw new IllegalArgumentException("@Command method " + method.toString() + " last vararg parameter unsupported type, must be String: " + arg.type);
else
commandElement = GenericArguments.onlyOne(commandElement);
commandElements.add(commandElement);
}
return commandElements;
}
示例3: getCommandElement
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
protected Optional<CommandElement> getCommandElement(String name, Type type, boolean isVarArgs) {
if (type instanceof Class) {
Class<?> typeClass = (Class<?>) type;
if (Player.class.isAssignableFrom(typeClass)) {
return Optional.of(GenericArguments.player(Text.of(name)));
} else if (CommandSource.class.isAssignableFrom(typeClass)) {
return Optional.of(GenericArguments.playerOrSource(Text.of(name)));
} else if (String.class.isAssignableFrom(typeClass)) {
return Optional.of(GenericArguments.string(Text.of(name)));
} else if (typeClass.isArray() && isVarArgs && typeClass.getComponentType().equals(String.class)) {
return Optional.of(GenericArguments.string(Text.of(name)));
} else if (Integer.TYPE.isAssignableFrom(typeClass) || Integer.class.isAssignableFrom(typeClass)) {
return Optional.of(GenericArguments.integer(Text.of(name)));
}
}
return Optional.empty();
}
示例4: parse
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException {
ArgumentParseException lastException = null;
for (CommandElement element : this.elements) {
Object startState = args.getState();
try {
element.parse(source, args, context);
return;
} catch (ArgumentParseException ex) {
lastException = ex;
args.setState(startState);
}
}
if (lastException != null) {
throw lastException;
}
}
示例5: getArguments
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
@Override
public CommandElement[] getArguments() {
HashMap<String, Key<Value<Boolean>>> choices = new HashMap<>();
choices.put("attribute", Keys.HIDE_ATTRIBUTES);
choices.put("attributes", Keys.HIDE_ATTRIBUTES);
choices.put("candestroy", Keys.HIDE_CAN_DESTROY);
choices.put("canbreak", Keys.HIDE_CAN_DESTROY);
choices.put("canplace", Keys.HIDE_CAN_PLACE);
choices.put("canplaceon", Keys.HIDE_CAN_PLACE);
choices.put("ench", Keys.HIDE_ENCHANTMENTS);
choices.put("enchantment", Keys.HIDE_ENCHANTMENTS);
choices.put("enchantments", Keys.HIDE_ENCHANTMENTS);
choices.put("misc", Keys.HIDE_MISCELLANEOUS);
choices.put("miscellaneous", Keys.HIDE_MISCELLANEOUS);
choices.put("unbreakable", Keys.HIDE_UNBREAKABLE);
return new CommandElement[]{
Arguments.builder(new ChoicesArgument(Text.of("tag"), choices)).onlyOne().usage("attributes/candestroy/canplaceon/enchantments/miscellaneous/unbreakable").build(),
Arguments.builder(new BooleanArgument(Text.of("enabled"))).usageKey("Enable/Disable").onlyOne().build()
};
}
示例6: getArguments
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
@Override
public CommandElement getArguments() {
return GenericArguments.flags()
.buildWith(GenericArguments.firstParsing(
GenericArguments.player(Texts.of(ADD)),
GenericArguments.string(Texts.of(ADD))));
}
示例7: AbstractPrintCommand
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
AbstractPrintCommand(
String name,
CommandElement arguments,
Map<List<String>, CommandCallable> children,
Function<SurvivalGame, Optional<Text>> function) {
super(PrintCommand.getInstance(), name, arguments, children);
this.function = checkNotNull(function, "function");
}
示例8: registerCommand
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
public Optional<CommandMapping> registerCommand(PluginContainer plugin, final List<String> commandNameAndAliases, String commandDescription, final CommandExecutor commandExecutor, CommandElement... args) {
final Builder builder = CommandSpec.builder();
if (!Strings.isNullOrEmpty(commandDescription))
builder.description(Text.of(commandDescription));
final CommandCallable spec = builder.arguments(args).executor(commandExecutor).build();
final Optional<CommandMapping> newCommand = game.getCommandManager().register(plugin, spec, commandNameAndAliases);
if (!newCommand.isPresent()) {
logger.error(commandNameAndAliases + " command could not be registered! :-(");
}
return newCommand;
}
示例9: createCommand
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
public Optional<CommandMapping> createCommand(PluginContainer plugin, final List<String> commandNameAndAliases,
String commandDescription,
final CommandExecutorWithoutResultThrowsThrowable commandExecutorWithoutResultThrowsThrowable,
CommandElement... args)
{
return registerCommand(plugin, commandNameAndAliases, commandDescription, CommandExecutorAdapter.adapt(commandExecutorWithoutResultThrowsThrowable), args);
}
示例10: getArguments
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
@Override
public CommandElement[] getArguments() {
return new CommandElement[]{
Arguments.builder(new PlayerArgument(Text.of("player"))).onlyOne().build(),
Arguments.builder(new JailArgument(Text.of("jail"))).optional().onlyOne().build(),
Arguments.builder(new TimeArgument(Text.of("time"))).optional().onlyOne().build(),
Arguments.builder(new RemainingStringsArgument(Text.of("reason"))).onlyOne().optional().build()
};
}
示例11: getArguments
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
@Override
public CommandElement[] getArguments() {
return new CommandElement[]{
Arguments.builder(new IntegerArgument(Text.of("first"))).usage("<Min>").onlyOne().build(),
Arguments.builder(new IntegerArgument(Text.of("second"))).usage("[Max]").onlyOne().optional().build()
};
}
示例12: builder
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
public static Arguments builder(CommandElement... elements) {
List<UCommandElement> uElements = new ArrayList<>();
for (CommandElement element : elements) {
uElements.add(element instanceof UCommandElement ? (UCommandElement) element : new SpongeArgument(element));
}
if (uElements.size() == 0) {
return null;
}
if (uElements.size() == 1) {
return new Arguments(uElements.get(0));
}
return new Arguments(new FirstParsingWrapper(uElements));
}
示例13: getArguments
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
@Override
public CommandElement[] getArguments() {
return new CommandElement[]{
Arguments.builder(new BoundedIntegerArgument(Text.of("line"), 1, 4)).onlyOne().build(),
Arguments.builder(new RemainingStringsArgument(Text.of("text"))).build()
};
}
示例14: getArguments
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
@Override
public CommandElement[] getArguments() {
return new CommandElement[]{
Arguments.builder(new GameprofileArgument(Text.of("player")), new IpAdressArgument(Text.of("ip"))).onlyOne().usage("<Player/IP>").build(),
Arguments.builder(new TimeArgument(Text.of("time"))).optionalWeak().build(),
Arguments.builder(new RemainingStringsArgument(Text.of("reason"))).optional().build()
};
}
示例15: parseValue
import org.spongepowered.api.command.args.CommandElement; //导入依赖的package包/类
@Nullable
@Override
public Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
try {
Method method = CommandElement.class.getMethod("parseValue", CommandSource.class, CommandArgs.class);
method.setAccessible(true);
return method.invoke(element, source, args);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}