本文整理汇总了Java中org.spongepowered.api.command.CommandCallable类的典型用法代码示例。如果您正苦于以下问题:Java CommandCallable类的具体用法?Java CommandCallable怎么用?Java CommandCallable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandCallable类属于org.spongepowered.api.command包,在下文中一共展示了CommandCallable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
/**
* Build a complete command hierarchy
* @return
*/
public static CommandSpec getCommand() {
ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder();
builder.put(ImmutableList.of("pos", "position"), PositionCommand.getCommand());
builder.put(ImmutableList.of("zone", "z"), ZoneCommands.getCommand());
builder.put(ImmutableList.of("reload"), ReloadCommand.getCommand());
builder.put(ImmutableList.of("?", "help"), HelpCommand.getCommand());
return CommandSpec.builder()
.executor((src, args) -> {
src.sendMessage(Text.of(
Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"),
TextColors.GRAY, "Help: ", TextColors.WHITE, "/sg ?\n",
TextColors.GRAY, "IRC: ", TextColors.WHITE, "irc.esper.net #helion3\n"
));
return CommandResult.empty();
})
.children(builder.build()).build();
}
示例2: execute
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args)
throws CommandException {
Optional<String> subcmd =
args.<String> getOne(Texts.toPlain(LEFTOVERS_KEY));
if (subcmd.isPresent()) {
String[] parts = subcmd.get().split(" ", 2);
Optional<CommandCallable> callable =
Optional.ofNullable(HIDDEN_CHILDREN.get(parts[0]));
if (callable.isPresent()) {
return callable.get().process(src, parts.length > 1 ? parts[1] : "");
}
}
src.sendMessage(Texts
.of("Not a command: " + subcmd.orElse("literally nothing")));
return CommandResult.success();
}
示例3: getCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
/**
* Build a complete command hierarchy
* @return
*/
public static CommandSpec getCommand() {
ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.builder();
builder.put(ImmutableList.of("add"), AddKeyCommand.getCommand());
builder.put(ImmutableList.of("remove", "del", "delete"), RemoveKeyCommand.getCommand());
builder.put(ImmutableList.of("reload"), ReloadCommand.getCommand());
builder.put(ImmutableList.of("?", "help"), HelpCommand.getCommand());
return CommandSpec.builder()
.permission("keys.use")
.executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
src.sendMessage(Text.of(
Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"),
TextColors.GRAY, "IRC: ", TextColors.WHITE, "irc.esper.net #helion3\n"
));
return CommandResult.empty();
}
})
.children(builder.build()).build();
}
示例4: callable
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
public CommandCallable callable() {
return CommandSpec.builder()
.description(Text.of("Teleport to another world"))
.permission("world.command.create")
.arguments(seq(onlyOne(string(Text.of(ARG_NAME)))))
/*
.arguments(GenericArguments.optional(GenericArguments.string(Text.of("name"))), GenericArguments.flags()
.valueFlag(GenericArguments.catalogedElement(Text.of("dimensionType"), DimensionType.class), "d")
.valueFlag(GenericArguments.catalogedElement(Text.of("generatorType"), GeneratorType.class), "g")
.valueFlag(GenericArguments.catalogedElement(Text.of("modifier"), WorldGeneratorModifier.class), "m")
.valueFlag(GenericArguments.string(Text.of("seed")), "s").buildWith(GenericArguments.none()))
.arguments(GenericArguments.optional(GenericArguments.string(Text.of("world"))), GenericArguments.optional(GenericArguments.catalogedElement(Text.of("dimensionType"), DimensionType.class)),
GenericArguments.optional(GenericArguments.catalogedElement(Text.of("generatorType"), GeneratorType.class)), GenericArguments.optional(GenericArguments.catalogedElement(Text.of("modifier"), WorldGeneratorModifier.class)))
*/
.executor(this)
.build();
}
示例5: toCommandCallable
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
/**
* Creates a {@link CommandCallable} from a {@link SurvivalGamesCommand}.
*
* @param command the {@link SurvivalGamesCommand}.
* @return a {@link CommandCallable}.
*/
static CommandCallable toCommandCallable(SurvivalGamesCommand command) {
CommandSpec.Builder builder = CommandSpec.builder();
builder.executor(command);
if (command.getChildren().size() > 0) {
// This is a parent command.
builder.children(command.getChildren());
} else {
// This is a leaf command.
builder.arguments(command.getArguments());
}
builder.permission(command.getPermission());
return builder.build();
}
示例6: BaseCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的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"));
});
}
示例7: PrintCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
private PrintCommand() {
super(
RootCommand.getInstance(),
"print",
ImmutableMap.<List<String>, CommandCallable>builder()
.put(toEntry(PrintBoundariesCommand.getInstance()))
.put(toEntry(PrintCenterLocationCommand.getInstance()))
.put(toEntry(PrintCountDownSecondsCommand.getInstance()))
.put(toEntry(PrintExitVectorCommand.getInstance()))
.put(toEntry(PrintExitWorldNameCommand.getInstance()))
.put(toEntry(PrintMobSpawnAreasCommand.getInstance()))
.put(toEntry(PrintPlayerLimitCommand.getInstance()))
.put(toEntry(PrintPlayersCommand.getInstance()))
.put(toEntry(PrintSpawnsCommand.getInstance()))
.put(toEntry(PrintSurvivalGameStateCommand.getInstance()))
.put(toEntry(PrintWorldNameCommand.getInstance()))
.put(toEntry(PrintEventIntervalsCommand.getInstance()))
.build());
}
示例8: SetCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
private SetCommand() {
super(
RootCommand.getInstance(),
"set",
ImmutableMap.<List<String>, CommandCallable>builder()
.put(toEntry(SetBlocksCommand.getInstance()))
.put(toEntry(SetBoundaryCommand.getInstance()))
.put(toEntry(SetCenterVectorCommand.getInstance()))
.put(toEntry(SetChestMidpointCommand.getInstance()))
.put(toEntry(SetChestRangeCommand.getInstance()))
.put(toEntry(SetCountDownSecondsCommand.getInstance()))
.put(toEntry(SetExitVectorCommand.getInstance()))
.put(toEntry(SetExitWorldNameCommand.getInstance()))
.put(toEntry(SetPlayerLimitCommand.getInstance()))
.put(toEntry(SetWorldNameCommand.getInstance()))
.build());
}
示例9: ParentCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
protected ParentCommand(
SurvivalGamesCommand parentCommand,
String name,
Map<List<String>, CommandCallable> children) {
super(parentCommand, name, GenericArguments.none(), children);
chooseChildMessage =
Text.of("Select a child command: ")
.concat(
Text.joinWith(
Text.of(':'),
children.keySet()
.stream()
.flatMap(Collection::stream)
.map(Text::of)
.collect(Collectors.toList())));
}
示例10: getCallable
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
@Override
default CommandSpec getCallable() {
CommandSpec.Builder cb = CommandSpec.builder();
cb.executor(new ExecutorListenerWrapper(this, this));
cb.arguments(getArguments());
cb.permission(getPermission().get());
cb.description(getShortDescription(null));
cb.extendedDescription(getLongDescription(null));
//Children
HashMap<List<String>, CommandCallable> children = new HashMap<>();
getChildren().forEach((cmd) -> {
children.put(cmd.getAliases(), cmd.getCallable());
});
//Only HighPermCommand can have children + avoid infinite loop
//TODO alternative
// if (this instanceof HighPermCommand && !(this instanceof HelpSubCommand)) {
// children.put(Arrays.asList("?", "help"), new HelpSubCommand((HighPermCommand) this).getCallable());
// }
//Sponge bug: If you submit an empty children list as children, sponge fucks up the children
if (!children.isEmpty()) {
cb.children(children);
}
return cb.build();
}
示例11: getCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
public static CommandSpec getCommand(Game game) {
Builder<List<String>, CommandCallable> builder = ImmutableMap.<List<String>, CommandCallable>builder();
builder.put(ImmutableList.of("ban"), ChannelBanCommand.getCommand());
builder.put(ImmutableList.of("force"), ChannelForceCommand.getCommand());
builder.put(ImmutableList.of("join"), ChannelJoinCommand.getCommand());
builder.put(ImmutableList.of("kick"), ChannelKickCommand.getCommand());
builder.put(ImmutableList.of("leave"), ChannelLeaveCommand.getCommand());
builder.put(ImmutableList.of("list"), ChannelListCommand.getCommand());
builder.put(ImmutableList.of("unban"), ChannelUnbanCommand.getCommand());
builder.put(ImmutableList.of("help", "?"), ChannelHelpCommand.getCommand());
return CommandSpec.builder().executor((src, args) -> {
src.sendMessage(Text.of(Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"),
TextColors.GRAY, "Help: ", TextColors.WHITE, "/ch ?\n", TextColors.GRAY, "IRC: ",
TextColors.WHITE, "irc.esper.net #helion3"));
return CommandResult.empty();
}).children(builder.build()).build();
}
示例12: getCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
public static CommandSpec getCommand() {
ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.<List<String>, CommandCallable>builder();
builder.put(ImmutableList.of("reload"), ReloadCommand.getCommand());
return CommandSpec.builder().executor((src, args) -> {
src.sendMessage(Text.of(Format.heading(TextColors.GRAY, "By ", TextColors.GOLD, "viveleroi.\n"),
TextColors.GRAY, "IRC: ",
TextColors.WHITE, "irc.esper.net #prism"));
return CommandResult.empty();
}).children(builder.build()).build();
}
示例13: getCommand
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
public static CommandSpec getCommand() {
ImmutableMap.Builder<List<String>, CommandCallable> builder = ImmutableMap.<List<String>, CommandCallable>builder();
builder.put(ImmutableList.of("difficulty"), DifficultyCommand.getCommand());
return CommandSpec.builder().executor((src, args) -> {
return CommandResult.empty();
}).children(builder.build()).build();
}
示例14: callable
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
public CommandCallable callable() {
return CommandSpec.builder()
.description(Text.of("rename a world"))
.permission("world.command.rename")
.arguments(seq(onlyOne(world(Text.of(ARG_WORLD))), onlyOne(string(Text.of(ARG_NEW_NAME)))))
.executor(this)
.build();
}
示例15: callable
import org.spongepowered.api.command.CommandCallable; //导入依赖的package包/类
public CommandCallable callable() {
return CommandSpec.builder()
.description(Text.of("Teleport to another world"))
.permission("world.command.delete")
.arguments(onlyOne(world(Text.of(ARG_WORLD))))
.executor(this)
.build();
}