创建提供程序失败

时间:2015-09-11 15:05:14

标签: java bukkit

我想用以下方法实现我的API:

private boolean setupGameAPI() {
    if (getServer().getPluginManager().getPlugin("GameAPI") != null) {
        System.out.println("GameAPI found");
        RegisteredServiceProvider<GameAPI> GameAPIProvider = getServer().getServicesManager().getRegistration(GameAPI.class);
        if (GameAPIProvider != null) {
            gameapi = GameAPIProvider.getProvider();
            System.out.println("GameAPIProvider found");
        } else {
            System.out.println("GameAPIProvider not found");
        }
        return (gameapi != null);
    } else {
        System.out.println("GameAPI not found");
    }
    return false;
}

输出结果为:

[16:55:07] [Server thread/INFO]: GameAPI found
[16:55:07] [Server thread/INFO]: GameAPIProvider not found

我该怎么做才能使GameAPIProvider不为空?也许我必须在我的API中添加一些内容。

1 个答案:

答案 0 :(得分:0)

注册。

// This block of code is a demonstration of
// how you register the service manager in your API.
ServicesManager sm = getServer().getServicesManager();

GameAPI service = getMyGameAPI(); 

sm.register(GameAPI.class, service, this, priority);