Skip to content

Commit

Permalink
Experimental support for ZNPCsPlus
Browse files Browse the repository at this point in the history
  • Loading branch information
PikaMug committed Apr 28, 2023
1 parent ab0879d commit 60368fd
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 116 deletions.
24 changes: 20 additions & 4 deletions api/pom.xml
Expand Up @@ -16,7 +16,7 @@

<repositories>
<repository>
<!-- DungeonsXL, mcMMO Classic, PhatLoots, Unite, ZNPCs -->
<!-- DungeonsXL, mcMMO Classic, PhatLoots, Unite -->
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Expand Down Expand Up @@ -54,6 +54,16 @@
<id>repsy-release</id>
<url>https://repo.repsy.io/mvn/niconeko/release</url>
</repository>
<repository>
<!-- PacketEvents for ZNPCsPlus -->
<id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository>
<repository>
<!-- ZNPCsPlus -->
<id>znpcsplus-repo</id>
<url>https://repo.pyr.lol/releases</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -130,9 +140,15 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.gonalez</groupId>
<artifactId>znpc-servers</artifactId>
<version>21a0650</version>
<groupId>com.github.retrooper.packetevents</groupId>
<artifactId>spigot</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>lol.pyr</groupId>
<artifactId>ZNPCsPlus</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -17,7 +17,7 @@
import com.gmail.nossr50.mcMMO;
import com.herocraftonline.heroes.Heroes;
import com.herocraftonline.heroes.characters.Hero;
import io.github.znetworkw.znpcservers.ServersNPC;
import lol.pyr.znpcsplus.ZNPCsPlus;
import me.blackvein.quests.player.IQuester;
import me.blackvein.quests.reflect.denizen.DenizenAPI;
import me.blackvein.quests.reflect.worldguard.WorldGuardAPI;
Expand Down Expand Up @@ -59,17 +59,17 @@ public interface IDependencies {

AstralBooksAPI getAstralBooksApi();

ServersNPC getZnpcs();
ZNPCsPlus getZnpcsPlus();

PartiesAPI getPartiesApi();

boolean isPluginAvailable(final String pluginName);

boolean runDenizenScript(final String scriptName, final IQuester quester, final UUID uuid);

Location getNPCLocation(final UUID uuid);
Location getNpcLocation(final UUID uuid);

String getNPCName(final UUID uuid);
String getNpcName(final UUID uuid);

int getMcmmoSkillLevel(final SkillType st, final String player);

Expand Down
24 changes: 20 additions & 4 deletions core/pom.xml
Expand Up @@ -16,7 +16,7 @@

<repositories>
<repository>
<!-- DungeonsXL, LocaleLib, mcMMO Classic, PhatLoots, Unite, ZNPCs -->
<!-- DungeonsXL, LocaleLib, mcMMO Classic, PhatLoots, Unite -->
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
Expand Down Expand Up @@ -54,6 +54,16 @@
<id>repsy-release</id>
<url>https://repo.repsy.io/mvn/niconeko/release</url>
</repository>
<repository>
<!-- PacketEvents for ZNPCsPlus -->
<id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository>
<repository>
<!-- ZNPCsPlus -->
<id>znpcsplus-repo</id>
<url>https://repo.pyr.lol/releases</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -124,9 +134,15 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.gonalez</groupId>
<artifactId>znpc-servers</artifactId>
<version>21a0650</version>
<groupId>com.github.retrooper.packetevents</groupId>
<artifactId>spigot</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>lol.pyr</groupId>
<artifactId>ZNPCsPlus</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
52 changes: 31 additions & 21 deletions core/src/main/java/me/blackvein/quests/Dependencies.java
Expand Up @@ -20,8 +20,8 @@
import com.gmail.nossr50.util.player.UserManager;
import com.herocraftonline.heroes.Heroes;
import com.herocraftonline.heroes.characters.Hero;
import io.github.znetworkw.znpcservers.ServersNPC;
import io.github.znetworkw.znpcservers.npc.NPC;
import lol.pyr.znpcsplus.ZNPCsPlus;
import me.blackvein.quests.dependencies.IDependencies;
import me.blackvein.quests.listeners.CitizensListener;
import me.blackvein.quests.player.IQuester;
Expand All @@ -40,8 +40,8 @@
import org.bukkit.plugin.RegisteredServiceProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import ro.niconeko.astralbooks.api.AstralBooksAPI;
import ro.niconeko.astralbooks.api.AstralBooks;
import ro.niconeko.astralbooks.api.AstralBooksAPI;

import java.util.Collections;
import java.util.HashSet;
Expand All @@ -65,8 +65,9 @@ public class Dependencies implements IDependencies {
public static CitizensPlugin citizens = null;
private static DenizenAPI denizen = null;
private static AstralBooksAPI astralBooks = null;
private static ServersNPC znpcs = null;
private static ZNPCsPlus znpcs = null;
private static PartiesAPI parties = null;
private int npcEffectThread = -1;

public Dependencies(final Quests plugin) {
this.plugin = plugin;
Expand Down Expand Up @@ -160,10 +161,7 @@ public void linkCitizens() {
}
if (!found) {
plugin.getServer().getPluginManager().registerEvents(plugin.getCitizensListener(), plugin);
if (plugin.getSettings().canNpcEffects()) {
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, plugin.getNpcEffectThread(),
20, 20);
}
startNpcEffectThread();
plugin.getLogger().info("Successfully linked Quests with Citizens "
+ citizens.getDescription().getVersion());
}
Expand Down Expand Up @@ -196,16 +194,16 @@ public AstralBooksAPI getAstralBooksApi() {
return astralBooks;
}

public ServersNPC getZnpcs() {
public ZNPCsPlus getZnpcsPlus() {
if (znpcs == null) {
znpcs = (ServersNPC) plugin.getServer().getPluginManager().getPlugin("ServersNPC");
znpcs = (ZNPCsPlus) plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus");
startNpcEffectThread();
}
return znpcs;
}

public Set<UUID> getZnpcsUuids() {
if (znpcs != null && isPluginAvailable("ServersNPC")) {
// TODO - it seems ZNPCs UUIDs do not persist restart
public Set<UUID> getZnpcsPlusUuids() {
if (znpcs != null && isPluginAvailable("ZNPCsPlus")) {
return io.github.znetworkw.znpcservers.npc.NPC.all().stream()
.map(io.github.znetworkw.znpcservers.npc.NPC::getUUID).collect(Collectors.toSet());
}
Expand Down Expand Up @@ -281,10 +279,10 @@ public boolean runDenizenScript(final String scriptName, final IQuester quester,
return plugin.getDenizenTrigger().runDenizenScript(scriptName, quester, uuid);
}

public @Nullable Location getNPCLocation(final UUID uuid) {
public @Nullable Location getNpcLocation(final UUID uuid) {
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
return citizens.getNPCRegistry().getByUniqueId(uuid).getStoredLocation();
} else if (getZnpcsUuids().contains(uuid)) {
} else if (znpcs != null && getZnpcsPlusUuids().contains(uuid)) {
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
if (opt.isPresent()) {
return opt.get().getLocation();
Expand All @@ -293,10 +291,10 @@ public boolean runDenizenScript(final String scriptName, final IQuester quester,
return null;
}

public @Nullable Entity getNPCEntity(final UUID uuid) {
public @Nullable Entity getNpcEntity(final UUID uuid) {
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
return citizens.getNPCRegistry().getByUniqueId(uuid).getEntity();
} else if (getZnpcsUuids().contains(uuid)) {
} else if (znpcs != null && getZnpcsPlusUuids().contains(uuid)) {
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
if (opt.isPresent()) {
return (Entity) opt.get().getBukkitEntity();
Expand All @@ -305,11 +303,11 @@ public boolean runDenizenScript(final String scriptName, final IQuester quester,
return null;
}

public @NotNull String getNPCName(final UUID uuid) {
Entity npc = null;
public @NotNull String getNpcName(final UUID uuid) {
Entity npc;
if (citizens != null && citizens.getNPCRegistry().getByUniqueId(uuid) != null) {
return citizens.getNPCRegistry().getByUniqueId(uuid).getName();
} else if (getZnpcsUuids().contains(uuid)) {
} else if (znpcs != null && getZnpcsPlusUuids().contains(uuid)) {
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
if (opt.isPresent()) {
npc = (Entity) opt.get().getBukkitEntity();
Expand All @@ -323,17 +321,29 @@ public boolean runDenizenScript(final String scriptName, final IQuester quester,
return "NPC";
}

public @Nullable UUID getUUIDFromNPC(final Entity entity) {
public @Nullable UUID getUuidFromNpc(final Entity entity) {
if (citizens != null && citizens.getNPCRegistry().isNPC(entity)) {
return citizens.getNPCRegistry().getNPC(entity).getUniqueId();
} else if (getZnpcsUuids().contains(entity.getUniqueId())) {
} else if (znpcs != null && getZnpcsPlusUuids().contains(entity.getUniqueId())) {
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(entity.getUniqueId())).findAny();
if (opt.isPresent()) {
return opt.get().getUUID();
}
}
return null;
}

public void startNpcEffectThread() {
if (npcEffectThread == -1 && plugin.getSettings().canNpcEffects()) {
npcEffectThread = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin,
plugin.getNpcEffectThread(), 20, 20);
}
}

@SuppressWarnings("unused")
public void stopNpcEffectThread() {
plugin.getServer().getScheduler().cancelTask(npcEffectThread);
}

public int getMcmmoSkillLevel(final SkillType st, final String player) {
final McMMOPlayer mPlayer = UserManager.getPlayer(player);
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/me/blackvein/quests/Quest.java
Expand Up @@ -199,7 +199,7 @@ public void setNpcStart(final UUID npcStart) {

@Override
public String getNpcStartName() {
return plugin.getDependencies().getNPCName(getNpcStart());
return plugin.getDependencies().getNpcName(getNpcStart());
}

@Override
Expand Down Expand Up @@ -386,9 +386,9 @@ public boolean updateCompass(final IQuester quester, final IStage stage) {
Bukkit.getScheduler().runTask(plugin, () -> {
Location targetLocation = null;
if (stage.getNpcsToInteract() != null && stage.getNpcsToInteract().size() > 0) {
targetLocation = plugin.getDependencies().getNPCLocation(stage.getNpcsToInteract().getFirst());
targetLocation = plugin.getDependencies().getNpcLocation(stage.getNpcsToInteract().getFirst());
} else if (stage.getNpcsToKill() != null && stage.getNpcsToKill().size() > 0) {
targetLocation = plugin.getDependencies().getNPCLocation(stage.getNpcsToKill().getFirst());
targetLocation = plugin.getDependencies().getNpcLocation(stage.getNpcsToKill().getFirst());
} else if (stage.getLocationsToReach() != null && stage.getLocationsToReach().size() > 0) {
targetLocation = stage.getLocationsToReach().getFirst();
} else if (stage.getItemDeliveryTargets() != null && stage.getItemDeliveryTargets().size() > 0) {
Expand All @@ -398,8 +398,8 @@ public boolean updateCompass(final IQuester quester, final IStage stage) {
targetLocation = plugin.getDependencies().getCitizens().getNPCRegistry().getByUniqueId(uuid)
.getStoredLocation();
}
if (plugin.getDependencies().getZnpcs() != null
&& plugin.getDependencies().getZnpcsUuids().contains(uuid)) {
if (plugin.getDependencies().getZnpcsPlus() != null
&& plugin.getDependencies().getZnpcsPlusUuids().contains(uuid)) {
final Optional<NPC> opt = NPC.all().stream().filter(npc1 -> npc1.getUUID().equals(uuid)).findAny();
if (opt.isPresent()) {
targetLocation = opt.get().getLocation();
Expand Down

0 comments on commit 60368fd

Please sign in to comment.