Verify compatibility of ZNPCsPlus version

This commit is contained in:
PikaMug 2023-11-11 00:30:25 -05:00
parent 4a935b0346
commit 2e6ab6c038

View File

@ -23,6 +23,7 @@ import io.github.znetworkw.znpcservers.npc.NPC;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNPCsPlus;
import me.pikamug.quests.BukkitQuestsPlugin; import me.pikamug.quests.BukkitQuestsPlugin;
import me.pikamug.quests.listeners.BukkitCitizensListener; import me.pikamug.quests.listeners.BukkitCitizensListener;
import me.pikamug.quests.listeners.BukkitZnpcsListener;
import me.pikamug.quests.player.Quester; import me.pikamug.quests.player.Quester;
import me.pikamug.quests.dependencies.reflect.denizen.DenizenAPI; import me.pikamug.quests.dependencies.reflect.denizen.DenizenAPI;
import me.pikamug.quests.dependencies.reflect.worldguard.WorldGuardAPI; import me.pikamug.quests.dependencies.reflect.worldguard.WorldGuardAPI;
@ -195,12 +196,33 @@ public class BukkitDependencies implements Dependencies {
public ZNPCsPlus getZnpcsPlus() { public ZNPCsPlus getZnpcsPlus() {
if (znpcsPlus == null) { if (znpcsPlus == null) {
znpcsPlus = (ZNPCsPlus) plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus"); linkZnpcsPlus();
startNpcEffectThread();
} }
return znpcsPlus; return znpcsPlus;
} }
public void linkZnpcsPlus() {
if (isPluginAvailable("ZNPCsPlus")) {
try {
znpcsPlus = (ZNPCsPlus) plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus");
boolean found = false;
for (final RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
if (listener.getListener() instanceof BukkitZnpcsListener) {
found = true;
}
}
if (!found) {
plugin.getServer().getPluginManager().registerEvents(plugin.getZnpcsListener(), plugin);
startNpcEffectThread();
plugin.getLogger().info("Successfully linked Quests with ZNPCsPlus "
+ znpcsPlus.getDescription().getVersion());
}
} catch (final Exception e) {
plugin.getLogger().warning("Incompatible version of ZNPCsPlus found. ZNPCsPlus in Quests not enabled.");
}
}
}
public Set<UUID> getZnpcsPlusUuids() { public Set<UUID> getZnpcsPlusUuids() {
if (znpcsPlus != null && isPluginAvailable("ZNPCsPlus")) { if (znpcsPlus != null && isPluginAvailable("ZNPCsPlus")) {
return io.github.znetworkw.znpcservers.npc.NPC.all().stream() return io.github.znetworkw.znpcservers.npc.NPC.all().stream()