summaryrefslogtreecommitdiffstats
path: root/bukkit/src
diff options
context:
space:
mode:
authorKrakenied <Krakenied1@gmail.com>2022-08-23 06:10:11 +0200
committerKrakenied <Krakenied1@gmail.com>2022-08-23 06:10:11 +0200
commit43588fef63a1e5caa1582645af7bf8678bb2d5e2 (patch)
treef3bc0c6d88888bcce9fea91e40b6238b4f9ac238 /bukkit/src
parent5d7c0db9b01327db59d68b03f985a23c3b6fd528 (diff)
Apply fixes to smithing task type too
Add support for more than 1 result item
Diffstat (limited to 'bukkit/src')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithingTaskType.java51
1 files changed, 40 insertions, 11 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithingTaskType.java
index 1c2849e5..70f97d17 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithingTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithingTaskType.java
@@ -14,6 +14,8 @@ import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
+import org.bukkit.event.inventory.ClickType;
+import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.SmithItemEvent;
import org.bukkit.inventory.ItemStack;
@@ -39,33 +41,60 @@ public final class SmithingTaskType extends BukkitTaskType {
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
- public void onItemSmith(SmithItemEvent event) {
- if (!event.getCursor().getType().equals(Material.AIR) || event.getCurrentItem() == null) return;
+ public void onSmithItem(SmithItemEvent event) {
+ //noinspection DuplicatedCode
+ if (event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR
+ || event.getAction() == InventoryAction.NOTHING
+ || event.getAction() == InventoryAction.HOTBAR_MOVE_AND_READD && event.getClick() == ClickType.NUMBER_KEY && !plugin.getVersionSpecificHandler().isHotbarMoveAndReaddSupported() // https://discord.com/channels/211910297810632704/510553623022010371/1011035743331819550
+ || event.getAction() == InventoryAction.DROP_ONE_SLOT && event.getClick() == ClickType.DROP && (event.getCursor() != null && event.getCursor().getType() != Material.AIR) // https://github.com/LMBishop/Quests/issues/430
+ || event.getAction() == InventoryAction.DROP_ALL_SLOT && event.getClick() == ClickType.CONTROL_DROP && (event.getCursor() != null && event.getCursor().getType() != Material.AIR) // https://github.com/LMBishop/Quests/issues/430
+ || event.getAction() == InventoryAction.UNKNOWN && event.getClick() == ClickType.UNKNOWN // for better ViaVersion support
+ || !(event.getWhoClicked() instanceof Player player)
+ || plugin.getVersionSpecificHandler().isOffHandSwap(event.getClick()) && !plugin.getVersionSpecificHandler().isOffHandEmpty(player)) {
+ return;
+ }
+
+ QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
+ if (qPlayer == null) {
+ return;
+ }
ItemStack item = event.getCurrentItem();
- Player player = (Player) event.getWhoClicked();
- QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
- if (qPlayer == null) return;
+ int eventAmount = item.getAmount();
+ if (event.isShiftClick() && event.getClick() != ClickType.CONTROL_DROP) { // https://github.com/LMBishop/Quests/issues/317
+ // https://cdn.discordapp.com/attachments/510553623022010371/1011483223446007849/unknown.png
+ eventAmount *= Math.min(event.getInventory().getInputEquipment().getAmount(), event.getInventory().getInputMineral().getAmount());
+ eventAmount = Math.min(eventAmount, plugin.getVersionSpecificHandler().getAvailableSpace(player, item));
+ if (eventAmount == 0) {
+ return;
+ }
+ }
for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskUtils.TaskConstraint.WORLD)) {
Quest quest = pendingTask.quest();
Task task = pendingTask.task();
TaskProgress taskProgress = pendingTask.taskProgress();
- int amount = (int) task.getConfigValue("amount");
+ QuestItem qi;
+ if ((qi = fixedQuestItemCache.get(quest.getId(), task.getId())) == null) {
+ QuestItem fetchedItem = TaskUtils.getConfigQuestItem(task, "item", "data");
+ fixedQuestItemCache.put(quest.getId(), task.getId(), fetchedItem);
+ qi = fetchedItem;
+ }
- super.debug("Player smith " + item.getType(), quest.getId(), task.getId(), player.getUniqueId());
+ super.debug("Player smithed " + eventAmount + " of " + item.getType(), quest.getId(), task.getId(), player.getUniqueId());
- QuestItem qi = TaskUtils.getConfigQuestItem(task, "item", "data");
- if (!qi.getItemStack().getType().equals(event.getCurrentItem().getType())) {
+ if (!qi.compareItemStack(item)) {
super.debug("Item does not match, continuing...", quest.getId(), task.getId(), player.getUniqueId());
continue;
}
+ int amount = (int) task.getConfigValue("amount");
+
int progress = TaskUtils.getIntegerTaskProgress(taskProgress);
- taskProgress.setProgress(progress + 1);
- super.debug("Updating task progress (now " + (progress + 1) + ")", quest.getId(), task.getId(), player.getUniqueId());
+ taskProgress.setProgress(progress + eventAmount);
+ super.debug("Updating task progress (now " + (progress + eventAmount) + ")", quest.getId(), task.getId(), player.getUniqueId());
if ((int) taskProgress.getProgress() >= amount) {
super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());