WIP fix for comment version number

This commit is contained in:
tastybento 2018-10-30 14:30:07 -07:00
parent d9783c8d73
commit 49fa079f13
3 changed files with 27 additions and 1 deletions

View File

@ -21,6 +21,7 @@ public class Config<T> {
private AbstractDatabaseHandler<T> handler; private AbstractDatabaseHandler<T> handler;
private Logger logger; private Logger logger;
private Addon addon;
public Config(BentoBox plugin, Class<T> type) { public Config(BentoBox plugin, Class<T> type) {
this.logger = plugin.getLogger(); this.logger = plugin.getLogger();
@ -29,6 +30,7 @@ public class Config<T> {
public Config(Addon addon, Class<T> type) { public Config(Addon addon, Class<T> type) {
this.logger = addon.getLogger(); this.logger = addon.getLogger();
this.addon = addon;
handler = new YamlDatabase().getConfig(type); handler = new YamlDatabase().getConfig(type);
} }
@ -77,6 +79,8 @@ public class Config<T> {
* @param instance to save * @param instance to save
*/ */
public boolean saveConfigObject(T instance) { public boolean saveConfigObject(T instance) {
// Set the addon (may be null)
handler.setAddon(addon);
try { try {
handler.saveObject(instance); handler.saveObject(instance);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException

View File

@ -5,6 +5,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.List; import java.util.List;
import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.Addon;
/** /**
* An abstract class that handles insert/select-operations into/from a database * An abstract class that handles insert/select-operations into/from a database
@ -34,6 +35,27 @@ public abstract class AbstractDatabaseHandler<T> {
protected BentoBox plugin; protected BentoBox plugin;
/**
* The addon that is accessing the database, if any.
*/
private Addon addon;
/**
* Get the addon that is accessing the database, if any. May be null.
* @return the addon
*/
public Addon getAddon() {
return addon;
}
/**
* Set the addon that is accessing the database, if any.
* @param addon the addon to set
*/
public void setAddon(Addon addon) {
this.addon = addon;
}
/** /**
* Constructor * Constructor
* *

View File

@ -433,7 +433,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Store placeholder // Store placeholder
config.set(parent + random, " "); config.set(parent + random, " ");
// Create comment // Create comment
yamlComments.put(random, "# " + comment.replace(TextVariables.VERSION, plugin.getDescription().getVersion())); yamlComments.put(random, "# " + comment.replace(TextVariables.VERSION, Objects.isNull(getAddon()) ? plugin.getDescription().getVersion() : getAddon().getDescription().getVersion()));
} }
/** /**