In some situation, you would like to let developers implement your services.
We provided overriding services after v0.0.6, the implementation must extend Overridable.
Here's the example shows the working flow like Vault .
First make the economy service middleware plugin as your dependency for your plugin, then implement the Economy Service.
publicclassMyEconomyServiceimplementsEconomyService{// only for demo, you should use I/O for offlineprivatefinalMap<Player,Double> economy =newConcurrentHashMap<>(); @OverridepublicResultgiveMoney(Player player,double money) {var balance =economy.getOrDefault(player,0.0);economy.put(player, balance + money);returnResult.SUCCESS; } @OverridepublicResulttakeMoney(Player player,double money) {var balance =economy.getOrDefault(player,0.0);if (balance < money) returnResult.FAILED;economy.put(player, balance - money);returnResult.SUCCESS; } @OverridepublicResultsetMoney(Player player,double money) {economy.put(player, money);returnResult.SUCCESS; }}
Finally, register in main class.
@OverrideprotectedvoidbindServices(ServiceCollection serviceCollection) {// you need to ues overrideService method or it will be ignored.serviceCollection.overrideService(EconomyService.class,MyEconomyService.class); }
The plugin that using the economy service (Any)
Finally,EconomyService will be injected by other instances.