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.
- Use the class which is
extends JavaPlugin
as main class that register command and multiple others. This class should contains aonEnable()
method which register commands. - Register command with
getCommand("daytime").setExecutor(new DayTimeCommand());
- Add it in the
plugin.yml
file like:
commands:
daytime:
- 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);
}