aboutsummaryrefslogtreecommitdiffstats
path: root/bukkit/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'bukkit/src/main/java')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockshearingTaskType.java2
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingTaskType.java67
2 files changed, 23 insertions, 46 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockshearingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockshearingTaskType.java
index 4c0fee8b..1bf2b93b 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockshearingTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BlockshearingTaskType.java
@@ -38,7 +38,7 @@ public final class BlockshearingTaskType extends BukkitTaskType {
return;
}
- for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player.getPlayer(), qPlayer, this, TaskUtils.TaskConstraint.WORLD)) {
+ for (TaskUtils.PendingTask pendingTask : TaskUtils.getApplicableTasks(player, qPlayer, this, TaskUtils.TaskConstraint.WORLD)) {
Quest quest = pendingTask.quest();
Task task = pendingTask.task();
TaskProgress taskProgress = pendingTask.taskProgress();
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingTaskType.java
index ad8ac269..a9a26adb 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingTaskType.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingTaskType.java
@@ -7,16 +7,16 @@ 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.block.Block;
import org.bukkit.block.data.Ageable;
+import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
-import java.util.List;
+import java.util.Arrays;
public final class FarmingTaskType extends BukkitTaskType {
@@ -34,27 +34,27 @@ public final class FarmingTaskType extends BukkitTaskType {
super.addConfigValidator(TaskUtils.useRequiredConfigValidator(this, "amount"));
super.addConfigValidator(TaskUtils.useIntegerConfigValidator(this, "amount"));
super.addConfigValidator(TaskUtils.useMaterialListConfigValidator(this, "block", "blocks"));
+ super.addConfigValidator(TaskUtils.useAcceptedValuesConfigValidator(this, Arrays.asList("break", "harvest"), "mode"));
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
- handle(event.getPlayer(), event.getBlock(), "break");
+ handle(event.getPlayer(), event.getBlock(), event.getBlock().getBlockData(), "break");
}
private final class HarvestBlockListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHarvestBlock(org.bukkit.event.player.PlayerHarvestBlockEvent event) {
- handle(event.getPlayer(), event.getHarvestedBlock(), "harvest");
+ handle(event.getPlayer(), event.getHarvestedBlock(), event.getHarvestedBlock().getBlockData(), "harvest");
}
}
- private void handle(Player player, Block block, String mode) {
- if (!(block.getState().getBlockData() instanceof Ageable)) {
+ private void handle(Player player, Block block, BlockData blockData, String mode) {
+ if (!(blockData instanceof Ageable crop && crop.getAge() == crop.getMaximumAge())) {
return;
}
- Ageable crop = (Ageable) block.getState().getBlockData();
- if (crop.getAge() != crop.getMaximumAge()) {
+ if (player.hasMetadata("NPC")) {
return;
}
@@ -68,49 +68,26 @@ public final class FarmingTaskType extends BukkitTaskType {
Task task = pendingTask.task();
TaskProgress taskProgress = pendingTask.taskProgress();
- super.debug("Player farmed crop " + crop.getMaterial() + " (mode = " + mode + ")", quest.getId(), task.getId(), player.getUniqueId());
+ super.debug("Player farmed a crop " + block.getType() + " (mode = " + mode + ")", quest.getId(), task.getId(), player.getUniqueId());
- if (task.getConfigValue("mode") != null
- && !mode.equalsIgnoreCase(task.getConfigValue("mode").toString())) {
- super.debug("Mode does not match required mode, continuing...", quest.getId(), task.getId(), player.getUniqueId());
- continue;
+ final String requiredMode = (String) task.getConfigValue("mode");
+ if (requiredMode != null && !mode.equals(requiredMode)) {
+ super.debug("Mode does not match the required mode, continuing...", quest.getId(), task.getId(), player.getUniqueId());
}
- if (matchBlock(task, quest, player, block)) {
- 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);
- }
+ if (!TaskUtils.matchBlock(this, pendingTask, block, player.getUniqueId())) {
+ super.debug("Continuing...", quest.getId(), task.getId(), player.getUniqueId());
+ continue;
}
- }
- }
-
- private boolean matchBlock(Task task, Quest quest, Player player, Block block) {
- Material material;
- List<String> checkBlocks = TaskUtils.getConfigStringList(task, task.getConfigValues().containsKey("block") ? "block" : "blocks");
- if (checkBlocks.isEmpty()) {
- return true;
- }
+ int progress = TaskUtils.incrementIntegerTaskProgress(taskProgress);
+ super.debug("Incrementing task progress (now " + progress + ")", quest.getId(), task.getId(), player.getUniqueId());
- for (String materialName : checkBlocks) {
- super.debug("Checking against '" + materialName + "'", quest.getId(), task.getId(), player.getUniqueId());
- material = Material.getMaterial(String.valueOf(materialName));
- Material blockType = block.getType();
-
- if (blockType == material) {
- super.debug("Type match", quest.getId(), task.getId(), player.getUniqueId());
- return true;
- } else {
- super.debug("Type mismatch", 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);
}
}
- return false;
}
-
-} \ No newline at end of file
+}