Home > Back-end >  How do I make my command works on minecraft?
How do I make my command works on minecraft?

Time:01-05

I'm trying to make a minecraft plugin that does /daytime, the plugin gets recognized by the /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;
        }
    }
}

CodePudding user response:

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.

CodePudding user response:

it gives me this error: class, interface, or enum expected in this part between public and void

@Override
public void onEnable() {
        Bukkit.getPluginManager().registerEvents(this, this);
}
  • Related