Command confusion

Discussion in 'Plugin Development' started by AchillePomeroy, Mar 7, 2011.

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

    AchillePomeroy

    Recently I've been trying to make a simple plugin that lets the members on my server see general info about the server (Playerlists, MOTD, rules, ventrilo server IP, etc). I've been having a lot of trouble with the commands, though. When players log in, they can see the player count just fine, but can't do anything after that. When people try to use commands like "/online", the server console says "AchillePomeroy used the unknown command online".
    To my understanding, this means that my plugin isn't catching the player's commands, and that the Minecraft server is trying to deal with the commands.

    The most likely reason why: I can not figure out how commands work. I've been looking around, and I see at least three different methods for commands.

    There's the registerEvent method:
    Code:
    pm.registerEvent(Event.Type.PLAYER_CHAT, playerListener, Priority.Normal, this);
    There's also the getCommand method that I've heard is deprecated.

    And lastly, the new command interface that "broke everything".
    I feel like this last one is the one I am going to end up using, but can't quite get it to work.


    I get the following error:

    Code:
    [SEVERE] Could not load plugins\Informer.jar in plugins: null
    org.bukkit.pluginInvalidPluginException
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java: 85)
    //many more similar errors
    Caused by: java.lang.NoClassDefFoundError: org/bukkit/command/CommandExecutor
    
    Here are the major points of my code:
    Informer.java (open)

    Code:
    public void onEnable() {
    		PluginManager pm = getServer().getPluginManager();
    		pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
    		pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
    		pdfFile = this.getDescription();
    		System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled.");
    		getCommand("count").setExecutor(new CommandExecutor() {
    			public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    				if (playerListener.getPlayerCount() != 1) {
    					sender.sendMessage("There are " + playerListener.getPlayerCount() + " players online.");
    				} else {
    					sender.sendMessage("There is " + playerListener.getPlayerCount() + " player online.");
    				}
    				return true;
    			}
    		});
    		getCommand("online").setExecutor(new CommandExecutor() {
    			public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    				sender.sendMessage("Online now: " + playerListener.getOnline());
    				return true;
    			}
    		});
    


    And plugin.yml:
    plugin.yml (open)

    name: Informer
    main: com.pomeroy6.brandonw.bukkit.Informer.Informer
    version: 0.0.1
    commands:
    online:
    description: Shows a list of the online players
    usage: /online
    count:
    description: Shows a count of the online players
    usage: /count


    Any help would be appreciated, thanks!
     
  2. Offline

    Gandalf

    Doing it wrong, make another class which implements player listener, then do onCommand and check the phrases which they type to hook them.

    I don't think you quite know what you are doing, look up basic bukkit skills.
     
  3. Offline

    lostaris

    This is doing it wrong too :p
    onCommand is goes in your main class, not in any other class.
     
  4. Offline

    AchillePomeroy

    I do have another class that implements player listener, my Informer code above references them. I did not post the code for that since it is essentially just a hashmap and an integer right now, and seemed superfluous. If I need to upload it I can. As for using onCommand and checking the phrases, I thought that that was what I was doing with my code there.

    As for your second point, you're right, I don't quite know what I'm doing. Where should I find info on these basic skills? I've watched both of samkio's video tutorials, but they seem to be out of date, in regards to both TSLPC and the way commands are done. I've looked at some source codes for some plugins as well. I've also checked out the javadoc for the various classes and methods, but the real problem is that I don't know exactly what I should be looking for. There are so many conflicting options (like the three different command set ups), that I don't know which one is right. :\
     
  5. Offline

    clash

    That's not true with CommandExecutor now. [​IMG]
     
  6. Offline

    Plague

    Okay, "onCommand goes into a CommandExecutor, which by default is your main class", happy? :D
     
  7. Offline

    clash

    Hehe, yes. Ecstatic! [​IMG]
     
  8. Offline

    AchillePomeroy

    Plague or clash, could you point me to where that is specified? Are you just getting that from looking at the code? Or is there some secret page that people can go to see all of this laid out in black and white? :p
     
  9. Offline

    Plague

    It's somewhere deeper in threads, just take someone's source code and look at it.
     
Thread Status:
Not open for further replies.

Share This Page