Create Listener
You can create listeners in two ways: implementing the Listener interface in a new class and registering it in onEnable, or creating inline event handlers inside your PluginBase.
Registering with PluginBase
Add event handlers directly in your PluginBase subclass. Example:
public class ExamplePlugin extends PluginBase implements Listener {
@Override
public void onEnable() {
this.getServer().getPluginManager().registerEvents(this, this);
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
player.sendMessage("Welcome, " + player.getName() + "!");
}
}Registering with new listener class
package com.example.listener;
import org.powernukkitx.event.EventHandler;
import org.powernukkitx.event.Listener;
import org.powernukkitx.event.player.PlayerJoinEvent;
import org.powernukkitx.Player;
public class JoinListener implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
player.sendMessage("Welcome, " + player.getName() + "!");
}
}You need to register your listener class when your plugin is enabled.
@Override
public void onEnable() {
this.getServer().getPluginManager().registerEvents(new JoinListener(), this);
}Don’t forget to import your listener class.
Need Help?
If you need assistance, check out the Example Plugin or join our Discord server for support.
Create commands
You can create commands with 2 option, creating new command class and registering it to command map or creating onCommand function on your PluginBase and adding command to your plugin.yml.
Create tasks
You can create tasks using scheduler system. Tasks allow you to run repeating or delayed code without blocking the main server thread.