简体   繁体   中英

Create Provider failed

I want to implement my API with:

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;
}

The output is:

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

The question how can I do it so that GameAPIProvider is not null? Maybe I have to add something in my API.

Register it.

// 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM