CommandBlocker API

Jul 31, 2016
CommandBlocker API
  • Hello!

    This wiki tutorial will teach you all about the new API for CommandBlocker!

    CommandBlocker is a new plugin to block any command!

    Usage:

    Events:

    First, let's do our events; The current events are "BlockCommandEvent" and "UnblockCommandEvent"

    Code (Text):
    @EventHandler
    public void cmdBlock(BlockCommandEvent event) {
       
    }

    @EventHandler
    public void cmdBlock(UnblockCommandEvent event) {
       
    }
    This will listen for our events, don't forget to register the class as a Listener and add it to your onEnable()

    Next, we want to find the command that was blocked and who blocked it!

    Code (Text):
    @EventHandler
    public void cmdBlock(BlockCommandEvent event) {

        String command = event.getCommand();
       
        CommandSender creator = event.getCreator();
       
    }

    @EventHandler
    public void cmdBlock(UnblockCommandEvent event) {
       
        String command = event.getCommand();
       
        CommandSender creator = event.getCreator();
       
    }
    Now we know the command and the creator. NOTE: If the creator was a Plugin using this API, event.getCreator() will return null.

    Code (Text):
    @EventHandler
    public void cmdBlock(BlockCommandEvent event) {

        String command = event.getCommand();
       
        CommandSender creator = event.getCreator();
       
        if (creator instanceof Player) {
            creator.sendMessage("You unblocked the command /" + command + "!")
        }
       
    }

    @EventHandler
    public void cmdBlock(UnblockCommandEvent event) {
       
        String command = event.getCommand();
       
        CommandSender creator = event.getCreator();
       
        if (creator instanceof Player) {
            creator.sendMessage("You unblocked the command /" + command + "!")
        }
       
    }

    Those are the events, and of course, you can do anything you want in the event.

    Main API:

    The main API can create or delete blocked commands whenever. It can be used in other commands or events!


    To get the main API instance, add this to your code:

    Code (Text):
    CommandBlocker cb = new CommandBlocker("SomeCommand");
    Command is not case sensitive.

    Note that the plugin does currently NOT support sub-commands, if you use them in the code it will block the main command.

    Now let's decide what we want to do with this command, Should we block it or unblock it? Here's how to do both!

    Block:
    Code (Text):
    cb.addCommand();
    Adds command to blocked commands list.

    Code (Text):
    if (cb.isBlocked()) {
        cb.removeCommand();
    }
    Checks if the command is blocked {cb.isBlocked()} and if it is blocked, unblocks it {cb.removeCommand();}


    That's currently it for this API! Make sure to PM @iShadey with API suggestions for this plugin!
  • Loading...
  • Loading...