How to Create Command Expansions

Apr 8, 2018
How to Create Command Expansions
  • This page is going to teach you how to create command expansions for Minecord, which directly handling command "minecord" will not work. Currently Minecord only supports 1 command expansion at the same time, but multiple command expansions support will be added in the future.

    First, create a class that implements com.rcextract.minecord.CommandExpansion:
    Code (Java):
    package me.rcextract;

    import com.rcextract.minecord.CommandExpansion;

    public class Example implements CommandExpansion {

    }
    Note that com.rcextract.minecord.CommandExpansion is only a marker interface, and will not force you or your subclasses to implement any methods.

    Then, create a method of any name with return type as boolean, which lets Bukkit determine the completion of command, and argument types are CommandSender and String[], which CommandSender is the command sender, and String[] is an array of arguments:
    Code (Java):
    package me.rcextract;

    import com.rcextract.minecord.CommandExpansion;

    import org.bukkit.command.CommandSender;

    public class Example implements CommandExpansion {

        public boolean onDisable(CommandSender sender, String[] args) {
            return true;
        }
     
    }
    After that, tag the method with @CommandHandler annotation, with an argument which lets Minecord to determine when to execute this method, according to the command label from the sender input:
    Code (Java):
    package me.rcextract;

    import com.rcextract.minecord.CommandExpansion;
    import com.rcextract.minecord.CommandHandler;

    import org.bukkit.command.CommandSender;

    public class Example implements CommandExpansion {

        @CommandHandler("disable")
        public boolean onDisable(CommandSender sender, String[] args) {
            return true;
        }
     
    }
    The content inside is fully customizable, for example:
    Code (Java):
    package me.rcextract;

    import com.rcextract.minecord.CommandExpansion;
    import com.rcextract.minecord.CommandHandler;

    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.ChatColor;

    public class Example implements CommandExpansion {

        @CommandHandler("disable")
        public boolean onDisable(CommandSender sender, String[] args) {
            if (!(sender.hasPermission("minecord.disable"))) {
                sender.sendMessage(ChatColor.RED + "You are not permitted to disable Minecord with command!");
                return true;
            }
            PluginManager pm = Bukkit.getPluginManager();
            pm.disablePlugin(pm.getPlugin("Minecord"));
            sender.sendMessage(ChatColor.GREEN + "Minecord is disabling!");
            return true;
        }
     
    }
    At last, don't forget the set the current command expansion to your class:
    Code (Java):
    Minecord.getPlugin().setCommandExpansion(new Example());
  • Loading...
  • Loading...