-
Notifications
You must be signed in to change notification settings - Fork 2
Guilherme Chaguri edited this page Apr 1, 2018
·
2 revisions
You can get an API instance with the following method:
IPvPTimeAPI api = PvPTimeAPI.getAPI();
You can't use PvPTime as a soft dependency using this method.
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("PvPTime");
if(plugin != null && plugin instanceof PvPTimeBukkit) {
IPvPTimeAPI<String> api = ((PvPTimeBukkit)plugin).getAPI();
// Use the API
}
Using the service manager:
Optional<IPvPTimeAPI> optional = Sponge.getServiceManager().provide(IPvPTimeAPI.class);
if(optional.isPresent()) {
IPvPTimeAPI pvptime = opt.get();
// Use the API
}
Getting directly from the plugin instance:
Optional<PluginContainer> optional = Sponge.getPluginManager().getPlugin("pvptime");
if(optional.isPresent()) {
Optional<?> plugin = optional.get().getInstance();
if(plugin.isPresent() && plugin.get() instanceof PvPTimeSponge) {
IPvPTimeAPI<String> api = ((PvPTimeSponge)plugin.get()).getAPI();
// Use the API
}
}
FMLInterModComms.sendFunctionMessage("pvptime", "api", APIRetriever.class.getName());
public class APIRetriever implements Function<IPvPTimeAPI<Integer>, Void> {
@Nullable
@Override
public Void apply(@Nullable IPvPTimeAPI<Integer> api) {
// Use the API
return null;
}
}