Solved Need help fixing my plugin

Discussion in 'Plugin Development' started by kindak, Jul 29, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    kindak

    Hey everyone :D!
    So this is whats up i am a new programer and trying to learn how things works with Api right now so i made a really short pretty useless plugin just for test but something seems to not work the plugin loads and everything but when i type in the command nothing happens ..

    so what i have made is a shortcut command to set your self as creative.

    here is the code,
    http://pastebin.com/H5MdWBib
     
  2. Offline

    ArsenArsen

    Why did you add this?
    , GameMode CREATIVE
     
  3. Offline

    N00BHUN73R

    @kindak
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args, GameMode CREATIVE){
    This is not a valid onCommand event.
    You'd need to remove the GameMode CREATIVE from the method and also make sure that you're registering your commands in your plugin.yml if you're not!
     
  4. Offline

    bdubz4552

    The problem is that the method
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args, GameMode CREATIVE)
    is actually supposed to be an override of the CommandExecutor interface's method. Furthermore, CommandExecutor implementations must be registered in your main class. My recommendation would be to make a separate class, that goes a little something like this:
    Code:
    public class CommandGamemodeChanger implements CommandExecutor {
        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            // Do whatever you need to do
            return true;
        }
    }
    Note that I return true no matter what happens while trying to execute the command; the intention of this method being a boolean is that plugin developers can then see if their commands successfully executed. While this could be useful in some niche cases, I never have found it useful, and I find that it printing out the plain colored usage string from plugin.yml can be a bit of an eye sore, and I opt to send my own usage messsages.

    I mentioned registering CommandExecutors in your main class; here's a sample of what that would look like:
    Code:
    getCommand("mycommandname").setExecutor(new CommandGamemodeChanger());
    Note that "mycommandname" should be whatever you named your command in plugin.yml.

    And building on what ArsenArsen said, since this is an override method, you cannot just redefine its parameters and add a GameMode object. If you want a player to use a command, lets say "/mygamemodeplugin creative" to enter creative mode, you would utilize the parameter "args", which holds any arguments a user may have entered with their command.
     
    I Al Istannen likes this.
  5. Offline

    kindak

    Yea i understand what you mean, and i am pretty sure That i am regestring the commands in plugin.YML isnt this right?

    plugin.yml
    _______________________
    name: Gmc
    main: creative.GMCPlugin
    version: 1.0
    commands:
    Gmc:
    description: Sets you to Creative
    usage: /<command>


    PS: I fixed it :D Thx alot for the selution!
     
    Last edited: Jul 29, 2016
  6. @kindak
    If your problem has been resolved, please mark the thread as such :)
     
Thread Status:
Not open for further replies.

Share This Page