From d91e29a2b7aa3c6000ac9ae88fb15da670fb02a1 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Thu, 21 Feb 2019 20:17:28 +0100 Subject: [PATCH 1/3] Improved ConfigEntry explicative comments in config --- .../database/yaml/YamlDatabaseHandler.java | 52 +++++++++++-------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java index aade37bec..43d4aefc8 100644 --- a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java +++ b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java @@ -375,34 +375,22 @@ public class YamlDatabaseHandler extends AbstractDatabaseHandler { ConfigEntry configEntry = field.getAnnotation(ConfigEntry.class); // If there is a config path annotation then do something - boolean experimental = false; - String since = "1.0"; if (configEntry != null && !configEntry.path().isEmpty()) { - storageLocation = configEntry.path(); - experimental = configEntry.experimental(); - since = configEntry.since(); - if (configEntry.hidden()) { // If the annotation tells us to not print the config entry, then we won't. continue; } - } - // Get path for comments - String parent = ""; - if (storageLocation.contains(".")) { - parent = storageLocation.substring(0, storageLocation.lastIndexOf('.')) + "."; - } - handleComments(field, config, yamlComments, parent); + // Get the storage location + storageLocation = configEntry.path(); - // If the configEntry has a "since" that differs from the default one, then tell it - if (!since.equals("1.0")) { - setComment("Added since " + since + ".", config, yamlComments, parent); - } - - // If the configEntry is experimental, then tell it - if (experimental) { - setComment("/!\\ This feature is experimental and might not work as expected or might not work at all.", config, yamlComments, parent); + // Get path for comments + String parent = ""; + if (storageLocation.contains(".")) { + parent = storageLocation.substring(0, storageLocation.lastIndexOf('.')) + "."; + } + handleComments(field, config, yamlComments, parent); + handleConfigEntryComments(configEntry, config, yamlComments, parent); } // Adapter @@ -480,6 +468,7 @@ public class YamlDatabaseHandler extends AbstractDatabaseHandler { /** * Handles comments that are set on a Field or a Class using the {@link ConfigComment} annotation. + * @since 1.3.0 */ private void handleComments(@NonNull AnnotatedElement annotatedElement, @NonNull YamlConfiguration config, @NonNull Map yamlComments, @NonNull String parent) { // See if there are multiple comments @@ -496,6 +485,27 @@ public class YamlDatabaseHandler extends AbstractDatabaseHandler { } } + /** + * Handles comments that should be added according to the values set in the {@link ConfigEntry} annotation of a Field. + * @since 1.3.0 + */ + private void handleConfigEntryComments(@NonNull ConfigEntry configEntry, @NonNull YamlConfiguration config, @NonNull Map yamlComments, @NonNull String parent) { + // Tell when the configEntry has been added (if it's not "1.0") + if (!configEntry.since().equals("1.0")) { + setComment("Added since " + configEntry.since() + ".", config, yamlComments, parent); + } + + // Tell if the configEntry is experimental + if (configEntry.experimental()) { + setComment("/!\\ This feature is experimental and might not work as expected or might not work at all.", config, yamlComments, parent); + } + + // Tell if the configEntry needs a reset. + if (configEntry.needsReset()) { + setComment("/!\\ BentoBox currently does not support changing this value mid-game. If you do need to change it, do a full reset of your databases and worlds.", config, yamlComments, parent); + } + } + private void setComment(@NonNull String comment, @NonNull YamlConfiguration config, @NonNull Map yamlComments, @NonNull String parent) { String random = "comment-" + UUID.randomUUID().toString(); // Store placeholder From 29c7adec446e28238277f62ac103a03013d783e5 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Thu, 21 Feb 2019 20:18:05 +0100 Subject: [PATCH 2/3] Marked 'general.database-type' ConfigEntry as "needsReset" --- src/main/java/world/bentobox/bentobox/Settings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/bentobox/Settings.java b/src/main/java/world/bentobox/bentobox/Settings.java index 39d41ae25..d20f7e8a2 100644 --- a/src/main/java/world/bentobox/bentobox/Settings.java +++ b/src/main/java/world/bentobox/bentobox/Settings.java @@ -43,7 +43,7 @@ public class Settings implements DataObject { @ConfigComment("MYSQL might not work with all implementations: if available, use a dedicated database type (e.g. MARIADB).") @ConfigComment("If you use MONGODB, you must also run the BSBMongo plugin (not addon).") @ConfigComment("See https://github.com/tastybento/bsbMongo/releases/.") - @ConfigEntry(path = "general.database.type") + @ConfigEntry(path = "general.database.type", needsReset = true) private DatabaseType databaseType = DatabaseType.YAML; @ConfigEntry(path = "general.database.host") From e7b2a6ed3910c4d7a96e26b9e4500cacac709007 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Thu, 21 Feb 2019 20:34:31 +0100 Subject: [PATCH 3/3] Updated the config header to talk about the ability to reload config --- src/main/java/world/bentobox/bentobox/Settings.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/Settings.java b/src/main/java/world/bentobox/bentobox/Settings.java index d20f7e8a2..645de37d6 100644 --- a/src/main/java/world/bentobox/bentobox/Settings.java +++ b/src/main/java/world/bentobox/bentobox/Settings.java @@ -18,9 +18,9 @@ import world.bentobox.bentobox.managers.RanksManager; */ @StoreAt(filename="config.yml") // Explicitly call out what name this should have. @ConfigComment("BentoBox Configuration [version]") -@ConfigComment("This config file is dynamic and saved when the server is shutdown.") -@ConfigComment("You cannot edit it while the server is running because changes will") -@ConfigComment("be lost! Use in-game settings GUI or edit when server is offline.") +@ConfigComment("This config file is dynamic and is updated right after BentoBox loaded its settings from it.") +@ConfigComment("You can edit it while the server is online and you can do '/bbox reload' to take the changes into account.") +@ConfigComment("However, it is a better practice to edit this file while the server is offline.") public class Settings implements DataObject { // ---------------------------------------------