本文整理汇总了Java中org.spongepowered.api.command.CommandMapping类的典型用法代码示例。如果您正苦于以下问题:Java CommandMapping类的具体用法?Java CommandMapping怎么用?Java CommandMapping使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CommandMapping类属于org.spongepowered.api.command包,在下文中一共展示了CommandMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: helpCommands
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
public void helpCommands(TreeSet<CommandMapping> commands, Text title, CommandSource source) {
List<Text> contents = new ArrayList<Text>();
for (CommandMapping command : commands) {
if (command.getCallable().testPermission(source)) {
Optional<Text> optHelp = command.getCallable().getHelp(source);
Optional<Text> optDescription = command.getCallable().getShortDescription(source);
if (optHelp.isPresent() && optDescription.isPresent() && !optHelp.get().isEmpty() && !optDescription.get().isEmpty()) {
Text help = optHelp.get().toBuilder().color(this.help_color_help).build();
Text description = optDescription.get().toBuilder().color(this.help_color_description).build();
contents.add(EAMessages.HELP_LINE.getFormat().toText(
"{name}", () -> this.getButtonName(command.getPrimaryAlias(), help),
"{description}", () -> description));
}
}
}
if (contents.isEmpty()) {
contents.add(this.help_empty);
}
this.send(title, this.help_padding, contents, source);
}
示例2: commandHelp
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
private CompletableFuture<Boolean> commandHelp(final CommandSource source, final String alias) {
Optional<? extends CommandMapping> command = this.plugin.getGame().getCommandManager().get(alias);
if (command.isPresent()) {
if (command.get().getCallable().testPermission(source)) {
source.sendMessage(command.get().getCallable().getHelp(source).orElse(Text.of("/" + command.get().getPrimaryAlias())));
return CompletableFuture.completedFuture(true);
} else {
source.sendMessage(EAMessages.NO_PERMISSION.getText());
}
} else {
Text title = EEMessages.HELP_SEARCH_TITLE.getFormat().toText("{command}", alias).toBuilder()
.onClick(TextActions.runCommand("/help " + alias))
.color(TextColors.RED)
.build();
TreeSet<CommandMapping> commands = new TreeSet<CommandMapping>((o1, o2) -> o1.getPrimaryAlias().compareTo(o2.getPrimaryAlias()));
for (CommandMapping mapping : this.plugin.getGame().getCommandManager().getAll().values()) {
if (mapping.getPrimaryAlias().contains(alias)) {
commands.add(mapping);
}
}
this.plugin.getEverAPI().getManagerService().getEPagination().helpCommands(commands, title, source);
}
return CompletableFuture.completedFuture(false);
}
示例3: getRegistration
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
@Override
protected Optional<CommandMapping> getRegistration(CommandRegistration service) {
if (service.callable() == null) {
LOG.error("callable() null; skipping CommandRegistration: {}", service);
return Optional.empty();
}
if (service.aliases() == null) {
LOG.error("aliases() null; skipping CommandRegistration: {}", service);
return Optional.empty();
}
Optional<CommandMapping> optCommandMapping = Sponge.getCommandManager().register(pluginContainer, service.callable(), service.aliases());
optCommandMapping.ifPresent(commandMapping ->
LOG.info("Command registered as (primary) /{} (all: {})", commandMapping.getPrimaryAlias(), commandMapping.getAllAliases())
);
return optCommandMapping;
}
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:17,代码来源:CommandRegistrationTrackerCustomizer.java
示例4: onCommand
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onCommand(SendCommandEvent commandEvent, @First Player player) {
String command = commandEvent.getCommand();
Optional<? extends CommandMapping> commandOpt = commandManager.get(command);
if (commandOpt.isPresent()) {
command = commandOpt.get().getPrimaryAlias();
}
//do not blacklist our own commands
if (ignoredCommands.contains(command)) {
return;
}
if (settings.getGeneral().isCommandOnlyProtection()) {
List<String> protectedCommands = settings.getGeneral().getProtectedCommands();
if ((protectedCommands.isEmpty() || protectedCommands.contains(command))) {
if (!plugin.getDatabase().isLoggedIn(player)) {
player.sendMessage(settings.getText().getProtectedCommand());
commandEvent.setCancelled(true);
}
}
} else {
checkLoginStatus(commandEvent, player);
}
}
示例5: register
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
@Override
public boolean register(String label, String fallbackPrefix, Command command) {
// TODO: Label
// TODO: Fallback prefix
Object plugin = Pore.getPlugin();
if (command instanceof PluginIdentifiableCommand) {
plugin = Pore.getPlugin(((PluginIdentifiableCommand) command).getPlugin());
}
List<String> aliases = Lists.newArrayList(command.getAliases());
String name = command.getName();
if (!name.equals(label)) {
aliases.add(0, label);
}
aliases.add(0, name);
Optional<CommandMapping> result = handle.register(plugin, new PoreCommandCallable(command), aliases);
if (result.isPresent()) {
command.register(this);
return true;
} else {
return false;
}
}
示例6: tabCompleter
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
@Override
public Collection<String> tabCompleter(final CommandSource source, final List<String> args) throws CommandException {
if (args.size() == 1) {
TreeSet<String> commands = new TreeSet<String>();
for (CommandMapping command : Collections2.filter(this.plugin.getGame().getCommandManager().getAll().values(), input -> input.getCallable().testPermission(source))) {
commands.add(command.getPrimaryAlias());
}
return commands;
}
return Arrays.asList();
}
示例7: CachedCommand
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
public CachedCommand(CommandMapping cmd) {
super(null);
this.name = cmd.getPrimaryAlias();
this.aliases = cmd.getAllAliases().toArray(new String[cmd.getAllAliases().size()]);
try {
this.usage = cmd.getCallable().getUsage(instance).toPlain();
this.description = cmd.getCallable().getShortDescription(instance).orElse(Text.EMPTY).toPlain();
this.help = cmd.getCallable().getHelp(instance).orElse(Text.EMPTY).toPlain();
} catch (Exception ignored) {}
}
示例8: validateCommandMapping
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
private static boolean validateCommandMapping(CommandSource src, String command, String pluginId) {
CommandMapping commandMapping = Sponge.getCommandManager().get(command).orElse(null);
if (commandMapping == null) {
src.sendMessage(Text.of(
TextColors.RED, "Could not locate the command '",
TextColors.GREEN, command,
TextColors.RED, "' for mod id '",
TextColors.AQUA, pluginId,
TextColors.RED, "'."));
return false;
}
return true;
}
示例9: removeMapping
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
@Override
public Optional<CommandMapping> removeMapping(CommandMapping mapping) {
synchronized (this.lock) {
final Optional<CommandMapping> removed = this.dispatcher.removeMapping(mapping);
removed.ifPresent(this::forgetMapping);
return removed;
}
}
示例10: forgetMapping
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
private void forgetMapping(CommandMapping mapping) {
Iterator<CommandMapping> it = this.owners.values().iterator();
while (it.hasNext()) {
if (it.next().equals(mapping)) {
it.remove();
break;
}
}
}
示例11: getOwnedBy
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
@Override
public Set<CommandMapping> getOwnedBy(Object instance) {
final Optional<PluginContainer> container = Sponge.getGame().getPluginManager().fromInstance(instance);
if (!container.isPresent()) {
throw new IllegalArgumentException("The provided plugin object does not have an associated plugin container "
+ "(in other words, is 'plugin' actually your plugin object?)");
}
synchronized (this.lock) {
return ImmutableSet.copyOf(this.owners.get(container.get()));
}
}
示例12: disambiguate
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
@Override
public Optional<CommandMapping> disambiguate(@Nullable CommandSource source, String aliasUsed, List<CommandMapping> availableOptions) {
if (availableOptions.size() > 1) {
final String chosenPlugin = this.game.getGlobalConfig().getCommandAliases().get(aliasUsed.toLowerCase());
if (chosenPlugin != null) {
final Optional<PluginContainer> container = this.game.getPluginManager().getPlugin(chosenPlugin);
if (!container.isPresent()) {
this.game.getServer().getConsole().sendMessage(t("Unable to find plugin '%s' for command '%s', falling back to default",
chosenPlugin, aliasUsed));
} else {
final Set<CommandMapping> ownedCommands = this.game.getCommandManager().getOwnedBy(container.get());
final List<CommandMapping> ownedMatchingCommands = availableOptions.stream()
.filter(Predicates.in(ownedCommands)::apply).collect(ImmutableList.toImmutableList());
if (ownedMatchingCommands.isEmpty()) {
this.game.getServer().getConsole().sendMessage(t("Plugin %s was specified as the preferred owner for %s, "
+ "but does not have any such command!", container.get().getName(), aliasUsed));
} else if (ownedMatchingCommands.size() > 1) {
throw new IllegalStateException("Plugin " + container.get().getName() + " seems to have multiple commands registered as "
+ aliasUsed + "! This is a programming error!");
} else {
return Optional.of(ownedMatchingCommands.get(0));
}
}
}
}
return SimpleDispatcher.FIRST_DISAMBIGUATOR.disambiguate(source, aliasUsed, availableOptions);
}
示例13: getDescription
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Text getDescription(CommandSource source, CommandMapping mapping) {
final Optional<Text> description = mapping.getCallable().getShortDescription(source);
Text.Builder text = Text.builder("/" + mapping.getPrimaryAlias());
text.color(TextColors.GREEN);
//End with a space, so tab completion works immediately.
text.onClick(TextActions.suggestCommand("/" + mapping.getPrimaryAlias() + " "));
Optional<? extends Text> longDescription = mapping.getCallable().getHelp(source);
if (longDescription.isPresent()) {
text.onHover(TextActions.showText(longDescription.get()));
}
return Text.of(text, " ", description.orElse(mapping.getCallable().getUsage(source)));
}
示例14: alias
import org.spongepowered.api.command.CommandMapping; //导入依赖的package包/类
public void alias(CommandSource commandSource, String name, String commandsToAlias) {
Script script = new Script(/*name, */commandsToAlias);
Optional<CommandMapping> command = commandHelper.createCommand(plugin, name, script.getCommands().toString(), script.asCommandExecutor(commandService));
if (command.isPresent())
commandRegistry.register(command.get());
else
// logger.error("Failed to create CommandMapping to register: " + name);
throw new IllegalArgumentException("Failed to create CommandMapping to register: " + name);
aliases.put(name, script);
}
示例15: registerCommand
import org.spongepowered.api.command.CommandMapping; //导入依赖的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;
}