LifeCycle class and Registry class must be no arg constructor.
Start to create your main class.
@ELDPlugin( registry =TesterRegistry.class,//point to registry class lifeCycle =TesterLifeCycle.class//point to lifecycle class)publicclassELDTesterextendsELDBukkitPlugin { @OverrideprotectedvoidbindServices(ServiceCollection serviceCollection) {// the place to bind service, bind singleton and add configuration } @OverrideprotectedvoidmanageProvider(ManagerProvider provider) {// operation before lifecycle }}
Finally, create plugin.yml and point your main into your class which extended ELDBukkitPlugin, then your first plugin will be done.
Command Creation
Below examples showing how to create sub commands
@Commander( name ="test", description ="test command", alias = {"tes","te"})publicclassTestCommandimplementsCommandNode { @Overridepublicvoidexecute(CommandSender commandSender) { }}
@Commander( name ="one", description ="test one command")publicclassTestOneCommandimplementsCommandNode {//command arg, the display name will be "string"//command order is 0 @CommandArg(order =0, labels = {"string"})privateString value; @Overridepublicvoidexecute(CommandSender commandSender) {commandSender.sendMessage("this is one command with value "+value); }}
@Commander( name ="two", description ="two command")publicclassTestTwoCommandimplementsCommandNode { @CommandArg(order =0)privateint number; @Overridepublicvoidexecute(CommandSender commandSender) {commandSender.sendMessage("this is two command with number "+number); }}
Finally, define the parent-child relationship from registry class.
publicclassTestManager {privatefinalTesterSingleton singleton; @InjectpublicTestManager(TesterSingleton singleton){this.singleton= singleton;singleton.setKey("start","started a insertion in constructor"); }publicvoiddoSomething(){System.out.println(singleton.getString()) }}
You can't use @inject on uninjectable instance or it will throw an error.
Injecting Service
Services and Singleton are different that services are using interface while singleton are using instance. Using interface can avoid the high coupling problem and commonly use for API, or with different implementations.
@Commander( name ="one", description ="one scheduler")publicclassTestSchedulerOneCommandimplementsCommandNode { @InjectprivateScheduleService service; // this is a service from framework @Overridepublicvoidexecute(CommandSender commandSender) {commandSender.sendMessage("wait for 5 secs");service.injectTask(newBukkitRunnable() { @InjectprivateScheduleService service; @Overridepublicvoidrun() { commandSender.sendMessage("scheduler service instance inside bukkit runnable is "+(service == null ? "null" : "not null !"));
} }).asynchronous(false).timeout(100L).run(ELDTester.getProvidingPlugin(ELDTester.class)); }}
You can inject instance from any instance which allow injection.
injectable instances as below
yaml mapping object
Service
Singleton
instance which allow injection as below
Command (which extended Command Node)
Listeners (which extended Listener or ELDListener)
Singleton (which registered from ServiceCollection)
Services (which registered from ServiceCollection)