aboutsummaryrefslogtreecommitdiffstats
path: root/bukkit/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'bukkit/src/main/java/com')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java4
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensInteractTaskType.java64
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/InteractTaskType.java78
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ServerNPCInteractTaskType.java44
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ZNPCsPlusInteractTaskType.java55
5 files changed, 189 insertions, 56 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
index f05c2454..fc033f4e 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
@@ -105,12 +105,14 @@ import com.leonardobishop.quests.bukkit.tasktype.type.dependent.PlaceholderAPIEv
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.PlayerPointsEarnTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.PyroFishingProFishingTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.ServerNPCDeliverTaskType;
+import com.leonardobishop.quests.bukkit.tasktype.type.dependent.ServerNPCInteractTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.ShopGUIPlusBuyTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.ShopGUIPlusSellTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.SuperiorSkyblockLevelType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.SuperiorSkyblockWorthType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.VotingPluginVoteType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.ZNPCsPlusDeliverTaskType;
+import com.leonardobishop.quests.bukkit.tasktype.type.dependent.ZNPCsPlusInteractTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.uSkyBlockLevelTaskType;
import com.leonardobishop.quests.bukkit.util.CompatUtils;
import com.leonardobishop.quests.bukkit.util.LogHistory;
@@ -444,6 +446,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
taskTypeManager.registerTaskType(() -> new PlayerPointsEarnTaskType(this), () -> CompatUtils.isPluginEnabled("PlayerPoints"));
taskTypeManager.registerTaskType(() -> new PyroFishingProFishingTaskType(this), () -> CompatUtils.isPluginEnabled("PyroFishingPro") && CompatUtils.classExists("me.arsmagica.API.PyroFishCatchEvent"));
taskTypeManager.registerTaskType(() -> new ServerNPCDeliverTaskType(this), () -> CompatUtils.isPluginEnabled("ServerNPC"));
+ taskTypeManager.registerTaskType(() -> new ServerNPCInteractTaskType(this), () -> CompatUtils.isPluginEnabled("ServerNPC"));
taskTypeManager.registerTaskType(() -> new ShopGUIPlusBuyTaskType(this), () -> CompatUtils.isPluginEnabled("ShopGUIPlus")); // not tested
taskTypeManager.registerTaskType(() -> new ShopGUIPlusSellTaskType(this), () -> CompatUtils.isPluginEnabled("ShopGUIPlus")); // not tested
taskTypeManager.registerTaskType(() -> new SuperiorSkyblockLevelType(this), () -> CompatUtils.isPluginEnabled("SuperiorSkyblock2")); // not tested
@@ -452,6 +455,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
taskTypeManager.registerTaskType(() -> new NuVotifierVoteTaskType(this), () -> CompatUtils.isPluginEnabled("Votifier")); // not tested
taskTypeManager.registerTaskType(() -> new VotingPluginVoteType(this), () -> CompatUtils.isPluginEnabled("VotingPlugin")); // not tested
taskTypeManager.registerTaskType(() -> new ZNPCsPlusDeliverTaskType(this), () -> CompatUtils.isPluginEnabled("ZNPCsPlus"));
+ taskTypeManager.registerTaskType(() -> new ZNPCsPlusInteractTaskType(this), () -> CompatUtils.isPluginEnabled("ZNPCsPlus"));
// Register task types with enabled specific version plugin compatibility requirement
taskTypeManager.registerTaskType(() -> new IridiumSkyblockValueTaskType(this), () -> { // TODO FIX
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensInteractTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensInteractTaskType.java
index 295d531f..a61dde2b 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensInteractTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/CitizensInteractTaskType.java
@@ -1,80 +1,32 @@
package com.leonardobishop.quests.bukkit.tasktype.type.dependent;
import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
-import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType;
import com.leonardobishop.quests.bukkit.util.TaskUtils;
-import com.leonardobishop.quests.bukkit.util.chat.Chat;
-import com.leonardobishop.quests.common.config.ConfigProblem;
-import com.leonardobishop.quests.common.player.QPlayer;
-import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress;
-import com.leonardobishop.quests.common.quest.Quest;
import com.leonardobishop.quests.common.quest.Task;
import net.citizensnpcs.api.event.NPCRightClickEvent;
import net.citizensnpcs.api.npc.NPC;
-import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
-public final class CitizensInteractTaskType extends BukkitTaskType {
+public final class CitizensInteractTaskType extends InteractTaskType<Integer> {
private final BukkitQuestsPlugin plugin;
public CitizensInteractTaskType(BukkitQuestsPlugin plugin) {
- super("citizens_interact", TaskUtils.TASK_ATTRIBUTION_STRING, "Interact with an NPC to complete the quest.");
+ super("citizens_interact", TaskUtils.TASK_ATTRIBUTION_STRING, "Interact with a Citizens NPC to complete the quest.");
this.plugin = plugin;
- super.addConfigValidator((config, problems) -> {
- if (config.containsKey("npc-name") && config.containsKey("npc-id")) {
- problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING,
- "Both npc-name and npc-id is specified; npc-name will be ignored", null, "npc-name"));
- }
- });
+ super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "npc-id"));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onNPCRightClick(NPCRightClickEvent event) {
- Player player = event.getClicker();
- if (player.hasMetadata("NPC")) {
- return;
- }
-
- QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
- if (qPlayer == null) {
- return;
- }
-
NPC npc = event.getNPC();
- String npcName = null;
-
- for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this)) {
- Quest quest = pendingTask.quest();
- Task task = pendingTask.task();
- TaskProgress taskProgress = pendingTask.taskProgress();
-
- super.debug("Player clicked NPC", quest.getId(), task.getId(), player.getUniqueId());
-
- Integer configNPCId = (Integer) task.getConfigValue("npc-id");
- if (configNPCId != null) {
- if (npc.getId() != configNPCId) {
- super.debug("NPC id " + npc.getId() + " does not match required id, continuing...", quest.getId(), task.getId(), player.getUniqueId());
- continue;
- }
- } else {
- String configNPCName = (String) task.getConfigValue("npc-name");
- if (configNPCName != null) {
- if (npcName == null) {
- npcName = Chat.legacyStrip(Chat.legacyColor(npc.getName()));
- }
-
- if (!configNPCName.equals(npcName)) {
- super.debug("NPC name " + npcName + " does not match required name, continuing...", quest.getId(), task.getId(), player.getUniqueId());
- continue;
- }
- }
- }
+ handle(event.getClicker(), npc.getId(), npc.getName(), plugin);
+ }
- super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());
- taskProgress.setCompleted(true);
- }
+ @Override
+ public Integer getNPCId(Task task) {
+ return (Integer) task.getConfigValue("npc-id");
}
}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/InteractTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/InteractTaskType.java
new file mode 100644
index 00000000..d5ec5ccf
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/InteractTaskType.java
@@ -0,0 +1,78 @@
+package com.leonardobishop.quests.bukkit.tasktype.type.dependent;
+
+import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType;
+import com.leonardobishop.quests.bukkit.util.TaskUtils;
+import com.leonardobishop.quests.bukkit.util.chat.Chat;
+import com.leonardobishop.quests.common.config.ConfigProblem;
+import com.leonardobishop.quests.common.player.QPlayer;
+import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress;
+import com.leonardobishop.quests.common.quest.Quest;
+import com.leonardobishop.quests.common.quest.Task;
+import org.bukkit.entity.Player;
+
+public abstract class InteractTaskType<T> extends BukkitTaskType {
+
+ public InteractTaskType(String type, String author, String description) {
+ super(type, author, description);
+
+ super.addConfigValidator((config, problems) -> {
+ if (config.containsKey("npc-name") && config.containsKey("npc-id")) {
+ problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING,
+ "Both npc-name and npc-id is specified; npc-name will be ignored", null, "npc-name"));
+ }
+ });
+ }
+
+ public abstract T getNPCId(Task task);
+
+ public void handle(Player player, T npcId, String npcName, BukkitQuestsPlugin plugin) {
+ if (!player.isOnline()) {
+ return;
+ }
+
+ QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
+ if (qPlayer == null) {
+ return;
+ }
+
+ boolean nameCorrected = false;
+
+ for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this)) {
+ Quest quest = pendingTask.quest();
+ Task task = pendingTask.task();
+ TaskProgress taskProgress = pendingTask.taskProgress();
+
+ super.debug("Player clicked NPC", quest.getId(), task.getId(), player.getUniqueId());
+
+ T configNPCId = getNPCId(task);
+ if (configNPCId != null) {
+ if (!npcId.equals(configNPCId)) {
+ super.debug("NPC id " + npcId + " does not match required id, continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ }
+ } else {
+ String configNPCName = (String) task.getConfigValue("npc-name");
+ if (configNPCName != null) {
+ if (npcName == null) {
+ super.debug("NPC name is empty and does not match required name, continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ }
+
+ if (!nameCorrected) {
+ npcName = Chat.legacyStrip(Chat.legacyColor(npcName));
+ nameCorrected = true;
+ }
+
+ if (!configNPCName.equals(npcName)) {
+ super.debug("NPC name " + npcName + " does not match required name, continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ }
+ }
+ }
+
+ super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());
+ taskProgress.setCompleted(true);
+ }
+ }
+}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ServerNPCInteractTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ServerNPCInteractTaskType.java
new file mode 100644
index 00000000..451efe04
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ServerNPCInteractTaskType.java
@@ -0,0 +1,44 @@
+package com.leonardobishop.quests.bukkit.tasktype.type.dependent;
+
+import com.isnakebuzz.npcapi.entities.SnakeHologram;
+import com.isnakebuzz.npcapi.entities.SnakeNPC;
+import com.isnakebuzz.npcapi.enums.ClickType;
+import com.isnakebuzz.npcapi.events.NPCInteractEvent;
+import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.bukkit.util.TaskUtils;
+import com.leonardobishop.quests.common.quest.Task;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+
+import java.util.List;
+
+public final class ServerNPCInteractTaskType extends InteractTaskType<String> {
+
+ private final BukkitQuestsPlugin plugin;
+
+ public ServerNPCInteractTaskType(BukkitQuestsPlugin plugin) {
+ super("servernpc_interact", TaskUtils.TASK_ATTRIBUTION_STRING, "Interact with a ServerNPC NPC to complete the quest.");
+ this.plugin = plugin;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onNPCInteract(NPCInteractEvent event) {
+ if (event.getClickType() != ClickType.RIGHT_CLICK) {
+ return;
+ }
+
+ SnakeNPC npc = event.getSnakeNPC();
+ SnakeHologram hologram = npc.getHologram();
+ List<String> hologramLines = hologram.getLines();
+ String name = !hologramLines.isEmpty()
+ ? String.join("\n", hologramLines)
+ : null;
+
+ handle(event.getPlayer(), npc.getName(), name, plugin);
+ }
+
+ @Override
+ public String getNPCId(Task task) {
+ return (String) task.getConfigValue("npc-id");
+ }
+}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ZNPCsPlusInteractTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ZNPCsPlusInteractTaskType.java
new file mode 100644
index 00000000..ec6816f6
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/ZNPCsPlusInteractTaskType.java
@@ -0,0 +1,55 @@
+package com.leonardobishop.quests.bukkit.tasktype.type.dependent;
+
+import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.bukkit.util.TaskUtils;
+import com.leonardobishop.quests.common.quest.Task;
+import lol.pyr.znpcsplus.api.event.NpcInteractEvent;
+import lol.pyr.znpcsplus.api.hologram.Hologram;
+import lol.pyr.znpcsplus.api.interaction.InteractionType;
+import lol.pyr.znpcsplus.api.npc.NpcEntry;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+
+public final class ZNPCsPlusInteractTaskType extends InteractTaskType<String> {
+
+ private final BukkitQuestsPlugin plugin;
+
+ public ZNPCsPlusInteractTaskType(BukkitQuestsPlugin plugin) {
+ super("znpcsplus_interact", TaskUtils.TASK_ATTRIBUTION_STRING, "Interact with a ZNPCsPlus NPC to complete the quest.");
+ this.plugin = plugin;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onNpcInteract(NpcInteractEvent event) {
+ if (event.getClickType() != InteractionType.RIGHT_CLICK) {
+ return;
+ }
+
+ NpcEntry entry = event.getEntry();
+ Hologram hologram = event.getNpc().getHologram();
+ String name;
+
+ int lineCount = hologram.lineCount();
+ if (lineCount > 0) {
+ StringBuilder nameBuilder = new StringBuilder();
+ for (int i = 0; i < lineCount; i++) {
+ String line = hologram.getLine(i);
+ nameBuilder.append(line);
+
+ if (i != lineCount - 1) {
+ nameBuilder.append('\n');
+ }
+ }
+ name = nameBuilder.toString();
+ } else {
+ name = null;
+ }
+
+ handle(event.getPlayer(), entry.getId(), name, plugin);
+ }
+
+ @Override
+ public String getNPCId(Task task) {
+ return (String) task.getConfigValue("npc-id");
+ }
+}