-
-
Notifications
You must be signed in to change notification settings - Fork 108
Add BedWars2023 compatibility + 2 new tasks #818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e03e61e
5c52526
fc67c34
6c978ed
da2704d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package com.leonardobishop.quests.bukkit.tasktype.type.dependent; | ||
|
|
||
| import com.andrei1058.bedwars.api.events.shop.ShopBuyEvent; | ||
| import com.andrei1058.bedwars.api.arena.shop.ICategoryContent; | ||
| 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.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.inventory.ItemStack; | ||
|
|
||
| public final class BedWars1058BuyTask extends BukkitTaskType { | ||
|
|
||
| private final BukkitQuestsPlugin plugin; | ||
|
|
||
| public BedWars1058BuyTask(BukkitQuestsPlugin plugin) { | ||
| super("bedwars1058_buy", TaskUtils.TASK_ATTRIBUTION_STRING, "Buy specific items from the BedWars1058 shop."); | ||
| this.plugin = plugin; | ||
|
|
||
| super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount")); | ||
| super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount")); | ||
| super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "item")); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onShopBuy(ShopBuyEvent event) { | ||
| Player buyer = event.getBuyer(); | ||
| if (buyer == null) { | ||
| return; | ||
| } | ||
|
|
||
| QPlayer qBuyer = plugin.getPlayerManager().getPlayer(buyer.getUniqueId()); | ||
| if (qBuyer == null) { | ||
| return; | ||
| } | ||
|
|
||
| ICategoryContent boughtContent = event.getCategoryContent(); | ||
| if (boughtContent == null) { | ||
| return; | ||
| } | ||
|
|
||
| String boughtIdentifier = boughtContent.getIdentifier(); | ||
| ItemStack boughtStack = boughtContent.getItemStack(buyer); | ||
| String boughtMaterial = boughtStack != null ? boughtStack.getType().name() : null; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use ItemStacks directly with |
||
|
|
||
| for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(buyer, qBuyer, this, TaskConstraintSet.ALL)) { | ||
| Quest quest = pendingTask.quest(); | ||
| Task task = pendingTask.task(); | ||
| TaskProgress taskProgress = pendingTask.taskProgress(); | ||
|
|
||
| String requiredId = (String) task.getConfigValue("item"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot be null if there's required config validator on that. |
||
| if (requiredId == null) { | ||
| continue; | ||
| } | ||
|
|
||
| boolean matched = false; | ||
|
|
||
| if (requiredId.equalsIgnoreCase(boughtIdentifier)) { | ||
| matched = true; | ||
| super.debug("Matched identifier " + boughtIdentifier, | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
| } | ||
|
|
||
| if (!matched && requiredId.equalsIgnoreCase(boughtMaterial)) { | ||
| matched = true; | ||
| super.debug("Matched material " + boughtMaterial, | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
| } | ||
|
|
||
| if (!matched) { | ||
| super.debug("Bought item (" + boughtIdentifier + "/" + boughtMaterial + ") does not match required " + requiredId, | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
| continue; | ||
| } | ||
|
Comment on lines
+65
to
+81
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
|
||
| int boughtAmount = (boughtStack != null) ? boughtStack.getAmount() : 1; | ||
|
|
||
| int progress = taskProgress.getProgress() instanceof Integer | ||
| ? (int) taskProgress.getProgress() | ||
| : 0; | ||
| progress += boughtAmount; | ||
| taskProgress.setProgress(progress); | ||
|
Comment on lines
+85
to
+89
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's dedicated method for that. Take a look into other task types. |
||
|
|
||
| int amount = (int) task.getConfigValue("amount"); | ||
|
|
||
| super.debug("Progress " + progress + "/" + amount, | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
|
|
||
| if (progress >= amount) { | ||
| taskProgress.setCompleted(true); | ||
| super.debug("Marking task as complete", | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
| } | ||
|
|
||
| TaskUtils.sendTrackAdvancement(buyer, quest, task, pendingTask, amount); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package com.leonardobishop.quests.bukkit.tasktype.type.dependent; | ||
|
|
||
| import com.andrei1058.bedwars.api.events.player.PlayerGeneratorCollectEvent; | ||
| 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.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.inventory.ItemStack; | ||
|
|
||
| public final class BedWars1058GeneratorCollectTask extends BukkitTaskType { | ||
|
|
||
| private final BukkitQuestsPlugin plugin; | ||
|
|
||
| public BedWars1058GeneratorCollectTask(BukkitQuestsPlugin plugin) { | ||
| super("bedwars1058_generator_collect", TaskUtils.TASK_ATTRIBUTION_STRING, "Collect specific items from BedWars1058 generators."); | ||
| this.plugin = plugin; | ||
|
|
||
| super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount")); | ||
| super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount")); | ||
| super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "item")); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onGeneratorCollect(PlayerGeneratorCollectEvent event) { | ||
| Player player = event.getPlayer(); | ||
| if (player == null) { | ||
| return; | ||
| } | ||
|
|
||
| QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId()); | ||
| if (qPlayer == null) { | ||
| return; | ||
| } | ||
|
|
||
| ItemStack collectedStack = event.getItemStack(); | ||
| if (collectedStack == null) { | ||
| return; | ||
| } | ||
|
|
||
| String collectedMaterial = collectedStack.getType().name(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the above. |
||
| int collectedAmount = collectedStack.getAmount(); | ||
|
|
||
| for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskConstraintSet.ALL)) { | ||
| Quest quest = pendingTask.quest(); | ||
| Task task = pendingTask.task(); | ||
| TaskProgress taskProgress = pendingTask.taskProgress(); | ||
|
|
||
| String requiredId = (String) task.getConfigValue("item"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| if (requiredId == null) { | ||
| continue; | ||
| } | ||
|
|
||
| if (!requiredId.equalsIgnoreCase(collectedMaterial)) { | ||
| super.debug("Collected " + collectedMaterial + " does not match required " + requiredId, | ||
| quest.getId(), task.getId(), player.getUniqueId()); | ||
| continue; | ||
| } | ||
|
|
||
| super.debug("Player collected required item (" + collectedMaterial + ")", | ||
| quest.getId(), task.getId(), player.getUniqueId()); | ||
|
|
||
| int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress, collectedAmount); | ||
| int amount = ((int) task.getConfigValue("amount")); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant parentheses. |
||
|
|
||
| super.debug("Progress " + progress + "/" + amount, | ||
| quest.getId(), task.getId(), player.getUniqueId()); | ||
|
|
||
| if (progress >= amount) { | ||
| taskProgress.setCompleted(true); | ||
| super.debug("Marking task as complete", | ||
| quest.getId(), task.getId(), player.getUniqueId()); | ||
| } | ||
|
|
||
| TaskUtils.sendTrackAdvancement(player, quest, task, pendingTask, amount); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 com.tomkeuper.bedwars.api.events.player.PlayerBedBreakEvent; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
|
|
||
| public final class BedWars2023BedBreakTask extends BukkitTaskType { | ||
|
|
||
| private final BukkitQuestsPlugin plugin; | ||
|
|
||
| public BedWars2023BedBreakTask(BukkitQuestsPlugin plugin) { | ||
| super("bedwars2023_bedbreak", TaskUtils.TASK_ATTRIBUTION_STRING, "Break a set amount of beds in BedWars2023."); | ||
| this.plugin = plugin; | ||
|
|
||
| super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount")); | ||
| super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount")); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onPlayerBedBreak(PlayerBedBreakEvent event) { | ||
| Player player = event.getPlayer(); | ||
| if (player.hasMetadata("NPC")) { | ||
| return; | ||
| } | ||
|
Comment on lines
+31
to
+34
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do the player null check and the NPC metadata check are present inconsistently only on some of the introduced task types? |
||
|
|
||
| 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 broke a bed in BedWars", 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); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| 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.tomkeuper.bedwars.api.arena.shop.ICategoryContent; | ||
| import com.tomkeuper.bedwars.api.events.shop.ShopBuyEvent; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.inventory.ItemStack; | ||
|
|
||
| public final class BedWars2023BuyTask extends BukkitTaskType { | ||
|
|
||
| private final BukkitQuestsPlugin plugin; | ||
|
|
||
| public BedWars2023BuyTask(BukkitQuestsPlugin plugin) { | ||
| super("bedwars2023_buy", TaskUtils.TASK_ATTRIBUTION_STRING, "Buy specific items from the BedWars2023 shop."); | ||
| this.plugin = plugin; | ||
|
|
||
| super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount")); | ||
| super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount")); | ||
| super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "item")); | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onShopBuy(ShopBuyEvent event) { | ||
| Player buyer = event.getBuyer(); | ||
| if (buyer == null) { | ||
| return; | ||
| } | ||
|
|
||
| QPlayer qBuyer = plugin.getPlayerManager().getPlayer(buyer.getUniqueId()); | ||
| if (qBuyer == null) { | ||
| return; | ||
| } | ||
|
|
||
| ICategoryContent boughtContent = event.getCategoryContent(); | ||
| if (boughtContent == null) { | ||
| return; | ||
| } | ||
|
|
||
| String boughtIdentifier = boughtContent.getIdentifier(); | ||
| ItemStack boughtStack = boughtContent.getItemStack(buyer); | ||
| String boughtMaterial = boughtStack != null ? boughtStack.getType().name() : null; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
|
||
| for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(buyer, qBuyer, this, TaskConstraintSet.ALL)) { | ||
| Quest quest = pendingTask.quest(); | ||
| Task task = pendingTask.task(); | ||
| TaskProgress taskProgress = pendingTask.taskProgress(); | ||
|
|
||
| String requiredId = (String) task.getConfigValue("item"); | ||
| if (requiredId == null) { | ||
| continue; | ||
| } | ||
|
|
||
| boolean matched = false; | ||
|
|
||
| if (requiredId.equalsIgnoreCase(boughtIdentifier)) { | ||
| matched = true; | ||
| super.debug("Matched identifier " + boughtIdentifier, | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
| } | ||
|
|
||
| if (!matched && requiredId.equalsIgnoreCase(boughtMaterial)) { | ||
| matched = true; | ||
| super.debug("Matched material " + boughtMaterial, | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
| } | ||
|
|
||
| if (!matched) { | ||
| super.debug("Bought item (" + boughtIdentifier + "/" + boughtMaterial + ") does not match required " + requiredId, | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
| continue; | ||
| } | ||
|
Comment on lines
+60
to
+82
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
|
||
| int boughtAmount = (boughtStack != null) ? boughtStack.getAmount() : 1; | ||
|
|
||
| int progress = taskProgress.getProgress() instanceof Integer | ||
| ? (int) taskProgress.getProgress() | ||
| : 0; | ||
|
Comment on lines
+86
to
+88
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
| progress += boughtAmount; | ||
| taskProgress.setProgress(progress); | ||
|
|
||
| int amount = (int) task.getConfigValue("amount"); | ||
|
|
||
| super.debug("Progress " + progress + "/" + amount, | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
|
|
||
| if (progress >= amount) { | ||
| taskProgress.setCompleted(true); | ||
| super.debug("Marking task as complete", | ||
| quest.getId(), task.getId(), buyer.getUniqueId()); | ||
| } | ||
|
|
||
| TaskUtils.sendTrackAdvancement(buyer, quest, task, pendingTask, amount); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep alphabetical order.