aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2019-07-15 16:15:27 +0100
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2019-07-15 16:15:27 +0100
commit8ac80d9ce8f75b632fbfc2ff616a1dda5c27edeb (patch)
treed6f7f1bc9f26ad464b7d4013f1f1a22c15a164df
parentd8502acae21167a15cdfa4c215345466ba526de4 (diff)
MythicMobs task type
- Added mythicmobs_killing task type
-rw-r--r--pom.xml19
-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
3 files changed, 113 insertions, 5 deletions
diff --git a/pom.xml b/pom.xml
index 7202f000..5eeea76c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,6 +42,12 @@
<id>everything</id>
<url>http://repo.citizensnpcs.co/</url>
</repository>
+
+ <!-- MythicMobs -->
+ <repository>
+ <id>mythicmobs</id>
+ <url>http://mc.hackerzlair.org:8888/repository/public</url>
+ </repository>
</repositories>
<dependencies>
@@ -66,6 +72,16 @@
<groupId>com.github.rlf</groupId>
<artifactId>uSkyBlock-API</artifactId>
<version>2.6.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- MythicMobs -->
+ <dependency>
+ <groupId>io.lumine.xikage</groupId>
+ <artifactId>mythicmobs</artifactId>
+ <version>4.5.7</version>
+ <type>jar</type>
+ <scope>provided</scope>
</dependency>
<!-- Citizens -->
@@ -77,7 +93,8 @@
<scope>provided</scope>
</dependency>
-<!-- &lt;!&ndash; Test &ndash;&gt;-->
+
+ <!-- &lt;!&ndash; Test &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.powermock</groupId>-->
<!-- <artifactId>powermock-module-junit4</artifactId>-->
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);
+ }
+ }
+ }
+ }
+ }
+
+}