Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added bukkit/libs/bedwars-api-2.0.0-SNAPSHOT.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars1058FinalKillTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars1058LoseTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars1058WinTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars1058BuyTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars1058GeneratorCollectTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars2023BedBreakTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars2023FinalKillTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars2023LoseTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars2023WinTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars2023BuyTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BedWars2023GeneratorCollectTask;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.BentoBoxLevelTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.CitizensDeliverTaskType;
import com.leonardobishop.quests.bukkit.tasktype.type.dependent.CitizensInteractTaskType;
Expand Down Expand Up @@ -501,6 +509,14 @@ public void onEnable() {
taskTypeManager.registerTaskType(() -> new BedWars1058FinalKillTask(this), () -> CompatUtils.isPluginEnabled("BedWars1058")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars1058LoseTask(this), () -> CompatUtils.isPluginEnabled("BedWars1058")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars1058WinTask(this), () -> CompatUtils.isPluginEnabled("BedWars1058")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars1058BuyTask(this), () -> CompatUtils.isPluginEnabled("BedWars1058")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars1058GeneratorCollectTask(this), () -> CompatUtils.isPluginEnabled("BedWars1058")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars2023BedBreakTask(this), () -> CompatUtils.isPluginEnabled("BedWars2023")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars2023FinalKillTask(this), () -> CompatUtils.isPluginEnabled("BedWars2023")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars2023LoseTask(this), () -> CompatUtils.isPluginEnabled("BedWars2023")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars2023WinTask(this), () -> CompatUtils.isPluginEnabled("BedWars2023")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars2023BuyTask(this), () -> CompatUtils.isPluginEnabled("BedWars2023")); // not tested
taskTypeManager.registerTaskType(() -> new BedWars2023GeneratorCollectTask(this), () -> CompatUtils.isPluginEnabled("BedWars2023")); // not tested
taskTypeManager.registerTaskType(() -> new BentoBoxLevelTaskType(this), () -> CompatUtils.isPluginEnabled("BentoBox") && CompatUtils.classExists("world.bentobox.level.events.IslandLevelCalculatedEvent"));
taskTypeManager.registerTaskType(() -> new CitizensDeliverTaskType(this), () -> CompatUtils.isPluginEnabled("Citizens"));
taskTypeManager.registerTaskType(() -> new CitizensInteractTaskType(this), () -> CompatUtils.isPluginEnabled("Citizens"));
Expand Down
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;

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;
}

int boughtAmount = (boughtStack != null) ? boughtStack.getAmount() : 1;

int progress = taskProgress.getProgress() instanceof Integer
? (int) taskProgress.getProgress()
: 0;
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);
}
}
}
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();
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");
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"));

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;
}

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;

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;
}

int boughtAmount = (boughtStack != null) ? boughtStack.getAmount() : 1;

int progress = taskProgress.getProgress() instanceof Integer
? (int) taskProgress.getProgress()
: 0;
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);
}
}
}
Loading