From 0cc65414946afbc689eeb56b5ad141f641a9c3a2 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Fri, 16 Feb 2024 08:36:49 +0100 Subject: Add PinataParty support Closes https://github.com/LMBishop/Quests/issues/518 --- bukkit/libs/PinataParty-2.63.9-API.jar | Bin 0 -> 1758 bytes .../quests/bukkit/BukkitQuestsPlugin.java | 2 + .../type/dependent/PinataPartyHitTaskType.java | 60 +++++++++++++++++++++ bukkit/src/main/resources/plugin.yml | 1 + 4 files changed, 63 insertions(+) create mode 100644 bukkit/libs/PinataParty-2.63.9-API.jar create mode 100644 bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/PinataPartyHitTaskType.java diff --git a/bukkit/libs/PinataParty-2.63.9-API.jar b/bukkit/libs/PinataParty-2.63.9-API.jar new file mode 100644 index 00000000..6321bd1f Binary files /dev/null and b/bukkit/libs/PinataParty-2.63.9-API.jar differ 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 cf2e2600..958bfdaa 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java @@ -101,6 +101,7 @@ import com.leonardobishop.quests.bukkit.tasktype.type.dependent.FabledSkyBlockLe import com.leonardobishop.quests.bukkit.tasktype.type.dependent.IridiumSkyblockValueTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.dependent.MythicMobsKillingTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.dependent.NuVotifierVoteTaskType; +import com.leonardobishop.quests.bukkit.tasktype.type.dependent.PinataPartyHitTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.dependent.PlaceholderAPIEvaluateTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.dependent.PlayerPointsEarnTaskType; import com.leonardobishop.quests.bukkit.tasktype.type.dependent.PyroFishingProFishingTaskType; @@ -442,6 +443,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { 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 + taskTypeManager.registerTaskType(() -> new PinataPartyHitTaskType(this), () -> CompatUtils.isPluginEnabled("PinataParty")); taskTypeManager.registerTaskType(() -> new PlaceholderAPIEvaluateTaskType(this), () -> CompatUtils.isPluginEnabled("PlaceholderAPI")); taskTypeManager.registerTaskType(() -> new PlayerPointsEarnTaskType(this), () -> CompatUtils.isPluginEnabled("PlayerPoints")); taskTypeManager.registerTaskType(() -> new PyroFishingProFishingTaskType(this), () -> CompatUtils.isPluginEnabled("PyroFishingPro") && CompatUtils.classExists("me.arsmagica.API.PyroFishCatchEvent")); diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/PinataPartyHitTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/PinataPartyHitTaskType.java new file mode 100644 index 00000000..d21b811c --- /dev/null +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/PinataPartyHitTaskType.java @@ -0,0 +1,60 @@ +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 me.hexedhero.pp.api.PinataHitEvent; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +public final class PinataPartyHitTaskType extends BukkitTaskType { + + private final BukkitQuestsPlugin plugin; + + public PinataPartyHitTaskType(BukkitQuestsPlugin plugin) { + super("pinataparty_hit", TaskUtils.TASK_ATTRIBUTION_STRING, "Hit the PinataParty pinata 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 onPinataHit(PinataHitEvent event) { + Player player = event.getPlayer(); + 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 hit pinata", 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, taskProgress, amount); + } + } +} diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml index 8a9eeab7..4c48f951 100644 --- a/bukkit/src/main/resources/plugin.yml +++ b/bukkit/src/main/resources/plugin.yml @@ -17,6 +17,7 @@ softdepend: - FabledSkyBlock - IridiumSkyblock - MythicMobs +- PinataParty - PlaceholderAPI - PlayerBlockTracker - PlayerPoints -- cgit v1.2.3-70-g09d2