aboutsummaryrefslogtreecommitdiffstats
path: root/bukkit/src
diff options
context:
space:
mode:
authorLMBishop <13875753+LMBishop@users.noreply.github.com>2021-07-26 16:37:13 +0100
committerLMBishop <13875753+LMBishop@users.noreply.github.com>2021-07-26 16:37:13 +0100
commita32d199bb149846f7fddd7dc861ae279e96857c0 (patch)
treef2ab0ccfad4dcb20a00525fede8469af03bb1dbd /bukkit/src
parent7dd39455d92a5118ebc5aedde68f4eba5c138c83 (diff)
Add categories.yml
Diffstat (limited to 'bukkit/src')
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java51
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java25
-rw-r--r--bukkit/src/main/resources/resources/bukkit/categories.yml34
-rw-r--r--bukkit/src/main/resources/resources/bukkit/config.yml36
4 files changed, 77 insertions, 69 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
index aedb94ee..cf30af2a 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java
@@ -464,22 +464,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
File config = new File(this.getDataFolder() + File.separator + "config.yml");
if (!config.exists()) {
- try {
- config.createNewFile();
- try (InputStream in = BukkitQuestsPlugin.class.getClassLoader().getResourceAsStream("resources/bukkit/config.yml");
- OutputStream out = new FileOutputStream(config)) {
- byte[] buffer = new byte[1024];
- int lenght = in.read(buffer);
- while (lenght != -1) {
- out.write(buffer, 0, lenght);
- lenght = in.read(buffer);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ writeResourceToFile("resources/bukkit/config.yml", config);
}
File questsDirectory = new File(this.getDataFolder() + File.separator + "quests");
@@ -498,23 +483,27 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests {
for (String name : examples) {
File file = new File(this.getDataFolder() + File.separator + "quests" + File.separator + name);
- try {
- file.createNewFile();
- try (InputStream in = BukkitQuestsPlugin.class.getClassLoader().getResourceAsStream("resources/bukkit/quests/" + name);
- OutputStream out = new FileOutputStream(file)) {
- byte[] buffer = new byte[1024];
- int lenght = in.read(buffer);
- while (lenght != -1) {
- out.write(buffer, 0, lenght);
- lenght = in.read(buffer);
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- } catch (IOException e) {
- e.printStackTrace();
+ writeResourceToFile("resources/bukkit/quests/" + name, file);
+ }
+ }
+ }
+
+ private void writeResourceToFile(String resource, File file) {
+ try {
+ file.createNewFile();
+ try (InputStream in = BukkitQuestsPlugin.class.getClassLoader().getResourceAsStream(resource);
+ OutputStream out = new FileOutputStream(file)) {
+ byte[] buffer = new byte[1024];
+ int length = in.read(buffer);
+ while (length != -1) {
+ out.write(buffer, 0, length);
+ length = in.read(buffer);
}
+ } catch (IOException e) {
+ e.printStackTrace();
}
+ } catch (IOException e) {
+ e.printStackTrace();
}
}
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java
index 89de88d7..d1f893b0 100644
--- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java
+++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/config/BukkitQuestsLoader.java
@@ -17,6 +17,8 @@ import com.leonardobishop.quests.common.questcontroller.QuestController;
import com.leonardobishop.quests.common.tasktype.TaskType;
import com.leonardobishop.quests.common.tasktype.TaskTypeManager;
import org.apache.commons.lang.StringUtils;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
@@ -78,9 +80,26 @@ public class BukkitQuestsLoader implements QuestsLoader {
}
}
- for (String id : plugin.getConfig().getConfigurationSection("categories").getKeys(false)) {
- ItemStack displayItem = plugin.getItemStack("categories." + id + ".display", plugin.getConfig());
- boolean permissionRequired = plugin.getConfig().getBoolean("categories." + id + ".permission-required", false);
+ ConfigurationSection categories;
+ File categoriesFile = new File(plugin.getDataFolder() + File.separator + "categories.yml");
+ if (categoriesFile.exists()) {
+ YamlConfiguration categoriesConfiguration = YamlConfiguration.loadConfiguration(categoriesFile);
+ if (categoriesConfiguration.isConfigurationSection("categories")) {
+ categories = categoriesConfiguration.getConfigurationSection("categories");
+ } else {
+ categories = new YamlConfiguration();
+ }
+ } else {
+ if (plugin.getConfig().isConfigurationSection("categories")) {
+ categories = plugin.getConfig().getConfigurationSection("categories");
+ } else {
+ categories = new YamlConfiguration();
+ }
+ }
+
+ for (String id : categories.getKeys(false)) {
+ ItemStack displayItem = plugin.getItemStack(id + ".display", categories);
+ boolean permissionRequired = categories.getBoolean(id + ".permission-required", false);
Category category = new Category(id, permissionRequired);
questManager.registerCategory(category);
diff --git a/bukkit/src/main/resources/resources/bukkit/categories.yml b/bukkit/src/main/resources/resources/bukkit/categories.yml
new file mode 100644
index 00000000..0ca444ec
--- /dev/null
+++ b/bukkit/src/main/resources/resources/bukkit/categories.yml
@@ -0,0 +1,34 @@
+# Categories are a way of grouping up quests.
+# When a player uses /quests, a menu of categories will be presented to them.
+# When a player clicks ona category, a list of quests under that category will show.
+# If categories are disabled, all quests will be shown under one big GUI.
+# Players can access specific categories by command using /quests c [category].
+# If a quest does not have a category, it will not be shown.
+categories:
+ examples:
+ display:
+ name: "&cExample Quests"
+ lore:
+ - "&7This category contains example quests"
+ - "&7which are commented in the config."
+ - "&7The comments should guide you with"
+ - "&7how the config works."
+ - ""
+ - "&cIt is highly recommended you read this"
+ - "&csection and all the comments so you can"
+ - "&cmake the most of this plugin."
+ type: "WATER_BUCKET"
+ permissionexample:
+ display:
+ name: "&cPermission Example"
+ lore:
+ - "&7This category is an example of one which"
+ - "&7requires a permission to open."
+ - ""
+ - "&cIt is highly recommended you read this"
+ - "&csection and all the comments so you can"
+ - "&cmake the most of this plugin."
+ type: "WATER_BUCKET"
+ # This category needs the permission "quests.category.permissionexample", because the category ID is 'permissionexample'.
+ # The permission for other categories is: "quests.category.<id>".
+ permission-required: true \ No newline at end of file
diff --git a/bukkit/src/main/resources/resources/bukkit/config.yml b/bukkit/src/main/resources/resources/bukkit/config.yml
index 85ef01fe..a9d32ce8 100644
--- a/bukkit/src/main/resources/resources/bukkit/config.yml
+++ b/bukkit/src/main/resources/resources/bukkit/config.yml
@@ -23,41 +23,7 @@
# | Discord link, or create an issue |
# | =================================================== |
-
-# Categories are a way of grouping up quests.
-# When a player uses /quests, a menu of categories will be presented to them.
-# When a player clicks ona category, a list of quests under that category will show.
-# If categories are disabled, all quests will be shown under one big GUI.
-# Players can access specific categories by command using /quests c [category].
-# If a quest does not have a category, it will not be shown.
-categories:
- examples:
- display:
- name: "&cExample Quests"
- lore:
- - "&7This category contains example quests"
- - "&7which are commented in the config."
- - "&7The comments should guide you with"
- - "&7how the config works."
- - ""
- - "&cIt is highly recommended you read this"
- - "&csection and all the comments so you can"
- - "&cmake the most of this plugin."
- type: "WATER_BUCKET"
- permissionexample:
- display:
- name: "&cPermission Example"
- lore:
- - "&7This category is an example of one which"
- - "&7requires a permission to open."
- - ""
- - "&cIt is highly recommended you read this"
- - "&csection and all the comments so you can"
- - "&cmake the most of this plugin."
- type: "WATER_BUCKET"
- # This category needs the permission "quests.category.permissionexample", because the category ID is 'permissionexample'.
- # The permission for other categories is: "quests.category.<id>".
- permission-required: true
+# Trying to add new categories? This has been moved to categories.yml
# The items listed below are placeholder items for quests which the player cannot start.
# You should change these for 1.8