Cant quite get onCommand correct

Discussion in 'Plugin Development' started by Raider, Mar 1, 2011.

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

    Raider

    Hey guys, Ive been trying to get onCommand working for me for a few hours now, but cant quite get what I'm missing on it to make it work. I have thought it could be becasue of the yml not having commands in it, but that doesn't make sense to me on it being done like that. Anyway, heres the code ive done and played around with

    Code:
    package com.bukkit.Raider00321.theBasics;
    
    
    import java.io.*;
    import java.util.HashMap;
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    /**
     * theBasics for Bukkit
     *
     * @author Raider00321
     */
    public class theBasics extends JavaPlugin {
        private final theBasicsPlayerListener playerListener = new theBasicsPlayerListener(this);
        private final theBasicsBlockListener blockListener = new theBasicsBlockListener(this);
        private final HashMap<Player, Boolean> debugees = new HashMap<Player, Boolean>();
    
    
    
       
    
        public void onEnable() {
    
             LoadSettings.loadMain();
    
            PluginManager pm = getServer().getPluginManager();
            getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
            pm.registerEvent(Event.Type.PLAYER_JOIN, playerListener, Event.Priority.Normal, this);
            pm.registerEvent(Event.Type.PLAYER_CHAT , playerListener,Priority.Normal, this);
            getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Priority.Monitor, this);
    
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
        } 
        public void onDisable() {
    
            System.out.println("Goodbye world!");
        }
        public boolean isDebugging(final Player player) {
            if (debugees.containsKey(player)) {
                return debugees.get(player);
            } else {
                return false;
            }
        }
    
        public void setDebugging(final Player player, final boolean value) {
            debugees.put(player, value);
        }
    
        public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) 
        {
            sender.sendMessage("You did a command!");
            return false;
        }
    }
    
    
    
    
    As you can see , im just trying to get a simple confirmation that any command is going through. But without any luck.
    I hope someone could tell me what im missing. Thanks for any help guys!
     
  2. Offline

    Cheesier

    The thing is that you need to declare the commands you want to occupy in the plugin.yml file

    plugin.yml
    Code:
    name: ScrapBukkit
    main: com.dinnerbone.bukkit.scrap.ScrapBukkit
    version: 0.1
    commands:
      clear:
        description: Clears your inventory
        usage: /<command>
    So if you want to use the command "/hi" you simply replace the "clear:" with "hi:".
    Returning false to the onCommand will trigger the usage text: returning the accepted paramaters given inside the yml file, just a heads up.

    Code:
    pm.registerEvent(Event.Type.PLAYER_CHAT , playerListener,Priority.Normal, this);
    wont be needed with onCommand.

    Edit: Saw thay you are using a package name with the name *.bukkit, as of a while ago i think they blocked it from even running. You should replace it with something like "com.Raider00321.theBasics".
     
  3. Offline

    Infernus

    I think this will explain very much to you, but forget about the Super thing, it's obsolete.
     
  4. Offline

    Raider

    Yeah, i was hoping i could get away with not using the yml... But if you have to you it.. you have to use it. Thanks cheesier
     
  5. Offline

    Cheesier

    The code in that tutorial was way old, even using the TSLPC and onPlayerCommand, onPlayerCommand was deprecated a month and a half ago. If you are using code like this, download the new bukkit and rewrite the command handeling of your plugin.
     
  6. Offline

    Infernus

    Yeah, I noticed later that the onCommand doesn't work anymore in newer versions, sorry if I did confuse you!
     
  7. Offline

    Plague

    onPlayerComand you mean.
     
  8. Offline

    petteyg359

    No. onCommand is also at least unofficially deprecated. The new way is getCommand() in onEnable() with a CommandExecutor implementation.
     
  9. Offline

    Plague

    http://forums.bukkit.org/threads/new-command-interface-everything-is-broken.6397/
    nowhere here is said it's deprecated.
    And from what I understand about it, it can't because what the default onCommand() is is just that the plugins the default command executor, so it cannot be deprecated ever.The could only have another default executor, which would be strange to do.
    --- merged: Mar 3, 2011 9:05 PM ---
    P.S.: What does "unoffically deprecated" even mean?
     
Thread Status:
Not open for further replies.

Share This Page