summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/leonardobishop/quests/Quests.java7
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MythicMobsKillingType.java92
2 files changed, 95 insertions, 4 deletions
diff --git a/src/main/java/com/leonardobishop/quests/Quests.java b/src/main/java/com/leonardobishop/quests/Quests.java
index 1cead356..332eae99 100644
--- a/src/main/java/com/leonardobishop/quests/Quests.java
+++ b/src/main/java/com/leonardobishop/quests/Quests.java
@@ -1,19 +1,16 @@
package com.leonardobishop.quests;
import com.google.common.io.ByteStreams;
-import com.leonardobishop.quests.blocktype.SimilarBlocks;
import com.leonardobishop.quests.bstats.Metrics;
import com.leonardobishop.quests.commands.CommandQuests;
import com.leonardobishop.quests.events.EventInventory;
import com.leonardobishop.quests.events.EventPlayerJoin;
import com.leonardobishop.quests.events.EventPlayerLeave;
-import com.leonardobishop.quests.obj.misc.QItemStack;
import com.leonardobishop.quests.player.QPlayer;
import com.leonardobishop.quests.player.QPlayerManager;
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.Category;
import com.leonardobishop.quests.quests.Quest;
import com.leonardobishop.quests.quests.QuestManager;
import com.leonardobishop.quests.quests.Task;
@@ -29,7 +26,6 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@@ -175,6 +171,9 @@ public class Quests extends JavaPlugin {
taskTypeManager.registerTaskType(new CitizensDeliverTaskType());
taskTypeManager.registerTaskType(new CitizensInteractTaskType());
}
+ if (Bukkit.getPluginManager().isPluginEnabled("MythicMobs")) {
+ taskTypeManager.registerTaskType(new MythicMobsKillingType());
+ }
reloadQuests();
if (!questsConfigLoader.getBrokenFiles().isEmpty()) {
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MythicMobsKillingType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MythicMobsKillingType.java
new file mode 100644
index 00000000..1964a228
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/MythicMobsKillingType.java
@@ -0,0 +1,92 @@
+package com.leonardobishop.quests.quests.tasktypes.types;
+
+import com.leonardobishop.quests.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 io.lumine.xikage.mythicmobs.api.bukkit.events.MythicMobDeathEvent;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public final class MythicMobsKillingType extends TaskType {
+
+ private List<ConfigValue> creatorConfigValues = new ArrayList<>();
+
+ public MythicMobsKillingType() {
+ super("mythicmobs_killing", "LMBishop", "Kill a set amount of a MythicMobs entity.");
+ this.creatorConfigValues.add(new ConfigValue("amount", true, "Amount of mobs to be killed."));
+ this.creatorConfigValues.add(new ConfigValue("name", true, "The 'internal name' of the MythicMob."));
+ }
+
+ @Override
+ public List<ConfigValue> getCreatorConfigValues() {
+ return creatorConfigValues;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onMobKill(MythicMobDeathEvent event) {
+ Entity killer = event.getKiller();
+ Entity mob = event.getEntity();
+
+ if (mob == null || mob instanceof Player) {
+ return;
+ }
+
+ if (killer == null) {
+ return;
+ }
+
+ Player player = (Player) event.getKiller();
+
+ String mobName = event.getMobType().getInternalName();
+
+ 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;
+ }
+
+ String configName = (String) task.getConfigValue("name");
+
+ if (!mobName.equals(configName)) {
+ return;
+ }
+
+ int mobKillsNeeded = (int) task.getConfigValue("amount");
+
+ int progressKills;
+ if (taskProgress.getProgress() == null) {
+ progressKills = 0;
+ } else {
+ progressKills = (int) taskProgress.getProgress();
+ }
+
+ taskProgress.setProgress(progressKills + 1);
+
+ if (((int) taskProgress.getProgress()) >= mobKillsNeeded) {
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+ }
+ }
+
+}