Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/EcoMobsKillingTaskType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |