summaryrefslogtreecommitdiffstats
path: root/bukkit
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2021-12-08 13:44:40 +0000
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2021-12-08 13:45:29 +0000
commitcc345e02eee0a64c5b660112d82758362353ae8d (patch)
treec3c37bde22dcd1fc9319cc41b0b62dc42512dce3 /bukkit
parenta6ed842af70856c447524101240cbe598379c0fa (diff)
Add NuVotifier task type (closes #299)
Diffstat (limited to 'bukkit')
-rw-r--r--bukkit/build.gradle4
-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/NuVotifierVoteType.java84
3 files changed, 92 insertions, 0 deletions
diff --git a/bukkit/build.gradle b/bukkit/build.gradle
index 1d902773..551dd456 100644
--- a/bukkit/build.gradle
+++ b/bukkit/build.gradle
@@ -40,6 +40,8 @@ repositories {
maven { url = 'https://repo.bg-software.com/repository/api/' }
// VotingPlugin
maven { url = 'https://nexus.bencodez.com/repository/maven-public/'}
+ // NuVotifier
+ maven { url = 'https://repo.leonardobishop.com/releases/'}
mavenCentral()
}
@@ -105,6 +107,8 @@ dependencies {
compileOnly 'io.lumine:MythicLib:1.1.1'
// Slimefun4
compileOnly 'com.github.Slimefun:Slimefun4:RC-28'
+ // NuVotifier
+ compileOnly "com.vexsoftware:NuVotifier:2.7.3"
// bStats
implementation 'org.bstats:bstats-bukkit-lite:1.8'
// HikariCP
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 1fbbfdf7..e017fb2c 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
@@ -340,6 +340,10 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
// not tested
taskTypeManager.registerTaskType(new VotingPluginVoteType(this));
}
+ if (Bukkit.getPluginManager().isPluginEnabled("NuVotifier")) {
+ // not tested
+ taskTypeManager.registerTaskType(new NuVotifierVoteType(this));
+ }
taskTypeManager.closeRegistrations();
questsLogger.info(taskTypeManager.getTaskTypes().size() + " task types have been registered"
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/NuVotifierVoteType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/NuVotifierVoteType.java
new file mode 100644
index 00000000..ad8a3d98
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/NuVotifierVoteType.java
@@ -0,0 +1,84 @@
+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.common.config.ConfigProblem;
+import com.leonardobishop.quests.common.player.QPlayer;
+import com.leonardobishop.quests.common.player.questprogressfile.QuestProgress;
+import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress;
+import com.leonardobishop.quests.common.quest.Quest;
+import com.leonardobishop.quests.common.quest.Task;
+import com.vexsoftware.votifier.model.VotifierEvent;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+public final class NuVotifierVoteType extends BukkitTaskType {
+
+ private final BukkitQuestsPlugin plugin;
+
+ public NuVotifierVoteType(BukkitQuestsPlugin plugin) {
+ super("nuvotifier_vote", TaskUtils.TASK_ATTRIBUTION_STRING, "Vote a set amount of times.");
+ this.plugin = plugin;
+ }
+
+ @Override
+ public @NotNull List<ConfigProblem> validateConfig(@NotNull String root, @NotNull HashMap<String, Object> config) {
+ ArrayList<ConfigProblem> problems = new ArrayList<>();
+ if (TaskUtils.configValidateExists(root + ".amount", config.get("amount"), problems, "amount", super.getType()))
+ TaskUtils.configValidateInt(root + ".amount", config.get("amount"), problems, false, true, "amount");
+ return problems;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onVote(VotifierEvent event) {
+ String voter = event.getVote().getUsername();
+ Player player = Bukkit.getPlayer(voter);
+
+ if (player == null) {
+ return;
+ }
+
+ QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
+ if (qPlayer == null) {
+ return;
+ }
+
+ for (Quest quest : super.getRegisteredQuests()) {
+ if (qPlayer.hasStartedQuest(quest)) {
+ QuestProgress questProgress = qPlayer.getQuestProgressFile().getQuestProgress(quest);
+
+ for (Task task : quest.getTasksOfType(super.getType())) {
+ TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
+
+ if (taskProgress.isCompleted()) {
+ continue;
+ }
+
+ int votesNeeded = (int) task.getConfigValue("amount");
+
+ int progressVotes;
+ if (taskProgress.getProgress() == null) {
+ progressVotes = 0;
+ } else {
+ progressVotes = (int) taskProgress.getProgress();
+ }
+
+ taskProgress.setProgress(progressVotes + 1);
+
+ if (((int) taskProgress.getProgress()) >= votesNeeded) {
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+ }
+ }
+
+}