diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2022-05-31 20:45:24 +0100 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2022-05-31 20:45:24 +0100 |
| commit | cf9150335738560f0e31203d1572f2d6791bed69 (patch) | |
| tree | a1229310ba0191cdd2aef96294a3a458a507967f /bukkit | |
| parent | 7cea3ec42aa084763a88221047ed50fff56444cf (diff) | |
Add extended problem descriptions and MiniMessage
Diffstat (limited to 'bukkit')
15 files changed, 185 insertions, 44 deletions
diff --git a/bukkit/build.gradle b/bukkit/build.gradle index fd8238fe..fa1c3e69 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -42,6 +42,7 @@ repositories { maven { url = 'https://nexus.bencodez.com/repository/maven-public/'} // NuVotifier maven { url = 'https://repo.leonardobishop.com/releases/'} + // Adventure mavenCentral() } @@ -103,7 +104,9 @@ dependencies { // SuperiorSkyblock compileOnly 'com.bgsoftware:SuperiorSkyblockAPI:1.8.4' // VotingPlugin - compileOnly 'com.bencodez:votingplugin:6.8.3' + compileOnly ('com.bencodez:votingplugin:6.8.3') { + exclude group: 'dev.dbassett' + } // MMOItems compileOnly 'net.Indyuce:MMOItems:6.5' compileOnly 'io.lumine:MythicLib:1.1.1' @@ -117,6 +120,10 @@ dependencies { implementation 'com.zaxxer:HikariCP:4.0.3' // slf4j implementation 'org.slf4j:slf4j-simple:1.7.30' + // adventure + implementation 'net.kyori:adventure-platform-bukkit:4.1.0' + // mini message + implementation "net.kyori:adventure-text-minimessage:4.10.1" compileOnly fileTree(dir: 'libs', includes: ['*.jar']) } @@ -129,5 +136,6 @@ shadowJar { relocate 'org.bstats', 'com.leonardobishop.quests.libs.bstats' relocate 'com.zaxxer.hikari', 'com.leonardobishop.quests.libs.hikaricp' relocate 'org.slf4j', 'com.leonardobishop.quests.libs.slf4j' + relocate 'net.kyori', 'com.leonardobishop.quests.libs.adventure' archiveClassifier.set('') }
\ No newline at end of file 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 d0f4e151..c6e3e260 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/BukkitQuestsPlugin.java @@ -438,7 +438,7 @@ public class BukkitQuestsPlugin extends JavaPlugin implements Quests { } } else { configProblems = Collections.singletonMap("<MAIN CONFIG> config.yml", - Collections.singletonList(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, ConfigProblemDescriptions.MALFORMED_YAML.getDescription()))); + Collections.singletonList(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, ConfigProblemDescriptions.MALFORMED_YAML.getDescription(), ConfigProblemDescriptions.MALFORMED_YAML.getExtendedDescription()))); } } 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 9291caee..56a0927e 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 @@ -20,6 +20,7 @@ import com.leonardobishop.quests.common.tasktype.TaskTypeManager; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; @@ -148,8 +149,12 @@ public class BukkitQuestsLoader implements QuestsLoader { // test QUEST file integrity try { config.loadFromString(processed.toString()); - } catch (Exception ex) { - configProblems.put(relativeLocation.getPath(), Collections.singletonList(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, ConfigProblemDescriptions.MALFORMED_YAML.getDescription()))); + } catch (InvalidConfigurationException ex) { + configProblems.put(relativeLocation.getPath(), Collections.singletonList(new ConfigProblem( + ConfigProblem.ConfigProblemType.ERROR, + ConfigProblemDescriptions.MALFORMED_YAML.getDescription(), + ConfigProblemDescriptions.MALFORMED_YAML.getExtendedDescription(ex.getMessage()) + ))); return FileVisitResult.CONTINUE; } @@ -158,13 +163,18 @@ public class BukkitQuestsLoader implements QuestsLoader { List<ConfigProblem> problems = new ArrayList<>(); if (!StringUtils.isAlphanumeric(id)) { - problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, ConfigProblemDescriptions.INVALID_QUEST_ID.getDescription(id))); + problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, + ConfigProblemDescriptions.INVALID_QUEST_ID.getDescription(id), + ConfigProblemDescriptions.INVALID_QUEST_ID.getExtendedDescription(id))); } // CHECK EVERYTHING WRONG WITH THE QUEST FILE BEFORE ACTUALLY LOADING THE QUEST if (!config.isConfigurationSection("tasks")) { - problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, ConfigProblemDescriptions.NO_TASKS.getDescription(), "tasks")); + problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, + ConfigProblemDescriptions.NO_TASKS.getDescription(), + ConfigProblemDescriptions.NO_TASKS.getExtendedDescription(), + "tasks")); } else { //continue int validTasks = 0; for (String taskId : config.getConfigurationSection("tasks").getKeys(false)) { @@ -173,12 +183,18 @@ public class BukkitQuestsLoader implements QuestsLoader { String taskType = config.getString(taskRoot + ".type"); if (!config.isConfigurationSection(taskRoot)) { - problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, ConfigProblemDescriptions.TASK_MALFORMED_NOT_SECTION.getDescription(taskId), taskRoot)); + problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, + ConfigProblemDescriptions.TASK_MALFORMED_NOT_SECTION.getDescription(taskId), + ConfigProblemDescriptions.TASK_MALFORMED_NOT_SECTION.getExtendedDescription(taskId), + taskRoot)); continue; } if (taskType == null) { - problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, ConfigProblemDescriptions.NO_TASK_TYPE.getDescription(), taskRoot)); + problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, + ConfigProblemDescriptions.NO_TASK_TYPE.getDescription(), + ConfigProblemDescriptions.NO_TASK_TYPE.getExtendedDescription(), + taskRoot)); continue; } @@ -192,7 +208,10 @@ public class BukkitQuestsLoader implements QuestsLoader { problems.addAll(t.validateConfig(taskRoot, configValues)); } else { - problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, ConfigProblemDescriptions.UNKNOWN_TASK_TYPE.getDescription(taskType), taskRoot)); + problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, + ConfigProblemDescriptions.UNKNOWN_TASK_TYPE.getDescription(taskType), + ConfigProblemDescriptions.UNKNOWN_TASK_TYPE.getExtendedDescription(taskType), + taskRoot)); isValid = false; } @@ -201,7 +220,10 @@ public class BukkitQuestsLoader implements QuestsLoader { } } if (validTasks == 0) { - problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, ConfigProblemDescriptions.NO_TASKS.getDescription(), "tasks")); + problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, + ConfigProblemDescriptions.NO_TASKS.getDescription(), + ConfigProblemDescriptions.NO_TASKS.getExtendedDescription(), + "tasks")); } } @@ -269,7 +291,10 @@ public class BukkitQuestsLoader implements QuestsLoader { if (c != null) { c.registerQuestId(id); } else { - problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, ConfigProblemDescriptions.UNKNOWN_CATEGORY.getDescription(category), "options.category")); + problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, + ConfigProblemDescriptions.UNKNOWN_CATEGORY.getDescription(category), + ConfigProblemDescriptions.UNKNOWN_CATEGORY.getExtendedDescription(category), + "options.category")); } } @@ -353,7 +378,10 @@ public class BukkitQuestsLoader implements QuestsLoader { List<ConfigProblem> problems = new ArrayList<>(); for (String req : loadedQuest.getValue().getRequirements()) { if (questManager.getQuestById(req) == null) { - problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, ConfigProblemDescriptions.UNKNOWN_REQUIREMENT.getDescription(req), "options.requires")); + problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, + ConfigProblemDescriptions.UNKNOWN_REQUIREMENT.getDescription(req), + ConfigProblemDescriptions.UNKNOWN_REQUIREMENT.getExtendedDescription(req), + "options.requires")); } } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BucketInteractionTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BucketInteractionTaskType.java index 48d72190..e070e27d 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BucketInteractionTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BucketInteractionTaskType.java @@ -36,7 +36,9 @@ public abstract class BucketInteractionTaskType extends BukkitTaskType { String[] split = configBlock.split(":"); if (Material.getMaterial(String.valueOf(split[0])) == null) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(configBlock), root + ".bucket")); + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(configBlock), + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getExtendedDescription(configBlock), + root + ".bucket")); } } if (TaskUtils.configValidateExists(root + ".amount", config.get("amount"), problems, "amount", super.getType())) diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingCertainTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingCertainTaskType.java index b52933cb..a8e59494 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingCertainTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/BuildingCertainTaskType.java @@ -58,7 +58,9 @@ public final class BuildingCertainTaskType extends BukkitTaskType { String[] split = materialName.split(":"); if (Material.getMaterial(String.valueOf(split[0])) == null) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(materialName), root + "." + source)); + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(materialName), + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getExtendedDescription(materialName), + root + "." + source)); } } } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java index 19dbc2ff..4f475780 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FarmingCertainTaskType.java @@ -64,7 +64,9 @@ public final class FarmingCertainTaskType extends BukkitTaskType { for (String materialName : checkBlocks) { if (Material.getMaterial(String.valueOf(materialName)) == null) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(materialName), root + "." + source)); + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(materialName), + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getExtendedDescription(materialName), + root + "." + source)); } } } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FishingCertainTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FishingCertainTaskType.java index fcd07cde..fbe846fa 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FishingCertainTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/FishingCertainTaskType.java @@ -38,7 +38,9 @@ public final class FishingCertainTaskType extends BukkitTaskType { if (TaskUtils.configValidateExists(root + ".item", config.get("item"), problems, "item", super.getType())) { if (Material.getMaterial(String.valueOf(config.get("item"))) == null) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(String.valueOf(config.get("item"))), root + ".item.item")); + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(String.valueOf(config.get("item"))), + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getExtendedDescription(String.valueOf(config.get("item"))), + root + ".item.item")); } } if (TaskUtils.configValidateExists(root + ".amount", config.get("amount"), problems, "amount", super.getType())) diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java index 9e3175fa..35fc9b81 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MiningCertainTaskType.java @@ -58,7 +58,9 @@ public final class MiningCertainTaskType extends BukkitTaskType { String[] split = materialName.split(":"); if (Material.getMaterial(String.valueOf(split[0])) == null) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(materialName), root + "." + source)); + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(materialName), + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getExtendedDescription(materialName), + root + "." + source)); } } } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingCertainTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingCertainTaskType.java index 8b2f488a..c68af762 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingCertainTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/MobkillingCertainTaskType.java @@ -58,7 +58,9 @@ public final class MobkillingCertainTaskType extends BukkitTaskType { EntityType.valueOf(mobName); } catch (IllegalArgumentException ex) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_ENTITY_TYPE.getDescription(mobName), root + "." + source)); + ConfigProblemDescriptions.UNKNOWN_ENTITY_TYPE.getDescription(mobName), + ConfigProblemDescriptions.UNKNOWN_ENTITY_TYPE.getExtendedDescription(mobName), + root + "." + source)); } } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/TamingCertainTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/TamingCertainTaskType.java index 002fbda6..70aef33b 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/TamingCertainTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/TamingCertainTaskType.java @@ -40,7 +40,9 @@ public final class TamingCertainTaskType extends BukkitTaskType { EntityType.valueOf(String.valueOf(config.get("mob"))); } catch (IllegalArgumentException ex) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_ENTITY_TYPE.getDescription(String.valueOf(config.get("mob"))), root + ".mob")); + ConfigProblemDescriptions.UNKNOWN_ENTITY_TYPE.getDescription(String.valueOf(config.get("mob"))), + ConfigProblemDescriptions.UNKNOWN_ENTITY_TYPE.getExtendedDescription(String.valueOf(config.get("mob"))), + root + ".mob")); } } return problems; diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/PlaceholderAPIEvaluateTaskType.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/PlaceholderAPIEvaluateTaskType.java index 706fcfcd..999beacf 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/PlaceholderAPIEvaluateTaskType.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/tasktype/type/dependent/PlaceholderAPIEvaluateTaskType.java @@ -43,7 +43,13 @@ public final class PlaceholderAPIEvaluateTaskType extends BukkitTaskType { operator = Operator.valueOf(operatorStr); } catch (IllegalArgumentException ex) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - "Operator '" + operatorStr + "' does not exist.", root + ".operator")); + "Operator '" + operatorStr + "' does not exist", + "Valid operators are:<br>" + + "- GREATER_THAN<br>" + + "- LESS_THAN<br>" + + "- GREATER_THAN_OR_EQUAL_TO<br>" + + "- LESS_THAN_OR_EQUAL_TO<br>", + root + ".operator")); } if (operator != null && evalExists) { String evalStr = String.valueOf(config.get("evaluates")); @@ -51,7 +57,7 @@ public final class PlaceholderAPIEvaluateTaskType extends BukkitTaskType { Double.parseDouble(evalStr); } catch (IllegalArgumentException ex) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - "Numeric operator specified, but placeholder evaluation '" + evalStr + "' is not numeric.", root + ".evaluates")); + "Numeric operator specified, but placeholder evaluation '" + evalStr + "' is not numeric", null, root + ".evaluates")); } } } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/CommandUtils.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/CommandUtils.java index 90e529a2..ca14e6ac 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/CommandUtils.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/CommandUtils.java @@ -5,6 +5,7 @@ import com.leonardobishop.quests.bukkit.util.chat.Chat; import com.leonardobishop.quests.common.config.ConfigProblem; import com.leonardobishop.quests.common.player.QPlayer; import com.leonardobishop.quests.common.player.questprogressfile.QuestProgressFile; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.OfflinePlayer; @@ -48,9 +49,26 @@ public class CommandUtils { for (ConfigProblem.ConfigProblemType type : ConfigProblem.ConfigProblemType.values()) { if (sortedProblems.containsKey(type)) { for (ConfigProblem problem : sortedProblems.get(type)) { - sender.sendMessage(ChatColor.DARK_GRAY + " | - " + Chat.matchConfigProblemToColor(problem.getType()) - + problem.getType().getShortened() + ChatColor.DARK_GRAY + ": " - + ChatColor.GRAY + problem.getDescription() + ChatColor.DARK_GRAY + " :" + problem.getLocation()); + String color = Chat.matchConfigProblemToColorName(problem.getType()); + String extendedDescription = String.format("<%s>%s</%s><br><gray>Problem location: </gray><white>%s</white><br><br><grey>%s</grey>", + color, + problem.getDescription(), + color, + problem.getLocation(), + problem.getExtendedDescription() + ); + extendedDescription = extendedDescription.replace("'", "\\'"); + + String message = String.format( + "<dark_gray> | - </dark_gray><%s>%s</%s><dark_gray>:</dark_gray> <hover:show_text:'%s'><gray>%s</gray></hover><dark_gray> :%s</dark_gray>", + color, + problem.getType().getShortened(), + color, + extendedDescription, + problem.getDescription(), + problem.getLocation() + ); + Chat.send(sender, message); count++; } } @@ -66,6 +84,7 @@ public class CommandUtils { sender.sendMessage(ChatColor.DARK_GRAY.toString() + "----"); sender.sendMessage(ChatColor.GRAY.toString() + count + " problem(s) | " + String.join(ChatColor.DARK_GRAY + ", ", legend)); + sender.sendMessage(ChatColor.DARK_GRAY.toString() + "Mouse-over for more information."); } else { sender.sendMessage(ChatColor.GRAY + "Quests did not detect any problems with your configuration."); } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java index c9f36b3e..66d804b6 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/TaskUtils.java @@ -53,7 +53,7 @@ public class TaskUtils { if (object == null) { if (!allowNull) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Expected a number for '%s', but got null instead", (Object[]) args), path)); + String.format("Expected a number for '%s', but got null instead", (Object[]) args), null, path)); } return; } @@ -62,11 +62,11 @@ public class TaskUtils { double d = Double.parseDouble(String.valueOf(object)); if (greaterThanZero && d <= 0) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Value for field '%s' must be greater than 0", (Object[]) args), path)); + String.format("Value for field '%s' must be greater than 0", (Object[]) args), null, path)); } } catch (ClassCastException ex) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Expected a number for '%s', but got '" + object + "' instead", (Object[]) args), path)); + String.format("Expected a number for '%s', but got '" + object + "' instead", (Object[]) args), null, path)); } } @@ -74,7 +74,7 @@ public class TaskUtils { if (object == null) { if (!allowNull) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Expected an integer for '%s', but got null instead", (Object[]) args), path)); + String.format("Expected an integer for '%s', but got null instead", (Object[]) args), null, path)); } return; } @@ -83,11 +83,11 @@ public class TaskUtils { Integer i = (Integer) object; if (greaterThanZero && i <= 0) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Value for field '%s' must be greater than 0", (Object[]) args), path)); + String.format("Value for field '%s' must be greater than 0", (Object[]) args), null, path)); } } catch (ClassCastException ex) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Expected an integer for '%s', but got '" + object + "' instead", (Object[]) args), path)); + String.format("Expected an integer for '%s', but got '" + object + "' instead", (Object[]) args), null, path)); } } @@ -95,7 +95,7 @@ public class TaskUtils { if (object == null) { if (!allowNull) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Expected a boolean for '%s', but got null instead", (Object[]) args), path)); + String.format("Expected a boolean for '%s', but got null instead", (Object[]) args), null, path)); } return; } @@ -104,7 +104,7 @@ public class TaskUtils { Boolean b = (Boolean) object; } catch (ClassCastException ex) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Expected a boolean for '%s', but got '" + object + "' instead", (Object[]) args), path)); + String.format("Expected a boolean for '%s', but got '" + object + "' instead", (Object[]) args), null, path)); } } @@ -112,7 +112,7 @@ public class TaskUtils { if (object == null) { if (!allowNull) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format("Expected item configuration for '%s', but got null instead", (Object[]) args), path)); + String.format("Expected item configuration for '%s', but got null instead", (Object[]) args), null, path)); } return; } @@ -124,7 +124,9 @@ public class TaskUtils { String type = section.getString("quest-item"); if (plugin.getQuestItemRegistry().getItem(section.getString("quest-item")) == null) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_QUEST_ITEM.getDescription(type), path + ".item.quest-item")); + ConfigProblemDescriptions.UNKNOWN_QUEST_ITEM.getDescription(type), + ConfigProblemDescriptions.UNKNOWN_QUEST_ITEM.getExtendedDescription(type), + path + ".item.quest-item")); } } else { String itemloc = "item"; @@ -133,19 +135,25 @@ public class TaskUtils { } if (!section.contains(itemloc)) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(""), path + ".type")); + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(""), + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getExtendedDescription(""), + path + ".type")); } else { String type = String.valueOf(section.get(itemloc)); if (!plugin.getItemGetter().isValidMaterial(type)) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(type), path + itemloc)); + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(type), + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getExtendedDescription(type), + path + itemloc)); } } } } else { if (Material.getMaterial(String.valueOf(object)) == null) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.WARNING, - ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(String.valueOf(object)), path)); + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getDescription(String.valueOf(object)), + ConfigProblemDescriptions.UNKNOWN_MATERIAL.getExtendedDescription(String.valueOf(object)), + path)); } } } @@ -153,7 +161,9 @@ public class TaskUtils { public static boolean configValidateExists(String path, Object object, List<ConfigProblem> problems, String... args) { if (object == null) { problems.add(new ConfigProblem(ConfigProblem.ConfigProblemType.ERROR, - String.format(ConfigProblemDescriptions.TASK_MISSING_FIELD.getDescription(args), (Object[]) args), path)); + ConfigProblemDescriptions.TASK_MISSING_FIELD.getDescription(args), + ConfigProblemDescriptions.TASK_MISSING_FIELD.getExtendedDescription(args), + path)); return false; } return true; diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/chat/Chat.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/chat/Chat.java index 9f81b08b..64c2fdc8 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/chat/Chat.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/chat/Chat.java @@ -1,8 +1,11 @@ package com.leonardobishop.quests.bukkit.util.chat; +import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; import com.leonardobishop.quests.common.config.ConfigProblem; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; @@ -11,38 +14,42 @@ import java.util.List; public class Chat { - private static final ColorAdapter colorAdapter; + private static final ColorAdapter legacyColorAdapter; + private static final MiniMessageParser miniMessageParser; static { String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];; if (version.startsWith("v1_7") || version.startsWith("v1_8") || version.startsWith("v1_9") || version.startsWith("v1_10") || version.startsWith("v1_11") || version.startsWith("v1_12") || version.startsWith("v1_13") || version.startsWith("v1_14") || version.startsWith("v1_15")) { - colorAdapter = new CodedColorAdapter(); + legacyColorAdapter = new CodedColorAdapter(); } else { - colorAdapter = new HexColorAdapter(); + legacyColorAdapter = new HexColorAdapter(); } + miniMessageParser = new MiniMessageParser(Bukkit.getPluginManager().getPlugin("Quests")); } @Contract("null -> null") + @Deprecated // use send instead public static String color(@Nullable String s) { - return colorAdapter.color(s); + return legacyColorAdapter.color(s); } @Contract("null -> null") + @Deprecated // use send instead public static List<String> color(@Nullable List<String> s) { if (s == null || s.size() == 0) return s; List<String> colored = new ArrayList<>(); for (String line : s) { - colored.add(colorAdapter.color(line)); + colored.add(legacyColorAdapter.color(line)); } return colored; } @Contract("null -> null") public static String strip(@Nullable String s) { - return colorAdapter.strip(s); + return legacyColorAdapter.strip(s); } public static ChatColor matchConfigProblemToColor(ConfigProblem.ConfigProblemType configProblem) { @@ -56,4 +63,27 @@ public class Chat { } } + public static String matchConfigProblemToColorName(ConfigProblem.ConfigProblemType configProblem) { + switch (configProblem) { + case ERROR: + return "red"; + case WARNING: + return "yellow"; + default: + return "white"; + } + } + + /** + * Send a message to a given command sender. The given message will be parsed for legacy + * colours and minimessage formatting. + * + * @param who the player to send to + * @param message the message to send + */ + public static void send(CommandSender who, String message) { +// String colouredMessage = legacyColorAdapter.color(message); + miniMessageParser.send(who, message); + } + } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/chat/MiniMessageParser.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/chat/MiniMessageParser.java new file mode 100644 index 00000000..c27df430 --- /dev/null +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/chat/MiniMessageParser.java @@ -0,0 +1,26 @@ +package com.leonardobishop.quests.bukkit.util.chat; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; + +public class MiniMessageParser { + + private final BukkitAudiences adventure; + private final MiniMessage miniMessage; + + public MiniMessageParser(Plugin plugin) { + adventure = BukkitAudiences.create(plugin); + miniMessage = MiniMessage.miniMessage(); + } + + public void send(CommandSender who, String message) { + Audience audience = adventure.sender(who); + Component component = miniMessage.deserialize(message); + audience.sendMessage(component); + } + +} |
