summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2020-02-19 19:40:42 +0000
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2020-02-19 19:40:42 +0000
commit648f1a91a49f6ebd58979948e5db6f9e034ebb70 (patch)
treec1f817262cbfd0a92a30da2f286c818a82d906fc /src/main/java
parentc86adf662247252deec7d0c3b6edda95868a8187 (diff)
Added Iridium Skyblock Value task type
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/leonardobishop/quests/Quests.java9
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/IridiumSkyblockValueType.java91
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/PlaytimeTaskType.java60
3 files changed, 137 insertions, 23 deletions
diff --git a/src/main/java/com/leonardobishop/quests/Quests.java b/src/main/java/com/leonardobishop/quests/Quests.java
index c8064f95..32178d5d 100644
--- a/src/main/java/com/leonardobishop/quests/Quests.java
+++ b/src/main/java/com/leonardobishop/quests/Quests.java
@@ -15,6 +15,7 @@ import com.leonardobishop.quests.player.questprogressfile.TaskProgress;
import com.leonardobishop.quests.quests.Quest;
import com.leonardobishop.quests.quests.QuestManager;
import com.leonardobishop.quests.quests.Task;
+import com.leonardobishop.quests.quests.tasktypes.TaskType;
import com.leonardobishop.quests.quests.tasktypes.TaskTypeManager;
import com.leonardobishop.quests.quests.tasktypes.types.*;
import com.leonardobishop.quests.title.Title;
@@ -149,6 +150,9 @@ public class Quests extends JavaPlugin {
if (Bukkit.getPluginManager().isPluginEnabled("BentoBox")) {
BentoBoxLevelTaskType.register(taskTypeManager);
}
+ if (Bukkit.getPluginManager().isPluginEnabled("IridiumSkyblock")) {
+ taskTypeManager.registerTaskType(new IridiumSkyblockValueType());
+ }
if (Bukkit.getPluginManager().isPluginEnabled("uSkyBlock")) {
taskTypeManager.registerTaskType(new uSkyBlockLevelType());
}
@@ -214,6 +218,11 @@ public class Quests extends JavaPlugin {
@Override
public void onDisable() {
+ for (TaskType taskType : getTaskTypeManager().getTaskTypes()) {
+ try {
+ taskType.onDisable();
+ } catch (Exception ignored) { }
+ }
for (QPlayer qPlayer : qPlayerManager.getQPlayers()) {
if (qPlayer.isOnlyDataLoaded()) {
continue;
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/IridiumSkyblockValueType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/IridiumSkyblockValueType.java
new file mode 100644
index 00000000..7a9e7ef6
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/IridiumSkyblockValueType.java
@@ -0,0 +1,91 @@
+package com.leonardobishop.quests.quests.tasktypes.types;
+
+import com.iridium.iridiumskyblock.IridiumSkyblock;
+import com.iridium.iridiumskyblock.Island;
+import com.iridium.iridiumskyblock.User;
+import com.leonardobishop.quests.Quests;
+import com.leonardobishop.quests.api.QuestsAPI;
+import com.leonardobishop.quests.player.QPlayer;
+import com.leonardobishop.quests.player.questprogressfile.QuestProgress;
+import com.leonardobishop.quests.player.questprogressfile.QuestProgressFile;
+import com.leonardobishop.quests.player.questprogressfile.TaskProgress;
+import com.leonardobishop.quests.quests.Quest;
+import com.leonardobishop.quests.quests.Task;
+import com.leonardobishop.quests.quests.tasktypes.ConfigValue;
+import com.leonardobishop.quests.quests.tasktypes.TaskType;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.bukkit.scheduler.BukkitTask;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public final class IridiumSkyblockValueType extends TaskType {
+
+ private List<ConfigValue> creatorConfigValues = new ArrayList<>();
+ private BukkitTask poll;
+
+ public IridiumSkyblockValueType() {
+ super("iridiumskyblock_value", "LMBishop", "Reach a certain island value for Iridium Skyblock.");
+ this.creatorConfigValues.add(new ConfigValue("value", true, "Minimum island value needed."));
+ }
+
+ @Override
+ public void onReady() {
+ this.poll = new BukkitRunnable() {
+ @Override
+ public void run() {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ Island island = null;
+ if ((island = User.getUser(player).getIsland()) == null) {
+ return;
+ }
+
+ QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId());
+ if (qPlayer == null) {
+ return;
+ }
+
+ QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();
+
+ for (Quest quest : IridiumSkyblockValueType.super.getRegisteredQuests()) {
+ if (questProgressFile.hasStartedQuest(quest)) {
+ QuestProgress questProgress = questProgressFile.getQuestProgress(quest);
+
+ for (Task task : quest.getTasksOfType(IridiumSkyblockValueType.super.getType())) {
+ TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
+
+ if (taskProgress.isCompleted()
+ || (taskProgress.getProgress() != null && (int) taskProgress.getProgress() == island.getValue())) {
+ continue;
+ }
+
+ int islandValueNeeded = (int) task.getConfigValue("value");
+
+ taskProgress.setProgress(island.getValue());
+
+ if (((int) taskProgress.getProgress()) >= islandValueNeeded) {
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+ }
+ }
+ }
+ }.runTaskTimer(Quests.get(), 50L, 50L);
+ }
+
+ @Override
+ public void onDisable() {
+ if (this.poll != null) {
+ this.poll.cancel();
+ }
+ }
+
+ @Override
+ public List<ConfigValue> getCreatorConfigValues() {
+ return creatorConfigValues;
+ }
+
+}
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/PlaytimeTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/PlaytimeTaskType.java
index bb42d8dd..bdc202ab 100644
--- a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/PlaytimeTaskType.java
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/PlaytimeTaskType.java
@@ -11,40 +11,54 @@ import com.leonardobishop.quests.quests.Task;
import com.leonardobishop.quests.quests.tasktypes.TaskType;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+import org.bukkit.scheduler.BukkitTask;
public final class PlaytimeTaskType extends TaskType {
+ private BukkitTask poll;
+
public PlaytimeTaskType() {
super("playtime", "Reinatix", "Track the amount of playing time a user has been on");
- playTime();
}
- public void playTime() {
- Bukkit.getScheduler().runTaskTimer(Quests.get(), () -> {
- for (Player player : Bukkit.getOnlinePlayers()) {
- QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId());
- QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();
- for (Quest quest : super.getRegisteredQuests()) {
- if (questProgressFile.hasStartedQuest(quest)) {
- QuestProgress questProgress = questProgressFile.getQuestProgress(quest);
- for (Task task : quest.getTasksOfType(super.getType())) {
- TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
- if (taskProgress.isCompleted()) {
- continue;
- }
- int minutes = (int) task.getConfigValue("minutes");
- if (taskProgress.getProgress() == null) {
- taskProgress.setProgress(1);
- } else {
- taskProgress.setProgress((int) taskProgress.getProgress() + 1);
- }
- if (((int) taskProgress.getProgress()) >= minutes) {
- taskProgress.setCompleted(true);
+ @Override
+ public void onReady() {
+ this.poll = new BukkitRunnable() {
+ @Override
+ public void run() {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ QPlayer qPlayer = QuestsAPI.getPlayerManager().getPlayer(player.getUniqueId());
+ QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();
+ for (Quest quest : PlaytimeTaskType.super.getRegisteredQuests()) {
+ if (questProgressFile.hasStartedQuest(quest)) {
+ QuestProgress questProgress = questProgressFile.getQuestProgress(quest);
+ for (Task task : quest.getTasksOfType(PlaytimeTaskType.super.getType())) {
+ TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
+ if (taskProgress.isCompleted()) {
+ continue;
+ }
+ int minutes = (int) task.getConfigValue("minutes");
+ if (taskProgress.getProgress() == null) {
+ taskProgress.setProgress(1);
+ } else {
+ taskProgress.setProgress((int) taskProgress.getProgress() + 1);
+ }
+ if (((int) taskProgress.getProgress()) >= minutes) {
+ taskProgress.setCompleted(true);
+ }
}
}
}
}
}
- }, 1200L, 1200L);
+ }.runTaskTimer(Quests.get(), 1200L, 1200L);
+ }
+
+ @Override
+ public void onDisable() {
+ if (this.poll != null) {
+ this.poll.cancel();
+ }
}
}