aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorToastedCoconut <bavo1997@gmail.com>2019-07-04 15:36:50 +0200
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2019-07-04 14:36:50 +0100
commit4e5a9f1703eb4a94319e7c7f6629814b8bfb6f96 (patch)
treee69c3f9aac3c26cfcfe2db53d022eeb29adb1f4c /src
parentffcc8e091435c8e6150722048f7c7b6cb7b90a3e (diff)
Another 2 new tasks + fix for fishing (#45)
* Two new tasks + a fix for fishing - Deal Damage task type - Enchanting task type - Fixes #37
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/DealDamageTaskType.java78
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/EnchantingTaskType.java71
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/FishingTaskType.java10
3 files changed, 159 insertions, 0 deletions
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/DealDamageTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/DealDamageTaskType.java
new file mode 100644
index 00000000..e46d9bf6
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/DealDamageTaskType.java
@@ -0,0 +1,78 @@
+package com.leonardobishop.quests.quests.tasktypes.types;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+
+import com.leonardobishop.quests.Quests;
+import com.leonardobishop.quests.player.QPlayer;
+import com.leonardobishop.quests.player.questprogressfile.QuestProgress;
+import com.leonardobishop.quests.player.questprogressfile.QuestProgressFile;
+import com.leonardobishop.quests.player.questprogressfile.TaskProgress;
+import com.leonardobishop.quests.quests.Quest;
+import com.leonardobishop.quests.quests.Task;
+import com.leonardobishop.quests.quests.tasktypes.ConfigValue;
+import com.leonardobishop.quests.quests.tasktypes.TaskType;
+
+public final class DealDamageTaskType extends TaskType {
+
+ private List<ConfigValue> creatorConfigValues = new ArrayList<>();
+
+ public DealDamageTaskType() {
+ super("dealdamage", "toasted", "Deal a certain amount of damage.");
+ this.creatorConfigValues.add(new ConfigValue("amount", true, "Amount of damage you need to deal"));
+ }
+
+ @Override
+ public List<ConfigValue> getCreatorConfigValues() {
+ return creatorConfigValues;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onDamage(EntityDamageByEntityEvent e) {
+
+ if (!(e.getDamager() instanceof Player)) {
+ return;
+ }
+
+ Player player = (Player) e.getDamager();
+ double damage = e.getDamage();
+
+ 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;
+ }
+
+ Double progressDamage;
+ int damageNeeded = (int) task.getConfigValue("amount");
+ Double damageNeededDouble = (double) damageNeeded;
+
+ if (taskProgress.getProgress() == null) {
+ progressDamage = 0.0;
+ } else {
+ progressDamage = (double) taskProgress.getProgress();
+ }
+
+ taskProgress.setProgress(progressDamage + damage);
+
+ if (((double) taskProgress.getProgress()) >= damageNeededDouble) {
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/EnchantingTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/EnchantingTaskType.java
new file mode 100644
index 00000000..014f6896
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/EnchantingTaskType.java
@@ -0,0 +1,71 @@
+package com.leonardobishop.quests.quests.tasktypes.types;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.enchantment.EnchantItemEvent;
+
+import com.leonardobishop.quests.Quests;
+import com.leonardobishop.quests.player.QPlayer;
+import com.leonardobishop.quests.player.questprogressfile.QuestProgress;
+import com.leonardobishop.quests.player.questprogressfile.QuestProgressFile;
+import com.leonardobishop.quests.player.questprogressfile.TaskProgress;
+import com.leonardobishop.quests.quests.Quest;
+import com.leonardobishop.quests.quests.Task;
+import com.leonardobishop.quests.quests.tasktypes.ConfigValue;
+import com.leonardobishop.quests.quests.tasktypes.TaskType;
+
+public final class EnchantingTaskType extends TaskType {
+
+ private List<ConfigValue> creatorConfigValues = new ArrayList<>();
+
+ public EnchantingTaskType() {
+ super("enchanting", "toasted", "Enchant a certain amount of items.");
+ this.creatorConfigValues.add(new ConfigValue("amount", true, "Amount of items you need to enchant."));
+ }
+
+ @Override
+ public List<ConfigValue> getCreatorConfigValues() {
+ return creatorConfigValues;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onEnchant(EnchantItemEvent e) {
+ Player player = e.getEnchanter();
+
+ 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 enchantsNeeded = (int) task.getConfigValue("amount");
+
+ int progressEnchant;
+ if (taskProgress.getProgress() == null) {
+ progressEnchant = 0;
+ } else {
+ progressEnchant = (int) taskProgress.getProgress();
+ }
+
+ taskProgress.setProgress(progressEnchant + 1);
+
+ if (((int) taskProgress.getProgress()) >= enchantsNeeded) {
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/FishingTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/FishingTaskType.java
index 28f78f05..22ac3444 100644
--- a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/FishingTaskType.java
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/FishingTaskType.java
@@ -9,6 +9,9 @@ import com.leonardobishop.quests.quests.Quest;
import com.leonardobishop.quests.quests.Task;
import com.leonardobishop.quests.quests.tasktypes.ConfigValue;
import com.leonardobishop.quests.quests.tasktypes.TaskType;
+
+import org.bukkit.Location;
+import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -36,6 +39,13 @@ public final class FishingTaskType extends TaskType {
if (event.getState() == PlayerFishEvent.State.BITE) {
return;
}
+
+ Location hookLocation = event.getHook().getLocation().add(0, -1, 0);
+ if (!hookLocation.getBlock().getType().equals(Material.STATIONARY_WATER) |
+ hookLocation.getBlock().getType().equals(Material.WATER)) {
+ return;
+ }
+
Player player = event.getPlayer();
QPlayer qPlayer = Quests.getPlayerManager().getPlayer(player.getUniqueId());