Java Minecraft Plugin command not working

1k views Asked by At

Ive just started Minecraft Plugin development, and was hoping to get some help on why my plugin isn't 100% working. What I mean by that, is things like "/help MyFirstPluginYay" are working, but the actual command "/hello" isn't so I believe it could be my code. (It could be one of my plugins, but doubt it) The plugin or so loads fine with out any errors, and does the message to the console when it boots.

Im using Craftbukkit 1.8 Snapshot.
Can someone else please test out my code, or point out any obvious mistakes.

Here is my source code for the plugin

package me.MorrisKid.myfirstplugin;

import java.util.logging.Logger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;

public class main extends JavaPlugin {
    public Logger logger = Logger.getLogger("Minecraft");
    public void onEnable(){
        PluginDescriptionFile pdffile = this.getDescription();
        this.logger.info(pdffile.getName() + " Has been enabled");
    }
    public void onDisable(){
        PluginDescriptionFile pdffile = this.getDescription();
        this.logger.info(pdffile + " Has been disabled");
    }
    public boolean onCommand(Command cmd, CommandSender sender, String label, String[] args){
        if(label.equalsIgnoreCase("hello")){
            Player p = (Player) sender;
            p.sendMessage("Hello!");
        }   
        return true;
    }
}

If you need to, you can get a copy of the plugin files, and/or the compiled Jar for the plugin

Download compiled jar from here
Download complete directory from here

1

There are 1 answers

0
Yotam Salmon On BEST ANSWER

You have to have a plugin.yml file - so bukkit would know what plugin is in charge for that command. If you don't have one, it would obviously not work. it probably has to look like this: (Make sure to not have a space in the name)

name: MorrisKid's_plugin
main: me.MorrisKid.myfirstplugin.main
version: 1.0.0
load: startup
description: this is my first plugin
commands:
  hello:
    description: greeting the player!
    usage: /<command>

*I didn't test this yml, so check that it's proper and there are no syntax errors.Check this youtuber's video: https://www.youtube.com/watch?v=_EUPVpqwvZw He explains about the plugin.yml file.