com.sk89q.minecraft.util.commands.Command Java Examples

The following examples show how to use com.sk89q.minecraft.util.commands.Command. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapSelectionCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"beginvote", "startvote"},
        desc = "Begins a map selection vote.",
        min = 0,
        max = 0,
        flags = "ct:"
)
@Console
@CommandPermissions("tourney.map.beginvote")
public void beginVote(CommandContext args, CommandSender sender) throws CommandException {
    if (!tourney.getState().equals(TourneyState.ENABLED_WAITING_FOR_READY)) {
        throw new CommandException("This match is not in a state that is eligible for map selection.");
    } else if (voteContext.voteInProgress()) {
        throw new CommandException("There is already a map selection vote in progress.");
    } else if (!args.hasFlag('c')) {
        throw new CommandException("Re-run command with -c to confirm. Map selection may not be ended pre-maturely.");
    }

    if (args.hasFlag('t')) {
        MapClassification classification = classificationManager.classificationFromSearch(args.getFlag('t'));
        if (classification == null) throw new CommandException("No classification matched query.");
        voteContext.startVote(Collections.singleton(classification));
    } else {
        voteContext.startVote(classificationManager.getClassifications());
    }
}
 
Example #2
Source File: WhitelistCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"add"},
    desc = "Add a player to the whitelist",
    usage = "<username>",
    min = 1,
    max = 1
)
public void add(CommandContext args, final CommandSender sender) throws CommandException {
    syncExecutor.callback(
        userFinder.findUser(sender, args, 0),
        CommandFutureCallback.onSuccess(sender, args, result -> {
            whitelist.add(result.user);
            audiences.get(sender).sendMessage(
                new TranslatableComponent(
                    "whitelist.add",
                    new PlayerComponent(identities.currentIdentity(result.user), NameStyle.FANCY)
                )
            );
        })
    );
}
 
Example #3
Source File: MapCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"maplist", "maps", "ml"},
    desc = "Shows the maps that are currently loaded",
    usage = "[page]",
    min = 0,
    max = 1,
    help = "Shows all the maps that are currently loaded including ones that are not in the rotation."
)
@CommandPermissions("pgm.maplist")
public static void maplist(CommandContext args, final CommandSender sender) throws CommandException {
    final Set<PGMMap> maps = ImmutableSortedSet.copyOf(new PGMMap.DisplayOrder(), PGM.getMatchManager().getMaps());

    new PrettyPaginatedResult<PGMMap>(PGMTranslations.get().t("command.map.mapList.title", sender)) {
        @Override public String format(PGMMap map, int index) {
            return (index + 1) + ". " + map.getInfo().getShortDescription(sender);
        }
    }.display(new BukkitWrappedCommandSender(sender), maps, args.getInteger(0, 1) /* page */);
}
 
Example #4
Source File: AdminCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"skipto"},
    desc = "Skip to a certain point in the rotation",
    usage = "[n]",
    min = 1,
    max = 1
)
@CommandPermissions("pgm.skip")
public void skipto(CommandContext args, CommandSender sender) throws CommandException {
    RotationManager manager = PGM.getMatchManager().getRotationManager();
    RotationState rotation = manager.getRotation();

    int newNextId = args.getInteger(0) - 1;
    if(RotationState.isNextIdValid(rotation.getMaps(), newNextId)) {
        rotation = rotation.skipTo(newNextId);
        manager.setRotation(rotation);
        sender.sendMessage(ChatColor.GREEN + PGMTranslations.get().t("command.admin.skipto.success", sender, rotation.getNext().getInfo().getShortDescription(sender) + ChatColor.GREEN));
    } else {
        throw new CommandException(PGMTranslations.get().t("command.admin.skipto.invalidPoint", sender));
    }
}
 
Example #5
Source File: TraceCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"off", "stop"},
    desc = "Stop logging packets",
    min = 0,
    max = 1
)
public void stop(CommandContext args, CommandSender sender) throws CommandException {
    if(sender instanceof Player || args.argsLength() >= 1) {
        final Player player = (Player) getCommandSenderOrSelf(args, sender, 0);
        if(PacketTracer.stop(player)) {
            sender.sendMessage("Stopped packet trace for " + player.getName(sender));
        }
    } else {
        traceAll.set(false);
        if(onlinePlayers.all().stream().anyMatch(PacketTracer::stop)) {
            sender.sendMessage("Stopped all packet tracing");
        }
    }
}
 
Example #6
Source File: PermissionCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@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);
    }
}
 
Example #7
Source File: WhisperCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"msg", "message", "whisper", "pm", "tell", "dm"},
    usage = "<target> <message...>",
    desc = "Private message a user",
    min = 2,
    max = -1
)
@CommandPermissions("projectares.msg")
public void message(final CommandContext args, final CommandSender sender) throws CommandException {
    final Player player = CommandUtils.senderToPlayer(sender);
    final Identity from = identityProvider.currentIdentity(player);
    final String content = args.getJoinedStrings(1);

    executor.callback(
        userFinder.findUser(sender, args, 0),
        CommandFutureCallback.onSuccess(sender, args, response -> {
            whisperSender.send(sender, from, identityProvider.createIdentity(response), content);
        })
    );
}
 
Example #8
Source File: AdminCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"restart"},
    desc = "Queues a server restart after a certain amount of time",
    usage = "[seconds] - defaults to 30 seconds",
    flags = "f",
    min = 0,
    max = 1
)
@CommandPermissions("server.restart")
public void restart(CommandContext args, CommandSender sender) throws CommandException {
    // Countdown defers automatic restart, so don't allow excessively long times
    Duration countdown = TimeUtils.min(
        tc.oc.commons.bukkit.commands.CommandUtils.getDuration(args, 0, Duration.ofSeconds(30)),
        Duration.ofMinutes(5)
    );

    final Match match = CommandUtils.getMatch(sender);
    if(!match.canAbort() && !args.hasFlag('f')) {
        throw new CommandException(PGMTranslations.get().t("command.admin.restart.matchRunning", sender));
    }

    restartListener.queueRestart(match, countdown, "/restart command");
}
 
Example #9
Source File: PunishmentCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = { "rp", "repeatpunish" },
    usage = "[player]",
    desc = "Show the last punishment you issued or repeat it for a different player",
    min = 0,
    max = 1
)
public void repeat(CommandContext args, CommandSender sender) throws CommandException {
    final User punisher = userFinder.getLocalUser(sender);
    final Audience audience = audiences.get(sender);
    if(permission(sender, null)) {
        syncExecutor.callback(
                userFinder.findUser(sender, args, 0, NULL),
                punished -> syncExecutor.callback(
                        punishmentService.find(PunishmentSearchRequest.punisher(punisher, 1)),
                        punishments -> punishments.documents().stream().findFirst().<Runnable>map(last -> () -> {
                            if (punished != null) {
                                punishmentCreator.repeat(last, punished.user);
                            } else {
                                audience.sendMessages(punishmentFormatter.format(last, false, false));
                            }
                        }).orElse(() -> audience.sendMessage(new WarningComponent("punishment.noneIssued"))).run()
                )
        );
    }
}
 
Example #10
Source File: FreeForAllCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"max", "size"},
    desc = "Change the maximum number of players allowed to participate in the match.",
    min = 1,
    max = 2
)
@CommandPermissions("pgm.team.size")
public static void max(CommandContext args, CommandSender sender) throws CommandException {
    FreeForAllMatchModule ffa = CommandUtils.getMatchModule(FreeForAllMatchModule.class, sender);
    if("default".equals(args.getString(0))) {
        ffa.setMaxPlayers(null, null);
    } else {
        int maxPlayers = args.getInteger(0);
        if(maxPlayers < 0) throw new CommandException("max-players cannot be less than 0");

        int maxOverfill = args.argsLength() >= 2 ? args.getInteger(1) : maxPlayers;
        if(maxOverfill < maxPlayers) throw new CommandException("max-overfill cannot be less than max-players");

        if(maxPlayers < ffa.getMinPlayers()) throw new CommandException("max-players cannot be less than min-players");

        ffa.setMaxPlayers(maxPlayers, maxOverfill);
    }

    sender.sendMessage(ChatColor.WHITE + "Maximum players is now " + ChatColor.AQUA + ffa.getMaxPlayers() +
                       ChatColor.WHITE + " and overfill is " + ChatColor.AQUA + ffa.getMaxOverfill());
}
 
Example #11
Source File: FreeForAllCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"min"},
    desc = "Change the minimum number of players required to start the match.",
    min = 1,
    max = 1
)
@CommandPermissions("pgm.team.size")
public static void min(CommandContext args, CommandSender sender) throws CommandException {
    FreeForAllMatchModule ffa = CommandUtils.getMatchModule(FreeForAllMatchModule.class, sender);
    if("default".equals(args.getString(0))) {
        ffa.setMinPlayers(null);
    } else {
        int minPlayers = args.getInteger(0);
        if(minPlayers < 0) throw new CommandException("min-players cannot be less than 0");
        if(minPlayers > ffa.getMaxPlayers()) throw new CommandException("min-players cannot be greater than max-players");
        ffa.setMinPlayers(minPlayers);
    }

    sender.sendMessage(ChatColor.WHITE + "Minimum players is now " + ChatColor.AQUA + ffa.getMinPlayers());
}
 
Example #12
Source File: ResourcePackCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"status"},
    desc = "Show info about the custom resource pack",
    min = 0,
    max = 0
)
public void status(CommandContext args, CommandSender sender) throws CommandException {
    sender.sendMessage("Custom resource packs are locally " + (manager.isEnabled() ? "ENABLED" : "DISABLED"));
    sender.sendMessage("Fast updating is " + (manager.isFastUpdate() ? "ENABLED" : "DISABLED"));
    if(manager.getUrl() == null) {
        sender.sendMessage("No resource pack is configured for this server");
    } else {
        sender.sendMessage("URL:  " + manager.getUrl());
        sender.sendMessage("SHA1: " + manager.getSha1());
    }
}
 
Example #13
Source File: RestartCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"cancelrestart", "cr"},
        desc = "Cancels a previously requested restart",
        min = 0,
        max = 0
)
@CommandPermissions("server.cancelrestart")
@Console
public void cancelRestart(CommandContext args, final CommandSender sender) throws CommandException {
    if(!restartManager.isRestartRequested()) {
        throw new TranslatableCommandException("command.admin.cancelRestart.noActionTaken");
    }

    syncExecutor.callback(
        restartManager.cancelRestart(),
        CommandFutureCallback.onSuccess(sender, args, o -> {
            audiences.get(sender).sendMessage(new TranslatableComponent("command.admin.cancelRestart.restartUnqueued"));
        })
    );
}
 
Example #14
Source File: TeamCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"shuffle"},
    desc = "Shuffle the teams",
    min = 0,
    max = 0
)
@CommandPermissions("pgm.team.shuffle")
public void shuffle(CommandContext args, CommandSender sender) throws CommandException {
    TeamMatchModule tmm = utils.module();
    Match match = tmm.getMatch();

    if(match.isRunning()) {
        throw new CommandException(Translations.get().t("command.team.shuffle.matchRunning", sender));
    } else {
        List<Team> teams = new ArrayList<>(this.teams);
        List<MatchPlayer> participating = new ArrayList<>(match.getParticipatingPlayers());
        Collections.shuffle(participating);
        for(int i = 0; i < participating.size(); i++) {
            tmm.forceJoin(participating.get(i), teams.get((i * teams.size()) / participating.size()));
        }
        match.sendMessage(new TranslatableComponent("command.team.shuffle.success"));
    }
}
 
Example #15
Source File: TicketCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = { "watch" },
    desc = "Spectate a game",
    usage = "[game]",
    min = 0,
    max = -1
)
public List<String> watch(final CommandContext args, final CommandSender sender) throws CommandException {
    final String name = args.argsLength() > 0 ? args.getRemainingString(0) : "";
    if(args.getSuggestionContext() != null) {
        return StringUtils.complete(name, ticketBooth.allGames(sender).stream().map(Game::name));
    }

    ticketBooth.watchGame(CommandUtils.senderToPlayer(sender), name);
    return null;
}
 
Example #16
Source File: TeamCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"min"},
    desc = "Change the minimum size of a team.",
    usage = "<team> (default | <min-players>)",
    min = 2,
    max = 2
)
@CommandPermissions("pgm.team.size")
public void min(CommandContext args, CommandSender sender) throws CommandException, SuggestException {
    Team team = utils.teamArgument(args, 0);

    if("default".equals(args.getString(1))) {
        team.resetMinSize();
    } else {
        int minPlayers = args.getInteger(1);
        if(minPlayers < 0) throw new CommandException("min-players cannot be less than 0");
        team.setMinSize(minPlayers);
    }

    sender.sendMessage(team.getColoredName() +
                       ChatColor.WHITE + " now has min size " + ChatColor.AQUA + team.getMinPlayers());
}
 
Example #17
Source File: InventoryCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"inventory", "inv", "vi"},
    desc = "View a player's inventory",
    usage = "<player>",
    min = 1,
    max = 1
)
public void inventory(CommandContext args, CommandSender sender) throws CommandException {
    final Player viewer = senderToPlayer(sender);
    Player holder = findOnlinePlayer(args, viewer, 0);

    if(vimm.canPreviewInventory(viewer, holder)) {
        vimm.previewInventory((Player) sender, holder.getInventory());
    } else {
        throw new TranslatableCommandException("player.inventoryPreview.notViewable");
    }
}
 
Example #18
Source File: DebugCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = "sleep",
    desc = "Put the main server thread to sleep for the given duration",
    usage = "<time>",
    flags = "",
    min = 1,
    max = 1
)
@CommandPermissions(Permissions.DEVELOPER)
public void sleep(CommandContext args, CommandSender sender) throws CommandException {
    try {
        Thread.sleep(durationParser.parse(args.getString(0)).toMillis());
    } catch(InterruptedException e) {
        throw new CommandException("Sleep was interrupted", e);
    }
}
 
Example #19
Source File: MapDevelopmentCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"matchfeatures", "features"},
    desc = "Lists all features by ID and type",
    min = 0,
    max = 1
)
@CommandPermissions(Permissions.MAPDEV)
public void featuresCommand(CommandContext args, CommandSender sender) throws CommandException {
    final Match match = tc.oc.pgm.commands.CommandUtils.getMatch(sender);
    new PrettyPaginatedResult<Feature>("Match Features") {
        @Override
        public String format(Feature feature, int i) {
            String text = (i + 1) + ". " + ChatColor.RED + feature.getClass().getSimpleName();
            if(feature instanceof SluggedFeature) {
                text += ChatColor.GRAY + " - " +ChatColor.GOLD + ((SluggedFeature) feature).slug();
            }
            return text;
        }
    }.display(new BukkitWrappedCommandSender(sender),
              match.features().all().collect(Collectors.toList()),
              args.getInteger(0, 1));
}
 
Example #20
Source File: ModelCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example #21
Source File: MapDevelopmentCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = {"feature", "fl"},
    desc = "Prints information regarding a specific feature",
    min = 1,
    max = -1
)
@CommandPermissions(Permissions.MAPDEV)
public void featureCommand(CommandContext args, CommandSender sender) throws CommandException {
    final String slug = args.getJoinedStrings(0);
    final Optional<Feature<?>> feature = matchManager.getCurrentMatch(sender).features().bySlug(slug);
    if(feature.isPresent()) {
        sender.sendMessage(ChatColor.GOLD + slug + ChatColor.GRAY + " corresponds to: " + ChatColor.WHITE + feature.get().toString());
    } else {
        sender.sendMessage(ChatColor.RED + "No feature by the name of " + ChatColor.GOLD + slug + ChatColor.RED + " was found.");
    }
}
 
Example #22
Source File: ServerCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"hub", "lobby"},
        desc = "Teleport to the lobby"
)
public void hub(final CommandContext args, CommandSender sender) throws CommandException {
    if(sender instanceof ProxiedPlayer) {
        final ProxiedPlayer player = (ProxiedPlayer) sender;
        final Server server = Futures.getUnchecked(executor.submit(() -> serverTracker.byPlayer(player)));
        if(server.role() == ServerDoc.Role.LOBBY || server.role() == ServerDoc.Role.PGM) {
            // If Bukkit server is running Commons, let it handle the command
            throw new CommandBypassException();
        }

        player.connect(proxy.getServerInfo("default"));
        player.sendMessage(new ComponentBuilder("Teleporting you to the lobby").color(ChatColor.GREEN).create());
    } else {
        sender.sendMessage(new ComponentBuilder("Only players may use this command").color(ChatColor.RED).create());
    }
}
 
Example #23
Source File: ObjectiveModeCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = "list",
    desc = "Lists all modes"
)
public void list(CommandContext args, CommandSender sender) throws CommandException {
    final ObjectiveModeManager manager = this.manager.get();
    final Audience audience = audiences.get(sender);
    final Map<ObjectiveMode, Duration> modes = manager.modes();

    if(modes.isEmpty()) {
        sendNoModes(audience);
    } else {
        audience.sendMessage(new HeaderComponent(new TranslatableComponent("match.objectiveMode.header")));
        modes.forEach((mode, time) -> audience.sendMessage(formatMode(mode, time)));
    }
}
 
Example #24
Source File: ServerCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"gqueuerestart", "gqr"},
        usage = "[-c]",
        desc = "Shutdown the next time the server is inactive and empty",
        flags = "c",
        help = "The -c flag cancels a previously queued restart"
)
@CommandPermissions("bungeecord.command.restart")
public void queueRestart(final CommandContext args, final CommandSender sender) throws CommandException {
    if(restartManager == null) {
        throw new CommandException("Scheduled restarts are not enabled");
    } else {
        if(args.hasFlag('c')) {
            sender.sendMessage(new TextComponent("Restart cancelled"));
            restartManager.cancelRestart();
        } else {
            sender.sendMessage(new TextComponent("Restart queued"));
            restartManager.requestRestart("/gqr command by " + sender.getName());
        }
    }
}
 
Example #25
Source File: FreezeCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = { "freeze", "f" },
    usage = "<player>",
    desc = "Freeze a player",
    min = 1,
    max = 1
)
@CommandPermissions(Freeze.PERMISSION)
public void freeze(final CommandContext args, final CommandSender sender) throws CommandException {
    if(!freeze.enabled()) {
        throw new ComponentCommandException(new TranslatableComponent("command.freeze.notEnabled"));
    }

    executor.callback(
        userFinder.findLocalPlayer(sender, args, 0),
        CommandFutureCallback.onSuccess(sender, args, response -> freeze.toggleFrozen(sender, response.player()))
    );
}
 
Example #26
Source File: TourneyCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"invalidate", "nosave", "norecord"},
        desc = "Indicates that the current match should not be saved to the database.",
        min = 0,
        max = 0,
        flags = "c"
)
@Console
@CommandPermissions("tourney.invalidate")
public static void invalidate(final CommandContext args, final CommandSender sender) throws CommandException {
    Tourney plugin = Tourney.get();
    if (!Arrays.asList(TourneyState.ENABLED_RUNNING, TourneyState.ENABLED_FINISHED).contains(plugin.getState())) {
        throw new CommandException("This match may not be invalidated at this time.");
    }

    if (plugin.isRecordQueued()) {
        if (args.hasFlag('c')) {
            plugin.setRecordQueued(false);
            sender.sendMessage(ChatColor.YELLOW + "Match successfully invalidated.");
        } else {
            throw new CommandException("Match is eligible for invalidation. Re-run command with -c to confirm. Invalidation may not be reversed.");
        }
    } else {
        throw new CommandException("This match is not queued to be recorded.");
    }
}
 
Example #27
Source File: TeamCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
        aliases = {"teams", "listteams"},
        desc = "Lists the teams registered for competition on this server.",
        min = 0,
        max = 1,
        usage = "[page]"
)
@Console
@CommandPermissions("tourney.listteams")
public void listTeams(final CommandContext args, final CommandSender sender) throws CommandException {
    new Paginator<team.Id>()
        .title(new TranslatableComponent("tourney.teams.title", tournamentName))
        .entries((team, index) -> teamName(team))
        .display(audiences.get(sender),
                 tournament.accepted_teams(),
                 args.getInteger(0, 1));
}
 
Example #28
Source File: TicketCommands.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Command(
    aliases = { "play", "replay" },
    desc = "Play a game",
    usage = "[game]",
    min = 0,
    max = -1
)
public List<String> play(final CommandContext args, final CommandSender sender) throws CommandException {
    final String name = args.argsLength() > 0 ? args.getRemainingString(0) : "";
    if(args.getSuggestionContext() != null) {
        return StringUtils.complete(name, ticketBooth.allGames(sender).stream().map(Game::name));
    }

    ticketBooth.playGame(CommandUtils.senderToPlayer(sender), name);
    return null;
}
 
Example #29
Source File: TourneyCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"unready"},
        desc = "Indicates that the executing team is no longer ready.",
        min = 0,
        max = 0
)
@CommandPermissions(TourneyPermissions.READY)
public static void unready(final CommandContext args, final CommandSender sender) throws CommandException {
    if (!(sender instanceof Player)) throw new CommandException("You must be a player to use this command.");
    Tourney plugin = Tourney.get();
    if (!(Arrays.asList(TourneyState.ENABLED_STARTING, TourneyState.ENABLED_WAITING_FOR_READY).contains(plugin.getState()))) {
        throw new CommandException("This match is not in an un-ready-able state.");
    }

    MatchPlayer player = CommandUtils.senderToMatchPlayer(sender);

    Party party = player.getParty();
    if(party.isObservingType()) {
        assertPermission(sender, TourneyPermissions.READY_OBSERVER);
    }

    ReadyManager readyManager = Preconditions.checkNotNull(plugin.getMatchManager(), "Match manager").getReadyManager();
    if (readyManager.isReady(party)) {
        readyManager.markNotReady(party);
    } else {
        throw new CommandException("Your team is not ready.");
    }
}
 
Example #30
Source File: TourneyCommands.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Command(
        aliases = {"ready"},
        desc = "Indicates that the executing team is ready.",
        min = 0,
        max = 0
)
@CommandPermissions(TourneyPermissions.READY)
public static void ready(final CommandContext args, final CommandSender sender) throws CommandException {
    Tourney plugin = Tourney.get();
    if (!(plugin.getState().equals(TourneyState.ENABLED_WAITING_FOR_READY))) {
        throw new CommandException("This match is not in a ready-able state.");
    }

    final Match match = CommandUtils.getMatch(sender);
    final Party party = match.player(sender)
                             .map(MatchPlayer::getParty)
                             .orElse(match.getDefaultParty());

    if(party.isObservingType()) {
        assertPermission(sender, TourneyPermissions.READY_OBSERVER);
    }

    ReadyManager readyManager = Preconditions.checkNotNull(plugin.getMatchManager(), "Match manager").getReadyManager();
    int minPlayers = plugin.getTournament().min_players_per_match();
    int presentPlayers = party.getPlayers().size();
    if (party.isParticipatingType() && minPlayers > presentPlayers) {
        throw new CommandException("You need at least " + (minPlayers - presentPlayers) + " more players present to ready your team.");
    } else {
        if (!readyManager.isReady(party)) {
            readyManager.markReady(party);
        } else {
            throw new CommandException("Your team is already ready.");
        }
    }
}