summaryrefslogtreecommitdiffstats
path: root/bukkit/src
diff options
context:
space:
mode:
Diffstat (limited to 'bukkit/src')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java1
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java2
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithTaskType.java77
-rw-r--r--bukkit/src/main/resources/plugin.yml2
4 files changed, 80 insertions, 2 deletions
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 dbb0fe00..deaec724 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
@@ -315,6 +315,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
taskTypeManager.registerTaskType(new BucketEmptyTaskType(this));
taskTypeManager.registerTaskType(new BucketFillTaskType(this));
taskTypeManager.registerTaskType(new InteractTaskType(this));
+ taskTypeManager.registerTaskType(new SmithTaskType(this));
// TODO: FIX
// taskTypeManager.registerTaskType(new BrewingCertainTaskType());
try {
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java
index 4ccb17bf..52665b51 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningTaskType.java
@@ -69,7 +69,7 @@ public final class MiningTaskType extends BukkitTaskType {
}
};
- if (plugin.getCoreProtectHook() != null) {
+ if (coreProtectEnabled && plugin.getCoreProtectHook() != null) {
super.debug("Running CoreProtect lookup (may take a while)", quest.getId(), task.getId(), player.getUniqueId());
plugin.getCoreProtectHook().checkBlock(event.getBlock(), coreProtectTime).thenAccept(result -> {
if (result) {
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithTaskType.java
new file mode 100644
index 00000000..10fa9ec8
--- /dev/null
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/SmithTaskType.java
@@ -0,0 +1,77 @@
+package com.leonardobishop.quests.bukkit.tasktype.type;
+
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
+import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
+import com.leonardobishop.quests.bukkit.item.QuestItem;
+import com.leonardobishop.quests.bukkit.tasktype.BukkitTaskType;
+import com.leonardobishop.quests.bukkit.util.TaskUtils;
+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.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.inventory.SmithItemEvent;
+import org.bukkit.inventory.ItemStack;
+
+public class SmithTaskType extends BukkitTaskType {
+
+ private final BukkitQuestsPlugin plugin;
+ private final Table<String, String, QuestItem> fixedQuestItemCache = HashBasedTable.create();
+
+ public SmithTaskType(BukkitQuestsPlugin plugin) {
+ super("smithing", TaskUtils.TASK_ATTRIBUTION_STRING, "Smith a specific item.");
+ this.plugin = plugin;
+
+ super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount"));
+ super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount"));
+ super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "item"));
+ super.addConfigValidator(TaskUtils.useItemStackConfigValidator(this, "item"));
+ super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "data"));
+ }
+
+ @Override
+ public void onReady() {
+ fixedQuestItemCache.clear();
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onItemSmith(SmithItemEvent event) {
+ if (!event.getCursor().getType().equals(Material.AIR) || event.getCurrentItem() == null) return;
+
+ ItemStack item = event.getCurrentItem();
+ Player player = (Player) event.getWhoClicked();
+
+ QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
+ if (qPlayer == null) 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");
+
+ super.debug("Player smith " + item.getType(), quest.getId(), task.getId(), player.getUniqueId());
+
+ QuestItem qi = TaskUtils.getConfigQuestItem(task, "item", "data");
+ if (!qi.getItemStack().getType().equals(event.getCurrentItem().getType())) {
+ super.debug("Item does not match, continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
+ }
+
+ int progress = TaskUtils.getIntegerTaskProgress(taskProgress);
+ taskProgress.setProgress(progress + 1);
+ super.debug("Updating task progress (now " + (progress + 1) + ")", quest.getId(), task.getId(), player.getUniqueId());
+
+ if ((int) taskProgress.getProgress() >= amount) {
+ super.debug("Marking task as complete", quest.getId(), task.getId(), player.getUniqueId());
+ taskProgress.setProgress(amount);
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+}
diff --git a/bukkit/src/main/resources/plugin.yml b/bukkit/src/main/resources/plugin.yml
index becdecd1..b9e47d50 100644
--- a/bukkit/src/main/resources/plugin.yml
+++ b/bukkit/src/main/resources/plugin.yml
@@ -27,4 +27,4 @@ permissions:
default: true
quests.admin:
description: Permission for the admin commands
- default: op \ No newline at end of file
+ default: op