001package com.ericlam.mc.bungee.hnmc.commands.caxerx;
002
003/**
004 * @author Eric Lam
005 * @see DefaultCommand
006 */
007public class DefaultCommandBuilder {
008    private String command;
009    private String description;
010    private String permission;
011    private CommandNode parent;
012    private CommandNode[] children;
013    private String[] alias = new String[0];
014
015    /**
016     * @param command 指令
017     */
018    public DefaultCommandBuilder(String command) {
019        this.command = command;
020    }
021
022    /**
023     * @param description 介紹
024     * @return this
025     */
026    public DefaultCommandBuilder description(String description) {
027        this.description = description;
028        return this;
029    }
030
031    /**
032     * @param permission 權限
033     * @return this
034     */
035    public DefaultCommandBuilder permission(String permission) {
036        this.permission = permission;
037        return this;
038    }
039
040    /**
041     * @param parent 父類指令
042     * @return this
043     */
044    public DefaultCommandBuilder parent(CommandNode parent) {
045        this.parent = parent;
046        return this;
047    }
048
049    /**
050     * DefaultCommand 將為 它其下的分支指令 製作幫助訊息
051     *
052     * @param children 其下分支指令
053     * @return this
054     */
055    public DefaultCommandBuilder children(CommandNode... children) {
056        this.children = children;
057        return this;
058    }
059
060    /**
061     * 若果是主指令,將會自動從 plugin.yml 添加
062     * @param alias 縮寫指令
063     * @return this
064     */
065    public DefaultCommandBuilder alias(String... alias) {
066        this.alias = alias;
067        return this;
068    }
069
070    /**
071     * @return 返回分支指令的幫助訊息的指令
072     */
073    public DefaultCommand build() {
074        DefaultCommand defaultCommand = new DefaultCommand(parent, command, permission, description, alias);
075        for (CommandNode node : children) {
076            node.setParent(defaultCommand);
077            defaultCommand.addSub(node);
078        }
079        return defaultCommand;
080    }
081}
082// 如何使用
083/*
084class DefaultCommandBuilderUse{
085    DefaultCommand getDefaultCommand(){
086        CommandNode node1 = new CommandNodeBuilder("setting").description("get setting help").tabComplete((sender, args) -> null)
087                .execute((sender, args) -> {
088                    MessageBuilder.sendMessage(sender,"help settings");
089                }).build();
090
091        CommandNode node2 = new CommandNodeBuilder("player").description("get player help").tabComplete((sender, args) -> null)
092                .execute((sender, args) -> {
093                    MessageBuilder.sendMessage(sender,"help player");
094                }).build();
095        return new DefaultCommandBuilder("help").permission("help.use").description("get help message").children(node1,node2).build();
096    }
097}
098
099 */
100
101