summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.classpath31
-rw-r--r--.gitignore3
-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/BreedingTaskType.java88
-rw-r--r--src/main/java/com/leonardobishop/quests/quests/tasktypes/types/ExpEarnTaskType.java68
6 files changed, 217 insertions, 1 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/.gitignore b/.gitignore
index 90f91134..b29bf82d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,4 +2,5 @@ out/
.idea/
*.iml
.github/
-target/ \ No newline at end of file
+target/
+/bin/
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/BreedingTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/BreedingTaskType.java
new file mode 100644
index 00000000..b77b05c6
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/BreedingTaskType.java
@@ -0,0 +1,88 @@
+package com.leonardobishop.quests.quests.tasktypes.types;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+
+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 BreedingTaskType extends TaskType {
+
+ private List<ConfigValue> creatorConfigValues = new ArrayList<>();
+
+ public BreedingTaskType() {
+ super("breeding", "toasted", "Breed a set amount of animals.");
+ this.creatorConfigValues.add(new ConfigValue("amount", true, "Amount of animals to be bred"));
+ }
+
+ @Override
+ public List<ConfigValue> getCreatorConfigValues() {
+ return creatorConfigValues;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onBreed(CreatureSpawnEvent e) {
+ if (!e.getSpawnReason().equals(SpawnReason.BREEDING)) {
+ return;
+ }
+
+ Entity ent = e.getEntity();
+ List<Entity> entList = ent.getNearbyEntities(10, 10, 10);
+
+ if (entList.isEmpty()) {
+ return;
+ }
+ // Check if there is a player in the list, otherwise: return.
+ for (Entity current : entList) {
+
+ if (current instanceof Player) {
+ Player player = (Player) current;
+ 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 breedingNeeded = (int) task.getConfigValue("amount");
+ int breedingProgress;
+
+ if (taskProgress.getProgress() == null) {
+ breedingProgress = 0;
+ } else {
+ breedingProgress = (int) taskProgress.getProgress();
+ }
+
+ taskProgress.setProgress(breedingProgress + 1);
+
+ if (((int) taskProgress.getProgress()) >= breedingNeeded) {
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/ExpEarnTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/ExpEarnTaskType.java
new file mode 100644
index 00000000..f186c9f9
--- /dev/null
+++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/ExpEarnTaskType.java
@@ -0,0 +1,68 @@
+package com.leonardobishop.quests.quests.tasktypes.types;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.player.PlayerExpChangeEvent;
+
+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 ExpEarnTaskType extends TaskType {
+
+ private List<ConfigValue> creatorConfigValues = new ArrayList<>();
+
+ public ExpEarnTaskType() {
+ super("expearn", "toasted", "Earn a set amount of exp.");
+ this.creatorConfigValues.add(new ConfigValue("amount", true, "Amount of exp that needs to be earned."));
+ }
+
+ @Override
+ public List<ConfigValue> getCreatorConfigValues() {
+ return creatorConfigValues;
+ }
+
+ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onExpEarn(PlayerExpChangeEvent e) {
+ QPlayer qPlayer = Quests.getPlayerManager().getPlayer(e.getPlayer().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 amount = e.getAmount();
+ int expNeeded = (int) task.getConfigValue("amount");
+
+ int progressExp;
+ if (taskProgress.getProgress() == null) {
+ progressExp = 0;
+ } else {
+ progressExp = (int) taskProgress.getProgress();
+ }
+
+ taskProgress.setProgress(progressExp + amount);
+
+ if (((int) taskProgress.getProgress()) >= expNeeded) {
+ taskProgress.setCompleted(true);
+ }
+ }
+ }
+ }
+ }
+}