diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2019-07-21 17:04:59 +0100 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2019-07-21 17:04:59 +0100 |
| commit | c6a12c75e25b4c6d8711a7e9c327a0c09b0837d6 (patch) | |
| tree | a28db5902aed1ed5a4ed221f4326e00f410a93a4 /src/main | |
| parent | 5820b3b7887e368e5ff402d59391cbbac6e524a3 (diff) | |
Added ability to sort quests
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java | 5 | ||||
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java | 6 | ||||
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/quests/Quest.java | 15 | ||||
| -rw-r--r-- | src/main/java/com/leonardobishop/quests/quests/QuestManager.java | 5 | ||||
| -rw-r--r-- | src/main/resources/quests/example1.yml | 4 | ||||
| -rw-r--r-- | src/main/resources/quests/example2.yml | 4 | ||||
| -rw-r--r-- | src/main/resources/quests/example3.yml | 3 | ||||
| -rw-r--r-- | src/main/resources/quests/example4.yml | 3 | ||||
| -rw-r--r-- | src/main/resources/quests/example5.yml | 3 | ||||
| -rw-r--r-- | src/main/resources/quests/example6.yml | 4 |
10 files changed, 32 insertions, 20 deletions
diff --git a/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java b/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java index 46678e6b..2880dc99 100644 --- a/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java +++ b/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java @@ -81,6 +81,7 @@ public class QuestsConfigLoader { boolean cooldown = config.getBoolean("options.cooldown.enabled", false); boolean permissionRequired = config.getBoolean("options.permission-required", false); int cooldownTime = config.getInt("options.cooldown.time", 10); + int sortOrder = config.getInt("options.sort-order", 1); String category = config.getString("options.category"); if (rewardString == null) { @@ -99,9 +100,9 @@ public class QuestsConfigLoader { Quest quest; if (category.equals("")) { - quest = new Quest(id, displayItem, rewards, requirements, repeatable, cooldown, cooldownTime, permissionRequired, rewardString); + quest = new Quest(id, displayItem, rewards, requirements, repeatable, cooldown, cooldownTime, permissionRequired, rewardString, sortOrder); } else { - quest = new Quest(id, displayItem, rewards, requirements, repeatable, cooldown, cooldownTime, permissionRequired, rewardString, category); + quest = new Quest(id, displayItem, rewards, requirements, repeatable, cooldown, cooldownTime, permissionRequired, rewardString, category, sortOrder); Category c = plugin.getQuestManager().getCategoryById(category); if (c != null) { c.registerQuestId(id); diff --git a/src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java b/src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java index 2ab4907b..4d9c00fa 100644 --- a/src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java +++ b/src/main/java/com/leonardobishop/quests/obj/misc/QMenuQuest.java @@ -11,10 +11,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.TimeUnit; /** @@ -40,6 +37,7 @@ public class QMenuQuest implements QMenu { } public void populate(List<Quest> quests) { + Collections.sort(quests); int slot = 0; for (Quest quest : quests) { if (Options.GUI_HIDE_LOCKED.getBooleanValue()) { diff --git a/src/main/java/com/leonardobishop/quests/quests/Quest.java b/src/main/java/com/leonardobishop/quests/quests/Quest.java index 35a61818..3f1ddd9b 100644 --- a/src/main/java/com/leonardobishop/quests/quests/Quest.java +++ b/src/main/java/com/leonardobishop/quests/quests/Quest.java @@ -5,7 +5,7 @@ import org.bukkit.ChatColor; import java.util.*; -public class Quest { +public class Quest implements Comparable<Quest> { private Map<String, Task> tasks = new HashMap<>(); //TODO: maybe store by <tasktypename (string), list<task>> since we never get task by id, but always get tasks by type. @@ -17,16 +17,17 @@ public class Quest { private boolean repeatable; private boolean cooldownEnabled; private int cooldown; + private int sortOrder; private boolean permissionRequired; private String categoryid; - public Quest(String id, QItemStack displayItem, List<String> rewards, List<String> requirements, boolean repeatable, boolean cooldownEnabled, int cooldown, boolean permissionRequired, List<String> rewardString, String categoryid) { - this(id, displayItem, rewards, requirements, repeatable, cooldownEnabled, cooldown, permissionRequired, rewardString); + public Quest(String id, QItemStack displayItem, List<String> rewards, List<String> requirements, boolean repeatable, boolean cooldownEnabled, int cooldown, boolean permissionRequired, List<String> rewardString, String categoryid, int sortOrder) { + this(id, displayItem, rewards, requirements, repeatable, cooldownEnabled, cooldown, permissionRequired, rewardString, sortOrder); this.categoryid = categoryid; } - public Quest(String id, QItemStack displayItem, List<String> rewards, List<String> requirements, boolean repeatable, boolean cooldownEnabled, int cooldown, boolean permissionRequired, List<String> rewardString) { + public Quest(String id, QItemStack displayItem, List<String> rewards, List<String> requirements, boolean repeatable, boolean cooldownEnabled, int cooldown, boolean permissionRequired, List<String> rewardString, int sortOrder) { this.id = id; this.displayItem = displayItem; this.rewards = rewards; @@ -36,6 +37,7 @@ public class Quest { this.cooldown = cooldown; this.permissionRequired = permissionRequired; this.rewardString = rewardString; + this.sortOrder = sortOrder; } public void registerTask(Task task) { @@ -104,4 +106,9 @@ public class Quest { public String getDisplayNameStripped() { return ChatColor.stripColor(this.displayItem.getName()); } + + @Override + public int compareTo(Quest quest) { + return(sortOrder - quest.sortOrder); + } } diff --git a/src/main/java/com/leonardobishop/quests/quests/QuestManager.java b/src/main/java/com/leonardobishop/quests/quests/QuestManager.java index 5d104cb6..e26a99e3 100644 --- a/src/main/java/com/leonardobishop/quests/quests/QuestManager.java +++ b/src/main/java/com/leonardobishop/quests/quests/QuestManager.java @@ -2,10 +2,7 @@ package com.leonardobishop.quests.quests; import com.leonardobishop.quests.Quests; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class QuestManager { diff --git a/src/main/resources/quests/example1.yml b/src/main/resources/quests/example1.yml index 7e38f01f..82e6e810 100644 --- a/src/main/resources/quests/example1.yml +++ b/src/main/resources/quests/example1.yml @@ -52,4 +52,6 @@ options: # If true, players will have to wait between repeating quests. enabled: true # Time (in minutes) - time: 1440
\ No newline at end of file + time: 1440 + # This is the relative position in the GUI + sort-order: 1
\ No newline at end of file diff --git a/src/main/resources/quests/example2.yml b/src/main/resources/quests/example2.yml index 8a3a367f..5b6d2c4e 100644 --- a/src/main/resources/quests/example2.yml +++ b/src/main/resources/quests/example2.yml @@ -39,4 +39,6 @@ options: repeatable: false cooldown: enabled: true - time: 1440
\ No newline at end of file + time: 1440 + # The sort order has been changed so this quest will appear after in the GUI + sort-order: 2
\ No newline at end of file diff --git a/src/main/resources/quests/example3.yml b/src/main/resources/quests/example3.yml index 598b94d1..8254a257 100644 --- a/src/main/resources/quests/example3.yml +++ b/src/main/resources/quests/example3.yml @@ -42,4 +42,5 @@ options: repeatable: true cooldown: enabled: true - time: 10
\ No newline at end of file + time: 10 + sort-order: 3
\ No newline at end of file diff --git a/src/main/resources/quests/example4.yml b/src/main/resources/quests/example4.yml index 37744eee..f8ee7d69 100644 --- a/src/main/resources/quests/example4.yml +++ b/src/main/resources/quests/example4.yml @@ -36,4 +36,5 @@ options: repeatable: true cooldown: enabled: true - time: 10
\ No newline at end of file + time: 10 + sort-order: 4
\ No newline at end of file diff --git a/src/main/resources/quests/example5.yml b/src/main/resources/quests/example5.yml index 38e9e601..a143d315 100644 --- a/src/main/resources/quests/example5.yml +++ b/src/main/resources/quests/example5.yml @@ -31,4 +31,5 @@ options: repeatable: false cooldown: enabled: true - time: 1440
\ No newline at end of file + time: 1440 + sort-order: 5
\ No newline at end of file diff --git a/src/main/resources/quests/example6.yml b/src/main/resources/quests/example6.yml index 3262b1a8..8d5a8feb 100644 --- a/src/main/resources/quests/example6.yml +++ b/src/main/resources/quests/example6.yml @@ -27,4 +27,6 @@ options: repeatable: false cooldown: enabled: true - time: 1440
\ No newline at end of file + time: 1440 + # The quest is in a different category so the sort order is 1. + sort-order: 1
\ No newline at end of file |
