mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-22 10:36:09 +01:00
Undo 2e6ab6c
but apply to 2.x since API can be null
This commit is contained in:
parent
90a38e06ae
commit
46e5364b88
@ -101,7 +101,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
|
|||||||
private BukkitItemListener itemListener;
|
private BukkitItemListener itemListener;
|
||||||
private BukkitCitizensListener citizensListener;
|
private BukkitCitizensListener citizensListener;
|
||||||
private BukkitZnpcsListener znpcsListener;
|
private BukkitZnpcsListener znpcsListener;
|
||||||
private BukkitZnpcsPlusListener znpcsPlusListener;
|
private BukkitZnpcsApiListener znpcsPlusListener;
|
||||||
private BukkitPlayerListener playerListener;
|
private BukkitPlayerListener playerListener;
|
||||||
private BukkitNpcEffectThread effectThread;
|
private BukkitNpcEffectThread effectThread;
|
||||||
private BukkitPlayerMoveThread moveThread;
|
private BukkitPlayerMoveThread moveThread;
|
||||||
@ -141,7 +141,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
|
|||||||
itemListener = new BukkitItemListener(this);
|
itemListener = new BukkitItemListener(this);
|
||||||
citizensListener = new BukkitCitizensListener(this);
|
citizensListener = new BukkitCitizensListener(this);
|
||||||
znpcsListener = new BukkitZnpcsListener(this);
|
znpcsListener = new BukkitZnpcsListener(this);
|
||||||
znpcsPlusListener = new BukkitZnpcsPlusListener(this);
|
znpcsPlusListener = new BukkitZnpcsApiListener(this);
|
||||||
playerListener = new BukkitPlayerListener(this);
|
playerListener = new BukkitPlayerListener(this);
|
||||||
uniteListener = new BukkitUniteListener();
|
uniteListener = new BukkitUniteListener();
|
||||||
partiesListener = new BukkitPartiesListener();
|
partiesListener = new BukkitPartiesListener();
|
||||||
@ -519,7 +519,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
|
|||||||
return znpcsListener;
|
return znpcsListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitZnpcsPlusListener getZNpcsPlusListener() {
|
public BukkitZnpcsApiListener getZNpcsPlusListener() {
|
||||||
return znpcsPlusListener;
|
return znpcsPlusListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -633,6 +633,11 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
|
|||||||
depends.unlinkCitizens();
|
depends.unlinkCitizens();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (depends.getZnpcsPlusApi() == null) {
|
||||||
|
getLogger().log(Level.SEVERE,
|
||||||
|
"ZNPCsPlus was enabled but NpcApiProvider was null. Disabling linkage.");
|
||||||
|
depends.unlinkZnpcsPlusApi();
|
||||||
|
}
|
||||||
customLoader.init();
|
customLoader.init();
|
||||||
questLoader.importQuests();
|
questLoader.importQuests();
|
||||||
if (getConfigSettings().canDisableCommandFeedback()) {
|
if (getConfigSettings().canDisableCommandFeedback()) {
|
||||||
|
@ -30,7 +30,7 @@ import me.pikamug.quests.BukkitQuestsPlugin;
|
|||||||
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;
|
||||||
import me.pikamug.quests.listeners.BukkitCitizensListener;
|
import me.pikamug.quests.listeners.BukkitCitizensListener;
|
||||||
import me.pikamug.quests.listeners.BukkitZnpcsListener;
|
import me.pikamug.quests.listeners.BukkitZnpcsApiListener;
|
||||||
import me.pikamug.quests.player.Quester;
|
import me.pikamug.quests.player.Quester;
|
||||||
import me.pikamug.unite.api.objects.PartyProvider;
|
import me.pikamug.unite.api.objects.PartyProvider;
|
||||||
import net.citizensnpcs.api.CitizensPlugin;
|
import net.citizensnpcs.api.CitizensPlugin;
|
||||||
@ -64,7 +64,7 @@ public class BukkitDependencies implements Dependencies {
|
|||||||
public static CitizensPlugin citizens = null;
|
public static CitizensPlugin citizens = null;
|
||||||
private static DenizenAPI denizen = null;
|
private static DenizenAPI denizen = null;
|
||||||
private static AstralBooksAPI astralBooks = null;
|
private static AstralBooksAPI astralBooks = null;
|
||||||
public static ZNPCsPlus znpcsPlus = null;
|
public static ZNPCsPlus znpcsPlusLegacy = null;
|
||||||
public static NpcApi znpcsPlusApi = null;
|
public static NpcApi znpcsPlusApi = null;
|
||||||
private static PartiesAPI parties = null;
|
private static PartiesAPI parties = null;
|
||||||
private int npcEffectThread = -1;
|
private int npcEffectThread = -1;
|
||||||
@ -195,32 +195,15 @@ public class BukkitDependencies implements Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ZNPCsPlus getZnpcsPlus() {
|
public ZNPCsPlus getZnpcsPlus() {
|
||||||
if (znpcsPlus == null) {
|
if (znpcsPlusLegacy == null) {
|
||||||
linkZnpcsPlus();
|
|
||||||
}
|
|
||||||
return znpcsPlus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void linkZnpcsPlus() {
|
|
||||||
if (isPluginAvailable("ZNPCsPlus")) {
|
|
||||||
try {
|
try {
|
||||||
Class.forName("lol.pyr.znpcsplus.ZNPCsPlus");
|
Class.forName("lol.pyr.znpcsplus.ZNPCsPlus");
|
||||||
znpcsPlus = (ZNPCsPlus) plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus");
|
znpcsPlusLegacy = (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();
|
startNpcEffectThread();
|
||||||
plugin.getLogger().info("Successfully linked Quests with ZNPCsPlus "
|
|
||||||
+ znpcsPlus.getDescription().getVersion());
|
|
||||||
}
|
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return znpcsPlusLegacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NpcApi getZnpcsPlusApi() {
|
public NpcApi getZnpcsPlusApi() {
|
||||||
@ -235,16 +218,29 @@ public class BukkitDependencies implements Dependencies {
|
|||||||
try {
|
try {
|
||||||
Class.forName("lol.pyr.znpcsplus.ZNpcsPlus");
|
Class.forName("lol.pyr.znpcsplus.ZNpcsPlus");
|
||||||
znpcsPlusApi = NpcApiProvider.get();
|
znpcsPlusApi = NpcApiProvider.get();
|
||||||
|
boolean found = false;
|
||||||
|
for (final RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
|
||||||
|
if (listener.getListener() instanceof BukkitZnpcsApiListener) {
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(plugin.getZNpcsPlusListener(), plugin);
|
||||||
startNpcEffectThread();
|
startNpcEffectThread();
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
plugin.getLogger().info("Successfully linked Quests with ZNPCsPlus " + plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus").getDescription().getVersion());
|
plugin.getLogger().info("Successfully linked Quests with ZNPCsPlus " + plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus").getDescription().getVersion());
|
||||||
|
}
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unlinkZnpcsPlusApi() {
|
||||||
|
znpcsPlusApi = null;
|
||||||
|
}
|
||||||
|
|
||||||
public Set<UUID> getZnpcsPlusUuids() {
|
public Set<UUID> getZnpcsPlusUuids() {
|
||||||
if (znpcsPlus != null && isPluginAvailable("ZNPCsPlus")) {
|
if (znpcsPlusLegacy != null && isPluginAvailable("ZNPCsPlus")) {
|
||||||
return io.github.znetworkw.znpcservers.npc.NPC.all().stream()
|
return io.github.znetworkw.znpcservers.npc.NPC.all().stream()
|
||||||
.map(io.github.znetworkw.znpcservers.npc.NPC::getUUID).collect(Collectors.toSet());
|
.map(io.github.znetworkw.znpcservers.npc.NPC::getUUID).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
@ -323,7 +319,7 @@ public class BukkitDependencies implements Dependencies {
|
|||||||
public @Nullable Location getNpcLocation(final UUID uuid) {
|
public @Nullable Location getNpcLocation(final UUID uuid) {
|
||||||
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
|
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
|
||||||
return citizens.getNPCRegistry().getByUniqueId(uuid).getStoredLocation();
|
return citizens.getNPCRegistry().getByUniqueId(uuid).getStoredLocation();
|
||||||
} else if (znpcsPlus != null && getZnpcsPlusUuids().contains(uuid)) {
|
} else if (znpcsPlusLegacy != null && getZnpcsPlusUuids().contains(uuid)) {
|
||||||
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
|
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
|
||||||
if (opt.isPresent()) {
|
if (opt.isPresent()) {
|
||||||
return opt.get().getLocation();
|
return opt.get().getLocation();
|
||||||
@ -339,7 +335,7 @@ public class BukkitDependencies implements Dependencies {
|
|||||||
public @Nullable Entity getNpcEntity(final UUID uuid) {
|
public @Nullable Entity getNpcEntity(final UUID uuid) {
|
||||||
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
|
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
|
||||||
return citizens.getNPCRegistry().getByUniqueId(uuid).getEntity();
|
return citizens.getNPCRegistry().getByUniqueId(uuid).getEntity();
|
||||||
} else if (znpcsPlus != null && getZnpcsPlusUuids().contains(uuid)) {
|
} else if (znpcsPlusLegacy != null && getZnpcsPlusUuids().contains(uuid)) {
|
||||||
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
|
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
|
||||||
if (opt.isPresent()) {
|
if (opt.isPresent()) {
|
||||||
return (Entity) opt.get().getBukkitEntity();
|
return (Entity) opt.get().getBukkitEntity();
|
||||||
@ -352,7 +348,7 @@ public class BukkitDependencies implements Dependencies {
|
|||||||
final Entity npc;
|
final Entity npc;
|
||||||
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
|
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
|
||||||
return citizens.getNPCRegistry().getByUniqueId(uuid).getName();
|
return citizens.getNPCRegistry().getByUniqueId(uuid).getName();
|
||||||
} else if (znpcsPlus != null && getZnpcsPlusUuids().contains(uuid)) {
|
} else if (znpcsPlusLegacy != null && getZnpcsPlusUuids().contains(uuid)) {
|
||||||
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
|
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
|
||||||
if (opt.isPresent()) {
|
if (opt.isPresent()) {
|
||||||
npc = (Entity) opt.get().getBukkitEntity();
|
npc = (Entity) opt.get().getBukkitEntity();
|
||||||
@ -375,7 +371,7 @@ public class BukkitDependencies implements Dependencies {
|
|||||||
public @Nullable UUID getUuidFromNpc(final Entity entity) {
|
public @Nullable UUID getUuidFromNpc(final Entity entity) {
|
||||||
if (citizens != null && citizens.getNPCRegistry().isNPC(entity)) {
|
if (citizens != null && citizens.getNPCRegistry().isNPC(entity)) {
|
||||||
return citizens.getNPCRegistry().getNPC(entity).getUniqueId();
|
return citizens.getNPCRegistry().getNPC(entity).getUniqueId();
|
||||||
} else if (znpcsPlus != null && getZnpcsPlusUuids().contains(entity.getUniqueId())) {
|
} else if (znpcsPlusLegacy != null && getZnpcsPlusUuids().contains(entity.getUniqueId())) {
|
||||||
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(entity.getUniqueId())).findAny();
|
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(entity.getUniqueId())).findAny();
|
||||||
if (opt.isPresent()) {
|
if (opt.isPresent()) {
|
||||||
return opt.get().getUUID();
|
return opt.get().getUUID();
|
||||||
|
@ -28,11 +28,14 @@ import java.util.LinkedList;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class BukkitZnpcsPlusListener implements Listener {
|
/**
|
||||||
|
* Listener for ZNPCsPlus 2.x+
|
||||||
|
*/
|
||||||
|
public class BukkitZnpcsApiListener implements Listener {
|
||||||
|
|
||||||
private final BukkitQuestsPlugin plugin;
|
private final BukkitQuestsPlugin plugin;
|
||||||
|
|
||||||
public BukkitZnpcsPlusListener(final BukkitQuestsPlugin plugin) {
|
public BukkitZnpcsApiListener(final BukkitQuestsPlugin plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
@ -38,6 +38,9 @@ import java.util.LinkedList;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener for legacy ZNPCsPlus 1.x
|
||||||
|
*/
|
||||||
public class BukkitZnpcsListener implements Listener {
|
public class BukkitZnpcsListener implements Listener {
|
||||||
|
|
||||||
private final BukkitQuestsPlugin plugin;
|
private final BukkitQuestsPlugin plugin;
|
||||||
|
@ -168,7 +168,7 @@ public class BukkitConfigUtil {
|
|||||||
if (parsed.contains("<npc>")) {
|
if (parsed.contains("<npc>")) {
|
||||||
if (BukkitDependencies.citizens != null) {
|
if (BukkitDependencies.citizens != null) {
|
||||||
parsed = parsed.replace("<npc>", BukkitDependencies.citizens.getNPCRegistry().getByUniqueId(npc).getName());
|
parsed = parsed.replace("<npc>", BukkitDependencies.citizens.getNPCRegistry().getByUniqueId(npc).getName());
|
||||||
} else if (BukkitDependencies.znpcsPlus != null) {
|
} else if (BukkitDependencies.znpcsPlusLegacy != null) {
|
||||||
String name = "null";
|
String name = "null";
|
||||||
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(npc)).findAny();
|
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(npc)).findAny();
|
||||||
if (opt.isPresent()) {
|
if (opt.isPresent()) {
|
||||||
@ -180,6 +180,8 @@ public class BukkitConfigUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
parsed = parsed.replace("<npc>", name);
|
parsed = parsed.replace("<npc>", name);
|
||||||
|
} else if (BukkitDependencies.znpcsPlusApi != null) {
|
||||||
|
// TODO - Find some way to get NPC name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parsed;
|
return parsed;
|
||||||
|
Loading…
Reference in New Issue
Block a user