From 49fa079f1301b31e74eeff732c64c2dbb7c2495b Mon Sep 17 00:00:00 2001
From: tastybento <tastybento@wasteofplastic.com>
Date: Tue, 30 Oct 2018 14:30:07 -0700
Subject: [PATCH] WIP fix for comment version number

---
 .../bentobox/api/configuration/Config.java    |  4 ++++
 .../database/AbstractDatabaseHandler.java     | 22 +++++++++++++++++++
 .../database/yaml/YamlDatabaseHandler.java    |  2 +-
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/main/java/world/bentobox/bentobox/api/configuration/Config.java b/src/main/java/world/bentobox/bentobox/api/configuration/Config.java
index 6624ae69f..013ba1a8b 100644
--- a/src/main/java/world/bentobox/bentobox/api/configuration/Config.java
+++ b/src/main/java/world/bentobox/bentobox/api/configuration/Config.java
@@ -21,6 +21,7 @@ public class Config<T> {
 
     private AbstractDatabaseHandler<T> handler;
     private Logger logger;
+    private Addon addon;
 
     public Config(BentoBox plugin, Class<T> type)  {
         this.logger = plugin.getLogger();
@@ -29,6 +30,7 @@ public class Config<T> {
 
     public Config(Addon addon, Class<T> type)  {
         this.logger = addon.getLogger();
+        this.addon = addon;
         handler = new YamlDatabase().getConfig(type);
     }
 
@@ -77,6 +79,8 @@ public class Config<T> {
      * @param instance to save
      */
     public boolean saveConfigObject(T instance) {
+        // Set the addon (may be null)
+        handler.setAddon(addon);
         try {
             handler.saveObject(instance);
         } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException
diff --git a/src/main/java/world/bentobox/bentobox/database/AbstractDatabaseHandler.java b/src/main/java/world/bentobox/bentobox/database/AbstractDatabaseHandler.java
index 202102127..a56eae483 100644
--- a/src/main/java/world/bentobox/bentobox/database/AbstractDatabaseHandler.java
+++ b/src/main/java/world/bentobox/bentobox/database/AbstractDatabaseHandler.java
@@ -5,6 +5,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 
 import world.bentobox.bentobox.BentoBox;
+import world.bentobox.bentobox.api.addons.Addon;
 
 /**
  * An abstract class that handles insert/select-operations into/from a database
@@ -34,6 +35,27 @@ public abstract class AbstractDatabaseHandler<T> {
 
     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
      *
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 f1081285b..371a4aa47 100644
--- a/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java
+++ b/src/main/java/world/bentobox/bentobox/database/yaml/YamlDatabaseHandler.java
@@ -433,7 +433,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
         // Store placeholder
         config.set(parent + random, " ");
         // 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()));
     }
 
     /**