xtrontross xtrontross - 3 months ago 19
Java Question

Bukkit plugin Syntax error, multiple classes

i'm trying to create plugin with multiple classes, but when I type the command in Minecraft, it shows me command syntax error msg (Syntax error! Simply type /ct create.). I think it is silly misstake somewhere, but i can't find it.

My core.java:

public class Core extends JavaPlugin {

public ArrayList<Block> chests = new ArrayList<>();

public boolean createMode = false;

public void onEnabled() {
getCommand("ct").setExecutor(new Commands(this));
getServer().getPluginManager().registerEvents(new Listeners(this), this);
}
}


My Commands.java:

public class Commands implements CommandExecutor {

private Core plugin;

public Commands(Core core) {
this.plugin = core;
}

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("ct")) {
sender.sendMessage("lol");
if(args.length > 0) {
sender.sendMessage("hi");
if(args[0].equalsIgnoreCase("create")) {
plugin.createMode = true;
sender.sendMessage(ChatColor.GOLD + "[ChestTreasure] " + ChatColor.RESET + "Now rightclick the chest");
}
} else {
sender.sendMessage(ChatColor.GOLD + "[ChestTreasure] " + ChatColor.RESET + "Too few arguments!");
}
}
return false;
}


}

My plugin.yml:

name: ChestTreasure
description: this plugin...
main: me.sudoman281.chestTreasure.Core
version: 1.0
author: sudoman281

commands:
ct:
description: ...
permission: ct.create
usage: Syntax error! Simply type /ct create.

Answer

You have to correctly override the method by having the same exact name and method signature/return type. To do this you must do the following:

  1. Your onEnabled method should be onEnable per the Bukkit API
  2. You should always use the @Override annotation to signify that you are overriding a superclass method. (Optional but highly recommended for finding errors and convention. It will work without this)

Your onEnable should look like this:

@Override
public void onEnable() {
    /* Do stuff when plugin starts */
}
Comments