Add support for ZNPCsPlus 2.x (#2161)

This commit is contained in:
D3v1s0m 2023-11-15 23:04:29 +05:30 committed by GitHub
parent 2e6ab6c038
commit 90a38e06ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 467 additions and 51 deletions

View File

@ -59,6 +59,12 @@
<id>codemc-snapshots</id> <id>codemc-snapshots</id>
<url>https://repo.codemc.io/repository/maven-snapshots/</url> <url>https://repo.codemc.io/repository/maven-snapshots/</url>
</repository> </repository>
<repository>
<!-- Pyr's Repo (ZNPCsPlus 2.X) -->
<id>pyr-snapshots</id>
<name>Pyr's Repo</name>
<url>https://repo.pyr.lol/snapshots</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -140,6 +146,12 @@
<version>271b087586</version> <version>271b087586</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>lol.pyr</groupId>
<artifactId>znpcsplus-api</artifactId>
<version>2.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>com.github.PikaMug</groupId> <groupId>com.github.PikaMug</groupId>
<artifactId>Unite</artifactId> <artifactId>Unite</artifactId>

View File

@ -22,15 +22,7 @@ import me.pikamug.quests.convo.misc.QuestAcceptPrompt;
import me.pikamug.quests.dependencies.BukkitDenizenTrigger; import me.pikamug.quests.dependencies.BukkitDenizenTrigger;
import me.pikamug.quests.dependencies.BukkitDependencies; import me.pikamug.quests.dependencies.BukkitDependencies;
import me.pikamug.quests.interfaces.ReloadCallback; import me.pikamug.quests.interfaces.ReloadCallback;
import me.pikamug.quests.listeners.BukkitBlockListener; import me.pikamug.quests.listeners.*;
import me.pikamug.quests.listeners.BukkitCitizensListener;
import me.pikamug.quests.listeners.BukkitCommandManager;
import me.pikamug.quests.listeners.BukkitConvoListener;
import me.pikamug.quests.listeners.BukkitItemListener;
import me.pikamug.quests.listeners.BukkitPartiesListener;
import me.pikamug.quests.listeners.BukkitPlayerListener;
import me.pikamug.quests.listeners.BukkitUniteListener;
import me.pikamug.quests.listeners.BukkitZnpcsListener;
import me.pikamug.quests.logging.BukkitQuestsLog4JFilter; import me.pikamug.quests.logging.BukkitQuestsLog4JFilter;
import me.pikamug.quests.storage.implementation.jar.BukkitModuleJarStorage; import me.pikamug.quests.storage.implementation.jar.BukkitModuleJarStorage;
import me.pikamug.quests.storage.implementation.ModuleStorageImpl; import me.pikamug.quests.storage.implementation.ModuleStorageImpl;
@ -109,6 +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 BukkitPlayerListener playerListener; private BukkitPlayerListener playerListener;
private BukkitNpcEffectThread effectThread; private BukkitNpcEffectThread effectThread;
private BukkitPlayerMoveThread moveThread; private BukkitPlayerMoveThread moveThread;
@ -148,6 +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);
playerListener = new BukkitPlayerListener(this); playerListener = new BukkitPlayerListener(this);
uniteListener = new BukkitUniteListener(); uniteListener = new BukkitUniteListener();
partiesListener = new BukkitPartiesListener(); partiesListener = new BukkitPartiesListener();
@ -222,6 +216,9 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
if (depends.getZnpcsPlus() != null) { if (depends.getZnpcsPlus() != null) {
getServer().getPluginManager().registerEvents(getZnpcsListener(), this); getServer().getPluginManager().registerEvents(getZnpcsListener(), this);
} }
if (depends.getZnpcsPlusApi() != null) {
getServer().getPluginManager().registerEvents(getZNpcsPlusListener(), this);
}
getServer().getPluginManager().registerEvents(getPlayerListener(), this); getServer().getPluginManager().registerEvents(getPlayerListener(), this);
if (configSettings.getStrictPlayerMovement() > 0) { if (configSettings.getStrictPlayerMovement() > 0) {
final long ticks = configSettings.getStrictPlayerMovement() * 20L; final long ticks = configSettings.getStrictPlayerMovement() * 20L;
@ -522,6 +519,10 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
return znpcsListener; return znpcsListener;
} }
public BukkitZnpcsPlusListener getZNpcsPlusListener() {
return znpcsPlusListener;
}
public BukkitPlayerListener getPlayerListener() { public BukkitPlayerListener getPlayerListener() {
return playerListener; return playerListener;
} }
@ -606,8 +607,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
} }
/** /**
* Load quests, actions, conditions, and modules * Load quests, actions, conditions, and modules<br>
*
* At startup, this lets soft-depends (namely Citizens) fully load first * At startup, this lets soft-depends (namely Citizens) fully load first
*/ */
private void delayLoadQuestInfo() { private void delayLoadQuestInfo() {

View File

@ -101,7 +101,7 @@ public class ConditionEntityPrompt extends ConditionsEditorNumericPrompt {
return text.toString(); return text.toString();
} }
case 2: case 2:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
if (context.getSessionData(Key.C_WHILE_RIDING_NPC) == null) { if (context.getSessionData(Key.C_WHILE_RIDING_NPC) == null) {
return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")";
} else { } else {
@ -277,6 +277,9 @@ public class ConditionEntityPrompt extends ConditionsEditorNumericPrompt {
final UUID uuid = UUID.fromString(s); final UUID uuid = UUID.fromString(s);
if (plugin.getDependencies().getNpcEntity(uuid) != null && npcs != null) { if (plugin.getDependencies().getNpcEntity(uuid) != null && npcs != null) {
npcs.add(uuid.toString()); npcs.add(uuid.toString());
} else if (plugin.getDependencies().getZnpcsPlusApi() != null && npcs!= null
&& plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid) != null) {
npcs.add(uuid.toString());
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC") context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC")
.replace("<input>", s)); .replace("<input>", s));

View File

@ -105,7 +105,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
return ChatColor.GRAY; return ChatColor.GRAY;
} }
case 7: case 7:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
return ChatColor.BLUE; return ChatColor.BLUE;
} else { } else {
return ChatColor.GRAY; return ChatColor.GRAY;
@ -130,7 +130,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
return ChatColor.YELLOW + BukkitLang.get("questEditorFinishMessage"); return ChatColor.YELLOW + BukkitLang.get("questEditorFinishMessage");
case 4: case 4:
if (context.getSessionData(Key.Q_START_NPC) == null || plugin.getDependencies().getCitizens() != null if (context.getSessionData(Key.Q_START_NPC) == null || plugin.getDependencies().getCitizens() != null
|| plugin.getDependencies().getZnpcsPlus() != null) { || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
return ChatColor.YELLOW + BukkitLang.get("questEditorNPCStart"); return ChatColor.YELLOW + BukkitLang.get("questEditorNPCStart");
} else { } else {
return ChatColor.GRAY + BukkitLang.get("questEditorNPCStart"); return ChatColor.GRAY + BukkitLang.get("questEditorNPCStart");
@ -148,7 +148,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
return ChatColor.GRAY + BukkitLang.get("questWGSetRegion"); return ChatColor.GRAY + BukkitLang.get("questWGSetRegion");
} }
case 7: case 7:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
return ChatColor.YELLOW + BukkitLang.get("questEditorSetGUI"); return ChatColor.YELLOW + BukkitLang.get("questEditorSetGUI");
} else { } else {
return ChatColor.GRAY + BukkitLang.get("questEditorSetGUI"); return ChatColor.GRAY + BukkitLang.get("questEditorSetGUI");
@ -192,9 +192,9 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
+ ChatColor.RESET + ChatColor.GRAY + ")"; + ChatColor.RESET + ChatColor.GRAY + ")";
case 4: case 4:
if (context.getSessionData(Key.Q_START_NPC) == null && (plugin.getDependencies().getCitizens() != null if (context.getSessionData(Key.Q_START_NPC) == null && (plugin.getDependencies().getCitizens() != null
|| plugin.getDependencies().getZnpcsPlus() != null)) { || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null)) {
return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")";
} else if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { } else if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
final UUID uuid = UUID.fromString((String) Objects.requireNonNull(context final UUID uuid = UUID.fromString((String) Objects.requireNonNull(context
.getSessionData(Key.Q_START_NPC))); .getSessionData(Key.Q_START_NPC)));
return ChatColor.GRAY + "(" + ChatColor.AQUA + plugin.getDependencies().getNpcName(uuid) return ChatColor.GRAY + "(" + ChatColor.AQUA + plugin.getDependencies().getNpcName(uuid)
@ -224,7 +224,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
return ChatColor.GRAY + "(" + BukkitLang.get("notInstalled") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("notInstalled") + ")";
} }
case 7: case 7:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
if (context.getSessionData(Key.Q_GUIDISPLAY) == null) { if (context.getSessionData(Key.Q_GUIDISPLAY) == null) {
return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")";
} else { } else {
@ -268,7 +268,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
case 3: case 3:
return new QuestFinishMessagePrompt(context); return new QuestFinishMessagePrompt(context);
case 4: case 4:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
return new QuestNPCStartPrompt(context); return new QuestNPCStartPrompt(context);
} else { } else {
return new QuestMainPrompt(context); return new QuestMainPrompt(context);
@ -290,7 +290,7 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
return new QuestMainPrompt(context); return new QuestMainPrompt(context);
} }
case 7: case 7:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
return new QuestGuiDisplayPrompt(context); return new QuestGuiDisplayPrompt(context);
} else { } else {
return new QuestMainPrompt(context); return new QuestMainPrompt(context);
@ -501,7 +501,8 @@ public class QuestMainPrompt extends QuestsEditorNumericPrompt {
if (!input.equalsIgnoreCase(BukkitLang.get("cmdCancel")) && !input.equalsIgnoreCase(BukkitLang.get("cmdClear"))) { if (!input.equalsIgnoreCase(BukkitLang.get("cmdCancel")) && !input.equalsIgnoreCase(BukkitLang.get("cmdClear"))) {
try { try {
final UUID uuid = UUID.fromString(input); final UUID uuid = UUID.fromString(input);
if (plugin.getDependencies().getNpcEntity(uuid) == null) { if (plugin.getDependencies().getNpcEntity(uuid) == null && (plugin.getDependencies().getZnpcsPlusApi() == null
|| plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid) == null)) {
context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC") context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC")
.replace("<input>", input)); .replace("<input>", input));
return new QuestNPCStartPrompt(context); return new QuestNPCStartPrompt(context);

View File

@ -93,7 +93,7 @@ public class QuestNpcsPrompt extends QuestsEditorNumericPrompt {
public String getAdditionalText(final ConversationContext context, final int number) { public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) { switch(number) {
case 1: case 1:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
if (context.getSessionData(pref + Key.S_DELIVERY_ITEMS) == null) { if (context.getSessionData(pref + Key.S_DELIVERY_ITEMS) == null) {
return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")";
} else { } else {
@ -117,7 +117,7 @@ public class QuestNpcsPrompt extends QuestsEditorNumericPrompt {
return ChatColor.GRAY + " (" + BukkitLang.get("notInstalled") + ")"; return ChatColor.GRAY + " (" + BukkitLang.get("notInstalled") + ")";
} }
case 2: case 2:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
if (context.getSessionData(pref + Key.S_NPCS_TO_TALK_TO) == null) { if (context.getSessionData(pref + Key.S_NPCS_TO_TALK_TO) == null) {
return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")";
} else { } else {
@ -136,7 +136,7 @@ public class QuestNpcsPrompt extends QuestsEditorNumericPrompt {
return ChatColor.GRAY + "(" + BukkitLang.get("notInstalled") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("notInstalled") + ")";
} }
case 3: case 3:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
if (context.getSessionData(pref + Key.S_NPCS_TO_KILL) == null) { if (context.getSessionData(pref + Key.S_NPCS_TO_KILL) == null) {
return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")";
} else { } else {
@ -185,21 +185,21 @@ public class QuestNpcsPrompt extends QuestsEditorNumericPrompt {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) { protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) { switch(input.intValue()) {
case 1: case 1:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
return new QuestNpcsDeliveryListPrompt(context); return new QuestNpcsDeliveryListPrompt(context);
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorNoCitizens")); context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorNoCitizens"));
return new QuestStageMainPrompt(stageNum, context); return new QuestStageMainPrompt(stageNum, context);
} }
case 2: case 2:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
return new QuestNpcsIdsToTalkToPrompt(context); return new QuestNpcsIdsToTalkToPrompt(context);
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorNoCitizens")); context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorNoCitizens"));
return new QuestStageMainPrompt(stageNum, context); return new QuestStageMainPrompt(stageNum, context);
} }
case 3: case 3:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
return new QuestNpcsKillListPrompt(context); return new QuestNpcsKillListPrompt(context);
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorNoCitizens")); context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorNoCitizens"));
@ -454,6 +454,9 @@ public class QuestNpcsPrompt extends QuestsEditorNumericPrompt {
final UUID uuid = UUID.fromString(s); final UUID uuid = UUID.fromString(s);
if (plugin.getDependencies().getNpcEntity(uuid) != null && npcs != null) { if (plugin.getDependencies().getNpcEntity(uuid) != null && npcs != null) {
npcs.add(uuid.toString()); npcs.add(uuid.toString());
} else if (plugin.getDependencies().getZnpcsPlusApi() != null && npcs!= null
&& plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid) != null) {
npcs.add(uuid.toString());
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC") context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC")
.replace("<input>", s)); .replace("<input>", s));
@ -570,6 +573,9 @@ public class QuestNpcsPrompt extends QuestsEditorNumericPrompt {
final UUID uuid = UUID.fromString(s); final UUID uuid = UUID.fromString(s);
if (plugin.getDependencies().getNpcEntity(uuid) != null && npcs != null) { if (plugin.getDependencies().getNpcEntity(uuid) != null && npcs != null) {
npcs.add(uuid.toString()); npcs.add(uuid.toString());
} else if (plugin.getDependencies().getZnpcsPlusApi() != null && npcs!= null
&& plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid) != null) {
npcs.add(uuid.toString());
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC") context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC")
.replace("<input>", s)); .replace("<input>", s));
@ -648,7 +654,7 @@ public class QuestNpcsPrompt extends QuestsEditorNumericPrompt {
public String getAdditionalText(final ConversationContext context, final int number) { public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) { switch(number) {
case 1: case 1:
if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null) { if (plugin.getDependencies().getCitizens() != null || plugin.getDependencies().getZnpcsPlus() != null || plugin.getDependencies().getZnpcsPlusApi() != null) {
if (context.getSessionData(pref + Key.S_NPCS_TO_KILL) == null) { if (context.getSessionData(pref + Key.S_NPCS_TO_KILL) == null) {
return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")"; return ChatColor.GRAY + "(" + BukkitLang.get("noneSet") + ")";
} else { } else {
@ -792,6 +798,9 @@ public class QuestNpcsPrompt extends QuestsEditorNumericPrompt {
final UUID uuid = UUID.fromString(s); final UUID uuid = UUID.fromString(s);
if (plugin.getDependencies().getNpcEntity(uuid) != null && npcs != null) { if (plugin.getDependencies().getNpcEntity(uuid) != null && npcs != null) {
npcs.add(uuid.toString()); npcs.add(uuid.toString());
} else if (plugin.getDependencies().getZnpcsPlusApi() != null && npcs!= null
&& plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid) != null) {
npcs.add(uuid.toString());
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC") context.getForWhom().sendRawMessage(ChatColor.RED + BukkitLang.get("stageEditorInvalidNPC")
.replace("<input>", s)); .replace("<input>", s));

View File

@ -21,13 +21,17 @@ import com.herocraftonline.heroes.characters.Hero;
import com.herocraftonline.heroes.characters.classes.HeroClass; import com.herocraftonline.heroes.characters.classes.HeroClass;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import lol.pyr.znpcsplus.ZNPCsPlus; import lol.pyr.znpcsplus.ZNPCsPlus;
import lol.pyr.znpcsplus.api.NpcApi;
import lol.pyr.znpcsplus.api.NpcApiProvider;
import lol.pyr.znpcsplus.api.entity.EntityProperty;
import lol.pyr.znpcsplus.api.npc.Npc;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.pikamug.quests.BukkitQuestsPlugin; import me.pikamug.quests.BukkitQuestsPlugin;
import me.pikamug.quests.dependencies.reflect.denizen.DenizenAPI;
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.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.worldguard.WorldGuardAPI;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.pikamug.unite.api.objects.PartyProvider; import me.pikamug.unite.api.objects.PartyProvider;
import net.citizensnpcs.api.CitizensPlugin; import net.citizensnpcs.api.CitizensPlugin;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
@ -43,12 +47,7 @@ import org.jetbrains.annotations.Nullable;
import ro.niconeko.astralbooks.api.AstralBooks; import ro.niconeko.astralbooks.api.AstralBooks;
import ro.niconeko.astralbooks.api.AstralBooksAPI; import ro.niconeko.astralbooks.api.AstralBooksAPI;
import java.util.Collections; import java.util.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BukkitDependencies implements Dependencies { public class BukkitDependencies implements Dependencies {
@ -66,6 +65,7 @@ public class BukkitDependencies implements Dependencies {
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 znpcsPlus = null;
public static NpcApi znpcsPlusApi = null;
private static PartiesAPI parties = null; private static PartiesAPI parties = null;
private int npcEffectThread = -1; private int npcEffectThread = -1;
@ -204,6 +204,7 @@ public class BukkitDependencies implements Dependencies {
public void linkZnpcsPlus() { public void linkZnpcsPlus() {
if (isPluginAvailable("ZNPCsPlus")) { if (isPluginAvailable("ZNPCsPlus")) {
try { try {
Class.forName("lol.pyr.znpcsplus.ZNPCsPlus");
znpcsPlus = (ZNPCsPlus) plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus"); znpcsPlus = (ZNPCsPlus) plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus");
boolean found = false; boolean found = false;
for (final RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) { for (final RegisteredListener listener : HandlerList.getRegisteredListeners(plugin)) {
@ -217,8 +218,27 @@ public class BukkitDependencies implements Dependencies {
plugin.getLogger().info("Successfully linked Quests with ZNPCsPlus " plugin.getLogger().info("Successfully linked Quests with ZNPCsPlus "
+ znpcsPlus.getDescription().getVersion()); + znpcsPlus.getDescription().getVersion());
} }
} catch (final Exception e) { } catch (Exception ignored) {
plugin.getLogger().warning("Incompatible version of ZNPCsPlus found. ZNPCsPlus in Quests not enabled."); }
}
}
public NpcApi getZnpcsPlusApi() {
if (znpcsPlusApi == null) {
linkZnpcsPlusApi();
}
return znpcsPlusApi;
}
public void linkZnpcsPlusApi() {
if (isPluginAvailable("ZNPCsPlus")) {
try {
Class.forName("lol.pyr.znpcsplus.ZNpcsPlus");
znpcsPlusApi = NpcApiProvider.get();
startNpcEffectThread();
//noinspection ConstantConditions
plugin.getLogger().info("Successfully linked Quests with ZNPCsPlus " + plugin.getServer().getPluginManager().getPlugin("ZNPCsPlus").getDescription().getVersion());
} catch (Exception ignored) {
} }
} }
} }
@ -308,6 +328,10 @@ public class BukkitDependencies implements Dependencies {
if (opt.isPresent()) { if (opt.isPresent()) {
return opt.get().getLocation(); return opt.get().getLocation();
} }
} else if (znpcsPlusApi != null && znpcsPlusApi.getNpcRegistry().getByUuid(uuid) != null) {
Npc znpc = znpcsPlusApi.getNpcRegistry().getByUuid(uuid).getNpc();
if (znpc.getWorld() == null) return null;
return znpc.getLocation().toBukkitLocation(znpc.getWorld());
} }
return null; return null;
} }
@ -338,6 +362,12 @@ public class BukkitDependencies implements Dependencies {
return opt.get().getNpcPojo().getHologramLines().get(0); return opt.get().getNpcPojo().getHologramLines().get(0);
} }
} }
} else if (znpcsPlusApi != null && getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid) != null) {
Npc znpc = getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid).getNpc();
EntityProperty<String> displayNameProperty = getZnpcsPlusApi().getPropertyRegistry().getByName("display_name", String.class);
if (displayNameProperty != null && znpc.hasProperty(displayNameProperty)) {
return znpc.getProperty(displayNameProperty);
}
} }
return "NPC"; return "NPC";
} }
@ -424,5 +454,6 @@ public class BukkitDependencies implements Dependencies {
getVaultEconomy(); getVaultEconomy();
getVaultPermission(); getVaultPermission();
getZnpcsPlus(); getZnpcsPlus();
getZnpcsPlusApi();
} }
} }

View File

@ -10,6 +10,7 @@
package me.pikamug.quests.events.quester; package me.pikamug.quests.events.quester;
import lol.pyr.znpcsplus.api.npc.Npc;
import me.pikamug.quests.player.BukkitQuester; import me.pikamug.quests.player.BukkitQuester;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -18,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
public class BukkitQuesterPostViewEffectEvent extends BukkitQuesterEvent { public class BukkitQuesterPostViewEffectEvent extends BukkitQuesterEvent {
private static final HandlerList HANDLERS = new HandlerList(); private static final HandlerList HANDLERS = new HandlerList();
private final Entity entity; private final Entity entity;
private final Npc npc;
private final String effect; private final String effect;
private final boolean redoable; private final boolean redoable;
@ -26,6 +28,15 @@ public class BukkitQuesterPostViewEffectEvent extends BukkitQuesterEvent {
this.entity = entity; this.entity = entity;
this.effect = effect; this.effect = effect;
this.redoable = redoable; this.redoable = redoable;
this.npc=null;
}
public BukkitQuesterPostViewEffectEvent(final BukkitQuester quester, Npc npc, String effect, boolean redoable) {
super(quester);
this.npc = npc;
this.effect = effect;
this.redoable = redoable;
this.entity = null;
} }
/** /**
@ -37,6 +48,15 @@ public class BukkitQuesterPostViewEffectEvent extends BukkitQuesterEvent {
return entity; return entity;
} }
/**
* Returns the npc involved in this event (only if using ZNPCsPlus 2.0.0 or higher)
*
* @return npc who is involved in this event
*/
public Npc getNpc() {
return npc;
}
/** /**
* Returns the effect involved in this event * Returns the effect involved in this event
* *

View File

@ -0,0 +1,271 @@
package me.pikamug.quests.listeners;
import lol.pyr.znpcsplus.api.event.NpcInteractEvent;
import lol.pyr.znpcsplus.api.interaction.InteractionType;
import lol.pyr.znpcsplus.api.npc.Npc;
import me.pikamug.quests.BukkitQuestsPlugin;
import me.pikamug.quests.enums.ObjectiveType;
import me.pikamug.quests.player.BukkitQuestProgress;
import me.pikamug.quests.player.Quester;
import me.pikamug.quests.quests.BukkitQuest;
import me.pikamug.quests.quests.Quest;
import me.pikamug.quests.quests.components.BukkitStage;
import me.pikamug.quests.util.BukkitItemUtil;
import me.pikamug.quests.util.BukkitLang;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.conversations.Conversation;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.UUID;
public class BukkitZnpcsPlusListener implements Listener {
private final BukkitQuestsPlugin plugin;
public BukkitZnpcsPlusListener(final BukkitQuestsPlugin plugin) {
this.plugin = plugin;
}
@EventHandler
public void onNPCInteract(final NpcInteractEvent event) {
if (plugin.getDependencies().getZnpcsPlusApi() == null) {
return;
}
// Needed because the NpcInteractEvent is fired async
plugin.getServer().getScheduler().runTask(plugin, () -> {
if (event.getClickType().equals(InteractionType.LEFT_CLICK)) {
if (plugin.getQuestFactory().getSelectingNpcs().contains(event.getPlayer().getUniqueId())) {
if (event.getNpc() == null) {
plugin.getLogger().severe("ZNPCsPlus was null while selecting by left-click");
return;
}
event.getPlayer().acceptConversationInput(String.valueOf(event.getNpc().getUuid()));
}
} else if (event.getClickType().equals(InteractionType.RIGHT_CLICK)) {
if (plugin.getQuestFactory().getSelectingNpcs().contains(event.getPlayer().getUniqueId())) {
if (event.getNpc() == null) {
plugin.getLogger().severe("ZNPCsPlus was null while selecting by right-click");
return;
}
event.getPlayer().acceptConversationInput(String.valueOf(event.getNpc().getUuid()));
}
if (!event.getPlayer().isConversing()) {
final Player player = event.getPlayer();
final Quester quester = plugin.getQuester(player.getUniqueId());
for (final Quest quest : quester.getCurrentQuests().keySet()) {
final BukkitStage currentStage = (BukkitStage) quester.getCurrentStage(quest);
if (currentStage.containsObjective(ObjectiveType.DELIVER_ITEM)) {
final ItemStack hand = player.getItemInHand();
int currentIndex = -1;
final LinkedList<Integer> matches = new LinkedList<>();
int reasonCode = 0;
for (final ItemStack is : currentStage.getItemsToDeliver()) {
currentIndex++;
reasonCode = BukkitItemUtil.compareItems(is, hand, true);
if (reasonCode == 0) {
matches.add(currentIndex);
}
}
final Npc clicked = event.getNpc();
if (!matches.isEmpty()) {
for (final Integer match : matches) {
final UUID uuid = currentStage.getItemDeliveryTargets().get(match);
if (uuid.equals(clicked.getUuid())) {
quester.deliverToNPC(quest, uuid, hand);
return;
}
}
} else if (!hand.getType().equals(Material.AIR)) {
for (final UUID uuid : currentStage.getItemDeliveryTargets()) {
if (uuid.equals(clicked.getUuid())) {
String text = "";
final boolean hasMeta = hand.getItemMeta() != null;
if (hasMeta) {
text += ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC
+ (hand.getItemMeta().hasDisplayName() ? hand.getItemMeta().getDisplayName()
+ ChatColor.GRAY + " (" : "");
}
text += ChatColor.AQUA + "<item>" + (hand.getDurability() != 0 ? (":" + ChatColor.BLUE
+ hand.getDurability()) : "") + ChatColor.GRAY;
if (hasMeta) {
text += (hand.getItemMeta().hasDisplayName() ? ")" : "");
}
text += " x " + ChatColor.DARK_AQUA + hand.getAmount() + ChatColor.GRAY;
if (plugin.getConfigSettings().canTranslateNames() && !hasMeta
&& !hand.getItemMeta().hasDisplayName()) {
plugin.getLocaleManager().sendMessage(player, BukkitLang
.get(player, "questInvalidDeliveryItem").replace("<item>", text), hand
.getType(), hand.getDurability(), null);
} else {
player.sendMessage(BukkitLang.get(player, "questInvalidDeliveryItem")
.replace("<item>", text).replace("<item>", BukkitItemUtil.getName(hand)));
}
switch (reasonCode) {
case 1:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "one item is null"));
break;
case 0:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "ERROR"));
break;
case -1:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "name"));
break;
case -2:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "amount"));
break;
case -3:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "durability"));
break;
case -4:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "display name or lore"));
break;
case -5:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "enchantments"));
break;
case -6:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "stored enchants"));
break;
case -7:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "item flags"));
break;
case -8:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "book data"));
break;
case -9:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "potion type"));
break;
case -10:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "fish variant"));
break;
default:
player.sendMessage(ChatColor.GRAY + BukkitLang.get(player, "difference")
.replace("<data>", "unknown"));
}
if (hasMeta) {
if (hand.getType().equals(Material.ENCHANTED_BOOK)) {
final EnchantmentStorageMeta esMeta = (EnchantmentStorageMeta) hand.getItemMeta();
if (esMeta.hasStoredEnchants()) {
for (final Map.Entry<Enchantment, Integer> e : esMeta.getStoredEnchants()
.entrySet()) {
final HashMap<Enchantment, Integer> single = new HashMap<>();
single.put(e.getKey(), e.getValue());
plugin.getLocaleManager().sendMessage(player, ChatColor.GRAY + "\u2515 "
+ ChatColor.DARK_GREEN + "<enchantment> <level>\n", single);
}
}
}
}
break;
}
}
}
}
}
boolean hasObjective = false;
for (final Quest quest : quester.getCurrentQuests().keySet()) {
if (!quester.meetsCondition(quest, true)) {
continue;
}
if (quester.getCurrentStage(quest).containsObjective(ObjectiveType.TALK_TO_NPC)) {
if (quester.getCurrentStage(quest).getNpcsToInteract().contains(event.getNpc().getUuid())) {
final int npcIndex = quester.getCurrentStage(quest).getNpcsToInteract().indexOf(event.getNpc()
.getUuid());
if (quester.getQuestDataOrDefault(quest) != null && npcIndex > -1
&& !((BukkitQuestProgress) quester.getQuestDataOrDefault(quest)).npcsInteracted.get(npcIndex)) {
hasObjective = true;
}
quester.interactWithNPC(quest, event.getNpc().getUuid());
}
}
}
if (hasObjective || !plugin.getQuestNpcUuids().contains(event.getNpc().getUuid())) {
return;
}
boolean hasAtLeastOneGUI = false;
final LinkedList<Quest> npcQuests = new LinkedList<>();
for (final Quest quest : plugin.getLoadedQuests()) {
final BukkitQuest bukkitQuest = (BukkitQuest) quest;
if (quester.getCurrentQuests().containsKey(bukkitQuest)) {
continue;
}
if (bukkitQuest.getNpcStart() != null && bukkitQuest.getNpcStart().equals(event.getNpc().getUuid())) {
if (plugin.getConfigSettings().canIgnoreLockedQuests()
&& (!quester.getCompletedQuests().contains(bukkitQuest)
|| bukkitQuest.getPlanner().getCooldown() > -1)) {
if (bukkitQuest.testRequirements(quester)) {
npcQuests.add(bukkitQuest);
if (bukkitQuest.getGUIDisplay() != null) {
hasAtLeastOneGUI = true;
}
}
} else if (!quester.getCompletedQuests().contains(bukkitQuest) || bukkitQuest.getPlanner().getCooldown() > -1) {
npcQuests.add(bukkitQuest);
if (bukkitQuest.getGUIDisplay() != null) {
hasAtLeastOneGUI = true;
}
}
}
}
if (npcQuests.size() == 1) {
final BukkitQuest quest = (BukkitQuest) npcQuests.get(0);
if (quester.canAcceptOffer(quest, true)) {
quester.setQuestIdToTake(quest.getId());
if (!plugin.getConfigSettings().canConfirmAccept()) {
quester.takeQuest(quest, false);
} else {
if (quest.getGUIDisplay() != null) {
quester.showGUIDisplay(event.getNpc().getUuid(), npcQuests);
} else {
for (final String msg : extracted(quester).split("<br>")) {
player.sendMessage(msg);
}
plugin.getConversationFactory().buildConversation(player).begin();
}
}
}
} else if (npcQuests.size() > 1) {
if (hasAtLeastOneGUI) {
quester.showGUIDisplay(event.getNpc().getUuid(), npcQuests);
} else {
final Conversation c = plugin.getNpcConversationFactory().buildConversation(player);
c.getContext().setSessionData("npcQuests", npcQuests);
//c.getContext().setSessionData("npc", event.getNpc().getGameProfile().getName());
c.getContext().setSessionData("npc", plugin.getDependencies().getNpcName(event.getNpc().getUuid()));
c.begin();
}
} else {
BukkitLang.send(player, ChatColor.YELLOW + BukkitLang.get(player, "noMoreQuest"));
}
}
}
});
}
private String extracted(final Quester quester) {
final Quest quest = plugin.getQuestById(quester.getQuestIdToTake());
return MessageFormat.format("{0}- {1}{2}{3} -\n\n{4}{5}\n", ChatColor.GOLD, ChatColor.DARK_PURPLE,
quest.getName(), ChatColor.GOLD, ChatColor.RESET, quest.getDescription());
}
}

View File

@ -15,6 +15,7 @@ import com.alessiodp.parties.api.interfaces.PartyPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType; import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import lol.pyr.znpcsplus.api.npc.Npc;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import me.pikamug.localelib.LocaleManager; import me.pikamug.localelib.LocaleManager;
import me.pikamug.quests.BukkitQuestsPlugin; import me.pikamug.quests.BukkitQuestsPlugin;
@ -568,6 +569,19 @@ public class BukkitQuester implements Quester {
} }
return false; return false;
} }
if (plugin.getDependencies().getZnpcsPlusApi() != null &&
plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid) != null) {
Npc znpc = plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid).getNpc();
if (znpc.getWorld() != null && znpc.getWorld().equals(getPlayer().getWorld()) &&
znpc.getLocation().toBukkitLocation(znpc.getWorld()).distance(getPlayer().getLocation()) > 6.0) {
if (giveReason) {
final String msg = BukkitLang.get(getPlayer(), "mustSpeakTo")
.replace("<npc>", ChatColor.DARK_PURPLE + plugin.getDependencies().getNpcName(znpc.getUuid()) + ChatColor.YELLOW);
sendMessage(ChatColor.YELLOW + msg);
}
return false;
}
}
} }
if (getCurrentQuests().size() >= plugin.getConfigSettings().getMaxQuests() if (getCurrentQuests().size() >= plugin.getConfigSettings().getMaxQuests()
&& plugin.getConfigSettings().getMaxQuests() > 0) { && plugin.getConfigSettings().getMaxQuests() > 0) {
@ -3347,10 +3361,8 @@ public class BukkitQuester implements Quester {
final String display = getCurrentStage(quest).getPasswordDisplays().get(index); final String display = getCurrentStage(quest).getPasswordDisplays().get(index);
bukkitQuestData.passwordsSaid.set(index, true); bukkitQuestData.passwordsSaid.set(index, true);
plugin.getServer().getScheduler().runTask(plugin, () -> { plugin.getServer().getScheduler().runTask(plugin, () -> finishObjective(quest, new BukkitObjective(type, null, new ItemStack(Material.AIR, 1),
finishObjective(quest, new BukkitObjective(type, null, new ItemStack(Material.AIR, 1), new ItemStack(Material.AIR, 1)), null, null, null, null, null, display, null));
new ItemStack(Material.AIR, 1)), null, null, null, null, null, display, null);
});
final int finalIndex = index; final int finalIndex = index;
dispatchedQuestIDs.addAll(dispatchMultiplayerEverything(quest, type, dispatchedQuestIDs.addAll(dispatchMultiplayerEverything(quest, type,
@ -4384,8 +4396,7 @@ public class BukkitQuester implements Quester {
} }
/** /**
* Forcibly set Quester's current stage, then update Quest Journal * Forcibly set Quester's current stage, then update Quest Journal<br>
*
* Does not save changes to disk. Consider calling {@link #saveData()} followed by {@link #loadData()} * Does not save changes to disk. Consider calling {@link #saveData()} followed by {@link #loadData()}
* *
* @param key The quest to set stage of * @param key The quest to set stage of

View File

@ -16,6 +16,7 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.player.UserManager;
import com.herocraftonline.heroes.characters.Hero; import com.herocraftonline.heroes.characters.Hero;
import io.github.znetworkw.znpcservers.npc.NPC; import io.github.znetworkw.znpcservers.npc.NPC;
import lol.pyr.znpcsplus.api.npc.Npc;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import me.pikamug.quests.BukkitQuestsPlugin; import me.pikamug.quests.BukkitQuestsPlugin;
import me.pikamug.quests.actions.Action; import me.pikamug.quests.actions.Action;
@ -422,6 +423,11 @@ public class BukkitQuest implements Quest {
targetLocation = opt.get().getLocation(); targetLocation = opt.get().getLocation();
} }
} }
if (plugin.getDependencies().getZnpcsPlusApi() != null
&& plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid) != null) {
Npc znpc = plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getByUuid(uuid).getNpc();
targetLocation = znpc.getLocation().toBukkitLocation(znpc.getWorld());
}
} else if (stage.getPlayersToKill() != null && stage.getPlayersToKill() > 0) { } else if (stage.getPlayersToKill() != null && stage.getPlayersToKill() > 0) {
if (quester.getPlayer() == null) { if (quester.getPlayer() == null) {
return; return;

View File

@ -154,7 +154,9 @@ public class BukkitQuestFactory implements QuestFactory, ConversationAbandonedLi
context.setSessionData(Key.Q_NAME, bukkitQuest.getName()); context.setSessionData(Key.Q_NAME, bukkitQuest.getName());
context.setSessionData(Key.Q_ASK_MESSAGE, bukkitQuest.getDescription()); context.setSessionData(Key.Q_ASK_MESSAGE, bukkitQuest.getDescription());
context.setSessionData(Key.Q_FINISH_MESSAGE, bukkitQuest.getFinished()); context.setSessionData(Key.Q_FINISH_MESSAGE, bukkitQuest.getFinished());
if (plugin.getDependencies().getCitizens() != null) { if (plugin.getDependencies().getCitizens() != null
|| plugin.getDependencies().getZnpcsPlus() != null
|| plugin.getDependencies().getZnpcsPlusApi() != null) {
if (bukkitQuest.getNpcStart() != null) { if (bukkitQuest.getNpcStart() != null) {
context.setSessionData(Key.Q_START_NPC, bukkitQuest.getNpcStart().toString()); context.setSessionData(Key.Q_START_NPC, bukkitQuest.getNpcStart().toString());
} }

View File

@ -10,6 +10,8 @@
package me.pikamug.quests.tasks; package me.pikamug.quests.tasks;
import lol.pyr.znpcsplus.api.npc.Npc;
import lol.pyr.znpcsplus.api.npc.NpcEntry;
import me.pikamug.quests.enums.BukkitPreBuiltParticle; import me.pikamug.quests.enums.BukkitPreBuiltParticle;
import me.pikamug.quests.player.BukkitQuester; import me.pikamug.quests.player.BukkitQuester;
import me.pikamug.quests.BukkitQuestsPlugin; import me.pikamug.quests.BukkitQuestsPlugin;
@ -20,6 +22,7 @@ import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -54,6 +57,20 @@ public class BukkitNpcEffectThread implements Runnable {
} }
} }
} }
if (plugin.getDependencies().getZnpcsPlusApi() != null) {
Collection<? extends NpcEntry> znpcs = plugin.getDependencies().getZnpcsPlusApi().getNpcRegistry().getAllPlayerMade();
for (NpcEntry npc : znpcs) {
if (npc.getNpc().getWorld() == null || player.getLocation().getWorld() == null) {
return;
}
if (npc.getNpc().getWorld().equals(player.getLocation().getWorld())) {
if (npc.getNpc().getLocation().toBukkitLocation(npc.getNpc().getWorld())
.distanceSquared(player.getLocation()) < 24) {
showConfigEffect(plugin.getQuester(player.getUniqueId()), npc.getNpc());
}
}
}
}
} }
} }
@ -76,12 +93,37 @@ public class BukkitNpcEffectThread implements Runnable {
showEffect(quester.getPlayer(), entity, plugin.getConfigSettings().getRedoEffect()); showEffect(quester.getPlayer(), entity, plugin.getConfigSettings().getRedoEffect());
event = new BukkitQuesterPostViewEffectEvent(quester, entity, event = new BukkitQuesterPostViewEffectEvent(quester, entity,
plugin.getConfigSettings().getEffect(), true); plugin.getConfigSettings().getRedoEffect(), true);
plugin.getServer().getPluginManager().callEvent(event); plugin.getServer().getPluginManager().callEvent(event);
} }
} }
} }
/**
* Display config setting particle effect above an {@link Npc} one time
* @param quester Target quester to let view the effect
* @param npc Target NPC to place the effect above
*/
public void showConfigEffect(final BukkitQuester quester, final Npc npc) {
if (npc == null) return;
final BukkitQuesterPostViewEffectEvent event;
if (quester.canAcceptQuest(npc.getUuid())) {
if (npc.getWorld() == null) return;
showEffect(quester.getPlayer(), npc.getLocation().toBukkitLocation(npc.getWorld()).add(0, 2, 0), plugin.getConfigSettings().getEffect());
event = new BukkitQuesterPostViewEffectEvent(quester, npc,
plugin.getConfigSettings().getEffect(), false);
plugin.getServer().getPluginManager().callEvent(event);
} else if (quester.canAcceptCompletedRedoableQuest(npc.getUuid())) {
if (npc.getWorld() == null) return;
showEffect(quester.getPlayer(), npc.getLocation().toBukkitLocation(npc.getWorld()).add(0, 2, 0), plugin.getConfigSettings().getRedoEffect());
event = new BukkitQuesterPostViewEffectEvent(quester, npc,
plugin.getConfigSettings().getRedoEffect(), true);
plugin.getServer().getPluginManager().callEvent(event);
}
}
/** /**
* Display specified particle effect above a Citizens NPC one time * Display specified particle effect above a Citizens NPC one time
* @param player Target player to let view the effect * @param player Target player to let view the effect
@ -111,13 +153,21 @@ public class BukkitNpcEffectThread implements Runnable {
* @param effectType Value of {@link org.bukkit.Particle} or {@link BukkitPreBuiltParticle} * @param effectType Value of {@link org.bukkit.Particle} or {@link BukkitPreBuiltParticle}
*/ */
public void showEffect(final Player player, final Entity entity, final String effectType) { public void showEffect(final Player player, final Entity entity, final String effectType) {
if (player == null || entity == null) { showEffect(player, entity.getLocation().add(0, 2, 0), effectType);
}
/**
* Display specified particle effect at a location one time
* @param player Target player to let view the effect
* @param location Target location to place the effect at
* @param effectType Value of {@link org.bukkit.Particle} or {@link BukkitPreBuiltParticle}
*/
public void showEffect(final Player player, final Location location, final String effectType) {
if (player == null || location == null) {
return; return;
} }
final Location eyeLoc = entity.getLocation();
eyeLoc.setY(eyeLoc.getY() + 2);
try { try {
BukkitParticleProvider.sendToPlayer(player, eyeLoc, effectType.toUpperCase()); BukkitParticleProvider.sendToPlayer(player, location, effectType.toUpperCase());
} catch (final NoClassDefFoundError e) { } catch (final NoClassDefFoundError e) {
// Unsupported Minecraft version // Unsupported Minecraft version
} }