diff options
| author | Krakenied <Krakenied1@gmail.com> | 2024-03-26 04:30:58 +0100 |
|---|---|---|
| committer | Leonardo Bishop <13875753+LMBishop@users.noreply.github.com> | 2024-06-03 18:48:22 +0100 |
| commit | ad82f711877169bf08caa3a2e16ba951a018a555 (patch) | |
| tree | 1a555208442fcfcaaf9d82f9ab24f6f7f19dfb78 /bukkit/src/main/java | |
| parent | 8cc9a4a7ecf4e284b2b0c614b91722b98d65880d (diff) | |
Add resurrecting task type
Diffstat (limited to 'bukkit/src/main/java')
| -rw-r--r-- | bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java | 2 | ||||
| -rw-r--r-- | bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/ResurrectingTaskType.java | 65 |
2 files changed, 67 insertions, 0 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java index 7267f1da..947d16c0 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java @@ -92,6 +92,7 @@ import com.leonardobishop.quests.bukkit.tasktype.type.PlaytimeTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.PositionTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.ProjectilelaunchingTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.ReplenishingTaskType; +import com.leonardobishop.quests.bukkit.tasktype.type.ResurrectingTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.ShearingTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.SmeltingTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.SmithingTaskType; @@ -449,6 +450,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { taskTypeManager.registerTaskType(() -> new HatchingTaskType(this), () -> CompatUtils.classExists("com.destroystokyo.paper.event.entity.ThrownEggHatchEvent")); taskTypeManager.registerTaskType(() -> new ItemmendingTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.player.PlayerItemMendEvent")); taskTypeManager.registerTaskType(() -> new ReplenishingTaskType(this), () -> CompatUtils.classExists("com.destroystokyo.paper.loottable.LootableInventoryReplenishEvent")); + taskTypeManager.registerTaskType(() -> new ResurrectingTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.entity.EntityResurrectEvent")); taskTypeManager.registerTaskType(() -> new SmithingTaskType(this), () -> CompatUtils.classExists("org.bukkit.event.inventory.SmithItemEvent")); // Register task types with enabled plugin compatibility requirement diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/ResurrectingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/ResurrectingTaskType.java new file mode 100644 index 00000000..e60bb70c --- /dev/null +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/ResurrectingTaskType.java @@ -0,0 +1,65 @@ +package com.leonardobishop.quests.bukkit.tasktype.type; + +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 org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityResurrectEvent; + +public final class ResurrectingTaskType extends BukkitTaskType { + + private final BukkitQuestsPlugin plugin; + + public ResurrectingTaskType(BukkitQuestsPlugin plugin) { + super("resurrecting", TaskUtils.TASK_ATTRIBUTION_STRING, "Resurrect a set amount of times."); + this.plugin = plugin; + + super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount")); + super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount")); + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onEntityResurrect(EntityResurrectEvent event) { + LivingEntity entity = event.getEntity(); + if (!(entity instanceof Player player)) { + return; + } + + if (player.hasMetadata("NPC")) { + return; + } + + QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId()); + if (qPlayer == null) { + return; + } + + 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 resurrected", quest.getId(), task.getId(), player.getUniqueId()); + + 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, pendingTask, amount); + } + } +} |
