Merge branch 'develop' of https://github.com/BentoBoxWorld/bentobox.git into develop

This commit is contained in:
tastybento 2019-02-21 12:43:03 -08:00
commit 2f432e9f35
2 changed files with 35 additions and 25 deletions

View File

@ -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 {
// ---------------------------------------------
@ -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")

View File

@ -375,34 +375,22 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
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<T> extends AbstractDatabaseHandler<T> {
/**
* 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<String, String> yamlComments, @NonNull String parent) {
// See if there are multiple comments
@ -496,6 +485,27 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
}
}
/**
* 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<String, String> 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<String, String> yamlComments, @NonNull String parent) {
String random = "comment-" + UUID.randomUUID().toString();
// Store placeholder