register api to ServicesManager
This commit is contained in:
parent
7234c7d20d
commit
491aaa7787
2 changed files with 13 additions and 7 deletions
|
@ -1,25 +1,31 @@
|
||||||
package lol.pyr.znpcsplus.api;
|
package lol.pyr.znpcsplus.api;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.ServicePriority;
|
||||||
|
|
||||||
public class NpcApiProvider {
|
public class NpcApiProvider {
|
||||||
private static NpcApi plugin = null;
|
private static NpcApi api = null;
|
||||||
|
|
||||||
private NpcApiProvider() {
|
private NpcApiProvider() {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NpcApi get() {
|
public static NpcApi get() {
|
||||||
if (plugin == null) throw new IllegalStateException(
|
if (api == null) throw new IllegalStateException(
|
||||||
"ZNPCsPlus plugin isn't enabled yet!\n" +
|
"ZNPCsPlus plugin isn't enabled yet!\n" +
|
||||||
"Please add it to your plugin.yml as a depend or softdepend."
|
"Please add it to your plugin.yml as a depend or softdepend."
|
||||||
);
|
);
|
||||||
return plugin;
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register(NpcApi plugin) {
|
public static void register(Plugin plugin, NpcApi api) {
|
||||||
NpcApiProvider.plugin = plugin;
|
NpcApiProvider.api = api;
|
||||||
|
Bukkit.getServicesManager().register(NpcApi.class, api, plugin, ServicePriority.Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void unregister() {
|
public static void unregister() {
|
||||||
NpcApiProvider.plugin = null;
|
Bukkit.getServicesManager().unregister(api);
|
||||||
|
NpcApiProvider.api = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,7 +142,7 @@ public class ZNpcsPlus extends JavaPlugin {
|
||||||
shutdownTasks.add(adventure::close);
|
shutdownTasks.add(adventure::close);
|
||||||
if (configManager.getConfig().autoSaveEnabled()) shutdownTasks.add(npcRegistry::save);
|
if (configManager.getConfig().autoSaveEnabled()) shutdownTasks.add(npcRegistry::save);
|
||||||
|
|
||||||
NpcApiProvider.register(new ZNPCsPlusApi(npcRegistry, typeRegistry, propertyRegistry));
|
NpcApiProvider.register(this, new ZNPCsPlusApi(npcRegistry, typeRegistry, propertyRegistry));
|
||||||
enabled = true;
|
enabled = true;
|
||||||
log(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)");
|
log(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)");
|
||||||
log("");
|
log("");
|
||||||
|
|
Loading…
Reference in a new issue