Reputation: 19
So this is my code:
And this is my plugin.yml:
name: Testing Plugin version: 1.0.0 main: me.TechnicPR.Main
Commands: Cameron description: Says the best developer in the world!
But for some reason when I do /cameron It says un known command, and when I do /pl it show nothing.
Upvotes: 0
Views: 1172
Reputation: 21
Ok, first off you have some major issues. I don't know if you're teaching yourself or using tutorials, but I would recommend using these tutorials. So I'll start with your plugin.yml file, as the setup for that is very specific. It should look exactly like this:
name: TestingPlugin
version: 1.0.0
main: me.TechnicPR.Main
commands:
cameron:
description: Says the best developer in the world!
usage: /<command>
These sections can be in any order; name does not have to go first, for instance. But every section must be lowercase. If it is capitalized as you had "Commands:", then it will throw an error. Also, you should always provide the "usage" section in each command. Remember to not use tabs; you must use spaces, or it will throw an error for that too.
As for your code, I first off would like to very strongly urge you to NOT put your onCommand method in your main class. You main class should only ever deal with file loading and saving, and your onEnable/onDisable methods. Having the plugin in your main class gets messy really quick, and complicates simple things.
But, whether or not you only use a Main class, you still need to register your command. Make a new method, above your onCommand method, called "onEnable()". Inside that, use
getCommand("Cameron").setExecutor(this, this);
It should look something like this:
public void onEnable(){
getCommand("Cameron").setExecutor(this, this);
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
if(cmd.getName().equalsIgnoreCase("Cameron")){
sender.sendMessage("Hello!");
}
return true;
}
Notice that the onCommand returns true. You will need to have it set to true to get a proper result. That's not everything that should be corrected, but you seem somewhat new to this and I don't want to seem heavy-handed. ;) Hope this helped! If you want or need more help with making commands, the above mentioned link will give you any information you will need. Request any tutorial to that guy, and He'll make it asap.
Upvotes: 1
Reputation: 1
It may be that you are not setting the executor class for the command, I'm not sure if it applies to the JavaPlugin class. Try adding this to your onEnable,
getCommand("Cameron").setExecutor(this);
Upvotes: 0
Reputation: 526
You must indent your informations. e.g
name: Name
version: 1.0
main: my.main.class
commands:
example:
description: Example command
If it's just StackOverflow, say it in the comments. And please post your log as well.
Upvotes: 1