summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfatpigsarefat <fatpigsarefat@outlook.com>2018-04-21 09:43:02 +0100
committerfatpigsarefat <fatpigsarefat@outlook.com>2018-04-21 09:43:02 +0100
commit627b3bfe53214cd8c8018e83a7ff1554eb1783d3 (patch)
treedff7eabb718c73b1d375ffc0090b5f135380b319
parent52675488794763c61e0c48a125c8b56374d4ea3f (diff)
added position task type
-rw-r--r--src/config.yml37
-rw-r--r--src/me/fatpigsarefat/quests/Quests.java1
-rw-r--r--src/me/fatpigsarefat/quests/quests/tasktypes/types/PositionTaskType.java87
-rw-r--r--src/plugin.yml2
4 files changed, 124 insertions, 3 deletions
diff --git a/src/config.yml b/src/config.yml
index 49745464..3e56f33d 100644
--- a/src/config.yml
+++ b/src/config.yml
@@ -196,7 +196,8 @@ quests:
- "&cThis category is designed to show you the different"
- "&cattributes a quest can have. This quest has a 'reward string'"
- "&c(a series of messages sent when a quest is complete),"
- "unlike the previous one."
+ - "&cunlike the previous one."
+ - ""
- "&7This quest requires you to:"
- "&7 - Kill 3 mobs."
- ""
@@ -220,7 +221,7 @@ quests:
repeatable: true
cooldown:
enabled: true
- time: 1440
+ time: 10
# This is the end of the config example quests.
# Hopefully you should be able to understand the quest config from this.
@@ -516,6 +517,38 @@ quests:
enabled: true
time: 1440
+ position1:
+ tasks:
+ position:
+ type: "position"
+ x: 0
+ y: 0
+ z: 0
+ world: "world"
+ display:
+ name: "&cOrigin Point"
+ lore-normal:
+ - "&7This quest requires you to:"
+ - "&7 - Reach position: 0, 0, 0 in world world."
+ - ""
+ - "&7Rewards:"
+ - "&7 - $100 added to your in-game balance."
+ lore-started:
+ - ""
+ - "&7Your current progression:"
+ - "&7 - Position reached: {position:complete}."
+ type: "GOLD_BOOTS"
+ rewards:
+ - "eco give {player} 100"
+ options:
+ category: "medium"
+ requires:
+ - ""
+ repeatable: true
+ cooldown:
+ enabled: true
+ time: 1440
+
mining2:
tasks:
mining:
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);
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/plugin.yml b/src/plugin.yml
index ecccb6f9..502fb4e6 100644
--- a/src/plugin.yml
+++ b/src/plugin.yml
@@ -1,5 +1,5 @@
name: Quests
-version: 2.0.0-beta
+version: 2.0.1-beta
main: me.fatpigsarefat.quests.Quests
author: fatpigsarefat
softdepend: [ASkyBlock, uSkyBlock]