本文整理汇总了Java中org.spongepowered.api.command.spec.CommandSpec类的典型用法代码示例。如果您正苦于以下问题:Java CommandSpec类的具体用法?Java CommandSpec怎么用?Java CommandSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandSpec类属于org.spongepowered.api.command.spec包,在下文中一共展示了CommandSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerCommand
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
private void registerCommand() {
this.commandProxy = new CommandProxy();
CommandSpec basics = CommandSpec.builder()
.description(Text.of("§2mcrmb.com"))
.executor(commandProxy)
.arguments(
GenericArguments.remainingRawJoinedStrings(Text.of("arg")))
.build();
Sponge.getCommandManager().register(this, basics, McrmbPluginInfo.config.command);
//注册命令
getCommandProxy().register(new HelpCommand());
getCommandProxy().register(new MoneyCommand());
getCommandProxy().register(new SetupCommand());
getCommandProxy().register(new TakeCommand());
getCommandProxy().register(new GiveCommand());
getCommandProxy().register(new SetCommand());
getCommandProxy().register(new AdminWhiteCommand());
getCommandProxy().register(new TestCommand());
}
示例2: registerSubCommand
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
/**
* Registers a {@link PhononSubcommand}
*
* @param subcommandToRegister The subcommand to register.
* @return <code>true</code> if successful.
*/
public boolean registerSubCommand(PhononSubcommand subcommandToRegister) {
// Work out how the sub command system will work - probably annotation based, but not sure yet.
// By definition, all subcommands will be lower case
// Register the command.
Collection<String> sc = Arrays.asList(subcommandToRegister.getAliases());
if (subCommands.keySet().stream().map(String::toLowerCase).noneMatch(sc::contains)) {
// We can register the aliases. Create the CommandSpec
// We might want to add descriptions in.
CommandSpec.Builder specbuilder = CommandSpec.builder();
subcommandToRegister.getPermission().ifPresent(specbuilder::permission);
CommandSpec spec = specbuilder
.arguments(subcommandToRegister.getArguments())
.executor(subcommandToRegister)
.build();
sc.forEach(x -> subCommands.put(x.toLowerCase(), spec));
return true;
}
return false;
}
示例3: process
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
@Override public CommandResult process(CommandSource source, String arguments) throws CommandException {
// Get the first argument, is it a child?
final CommandArgs args = new CommandArgs(arguments, tokenizer.tokenize(arguments, false));
Optional<CommandSpec> optionalSpec = getSpec(args);
if (optionalSpec.isPresent()) {
CommandSpec spec = optionalSpec.get();
CommandContext context = new CommandContext();
spec.checkPermission(source);
spec.populateContext(source, args, context);
return spec.getExecutor().execute(source, context);
}
if (testPermission(source)) {
// Else, what do we want to do here?
source.sendMessage(Text.of("Phonon from Nucleus."));
return CommandResult.success();
}
throw new CommandPermissionException();
}
示例4: onServerStart
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
@Listener
public void onServerStart(GameStartedServerEvent event) {
instance = this;
ConfigBuilder.configPath = Paths.get(configDir.toString(), "config.json");
RText.impl(new RTextSponge());
RColour.impl(new RColourSponge());
Travellers.impl(new SpongeTravellers());
CommandSpec camCommandSpec = CommandSpec.builder()
.arguments(GenericArguments.optional(GenericArguments.remainingJoinedStrings(Text.of("cmd"))))
.executor(new SpongeCommandManager())
.build();
Sponge.getCommandManager().register(this, camCommandSpec, "cam", "camerastudio");
}
示例5: getAddTrailCommand
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
private static CommandSpec getAddTrailCommand() {
return CommandSpec.builder()
.permission("happytrails.command.add")
.description(Text.of("Adds a new trail"))
.executor((src, args) -> {
if (!(src instanceof Player)) {
return CommandResult.empty();
}
final Inventory creator = Inventory.builder()
.of(InventoryArchetypes.CHEST)
.property(InventoryTitle.PROPERTY_NAME, new InventoryTitle(Text.of(TextColors.AQUA, "Create a Trail")))
.listener(ClickInventoryEvent.Primary.class, (event) -> {
})
.build(HappyTrails.getInstance());
creator.offer(ItemStack.of(ItemTypes.FIREWORKS, 1));
creator.offer(ItemStack.builder().fromBlockState(BlockTypes.REDSTONE_BLOCK.getDefaultState()).build());
((Player) src).openInventory(creator);
return CommandResult.success();
})
.build();
}
示例6: init
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
@Listener(order=Order.FIRST)
public void init(GameInitializationEvent event) { instance = this; //myL=L.createLang(this);
reload();
Sponge.getServiceManager().setProvider(this, LanguageService.class, new LanguageServiceProvider());
l("The LanguageService is now available!");
Map<String, String> listMap = new HashMap<>();
for (String al : available) listMap.put(al, al);
Sponge.getCommandManager().register(this, CommandSpec.builder().arguments(GenericArguments.onlyOne(GenericArguments.choices(Text.of("Language"), listMap))).executor(new CommandExecutor() {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) { src.sendMessage(Text.of("Only available for players")); return CommandResult.success(); }
Optional<String> la = args.<String>getOne("Language");
if (!la.isPresent()) {
src.sendMessage(Text.of(playerLang.get(((Player)src).getUniqueId()).toString()));
} else {
String lang = la.get();
lang = lang.replace('_', '-'); //Locales toString used a underscore but the language tag requires a dash
Locale locale = Locale.forLanguageTag(lang);
playerChangedLang(((Player)src).getProfile(), locale);
}
return CommandResult.success();
}
}).build(), "language");
}
示例7: onServerStart
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
@Listener
public void onServerStart(GameStartingServerEvent event) {
Sponge.getCommandManager().register(this, CommandSpec.builder()
.description(Text.of("Gets info on the user."))
.arguments(flags()
.permissionFlag("whois.all", ALL, "-all")
.permissionFlag("whois.address", IP, "-ip")
.flag(FIRST, "-firstjoined")
.flag(LAST, "-lastjoined")
.flag(WORLD, "-world")
.flag(COORDINATES, "-coords")
.flag(GAMEMODE, "-gamemode")
.flag(BAN, "-ban")
.buildWith(optional(user(KEY_USER))))
.permission("whois.command")
.executor(this::whois)
.build(), "whois");
}
示例8: getCommand
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的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();
}
示例9: useKey
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
/**Command to activate a vip using a key.
*
* @return CommandSpec
*/
public CommandSpec useKey() {
return CommandSpec.builder()
.description(Text.of("Use a key to activate the Vip."))
.permission("pixelvip.cmd.player")
.arguments(GenericArguments.string(Text.of("key")))
.executor((src, args) -> { {
if (src instanceof Player){
Player p = (Player) src;
String key = args.<String>getOne(Text.of("key")).get().toUpperCase();
return plugin.getConfig().activateVip(p, key, "", 0, p.getName());
}
throw new CommandException(plugin.getUtil().toText(plugin.getConfig().getLang("_pluginTag","onlyPlayers")));
}
})
.build();
}
示例10: create
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
public static void create(CommandSpec.Builder cmd) {
CommandSpec subCmd = CommandSpec.builder()
.description(Text.of(""))
.permission("nations.command.nation.claim.outpost")
.arguments()
.executor(new NationClaimOutpostExecutor())
.build();
cmd.child(CommandSpec.builder()
.description(Text.of(""))
.permission("nations.command.nation.claim")
.arguments()
.executor(new NationClaimExecutor())
.child(subCmd, "outpost", "o")
.build(), "claim");
}
示例11: create
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
public static void create(CommandSpec.Builder cmd) {
cmd.child(CommandSpec.builder()
.description(Text.of(""))
.permission("nations.command.nationadmin.perm")
.arguments(
GenericArguments.optional(new NationNameElement(Text.of("nation"))),
GenericArguments.optional(GenericArguments.choices(Text.of("type"),
ImmutableMap.<String, String> builder()
.put(Nation.TYPE_OUTSIDER, Nation.TYPE_OUTSIDER)
.put(Nation.TYPE_CITIZEN, Nation.TYPE_CITIZEN)
.put(Nation.TYPE_COOWNER, Nation.TYPE_COOWNER)
.build())),
GenericArguments.optional(GenericArguments.choices(Text.of("perm"),
ImmutableMap.<String, String> builder()
.put(Nation.PERM_BUILD, Nation.PERM_BUILD)
.put(Nation.PERM_INTERACT, Nation.PERM_INTERACT)
.build())),
GenericArguments.optional(GenericArguments.bool(Text.of("bool"))))
.executor(new NationadminPermExecutor())
.build(), "perm");
}
示例12: vipTime
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
/**Command to check the vip time.
*
* @return CommandSpec
*/
public CommandSpec vipTime() {
return CommandSpec.builder()
.description(Text.of("Use to check the vip time."))
.permission("pixelvip.cmd.player")
.arguments(GenericArguments.optional(GenericArguments.user(Text.of("player"))))
.executor((src, args) -> { {
if (!(src instanceof Player) && !args.hasAny("player")){
throw new CommandException(plugin.getUtil().toText(plugin.getConfig().getLang("_pluginTag","onlyPlayers")), true);
}
if (src.hasPermission("pixelvip.cmd.player.others") && args.hasAny("player")){
Optional<User> optp = args.<User>getOne("player");
if (optp.isPresent()){
User p = optp.get();
return plugin.getUtil().sendVipTime(src, p.getUniqueId().toString(), p.getName());
} else {
throw new CommandException(plugin.getUtil().toText(plugin.getConfig().getLang("_pluginTag","noPlayersByName")));
}
} else {
return plugin.getUtil().sendVipTime(src, ((Player)src).getUniqueId().toString(), ((Player)src).getName());
}
}
})
.build();
}
示例13: create
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
public static void create(CommandSpec.Builder cmd) {
cmd.child(CommandSpec.builder()
.description(Text.of(""))
.permission("nations.command.nationadmin.extra")
.arguments(
GenericArguments.optional(GenericArguments.choices(Text.of("give|take|set"),
ImmutableMap.<String, String> builder()
.put("give", "give")
.put("take", "take")
.put("set", "set")
.build())),
GenericArguments.optional(new NationNameElement(Text.of("nation"))),
GenericArguments.optional(GenericArguments.integer(Text.of("amount"))))
.executor(new NationadminExtraExecutor())
.build(), "extra");
}
示例14: getCommand
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的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();
}
示例15: registerUmsgAliases
import org.spongepowered.api.command.spec.CommandSpec; //导入依赖的package包/类
private void registerUmsgAliases() {
//register umsg aliases
for (String msga:UChat.get().getConfig().getMsgAliases()){
unregisterCmd(msga);
manager.register(UChat.get().instance(), CommandSpec.builder()
.arguments(GenericArguments.player(Text.of("player")), GenericArguments.remainingJoinedStrings(Text.of("message")))
.permission("uchat.cmd.umsg")
.description(Text.of("Send a message directly to a player."))
.executor((src, args) -> { {
Player receiver = args.<Player>getOne("player").get();
String msg = args.<String>getOne("message").get();
receiver.sendMessage(UCUtil.toText(msg));
Sponge.getServer().getConsole().sendMessage(UCUtil.toText("&8> Private to &6"+receiver.getName()+"&8: &r"+msg));
return CommandResult.success();
}})
.build(), msga);
}
}