Player command

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

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

    Snakeruler

    I've done some looking around, but I can't find a proper answer to my question;

    How do I make a proper custom command to work, what am I doing wrong?

    Base.class

    Code:
    package jacob.Base;
    
    import java.io.File;
    import java.util.HashMap;
    import org.bukkit.entity.Player;
    import org.bukkit.Server;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    
    import jacob.Base.BaseBlockListener;
    
    /**
     * Test for Bukkit
     *
     * @author Jacob
     */
    public class Base extends JavaPlugin {
        private final BaseBlockListener blockListener = new BaseBlockListener(this);
        private final BaseChatListener chatListener = new BaseChatListener(this);
    
        public void onEnable() {
            // TODO: Place any custom enable code here including the registration of
            // any events
    
            // Register our events
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener,
                    Event.Priority.Normal, this);
            pm.registerEvent(Event.Type.PLAYER_CHAT, this.chatListener,
                    Event.Priority.Normal, this);
            // EXAMPLE: Custom code, here we just output some info so we can check
            // all is well
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println(pdfFile.getName() + " version "
                    + pdfFile.getVersion() + " is enabled!");
        }
    
        public void onDisable() {
            // TODO: Place any custom disable code here
    
            // NOTE: All registered events are automatically unregistered when a
            // plugin is disabled
    
            // EXAMPLE: Custom code, here we just output some info so we can check
            // all is well
            System.out.println("Goodbye world!");
        }
    }
    
    BaseBlockListener.class

    Code:
    package jacob.Base;
    
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.block.BlockListener;
    
    import jacob.Base.Base;
    
    public class BaseBlockListener extends BlockListener {
        public static Base plugin;
    
        public BaseBlockListener(Base instance) {
            plugin = instance;
        }
    
        public void onBlockPlace(BlockPlaceEvent event) {
            Player player = event.getPlayer();
            Block block = event.getBlockPlaced();
    
            if (block.getType() == Material.LOG) {
                player.sendMessage("You got wood?");
            }
    
        }
    
    }
    
    BaseChatListener.class
    Code:
    package jacob.Base;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerListener;
     
    public class BaseChatListener extends PlayerListener {
        public static Base plugin;
    
        public BaseChatListener(Base instance) {
            plugin = instance;
        }
    
        public void onCommand(PlayerChatEvent event) {
            Player player = event.getPlayer();
            Server sv = player.getServer();
            String[] MsgSplit = event.getMessage().split(" ");
            if (MsgSplit[0].equalsIgnoreCase("/green")) {
                player.sendMessage(ChatColor.GREEN + MsgSplit[1]);
            }
        }
    }
    
    Any help I would be grateful. :)
     
  2. Offline

    Plague

    onCommand belongs to the main class.
     
  3. Offline

    Snakeruler

    Okay, I've changed it to that now, I have this now (It still doesn't work)

    Code:
    package jacob.Base;
    
    import java.io.File;
    import java.util.HashMap;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.Server;
    import org.bukkit.event.Event.Priority;
    import org.bukkit.event.Event;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.plugin.PluginManager;
    
    import jacob.Base.BaseBlockListener;
    
    /**
     * Test for Bukkit
     *
     * @author Jacob
     */
    public class Base extends JavaPlugin {
        private final BaseBlockListener blockListener = new BaseBlockListener(this);
        private final BaseChatListener chatListener = new BaseChatListener(this);
    
        public void onEnable() {
            // TODO: Place any custom enable code here including the registration of
            // any events
    
            // Register our events
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.BLOCK_PLACED, this.blockListener,
                    Event.Priority.Normal, this);
            // EXAMPLE: Custom code, here we just output some info so we can check
            // all is well
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println(pdfFile.getName() + " version "
                    + pdfFile.getVersion() + " is enabled!");
        }
    
        public void onDisable() {
            // TODO: Place any custom disable code here
    
            // NOTE: All registered events are automatically unregistered when a
            // plugin is disabled
    
            // EXAMPLE: Custom code, here we just output some info so we can check
            // all is well
            System.out.println("Goodbye world!");
        }
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player from = (Player)sender;
            from.sendMessage(sender.toString());
            from.sendMessage(cmd.toString());
            from.sendMessage(commandLabel);
            from.sendMessage(args[0]);
            return true;
        }
    }
    
    Edit: I've tried loads of different things in the onCommand bit, like comparing with if statements, but nothing seems to change, I assume It's not being called, and I've made some mistake
     
  4. Offline

    BenyTheBuff

    I would also like to know
     
  5. Offline

    matter123

    is the command in the plugin.yml?
     
  6. Offline

    geekygenius

    I just read the "This needs to stop." thread, and a comment brought up people with the title of Plugin Devloper asking silly questions. What did you do to earn the title that doesn't involve commands?!? Matter is right though. I think.
     
  7. Offline

    Deamonicon

    I Think u did int edit the .yml props
    COLORCRAFT
     
  8. Offline

    stelar7

    I assume there are no commands, and you've made a lot of mistakes
     
Thread Status:
Not open for further replies.

Share This Page