Overriding Services

After v0.0.6.

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 .

Economy Service Middleware

First define an economy service

public interface EconomyService extends Overridable {

    Result giveMoney(Player player, double money);

    Result takeMoney(Player player, double money);

    Result setMoney(Player player, double money);

    enum Result {
        SUCCESS, FAILED
    }
}

implement a default economy service. In this example, we throw an exception that developers not implement any class.

public class DefaultEconomyService implements EconomyService {

    @Override
    public Result giveMoney(Player player, double money) {
        throw new IllegalStateException("not implement any class!");
    }

    @Override
    public Result takeMoney(Player player, double money) {
        throw new IllegalStateException("not implement any class!");
    }

    @Override
    public Result setMoney(Player player, double money) {
        throw new IllegalStateException("not implement any class!");
    }
}

Register in main class

Economy Service Provider (Economy Plugin)

First make the economy service middleware plugin as your dependency for your plugin, then implement the Economy Service.

Finally, register in main class.

The plugin that using the economy service (Any)

Finally,EconomyService will be injected by other instances.

And of course! You need to register it via main class.

最后更新于