From af769229795d3c2ca689b3d80d048b2aabc94ef6 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Fri, 6 Sep 2024 21:02:44 +0200 Subject: Add option to specify the trader mob --- .../bukkit/tasktype/type/TradingTaskType.java | 10 +++++++++- docs/task-types/trading-(task-type).md | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/TradingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/TradingTaskType.java index e1790344..09eeaa59 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/TradingTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/TradingTaskType.java @@ -12,6 +12,7 @@ import com.leonardobishop.quests.common.player.questprogressfile.TaskProgress; import com.leonardobishop.quests.common.quest.Quest; import com.leonardobishop.quests.common.quest.Task; import io.papermc.paper.event.player.PlayerTradeEvent; +import org.bukkit.entity.AbstractVillager; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -34,6 +35,7 @@ public final class TradingTaskType extends BukkitTaskType { super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount")); super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount")); + super.addConfigValidator(TaskUtils.useEntityListConfigValidator(this, "mob", "mobs")); super.addConfigValidator(TaskUtils.useItemStackConfigValidator(this, "item")); super.addConfigValidator(TaskUtils.useItemStackConfigValidator(this, "first-ingredient")); super.addConfigValidator(TaskUtils.useItemStackConfigValidator(this, "second-ingredient")); @@ -63,6 +65,7 @@ public final class TradingTaskType extends BukkitTaskType { return; } + AbstractVillager villager = event.getVillager(); MerchantRecipe recipe = event.getTrade(); ItemStack item = recipe.getResult(); int itemAmount = item.getAmount(); @@ -76,8 +79,13 @@ public final class TradingTaskType extends BukkitTaskType { Task task = pendingTask.task(); TaskProgress taskProgress = pendingTask.taskProgress(); + if (!TaskUtils.matchEntity(this, pendingTask, villager, player.getUniqueId())) { + super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId()); + continue; + } + // TODO: add villager-type and villager-profession options - // TODO: add option to set villager/wandering trader + // not that simple especially after the change in 1.21 if (task.hasConfigKey("item")) { QuestItem qi; diff --git a/docs/task-types/trading-(task-type).md b/docs/task-types/trading-(task-type).md index 67bd2838..3d9ce944 100644 --- a/docs/task-types/trading-(task-type).md +++ b/docs/task-types/trading-(task-type).md @@ -19,16 +19,17 @@ Trade with a Villager or Wandering Trader. ## Options -| Key | Description | Type | Required | Default | Notes | -|---------------------------------|--------------------------------------------------------------------------|------------------------|----------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `amount` | The number of items to trade. | Integer | Yes | \- | \- | -| `item` | The specific item to trade. | Material, or ItemStack | No | \- | Accepts standard [item definition](../configuration/defining-items). Please see [this list](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html) (1.13+) or [this list](https://helpch.at/docs/1.12.2/org/bukkit/Material.html) (1.8-1.12) for material names. | -| `exact-match` | Whether the item should exactly match what is defined. | Boolean | No | true | \- | -| `first-ingredient` | The specific item to be used as the first ingredient in a trade. | Material, or ItemStack | No | \- | Accepts standard [item definition](../configuration/defining-items). Please see [this list](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html) (1.13+) or [this list](https://helpch.at/docs/1.12.2/org/bukkit/Material.html) (1.8-1.12) for material names. | -| `first-ingredient-exact-match` | Whether the first ingredient item should exactly match what is defined. | Boolean | No | true | \- | -| `second-ingredient` | The specific item to be used as the second ingredient in a trade. | Material, or ItemStack | No | \- | Accepts standard [item definition](../configuration/defining-items). Please see [this list](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html) (1.13+) or [this list](https://helpch.at/docs/1.12.2/org/bukkit/Material.html) (1.8-1.12) for material names. | -| `second-ingredient-exact-match` | Whether the second ingredient item should exactly match what is defined. | Boolean | No | true | \- | -| `worlds` | Worlds which should count towards the progress. | List of world names | No | \- | \- | +| Key | Description | Type | Required | Default | Notes | +|---------------------------------|--------------------------------------------------------------------------|----------------------------------|----------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `amount` | The number of items to trade. | Integer | Yes | \- | \- | +| `mob` / `mobs` | The specific mob(s) to trade with. | Entity type, or list of entities | No | \- | Not specifying this field will allow all mob types to count towards the task. Please see [this list](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html) for entity types. | +| `item` | The specific item to trade. | Material, or ItemStack | No | \- | Accepts standard [item definition](../configuration/defining-items). Please see [this list](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html) (1.13+) or [this list](https://helpch.at/docs/1.12.2/org/bukkit/Material.html) (1.8-1.12) for material names. | +| `exact-match` | Whether the item should exactly match what is defined. | Boolean | No | true | \- | +| `first-ingredient` | The specific item to be used as the first ingredient in a trade. | Material, or ItemStack | No | \- | Accepts standard [item definition](../configuration/defining-items). Please see [this list](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html) (1.13+) or [this list](https://helpch.at/docs/1.12.2/org/bukkit/Material.html) (1.8-1.12) for material names. | +| `first-ingredient-exact-match` | Whether the first ingredient item should exactly match what is defined. | Boolean | No | true | \- | +| `second-ingredient` | The specific item to be used as the second ingredient in a trade. | Material, or ItemStack | No | \- | Accepts standard [item definition](../configuration/defining-items). Please see [this list](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html) (1.13+) or [this list](https://helpch.at/docs/1.12.2/org/bukkit/Material.html) (1.8-1.12) for material names. | +| `second-ingredient-exact-match` | Whether the second ingredient item should exactly match what is defined. | Boolean | No | true | \- | +| `worlds` | Worlds which should count towards the progress. | List of world names | No | \- | \- | ## Examples @@ -38,6 +39,7 @@ Buy 10 carrots from a Villager: tradecarrots: type: "trading" amount: 10 # amount of items to trade + mob: VILLAGER # (OPTIONAL) trader type item: CARROT # (OPTIONAL) item to trade worlds: # (OPTIONAL) restrict to certain worlds - "world" -- cgit v1.2.3-70-g09d2