
package io.github.deathcap.bukkit2sponge;

import com.google.common.base.Throwables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import io.github.deathcap.bukkit2sponge.event.GraniteEventFactory;
import io.github.deathcap.bukkit2sponge.guice.ShinyGuiceModule;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongepowered.api.event.state.ConstructionEvent;
import org.spongepowered.api.event.state.PreInitializationEvent;
import org.spongepowered.api.event.state.StateEvent;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;

public class Bukkit2Sponge extends JavaPlugin {

    public static final Bukkit2Sponge instance = new Bukkit2Sponge();

    public Injector getInjector() {
        return injector;
    }

    private Injector injector;

    private ShinyGame game;

    @Override
    public void onDisable() {
        getLogger().info("Goodbye world!");
    }

    @Override
    public void onEnable() {
        PluginDescriptionFile pdfFile = this.getDescription();
        getLogger().info( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );

        load();
    }

    public Collection<URL> load() {
        Collection<URL> loadedPluginURLs = null;

        try {
            injector = Guice.createInjector(new ShinyGuiceModule());

            /*
             CONSTRUCTION,
             LOAD_COMPLETE,
             PRE_INITIALIZATION,
             INITIALIZATION,
             POST_INITIALIZATION,
             SERVER_ABOUT_TO_START,
             SERVER_STARTING,
             SERVER_STARTED,
             SERVER_STOPPING,
             SERVER_STOPPED
             */

            getLogger().info("Loading Bukkit2Sponge...");
            this.game = injector.getInstance(ShinyGame.class);

            getLogger().info("Bukkit2Sponge " + this.game.getImplementationVersion() + " is starting...");
            getLogger().info("SpongeAPI version: " + this.game.getApiVersion());

            getLogger().info("Loading plugins...");
            loadedPluginURLs = this.game.getPluginManager().loadPlugins();
            postState(ConstructionEvent.class);
            getLogger().info("Initializing " + loadedPluginURLs.size() + " SpongeAPI plugins...");
            postState(PreInitializationEvent.class);
        } catch (IOException e) {
            throw Throwables.propagate(e);
        }

        return loadedPluginURLs;
    }

    public ShinyGame getGame() {
        return this.game;
    }

    public void postState(Class<? extends StateEvent> type) {
        this.game.getEventManager().post(GraniteEventFactory.createStateEvent(type, this.game));
    }

    public File getPluginsDirectory() {
        return new File("plugins"); // TODO
    }

    public File getConfigDirectory() {
        return new File("config"); // TODO
    }
}
@@ -371,65 +371,8 @@
 in;%0A
-import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 impo
@@ -419,32 +419,32 @@
 structionEvent;%0A
+
 import org.spong
@@ -717,14 +717,8 @@
 tic 
-final 
 Bukk
@@ -743,26 +743,11 @@
  = n
-ew Bukkit2Sponge()
+ull
 ;%0A%0A 
@@ -975,32 +975,32 @@
 %0A%0A    @Override%0A
-
     public void 
@@ -1004,32 +1004,72 @@
 id onEnable() %7B%0A
+        Bukkit2Sponge.instance = this;%0A%0A
         PluginDe
@@ -2736,32 +2736,105 @@
 .game));%0A    %7D%0A%0A
+    // Sponge directories relative to our own Bukkit plugin data folder%0A%0A
     public File 
@@ -2881,16 +2881,38 @@
 ew File(
+this.getDataFolder(), 
 %22plugins
@@ -2914,24 +2914,16 @@
 ugins%22);
- // TODO
 %0A    %7D%0A%0A
@@ -2985,16 +2985,38 @@
 ew File(
+this.getDataFolder(), 
 %22config%22
@@ -3021,16 +3021,8 @@
 g%22);
- // TODO
 %0A   

Use plugin-relative data folders, fix duplicate init