自定義安裝

自定義安裝為 v0.1.1 版本之後的重大更新之一。

你還記得剛剛所說過的 安裝器 嗎?

/**
 * 我的安裝
 */
public interface MyExampleInstallation {

    /**
     * 放一些 String 進去
     * @param key key
     * @param value value
     */
    void putSomeValue(String key, String value);

}

在 v0.1.1 版本後,為了擺脫僅限 ServiceCollection 所提供的 method 上的安裝,新增了自定義安裝器的功能。

其新增方式在 TutorialPlugin.java 可見:

@ELDPlugin(
        lifeCycle = TutorialLifeCycle.class,
        registry = TutorialRegistry.class
)
public class TutorialPlugin extends ELDBukkitAddon {

    @Override
    protected void bindServices(ServiceCollection serviceCollection) {
        serviceCollection.bindService(ExampleService.class, ExampleServiceImpl.class);
    }


    @Override
    protected void preAddonInstall(ManagerProvider managerProvider, AddonManager addonManager) {
        // 初始化安裝器
        MyExampleInstallationImpl installation = new MyExampleInstallationImpl();
        // 添加安裝器
        addonManager.customInstallation(MyExampleInstallation.class, installation);
        // 安裝 guice module
        addonManager.installModule(new MyExampleModule(installation));
    }
}

這樣,你的使用者就可在掛接你的插件後使用如下方式安裝:

被註冊後的處理

關於這點,目前可提供的處理方式是用到 guice 的 Module 之中。

以上的使用方式為把安裝器注入到你的服務之中,範例如下:

最后更新于