package roycurtis.signshopexport;

import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import roycurtis.signshopexport.quickshop.QSDataSource;
import roycurtis.signshopexport.signshop.SSDataSource;

import java.util.logging.Logger;

/** Core class of the SignShopExport plugin. Handles manager creation and reload. */
public class SignShopExport extends JavaPlugin
{
    static SignShopExport PLUGIN;
    static Logger         LOGGER;
    static Server         SERVER;
    static Config         CONFIG;
    static DataManager    DATAMANAGER;

    @Override
    public void onLoad()
    {
        PLUGIN = this;
        LOGGER = getLogger();
        SERVER = this.getServer();
    }

    @Override
    public void onEnable()
    {
        boolean signShop  = getServer().getPluginManager().getPlugin("SignShop")  != null;
        boolean quickShop = getServer().getPluginManager().getPlugin("QuickShop") != null;

        if (!signShop && !quickShop)
        {
            LOGGER.warning("Neither SignShop nor QuickShop are loaded.");
            LOGGER.warning("SignShopExport will do nothing.");
            return;
        }
        else if (signShop && quickShop)
        {
            LOGGER.warning("Both SignShop and QuickShop are loaded.");
            LOGGER.warning("SignShopExport will do nothing, as it cannot handle both.");
            return;
        }

        CONFIG      = new Config();
        DATAMANAGER = new DataManager( signShop ? new SSDataSource() : new QSDataSource() );

        DATAMANAGER.run();
        LOGGER.info("To reload this plugin, do `/signshopexport`");
    }

    @Override
    public void onDisable()
    {
        CONFIG      = null;
        DATAMANAGER = null;
        SERVER.getScheduler().cancelTasks(this);
        LOGGER.fine("All managers released and tasks cancelled");
    }

    @Override
    public boolean onCommand(CommandSender who, Command what, String label, String[] args)
    {
        this.setEnabled(false);
        this.setEnabled(true);
        who.sendMessage("*** SignShopExport's config reloaded; export triggered");
        return true;
    }
}

@@ -126,24 +126,57 @@
 mandSender;%0A
+import org.bukkit.plugin.Plugin;%0A
 import org.b
@@ -856,23 +856,23 @@
         
-boolean
+Plugin 
  signSho
@@ -874,16 +874,19 @@
 gnShop  
+   
 = getSer
@@ -935,17 +935,8 @@
 op%22)
-  != null
 ;%0A  
@@ -941,23 +941,23 @@
         
-boolean
+Plugin 
  quickSh
@@ -959,16 +959,19 @@
 ickShop 
+   
 = getSer
@@ -1021,16 +1021,157 @@
 op%22)
- != null
+;%0A        boolean hasSignShop  = signShop  != null && signShop.isEnabled();%0A        boolean hasQuickShop = quickShop != null && quickShop.isEnabled()
 ;%0A%0A 
@@ -1182,17 +1182,20 @@
    if (!
-s
+hasS
 ignShop 
@@ -1198,17 +1198,20 @@
 hop && !
-q
+hasQ
 uickShop
@@ -1283,32 +1283,43 @@
 kShop are loaded
+ or enabled
 .%22);%0A           
@@ -1417,17 +1417,20 @@
 lse if (
-s
+hasS
 ignShop 
@@ -1428,25 +1428,28 @@
 SignShop && 
-q
+hasQ
 uickShop)%0A  
@@ -1522,16 +1522,28 @@
 e loaded
+ and enabled
 .%22);%0A   
@@ -1734,17 +1734,20 @@
 anager( 
-s
+hasS
 ignShop 

Fix exception when trying to use disabled plugins