Skip to content

Create Your First Plugin with ELDependenci

Eric Lam edited this page Jun 13, 2022 · 3 revisions

Instead of creating a main class and extending Plugin/JavaPlugin, here, you will need to create three java classes to be declared as main:

  1. Registry class - to register commands and event listeners
  2. Main class - to register services and binding, also installation (if any)
  3. LifeCycle class - to hook the plugin life cycle

Registry class

public class TesterRegistry implements ComponentsRegistry {


    @Override
    public void registerCommand(CommandRegistry<CommandSender> commandRegistry) { //register command here
    }

    @Override
    public void registerListeners(ListenerRegistry<Listener> listenerRegistry) { //register listener here
    }

}

Life Cycle class (spigot)

public class TesterLifeCycle implements ELDLifeCycle {

    @Override
    public void onEnable(JavaPlugin javaPlugin) {
        javaPlugin.getLogger().info("hello world!"); // print hello world!
    }

    @Override
    public void onDisable(JavaPlugin javaPlugin) {
        javaPlugin.getLogger().info("plugin disabled!"); //print plugin disabled!
    }
}

Life Cycle class (bungee)

public class TesterLifeCycle implements ELDLifeCycle {

    @Override
    public void onEnable(Plugin plugin) {
        plugin.getLogger().info("hello world!"); // print hello world!
    }

    @Override
    public void onDisable(Plugin plugin) {
        plugin.getLogger().info("plugin disabled!"); //print plugin disabled!
    }
}

After that, you can create a main class

For spigot

@ELDBukkit(
        registry = TesterRegistry.class, //point to registry class
        lifeCycle = TesterLifeCycle.class //point to lifecycle class
)
public class ELDTester extends ELDBukkitPlugin {

    @Override
    public void bindServices(ServiceCollection serviceCollection) {
        // binding service, configuration or singleton
    }

    @Override
    protected void manageProvider(BukkitManagerProvider provider) {
        // do before lifecycle
    }
}

For bungee

@ELDBungee(
        registry = TesterRegistry.class, //point to registry class
        lifeCycle = TesterLifeCycle.class //point to lifecycle class
)
public class ELDTester extends ELDBungeePlugin {

    @Override
    public void bindServices(ServiceCollection serviceCollection) {
        // binding service, configuration or singleton
    }

    @Override
    protected void manageProvider(BungeeManagerProvider provider) {
        // do before lifecycle
    }
}
Clone this wiki locally