我想用以下方法实现我的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中添加一些内容。
答案 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);