aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--.classpath31
-rw-r--r--.project23
-rw-r--r--.settings/org.eclipse.jdt.core.prefs5
-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
6 files changed, 218 insertions, 0 deletions
diff --git a/.classpath b/.classpath
new file mode 100644
index 00000000..6d7587a8
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/.project b/.project
new file mode 100644
index 00000000..d9f85e2b
--- /dev/null
+++ b/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Quests</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ </natures>
+</projectDescription>
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..714351ae
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.8
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());