Hi, I'm still learning Bukkit but have an issue with the commands. I've complied a simple script which should make it so, when a player types /myinfo, it will open a chest-type interface in which the user will be presented with various options. I wasn't sure whether to use various classes or not, so I've just clumped everything in one 'main' class. Here's my code: Code:java package net.blastmc.playerstats; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; public class main extends JavaPlugin implements Listener { public void onEnable() { getServer().getPluginManager().registerEvents(this, this); } public static Inventory myInventory = Bukkit.createInventory(null, 9, "Player Info"); static { myInventory.setItem(0, new ItemStack(Material.DIRT, 1)); myInventory.setItem(8, new ItemStack(Material.GOLD_BLOCK, 1)); } @EventHandler public void onInventoryClick(InventoryClickEvent event) { ItemStack clicked = event.getCurrentItem(); Inventory inventory = event.getInventory(); if (inventory.getName().equals(myInventory.getName())) { if (clicked.getType() == Material.DIRT) { event.setCancelled(true); } } } @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (cmd.getName().equalsIgnoreCase("myinfo")) { Player player = (Player) sender; player.openInventory(myInventory); return true; } return false; } } And here is the plugin.yml file that the plugin (should) be using: Code: name: PlayerStats version: 1.1 description: Allows a player to view their own economics, or an Administrator to view anybody's economics (soon!). main: net.blastmc.playerstats.main commands: myinfo: description: Allows you to view your economics. As I say, I'm pretty new to this and am still learning as days pass by - so if anybody would be able to lend a simple solution to the issue (as to why the command won't do anything) it would be a great assistance. Best Regards, Rees.
What sort of error are you getting? Is it that the plugin isn't loading in at all (try /pl or /?) or something different? One thing, I personally like to write in different classses for larger projects, as it keeps the code clear and easy to alter.
Like will181 said, multiple classes makes a project more organised. I usually have: Main MyCommandHander MyEventHandler If I use more than one command: Cmd_NAME Cmd_NAME2 Cmd_NAME3 And if I use other methods, like connecting to / getting from / adding to a database, or making an inventory: DatabaseHandler InventoryHandler