Search in sources :

Example 1 with GameMode

use of com.voxelgameslib.voxelgameslib.game.GameMode in project VoxelGamesLibv2 by VoxelGamesLib.

the class VoxelGamesLib method registerCommandContexts.

private void registerCommandContexts() {
    CommandContexts<BukkitCommandExecutionContext> con = commandManager.getCommandContexts();
    con.registerIssuerAwareContext(User.class, c -> {
        boolean isOptional = c.hasAnnotation(Optional.class);
        CommandSender sender = c.getSender();
        boolean isPlayerSender = sender instanceof Player;
        if (!c.hasFlag("other")) {
            Player player = isPlayerSender ? (Player) sender : null;
            if (player == null) {
                if (!isOptional) {
                    throw new InvalidCommandArgument(MessageKeys.NOT_ALLOWED_ON_CONSOLE, false);
                } else {
                    return null;
                }
            }
            return userHandler.getUser(player.getUniqueId()).orElseThrow(() -> new VoxelGameLibException("Unknown user " + player.getDisplayName()));
        } else {
            String arg = c.popFirstArg();
            if (arg == null) {
                if (isOptional) {
                    if (c.hasFlag("defaultself")) {
                        if (isPlayerSender) {
                            return userHandler.getUser(((Player) sender).getUniqueId()).orElseThrow(() -> new VoxelGameLibException("Unknown user " + ((Player) sender).getDisplayName()));
                        } else {
                            throw new InvalidCommandArgument(MessageKeys.NOT_ALLOWED_ON_CONSOLE, false);
                        }
                    }
                }
                return null;
            } else {
                return userHandler.getUser(arg).orElseThrow(() -> new VoxelGameLibException("Unknown user " + arg));
            }
        }
    });
    con.registerContext(int.class, c -> Integer.parseInt(c.popFirstArg()));
    con.registerContext(GameMode.class, c -> {
        GameMode mode = gameHandler.getGameModes().stream().filter(gameMode -> gameMode.getName().equalsIgnoreCase(c.getFirstArg())).findAny().orElseThrow(() -> new InvalidCommandArgument("Unknown gamemode " + c.getFirstArg()));
        // pop later so that we can get a nice error message
        c.popLastArg();
        return mode;
    });
    con.registerContext(Locale.class, c -> {
        Locale locale = Locale.fromName(c.getFirstArg()).orElse(Locale.fromTag(c.getFirstArg()).orElseThrow(() -> new InvalidCommandArgument("Unknown locale " + c.getFirstArg())));
        // pop later so that we can get a nice error message
        c.popFirstArg();
        return locale;
    });
    con.registerContext(Role.class, c -> Role.fromName(c.popFirstArg()));
    con.registerContext(UUID.class, c -> UUID.fromString(c.popFirstArg()));
    con.registerContext(Trackable.class, c -> {
        Trackable s = StatsHandler.fromName(c.getFirstArg()).orElseThrow(() -> new InvalidCommandArgument("Unknown stats type " + c.getFirstArg()));
        // pop later so that we can get a nice error message
        c.popFirstArg();
        return s;
    });
}
Also used : Locale(com.voxelgameslib.voxelgameslib.lang.Locale) GameMode(com.voxelgameslib.voxelgameslib.game.GameMode) Player(org.bukkit.entity.Player) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) VoxelGameLibException(com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException) CommandSender(org.bukkit.command.CommandSender) Trackable(com.voxelgameslib.voxelgameslib.stats.Trackable) BukkitCommandExecutionContext(co.aikar.commands.BukkitCommandExecutionContext)

Example 2 with GameMode

use of com.voxelgameslib.voxelgameslib.game.GameMode in project VoxelGamesLibv2 by VoxelGamesLib.

the class VoxelGamesLib method registerCommandReplacements.

private void registerCommandReplacements() {
    CommandReplacements rep = commandManager.getCommandReplacements();
    rep.addReplacement("@gamemodes", gameHandler.getGameModes().stream().map(GameMode::getName).collect(Collectors.joining("|")));
    rep.addReplacement("@locales", Arrays.stream(Locale.values()).map(locale -> locale.getName() + "|" + locale.getTag()).collect(Collectors.joining("|")));
    rep.addReplacement("@roles", Arrays.stream(Role.values()).map(Role::getName).collect(Collectors.joining("|")));
    rep.addReplacement("@stats", statsHandler.getStatTypes().stream().map(stat -> stat.getPrefix() + ":" + stat.name()).collect(Collectors.joining("|")));
    rep.addReplacement("%user", "voxelgameslib.role.user");
    rep.addReplacement("%premium", "voxelgameslib.role.premium");
    rep.addReplacement("%moderator", "voxelgameslib.role.moderator");
    rep.addReplacement("%admin", "voxelgameslib.role.admin");
}
Also used : Role(com.voxelgameslib.voxelgameslib.role.Role) GameMode(com.voxelgameslib.voxelgameslib.game.GameMode) CommandReplacements(co.aikar.commands.CommandReplacements)

Example 3 with GameMode

use of com.voxelgameslib.voxelgameslib.game.GameMode in project VoxelGamesLibv2 by VoxelGamesLib.

the class WorldCreator method author.

@Subcommand("author")
@CommandPermission("%admin")
public void author(@Nonnull User sender, @Nonnull String author) {
    if (step != 5) {
        Lang.msg(sender, LangKey.WORLD_CREATOR_WRONG_STEP, step, 5);
        return;
    }
    this.author = author;
    Lang.msg(sender, LangKey.WORLD_CREATOR_AUTHOR_SET, author);
    for (GameMode mode : gameHandler.getGameModes()) {
        sender.sendMessage(TextComponent.of(mode.getName() + " ").color(TextColor.YELLOW).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/worldcreator gamemode " + mode.getName())));
    }
    Lang.msg(sender, LangKey.WORLD_CREATOR_DONE_QUERY, "/worldcreator gamemode done");
    step = 6;
}
Also used : GameMode(com.voxelgameslib.voxelgameslib.game.GameMode) ClickEvent(net.kyori.text.event.ClickEvent) Subcommand(co.aikar.commands.annotation.Subcommand) CommandPermission(co.aikar.commands.annotation.CommandPermission)

Aggregations

GameMode (com.voxelgameslib.voxelgameslib.game.GameMode)3 BukkitCommandExecutionContext (co.aikar.commands.BukkitCommandExecutionContext)1 CommandReplacements (co.aikar.commands.CommandReplacements)1 InvalidCommandArgument (co.aikar.commands.InvalidCommandArgument)1 CommandPermission (co.aikar.commands.annotation.CommandPermission)1 Subcommand (co.aikar.commands.annotation.Subcommand)1 VoxelGameLibException (com.voxelgameslib.voxelgameslib.exception.VoxelGameLibException)1 Locale (com.voxelgameslib.voxelgameslib.lang.Locale)1 Role (com.voxelgameslib.voxelgameslib.role.Role)1 Trackable (com.voxelgameslib.voxelgameslib.stats.Trackable)1 ClickEvent (net.kyori.text.event.ClickEvent)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1