diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2021-02-15 20:58:32 +0000 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2021-02-15 20:58:32 +0000 |
| commit | f3955ce0ab18f4938f0dc3563a5bd48bf1191e53 (patch) | |
| tree | e8a9c2988ab9e304d5ede9c9484e1c8ca81c012d /src | |
| parent | b448b72654e0df8be9f7b000be7a6509d3024014 (diff) | |
Add global task config
Diffstat (limited to 'src')
6 files changed, 87 insertions, 2 deletions
diff --git a/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java b/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java index ae61c2f3..8a25ee6d 100644 --- a/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java +++ b/src/main/java/com/leonardobishop/quests/QuestsConfigLoader.java @@ -50,7 +50,9 @@ public class QuestsConfigLoader { plugin.setBrokenConfig(true); } + if (!plugin.isBrokenConfig()) { + HashMap<String, Map<String, Object>> globalTaskConfig = new HashMap<>(); 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); @@ -62,6 +64,18 @@ public class QuestsConfigLoader { HashMap<String, Quest> pathToQuest = new HashMap<>(); + if (plugin.getConfig().isConfigurationSection("global-task-configuration.types")) { + for (String type : plugin.getConfig().getConfigurationSection("global-task-configuration.types").getKeys(false)) { + HashMap<String, Object> configValues = new HashMap<>(); + for (String key : plugin.getConfig().getConfigurationSection("global-task-configuration.types." + type).getKeys(false)) { + configValues.put(key, plugin.getConfig().get("global-task-configuration.types." + type + "." + key)); + } + globalTaskConfig.putIfAbsent(type, configValues); + } + } + + System.out.println(globalTaskConfig); + FileVisitor<Path> fileVisitor = new SimpleFileVisitor<Path>() { final URI questsRoot = Paths.get(plugin.getDataFolder() + File.separator + "quests").toUri(); @@ -137,6 +151,7 @@ public class QuestsConfigLoader { for (ConfigProblem problem : configProblems) { if (problem.getType() == ConfigProblemType.ERROR) { error = true; + break; } } @@ -179,6 +194,13 @@ public class QuestsConfigLoader { task.addConfigValue(key, config.get(taskRoot + "." + key)); } + if (globalTaskConfig.containsKey(taskType)) { + for (Map.Entry<String, Object> entry : globalTaskConfig.get(taskType).entrySet()) { + if (Options.GLOBAL_TASK_CONFIGURATION_OVERRIDE.getBooleanValue() && task.getConfigValue(entry.getKey()) != null) continue; + task.addConfigValue(entry.getKey(), entry.getValue()); + } + } + quest.registerTask(task); } diff --git a/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java b/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java index 6c72a4e8..351806e2 100644 --- a/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java +++ b/src/main/java/com/leonardobishop/quests/commands/CommandQuests.java @@ -9,6 +9,7 @@ import com.leonardobishop.quests.player.QPlayer; import com.leonardobishop.quests.player.questprogressfile.QuestProgressFile; import com.leonardobishop.quests.quests.Category; import com.leonardobishop.quests.quests.Quest; +import com.leonardobishop.quests.quests.Task; import com.leonardobishop.quests.quests.tasktypes.TaskType; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -90,6 +91,13 @@ public class CommandQuests implements TabExecutor { } sender.sendMessage(ChatColor.DARK_GRAY + "View info using /q a types [type]."); return true; + } else if (args[1].equalsIgnoreCase("info")) { + sender.sendMessage(ChatColor.GRAY + "Loaded quests:"); + for (Quest quest : plugin.getQuestManager().getQuests().values()) { + sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.RED + quest.getId() + ChatColor.GRAY + " [" + quest.getTasks().size() + " tasks]"); + } + sender.sendMessage(ChatColor.DARK_GRAY + "View info using /q a info [quest]."); + return true; } else if (args[1].equalsIgnoreCase("update")) { sender.sendMessage(ChatColor.GRAY + "Checking for updates..."); Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { @@ -159,6 +167,39 @@ public class CommandQuests implements TabExecutor { sender.sendMessage(ChatColor.RED + "Description: " + ChatColor.GRAY + taskType.getDescription()); } return true; + } else if (args[1].equalsIgnoreCase("info")) { + Quest quest = plugin.getQuestManager().getQuestById(args[2]); + if (quest == null) { + sender.sendMessage(Messages.COMMAND_QUEST_GENERAL_DOESNTEXIST.getMessage().replace("{quest}", args[2])); + } else { + sender.sendMessage(ChatColor.RED.toString() + ChatColor.BOLD + "Information for quest '" + quest.getId() + "'"); + sender.sendMessage(ChatColor.RED.toString() + ChatColor.UNDERLINE + "Task configurations (" + quest.getTasks().size() + ")"); + for (Task task : quest.getTasks()) { + sender.sendMessage(ChatColor.RED + "Task '" + task.getId() + "':"); + for (Map.Entry<String, Object> config : task.getConfigValues().entrySet()) { + sender.sendMessage(ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + config.getKey() + ": " + ChatColor.GRAY + ChatColor.ITALIC + config.getValue()); + } + } + sender.sendMessage(ChatColor.RED.toString() + ChatColor.UNDERLINE + "Start string"); + for (String s : quest.getStartString()) { + sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.GRAY + s); + } + sender.sendMessage(ChatColor.RED.toString() + ChatColor.UNDERLINE + "Reward string"); + for (String s : quest.getRewardString()) { + sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.GRAY + s); + } + sender.sendMessage(ChatColor.RED.toString() + ChatColor.UNDERLINE + "Rewards"); + for (String s : quest.getRewards()) { + sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.GRAY + s); + } + sender.sendMessage(ChatColor.RED.toString() + ChatColor.UNDERLINE + "Quest options"); + sender.sendMessage(ChatColor.RED + "Category: " + ChatColor.GRAY + quest.getCategoryId()); + sender.sendMessage(ChatColor.RED + "Repeatable: " + ChatColor.GRAY + quest.isRepeatable()); + sender.sendMessage(ChatColor.RED + "Requirements: " + ChatColor.GRAY + String.join(", ", quest.getRequirements())); + sender.sendMessage(ChatColor.RED + "Cooldown enabled: " + ChatColor.GRAY + quest.isCooldownEnabled()); + sender.sendMessage(ChatColor.RED + "Cooldown time: " + ChatColor.GRAY + quest.getCooldown()); + } + return true; } } else if (args.length == 4) { if (args[1].equalsIgnoreCase("opengui")) { @@ -471,6 +512,7 @@ public class CommandQuests implements TabExecutor { sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.RED + "/quests a opengui " + ChatColor.DARK_GRAY + ": view help for opengui"); sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.RED + "/quests a moddata " + ChatColor.DARK_GRAY + ": view help for quest progression"); sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.RED + "/quests a types [type]" + ChatColor.DARK_GRAY + ": view registered task types"); + sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.RED + "/quests a info [quest]" + ChatColor.DARK_GRAY + ": see information about loaded quests"); sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.RED + "/quests a reload " + ChatColor.DARK_GRAY + ": reload Quests configuration"); sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.RED + "/quests a config " + ChatColor.DARK_GRAY + ": see detected problems in config"); sender.sendMessage(ChatColor.DARK_GRAY + " * " + ChatColor.RED + "/quests a update " + ChatColor.DARK_GRAY + ": check for updates"); @@ -519,7 +561,7 @@ public class CommandQuests implements TabExecutor { return tabCompleteQuests(args[1]); } else if (args[0].equalsIgnoreCase("a") || args[0].equalsIgnoreCase("admin") && sender.hasPermission("quests.admin")) { - List<String> options = Arrays.asList("opengui", "moddata", "types", "reload", "update", "config"); + List<String> options = Arrays.asList("opengui", "moddata", "types", "reload", "update", "config", "info"); return matchTabComplete(args[1], options); } } else if (args.length == 3) { @@ -544,6 +586,8 @@ public class CommandQuests implements TabExecutor { } else if (args[1].equalsIgnoreCase("moddata")) { List<String> options = Arrays.asList("fullreset", "reset", "start", "complete", "clean"); return matchTabComplete(args[2], options); + } else if (args[1].equalsIgnoreCase("info")) { + return tabCompleteQuests(args[2]); } } } else if (args.length == 4) { diff --git a/src/main/java/com/leonardobishop/quests/obj/Messages.java b/src/main/java/com/leonardobishop/quests/obj/Messages.java index 92a0dca9..31e74b0b 100644 --- a/src/main/java/com/leonardobishop/quests/obj/Messages.java +++ b/src/main/java/com/leonardobishop/quests/obj/Messages.java @@ -21,6 +21,7 @@ public enum Messages { QUEST_UPDATER("messages.quest-updater"), COMMAND_SUB_DOESNTEXIST("messages.command-sub-doesntexist"), COMMAND_QUEST_START_DOESNTEXIST("messages.command-quest-start-doesntexist"), + COMMAND_QUEST_GENERAL_DOESNTEXIST("messages.command-quest-general-doesntexist"), COMMAND_QUEST_OPENCATEGORY_ADMIN_SUCCESS("messages.command-quest-opencategory-admin-success"), COMMAND_QUEST_OPENQUESTS_ADMIN_SUCCESS("messages.command-quest-openquests-admin-success"), COMMAND_QUEST_ADMIN_PLAYERNOTFOUND("messages.command-quest-admin-playernotfound"), diff --git a/src/main/java/com/leonardobishop/quests/obj/Options.java b/src/main/java/com/leonardobishop/quests/obj/Options.java index 37a1729b..18611dfb 100644 --- a/src/main/java/com/leonardobishop/quests/obj/Options.java +++ b/src/main/java/com/leonardobishop/quests/obj/Options.java @@ -26,7 +26,8 @@ public enum Options { PUSH_SOFT_CLEAN_TO_DISK("options.tab-completion.push-soft-clean-to-disk"), TAB_COMPLETE_ENABLED("options.tab-completion.enabled"), ERROR_CHECKING_OVERRIDE("options.error-checking.override-errors"), - QUEST_AUTOSTART("options.quest-autostart"); + QUEST_AUTOSTART("options.quest-autostart"), + GLOBAL_TASK_CONFIGURATION_OVERRIDE("options.global-task-configuration-override"); private static final Map<String, Boolean> cachedBooleans = new HashMap<>(); diff --git a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java index 93a4763f..e4e4ead6 100644 --- a/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java +++ b/src/main/java/com/leonardobishop/quests/quests/tasktypes/types/InventoryTaskType.java @@ -147,6 +147,8 @@ public final class InventoryTaskType extends TaskType { int inInv = getAmount(player, is, amount); if (taskProgress.getProgress() != null && (int) taskProgress.getProgress() != inInv) { taskProgress.setProgress(inInv); + } else if (taskProgress.getProgress() == null) { + taskProgress.setProgress(inInv); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b533b5fe..0d6e8fa5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -174,6 +174,8 @@ options: override-errors: false # How many time (in seconds) plugin save placeholders placeholder-cache-time: 10 + # Whether or not the global task configuration will override per-task configuration settings + global-task-configuration-override: false # This switches up the entire quest system. # By enabling daily-quests, players will no longer be presented with the standard Quest GUI. @@ -188,6 +190,18 @@ options: daily-quests: enabled: false # <----- NOT YET IMPLEMENTED (THIS WILL NOT DO ANYTHING) +# The global task configuration will apply to the config of each task of a specified type in each quest. +# In the example below, every task with a type of "inventory" will have the config option "update-progress" +# set to true. This is useful if you do not want to go through each quest if you want to update the configuration +# for every task of a specific type. +# +# You must uncomment all below lines for the example to have any effect +# vvvvvvvvvvvvvvvvvvvvvvvvv +#global-task-configuration: +# types: +# inventory: +# update-progress: true + # Configure titles titles: quest-start: @@ -215,6 +229,7 @@ messages: quest-updater: "&cQuests > &7A new version &c{newver} &7was found on Spigot (your version: &c{oldver}&7). Please update me! <3 - Link: {link}" command-sub-doesntexist: "&7The specified subcommand '&c{sub}' &7does not exist." command-quest-start-doesntexist: "&7The specified quest '&c{quest}&7' does not exist." + command-quest-general-doesntexist: "&7The specified quest '&c{quest}&7' does not exist." command-category-open-disabled: "&7Categories are disabled." command-category-open-doesntexist: "&7The specified category '&c{category}&7' does not exist." command-quest-admin-playernotfound: "&7Player '&c{player}&7' could not be found." |
