Skip to content

Commit

Permalink
EcoMobs support
Browse files Browse the repository at this point in the history
  • Loading branch information
Krakenied authored and LMBishop committed Jan 9, 2024
1 parent e6f0d05 commit 3551c1e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 14 deletions.
7 changes: 4 additions & 3 deletions bukkit/build.gradle
Expand Up @@ -20,7 +20,7 @@ repositories {
maven { url = 'https://libraries.minecraft.net/' }
// CoreProtect
maven { url = 'https://maven.playpro.com/' }
// EcoBosses
// EcoBosses, EcoMobs
maven { url = 'https://repo.auxilor.io/repository/maven-public/' }
// EssentialsX
maven { url = 'https://repo.essentialsx.net/releases/' }
Expand Down Expand Up @@ -69,8 +69,9 @@ dependencies {
compileOnly('net.citizensnpcs:citizensapi:2.0.30-SNAPSHOT') { transitive = false }
// CoreProtect
compileOnly 'net.coreprotect:coreprotect:21.2'
// EcoBosses
// EcoBosses, EcoMobs
compileOnly 'com.willfp:EcoBosses:9.14.0'
compileOnly 'com.willfp:EcoMobs:10.0.0-b1'
compileOnly 'com.willfp:eco:6.65.1'
compileOnly 'com.willfp:libreforge:4.21.1'
// EssentialsX
Expand Down Expand Up @@ -112,7 +113,7 @@ dependencies {
// VotingPlugin
compileOnly('com.bencodez:votingplugin:6.15') { transitive = false }

// IridiumSkyblock, uSkyBlock
// IridiumSkyblock, PyroFishingPro, uSkyBlock
compileOnly fileTree(dir: 'libs', includes: ['*.jar'])

// bStats
Expand Down
Expand Up @@ -92,6 +92,7 @@
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.CitizensDeliverTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.CitizensInteractTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.EcoBossesKillingTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.EcoMobsKillingTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.EssentialsBalanceTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.EssentialsMoneyEarnTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.FabledSkyBlockLevelTaskType;
Expand Down Expand Up @@ -426,6 +427,7 @@ public void onEnable() {
taskTypeManager.registerTaskType(() -> new CitizensDeliverTaskType(this), () -> CompatUtils.isPluginEnabled("Citizens"));
taskTypeManager.registerTaskType(() -> new CitizensInteractTaskType(this), () -> CompatUtils.isPluginEnabled("Citizens"));
taskTypeManager.registerTaskType(() -> new EcoBossesKillingTaskType(this), () -> CompatUtils.isPluginEnabled("EcoBosses"));
taskTypeManager.registerTaskType(() -> new EcoMobsKillingTaskType(this), () -> CompatUtils.isPluginEnabled("EcoMobs"));
taskTypeManager.registerTaskType(() -> new EssentialsBalanceTaskType(this), () -> CompatUtils.isPluginEnabled("Essentials"));
taskTypeManager.registerTaskType(() -> new EssentialsMoneyEarnTaskType(this), () -> CompatUtils.isPluginEnabled("Essentials"));
taskTypeManager.registerTaskType(() -> new FabledSkyBlockLevelTaskType(this), () -> CompatUtils.isPluginEnabled("FabledSkyBlock")); // not tested
Expand Down
Expand Up @@ -3,11 +3,13 @@
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.constraint.TaskConstraintSet;
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 com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.LivingEcoBoss;
import com.willfp.ecobosses.events.BossKillEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -28,37 +30,41 @@ public EcoBossesKillingTaskType(BukkitQuestsPlugin plugin) {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBossKill(BossKillEvent event) {
Player killer = event.getKiller();
EcoBoss boss = event.getBoss().getBoss();
Player player = event.getKiller();
if (player == null || player.hasMetadata("NPC")) {
return;
}

QPlayer qPlayer = plugin.getPlayerManager().getPlayer(killer.getUniqueId());
QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
if (qPlayer == null) {
return;
}

for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(killer, qPlayer, this)) {
LivingEcoBoss boss = event.getBoss();
EcoBoss ecoBoss = boss.getBoss();

for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) {
Quest quest = pendingTask.quest();
Task task = pendingTask.task();
TaskProgress taskProgress = pendingTask.taskProgress();

super.debug("Player killed EcoBosses mob '" + boss.getDisplayName() + "' (id = " + boss.getID() + ")", quest.getId(), task.getId(), killer.getUniqueId());
super.debug("Player killed EcoBosses boss '" + ecoBoss.getDisplayName() + "' (id = " + ecoBoss.getID() + ")", quest.getId(), task.getId(), player.getUniqueId());

if (!TaskUtils.matchString(this, pendingTask, boss.getID(), killer.getUniqueId(), "id", "ids", false, false)) {
super.debug("Continuing...", quest.getId(), task.getId(), killer.getUniqueId());
if (!TaskUtils.matchString(this, pendingTask, ecoBoss.getID(), player.getUniqueId(), "id", "ids", false, false)) {
super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId());
continue;
}

int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress);
super.debug("Incrementing task progress (now " + progress + ")", quest.getId(), task.getId(), killer.getUniqueId());
super.debug("Incrementing task progress (now " + progress + ")", quest.getId(), task.getId(), player.getUniqueId());

int amount = (int) task.getConfigValue("amount");

if (progress >= amount) {
super.debug("Marking task as complete", quest.getId(), task.getId(), killer.getUniqueId());
super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());
taskProgress.setCompleted(true);
}

TaskUtils.sendTrackAdvancement(killer, quest, task, taskProgress, amount);
TaskUtils.sendTrackAdvancement(player, quest, task, taskProgress, amount);
}
}
}
@@ -0,0 +1,70 @@
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.constraint.TaskConstraintSet;
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 com.willfp.ecomobs.event.EcoMobKillEvent;
import com.willfp.ecomobs.mob.EcoMob;
import com.willfp.ecomobs.mob.LivingMob;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;

public final class EcoMobsKillingTaskType extends BukkitTaskType {

private final BukkitQuestsPlugin plugin;

public EcoMobsKillingTaskType(BukkitQuestsPlugin plugin) {
super("ecomobs_killing", TaskUtils.TASK_ATTRIBUTION_STRING, "Kill a set amount of an EcoMobs entity.");
this.plugin = plugin;

super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "id", "ids"));
super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount"));
super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount"));
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEcoMobKill(EcoMobKillEvent event) {
Player player = event.getPlayer();
if (player.hasMetadata("NPC")) {
return;
}

QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
if (qPlayer == null) {
return;
}

LivingMob mob = event.getMob();
EcoMob ecoMob = mob.getMob();

for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) {
Quest quest = pendingTask.quest();
Task task = pendingTask.task();
TaskProgress taskProgress = pendingTask.taskProgress();

super.debug("Player killed EcoMobs mob '" + mob.getDisplayName() + "' (id = " + mob.getMob().getID() + ")", quest.getId(), task.getId(), player.getUniqueId());

if (!TaskUtils.matchString(this, pendingTask, ecoMob.getID(), player.getUniqueId(), "id", "ids", false, false)) {
super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId());
continue;
}

int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress);
super.debug("Incrementing task progress (now " + progress + ")", quest.getId(), task.getId(), player.getUniqueId());

int amount = (int) task.getConfigValue("amount");
if (progress >= amount) {
super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());
taskProgress.setCompleted(true);
}

TaskUtils.sendTrackAdvancement(player, quest, task, taskProgress, amount);
}
}
}

0 comments on commit 3551c1e

Please sign in to comment.