aboutsummaryrefslogtreecommitdiffstats
path: root/src/me
diff options
context:
space:
mode:
Diffstat (limited to 'src/me')
-rw-r--r--src/me/fatpigsarefat/quests/Quests.java1
-rw-r--r--src/me/fatpigsarefat/quests/quests/tasktypes/types/PositionTaskType.java87
2 files changed, 88 insertions, 0 deletions
diff --git a/src/me/fatpigsarefat/quests/Quests.java b/src/me/fatpigsarefat/quests/Quests.java
index 90ee6f5b..1f2b8951 100644
--- a/src/me/fatpigsarefat/quests/Quests.java
+++ b/src/me/fatpigsarefat/quests/Quests.java
@@ -117,6 +117,7 @@ public class Quests extends JavaPlugin {
taskTypeManager.registerTaskType(new TamingTaskType());
taskTypeManager.registerTaskType(new MilkingTaskType());
taskTypeManager.registerTaskType(new ShearingTaskType());
+ taskTypeManager.registerTaskType(new PositionTaskType());
if (Bukkit.getPluginManager().isPluginEnabled("ASkyBlock")) {
taskTypeManager.registerTaskType(new ASkyBlockLevelType());
}
diff --git a/src/me/fatpigsarefat/quests/quests/tasktypes/types/PositionTaskType.java b/src/me/fatpigsarefat/quests/quests/tasktypes/types/PositionTaskType.java
new file mode 100644
index 00000000..6702f732
--- /dev/null
+++ b/src/me/fatpigsarefat/quests/quests/tasktypes/types/PositionTaskType.java
@@ -0,0 +1,87 @@
+package me.fatpigsarefat.quests.quests.tasktypes.types;
+
+import me.fatpigsarefat.quests.Quests;
+import me.fatpigsarefat.quests.player.QPlayer;
+import me.fatpigsarefat.quests.player.questprogressfile.QuestProgress;
+import me.fatpigsarefat.quests.player.questprogressfile.QuestProgressFile;
+import me.fatpigsarefat.quests.player.questprogressfile.TaskProgress;
+import me.fatpigsarefat.quests.quests.Quest;
+import me.fatpigsarefat.quests.quests.Task;
+import me.fatpigsarefat.quests.quests.tasktypes.ConfigValue;
+import me.fatpigsarefat.quests.quests.tasktypes.TaskType;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.player.PlayerMoveEvent;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public final class PositionTaskType extends TaskType {
+
+ private List<ConfigValue> creatorConfigValues = new ArrayList<>();
+
+ public PositionTaskType() {
+ super("position", "fatpigsarefat", "Reach a set of co-ordinates.");
+ this.creatorConfigValues.add(new ConfigValue("x", true, "X position."));
+ this.creatorConfigValues.add(new ConfigValue("y", true, "Y position."));
+ this.creatorConfigValues.add(new ConfigValue("z", true, "Z position."));
+ this.creatorConfigValues.add(new ConfigValue("world", true, "Name of world."));
+ this.creatorConfigValues.add(new ConfigValue("distance-padding", false, "Padding zone in meters/blocks (default/unspecified = 0)."));
+ }
+
+ @Override
+ public List<ConfigValue> getCreatorConfigValues() {
+ return creatorConfigValues;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onMove(PlayerMoveEvent event) {
+ if (event.getFrom().getBlockX() == event.getTo().getBlockX() && event.getFrom().getBlockZ() == event.getTo().getBlockZ()) {
+ return;
+ }
+
+ Player player = event.getPlayer();
+
+ QPlayer qPlayer = Quests.getPlayerManager().getPlayer(player.getUniqueId());
+ QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();
+
+ for (Quest quest : super.getRegisteredQuests()) {
+ if (questProgressFile.hasStartedQuest(quest)) {
+ QuestProgress questProgress = questProgressFile.getQuestProgress(quest);
+
+ for (Task task : quest.getTasksOfType(super.getType())) {
+ TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
+
+ if (taskProgress.isCompleted()) {
+ continue;
+ }
+
+ int x = (int) task.getConfigValue("x");
+ int y = (int) task.getConfigValue("y");
+ int z = (int) task.getConfigValue("z");
+ String worldString = (String) task.getConfigValue("world");
+ int padding = 0;
+ if (task.getConfigValue("distance-padding") != null) {
+ padding = (int) task.getConfigValue("distance-padding");
+ }
+ World world = Bukkit.getWorld(worldString);
+ if (world == null) {
+ return;
+ }
+
+ Location location = new Location(world, x, y, z);
+ if (player.getWorld().equals(world) && player.getLocation().getBlockX() == location.getBlockX() && player.getLocation().getBlockY() == location.getBlockY() && player.getLocation().getBlockZ() == location.getBlockZ()) {
+ taskProgress.setCompleted(true);
+ } else if (player.getWorld().equals(world) && player.getLocation().distance(location) < padding) {
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+ }
+ }
+
+}