Bryionake: The Groundbreaking BukkitCommand Framework 1.0.0

A framework to make it easy to define bukkit commands

  1. amata1219
    Native Minecraft Version:
    1.16
    Tested Minecraft Versions:
    • 1.16
    Source Code:
    https://github.com/amata1219/Bryionake
    Languages Supported:
    Japanese
    [​IMG]

    Overview


    This is a Spigot plugin that provides a framework for easily defining bukkit commands.

    Example of use
    Code (Text):
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin {

        @Override
        public void onEnable() {
            //Register your bukkit command.
            getCommand("sample").setExecutor(new SampleCommand());
        }

        @Override
        public void onDisable() {

        }

    }
    Code (Text):
    import amata1219.bryionake.constant.CommandSenderCasters;
    import amata1219.bryionake.constant.Parsers;
    import amata1219.bryionake.dsl.BukkitCommandExecutor;
    import amata1219.bryionake.dsl.context.BranchContext;
    import amata1219.bryionake.dsl.context.CommandContext;
    import amata1219.bryionake.dsl.context.ExecutionContext;
    import amata1219.bryionake.dsl.parser.FailableParser;
    import org.bukkit.GameMode;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class SampleCommand implements BukkitCommandExecutor {

        private final CommandContext<CommandSender> executor;

        {
            ExecutionContext<Player> setHealth = define(
                    () ->  "Specify the HP to be set.",
                    (sender, unparsedArguments, parsedArguments) -> {
                        int newHealth = parsedArguments.poll();
                        sender.setHealth(newHealth);
                    },
                    Parsers.i32
            );

            FailableParser<GameMode> gameMode = Parsers.define(
                    GameMode::valueOf,
                    () -> "Select a game mode from SURVIVAL, CREATIVE, ADVENTURE, and SPECTATOR."
            );

            ExecutionContext<Player> setGameMode = define(
                    () -> "Specify the game mode to be set.",
                    (sender, unparsedArguments, parsedArguments) -> {
                        GameMode newGameMode = parsedArguments.poll();
                        sender.setGameMode(newGameMode);
                    },
                    gameMode
            );

            BranchContext<Player> setCommandBranches = define(
                    () -> "The argument must be health or gamemode.",
                    bind("health", setHealth),
                    bind("gamemode", setGameMode)
            );

            executor = define(CommandSenderCasters.casterToPlayer, setCommandBranches);
        }

        @Override
        public CommandContext<CommandSender> executor() {
            return executor;
        }

    }