当前位置: 首页>>代码示例>>Java>>正文


Java CommandContext.getString方法代码示例

本文整理汇总了Java中com.sk89q.minecraft.util.commands.CommandContext.getString方法的典型用法代码示例。如果您正苦于以下问题:Java CommandContext.getString方法的具体用法?Java CommandContext.getString怎么用?Java CommandContext.getString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sk89q.minecraft.util.commands.CommandContext的用法示例。


在下文中一共展示了CommandContext.getString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: force

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
    aliases = {"force"},
    desc = "Force a player onto a team",
    usage = "<player> [team]",
    min = 1,
    max = 2
)
@CommandPermissions("pgm.team.force")
public void force(CommandContext args, CommandSender sender) throws CommandException, SuggestException {
    MatchPlayer player = CommandUtils.findSingleMatchPlayer(args, sender, 0);

    if(args.argsLength() >= 2) {
        String name = args.getString(1);
        if(name.trim().toLowerCase().startsWith("obs")) {
            player.getMatch().setPlayerParty(player, player.getMatch().getDefaultParty());
        } else {
            Team team = utils.teamArgument(args, 1);
            utils.module().forceJoin(player, team);
        }
    } else {
        utils.module().forceJoin(player, null);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:24,代码来源:TeamCommands.java

示例2: all

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
    aliases = "all",
    usage = "<model>",
    desc = "List all stored instances of a model",
    min = 1,
    max = 1
)
public List<String> all(CommandContext args, CommandSender sender) throws CommandException {
    final String modelName = args.getString(0, "");

    if(args.getSuggestionContext() != null) {
        return completeModel(modelName);
    }
    for(Model doc : parseModel(modelName).store().get().set()) {
        sender.sendMessage(new Component(doc._id() + " " + doc.toShortString()));
    }
    return null;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:19,代码来源:ModelCommands.java

示例3: refresh

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
    aliases = "refresh",
    usage = "<model>",
    desc = "Refresh a model store from the API",
    min = 1,
    max = 1
)
public List<String> refresh(CommandContext args, CommandSender sender) throws CommandException {
    final String modelName = args.getString(0, "");

    if(args.getSuggestionContext() != null) {
        return completeModel(modelName);
    }

    final ModelMeta<?, ?> model = parseModel(modelName);
    sender.sendMessage("Refreshing model " + model.name() + "...");
    syncExecutor.callback(
        model.store().get().refreshAll(),
        response -> sender.sendMessage("Refreshed " + response.documents().size() + " " + model.name() + " document(s)")
    );
    return null;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:23,代码来源:ModelCommands.java

示例4: test

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
    aliases = {"test"},
    desc = "Test for a specific permission",
    usage = "<permission> [player]",
    min = 1,
    max = 2
)
public void test(CommandContext args, CommandSender sender) throws CommandException {
    CommandSender player = CommandUtils.getCommandSenderOrSelf(args, sender, 1);
    String perm = args.getString(0);
    if(player.hasPermission(perm)) {
        sender.sendMessage(ChatColor.GREEN + player.getName() + " has permission " + perm);
    } else {
        sender.sendMessage(ChatColor.RED + player.getName() + " does NOT have permission " + perm);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:17,代码来源:PermissionCommands.java

示例5: remove

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
    aliases = {"remove"},
    desc = "Remove a player from the whitelist",
    usage = "<username>",
    min = 1,
    max = 1
)
public void remove(CommandContext args, final CommandSender sender) throws CommandException {
    final String username = args.getString(0);
    for(Iterator<PlayerId> iter = whitelist.iterator(); iter.hasNext();) {
        PlayerId playerId = iter.next();
        if(username.equalsIgnoreCase(playerId.username())) {
            iter.remove();
            audiences.get(sender).sendMessage(
                new TranslatableComponent(
                    "whitelist.remove",
                    new PlayerComponent(identities.currentIdentity(playerId), NameStyle.FANCY)
                )
            );
            return;
        }
    }
    throw new TranslatableCommandException("whitelist.notFound", username);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:25,代码来源:WhitelistCommands.java

示例6: gserver

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
        aliases = {"gserver"},
        desc = "Global server teleport",
        usage = "<server>",
        min = 1,
        max = 1
)
@CommandPermissions("bungeecord.command.server")
public void gserver(final CommandContext args, CommandSender sender) {
    if(sender instanceof ProxiedPlayer) {
        String name = args.getString(0);
        ServerInfo info = proxy.getServerInfo(name);
        if(info != null) {
            ((ProxiedPlayer) sender).connect(info);
            sender.sendMessage(new ComponentBuilder("Teleporting you to: ").color(ChatColor.GREEN).append(name).color(ChatColor.GOLD).create());
        } else {
            sender.sendMessage(new ComponentBuilder("Invalid server: ").color(ChatColor.RED).append(name).color(ChatColor.GOLD).create());
        }
    } else {
        sender.sendMessage(new ComponentBuilder("Only players may use this command").color(ChatColor.RED).create());
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:23,代码来源:ServerCommands.java

示例7: session

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
        aliases = {"session"},
        desc = "Session status control",
        usage = "[on|off|clear]",
        max = 1
)
@CommandPermissions("bungeecord.command.session")
public void session(final CommandContext args, CommandSender sender) throws CommandException {
    if (args.argsLength() == 1) {
        String arg = args.getString(0);
        SessionState newState = parseSessionStateCommand(arg);
        if (newState == null) throw new CommandException("Unknown session state command: " + arg);

        sender.sendMessage(new ComponentBuilder("Old Force Status: " + monitor.getForceState()).color(ChatColor.LIGHT_PURPLE).create());

        monitor.setForceState(newState);
    }

    sender.sendMessage(new ComponentBuilder("Current Force Status: " + monitor.getForceState()).color(ChatColor.GOLD).create());
    sender.sendMessage(new ComponentBuilder("Current Session Status: " + monitor.getDiscoveredState()).color(ChatColor.GOLD).create());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:22,代码来源:MojangSessionServiceCommands.java

示例8: environment

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
    aliases = {"environment", "env"},
    desc = "Get/set map environment variables"
)
@CommandPermissions(Permissions.MAPDEV)
public void environment(CommandContext args, final CommandSender sender) throws CommandException {
    final Audience audience = audiences.get(sender);

    boolean reset = false;
    Map<String, Boolean> vars = new HashMap<>();
    Pattern pattern = Pattern.compile("([A-Za-z0-9_]+)=(true|false)");

    for(int i = 0; i < args.argsLength(); i++) {
        String arg = args.getString(i);
        if("reset".equals(arg)) {
            reset = true;
        } else {
            Matcher matcher = pattern.matcher(arg);
            if(!matcher.matches()) {
                throw new CommandException("Can't understand variable assignment '" + arg + "'");
            }
            vars.put(matcher.group(1).toLowerCase(), "true".equals(matcher.group(2)));
        }
    }

    if(reset) mapEnvironment.clear();
    mapEnvironment.putAll(vars);

    for(Map.Entry<String, Boolean> entry : mapEnvironment.entrySet()) {
        audience.sendMessage(
            new Component(ChatColor.GRAY)
                .extra(new Component(entry.getKey(), ChatColor.WHITE))
                .extra("=")
                .extra(new Component(String.valueOf(entry.getValue()), ChatColor.BLUE))
        );
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:38,代码来源:MapDevelopmentCommands.java

示例9: set

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
public void set(CommandContext args, final CommandSender sender, final boolean value) throws CommandException {
    final MutationMatchModule module = verify(sender);
    final Match match = module.getMatch();
    String action = args.getString(0);
    // Mutations that *will* be added or removed
    final Collection<Mutation> mutations = new HashSet<>();
    // Mutations that *are allowed* to be added or removed
    final Collection<Mutation> availableMutations = Sets.newHashSet(Mutation.values());

    final Collection<Mutation> queue = mutationQueue.mutations();
    if(value) availableMutations.removeAll(queue); else availableMutations.retainAll(queue);
    // Check if all mutations have been enabled/disabled
    if((queue.size() == Mutation.values().length && value) || (queue.isEmpty() && !value)) {
        throw newCommandException(sender, new TranslatableComponent(value ? "command.mutation.error.enabled" : "command.mutation.error.disabled"));
    }
    // Get which action the user wants to preform
    switch (action) {
        case "*": mutations.addAll(availableMutations); break;
        case "?": mutations.add(Iterables.get(availableMutations, RandomUtils.safeNextInt(match.getRandom(), availableMutations.size()))); break;
        default:
            Mutation query = StringUtils.bestFuzzyMatch(action, Sets.newHashSet(Mutation.values()), 0.9);
            if (query == null) {
                throw newCommandException(sender, new TranslatableComponent("command.mutation.error.find", action));
            } else {
                mutations.add(query);
            }
    }

    // Send the queued changes off to the api
    syncExecutor.callback(
        value ? mutationQueue.mergeAll(mutations)
              : mutationQueue.removeAll(mutations),
        result -> {
            audiences.get(sender).sendMessage(new Component(new TranslatableComponent(
                message(false, value, mutations.size() == 1),
                new ListComponent(Collections2.transform(mutations, Mutation.toComponent(ChatColor.AQUA)))
            ), ChatColor.WHITE));
        }
    );
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:41,代码来源:MutationCommands.java

示例10: ping

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
    aliases = {"ping"},
    desc = "Send a Ping message to the direct exchange, -r to wait for a reply",
    usage = "<routing key> [-s | -f | -e]",
    flags = "sfe",
    min = 1,
    max = 1
)
public void ping(CommandContext args, CommandSender sender) throws CommandException {
    final String routingKey = args.getString(0);
    final Audience audience = audiences.get(sender);

    audience.sendMessage("ping " + routingKey);

    final Ping.ReplyWith replyWith;
    if(args.hasFlag('s')) {
        replyWith = Ping.ReplyWith.success;
    } else if(args.hasFlag('f')) {
        replyWith = Ping.ReplyWith.failure;
    } else if(args.hasFlag('e')) {
        replyWith = Ping.ReplyWith.exception;
    } else {
        replyWith = null;
    }

    if(replyWith == null) {
        exchange.publishAsync(new Ping(), routingKey);
    } else {
        final Transaction<Reply> transaction = transactions.request(new Ping(replyWith), routingKey);
        syncExecutor.callback(
            transaction,
            CommandFutureCallback.onSuccess(sender, args, reply -> {
                audience.sendMessage(reply.getClass().getSimpleName() + String.format(" (%.3fms)", transaction.elapsedTimeMillis()));
            })
        );
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:38,代码来源:QueueCommands.java

示例11: findOnlinePlayer

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
/**
 * Get an online {@link Player} by partial name.
 * @throws CommandException if the name does not match any player, or matches multiple players
 */
public static Player findOnlinePlayer(CommandContext args, CommandSender sender, int index) throws CommandException {
    if(args.argsLength() > index) {
        String name = args.getString(index);
        List<Player> players = sender.getServer().matchPlayer(name, sender);
        switch(players.size()) {
            case 0: throw new CommandException(Translations.get().t("command.playerNotFound", sender));
            case 1: return players.get(0);
            default: throw new CommandException(Translations.get().t("command.multiplePlayersFound", sender));
        }
    } else {
        throw new CommandException(Translations.get().t("command.specifyPlayer", sender));
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:18,代码来源:CommandUtils.java

示例12: list

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(
    aliases = {"list"},
    desc = "List all permissions",
    usage = "[player] [prefix]",
    min = 0,
    max = 2
)
public void list(CommandContext args, CommandSender sender) throws CommandException {
    CommandSender player = CommandUtils.getCommandSenderOrSelf(args, sender, 0);
    String prefix = args.getString(1, "");

    sender.sendMessage(ChatColor.WHITE + "Permissions for " + player.getName() + ":");

    List<PermissionAttachmentInfo> perms = new ArrayList<>(player.getEffectivePermissions());
    Collections.sort(perms, new Comparator<PermissionAttachmentInfo>() {
        @Override
        public int compare(PermissionAttachmentInfo a, PermissionAttachmentInfo b) {
            return a.getPermission().compareTo(b.getPermission());
        }
    });

    for(PermissionAttachmentInfo perm : perms) {
        if(perm.getPermission().startsWith(prefix)) {
            sender.sendMessage((perm.getValue() ? ChatColor.GREEN : ChatColor.RED) +
                               "  " + perm.getPermission() +
                               (perm.getAttachment() == null ? "" : " (" + perm.getAttachment().getPlugin().getName() + ")"));
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:30,代码来源:PermissionCommands.java

示例13: nick

import com.sk89q.minecraft.util.commands.CommandContext; //导入方法依赖的package包/类
@Command(aliases = {"nick" },
         usage = "list | show [player] | set <nickname> [player] | clear [player] | <nickname> [player]",
         desc = "Show, set, or clear a nickname for yourself or another player. " +
                "Changes will take effect the next time the player " +
                "connects to the server. The -i option makes the change " +
                "visible immediately.",
         flags = "i",
         min = 0,
         max = 3)
@CommandPermissions(PERMISSION)
public void nick(final CommandContext args, final CommandSender sender) throws CommandException {
    if(!config.enabled()) {
        throw new CommandException(Translations.get().t("command.nick.notEnabled", sender));
    }

    final boolean immediate = args.hasFlag('i');

    if(args.argsLength() == 0) {
        show(sender, null);
    } else {
        final String arg = args.getString(0);
        switch(arg) {
            case "list":
                list(sender);
                break;

            case "show":
                show(sender, args.getString(1, null));
                break;

            case "set":
                if(args.argsLength() < 2) CommandUtils.notEnoughArguments(sender);
                set(sender, args.getString(1), args.getString(2, null), immediate);
                break;

            case "clear":
                set(sender, null, args.getString(1, null), immediate);
                break;

            default:
                set(sender, arg, args.getString(1, null), immediate);
                break;
        }
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:46,代码来源:NicknameCommands.java


注:本文中的com.sk89q.minecraft.util.commands.CommandContext.getString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。