How do I make my command work on minecraft?

128 Views Asked by At

I'm trying to make a Minecraft plugin that does /daytime. The plugin gets recognized by /pl, but if I execute the command it does not work.

I tried modifying and moving the plugin.xml thinking Bukkit did not know where the main class was.

package domenicoplugin.domenicopluginbello;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

public final class Domenicopluginbello extends JavaPlugin {

        @Override
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (command.getName().equalsIgnoreCase("daytime")) {
                getServer().getWorlds().get(0).setTime(1000); // set time to morning (1000 ticks)
                sender.sendMessage("The time has been set to morning.");
                return true;
            }
            return false;
        }
    }
}
2

There are 2 best solutions below

0
Elikill58 On

You should follow wiki to create a command.

  1. Use the class which is extends JavaPlugin as main class that register command and multiple others. This class should contains a onEnable() method which register commands.
  2. Register command with getCommand("daytime").setExecutor(new DayTimeCommand());
  3. Add it in the plugin.yml file like:
commands:
   daytime:
  1. Create the class DayTimeCommand that will be like:
public class DayTimeCommand implements CommandExecutor {

    // This method is called, when somebody uses our command
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        getServer().getWorlds().get(0).setTime(1000); // set time to morning (1000 ticks)
        sender.sendMessage("The time has been set to morning.");
        return false;
    }
}

PS: I suggest you to change the name of package/class, and use domenico.bello as package, and Bello or Main as class name.

0
nullentry On

Use plugin.yml instead of plugin.xml