// Path: src/main/java/src/john01dav/serverforge/ServerForge.java
// @Mod(modid = "ServerForge", name = "ServerForge", version = ServerForge.VERSION, acceptableRemoteVersions = "*")
// public class ServerForge{
//     public static final String VERSION = "PRE-ALPHA 0.0.1";
// 
//     private EventManager eventManager;
//     private PermissionsManager permissionsManager;
//     private PluginLoader pluginLoader;
// 
//     private FMLServerStartingEvent serverStartingEvent;
// 
//     @Mod.Instance("ServerForge")
//     public static ServerForge instance;
// 
//     public static void info(String info){
//         System.out.println("[SERVERFORGE INFO]: " + info);
//     }
// 
//     public static void error(String error){
//         System.out.println("[SERVERFORGE ERROR]: " + error);
//     }
// 
//     @Mod.EventHandler
//     public void serverStartingEvent(FMLServerStartingEvent e){
//         info("Starting ServerForge...");
//         this.serverStartingEvent = e;
// 
//         eventManager = new EventManager();
//         eventManager.onServerStart();
// 
//         permissionsManager = new PermissionsManager();
//         permissionsManager.onServerStart();
// 
//         pluginLoader = new PluginLoader();
//         pluginLoader.onServerStart();
// 
//         this.serverStartingEvent = null;
//         info("ServerForge started");
//     }
// 
//     /**
//      * Registers a command for use in the server, can only be called from onServerStart() or it's submethods
//      * @param name The name of the command to add, to be used as the name to execute (ie. name = "example", to type in chat = "/example")
//      * @param command The command object to register
//      * @param aliases Array containing the aliases for this command
//      */
//     public void registerCommand(String name, ServerForgeCommand command, String[] aliases){
//         CommandWrapper wrapper = new CommandWrapper(name, command, aliases);
//         serverStartingEvent.registerServerCommand(wrapper);
//     }
// 
//     /**
//      * Registers a command for use in the server, can only be called from onServerStart() or it's submethods
//      * @param name The name of the command to add, to be used as the name to execute (ie. name = "example", to type in chat = "/example")
//      * @param command The command object to register
//      */
//     public void registerCommand(String name, ServerForgeCommand command){
//         registerCommand(name, command, new String[0]);
//     }
// 
//     /**
//      * Returns the plugin loader (the class responsible for the loading and management of plugins)
//      * @return the plugin loader
//      */
//     public PluginLoader getPluginLoader(){
//         return pluginLoader;
//     }
// 
//     /**
//      * Returns the event manager (the class responsible for the registering and calling of events)
//      * @return The event manager
//      */
//     public EventManager getEventManager(){
//         return eventManager;
//     }
// 
//     /**
//      * Returns the permissions manager (the class responsible for the setting and getting of player's permissions)
//      * @return the permissions manager
//      */
//     public PermissionsManager getPermissionsManager(){
//         return permissionsManager;
//     }
// 
//     /**
//      * Returns the Minecraft version running this server
//      * @return The Minecraft version running this server
//      */
//     public String getMinecraftVersion(){
//         return MinecraftForge.MC_VERSION;
//     }
// 
//     /**
//      * Returns all online players
//      * @return All online players
//      */
//     public ArrayList<Player> getOnlinePlayers(){
//         ArrayList<Player> list = new ArrayList<Player>();
// 
//         for(World world : MinecraftServer.getServer().worldServers){
//             for(Object o : world.playerEntities){
//                 EntityPlayerMP playerMP = ((EntityPlayerMP) o);
//                 Player player = Player.get(playerMP);
//                 list.add(player);
//             }
//         }
// 
//         return list;
//     }
// 
// }
// 
// Path: src/main/java/src/john01dav/serverforge/api/ServerForgePlugin.java
// public abstract class ServerForgePlugin{
//     public PluginWrapper wrapper;
// 
//     /**
//      * Called when the server loads
//      */
//     public abstract void onServerStart();
// 
//     /**
//      * Called when the server unloads
//      */
//     public abstract void onServerStop();
// 
// }
// 
// Path: src/main/java/src/john01dav/serverforge/plugin/ServerForgeDefaultPlugin.java
// public class ServerForgeDefaultPlugin extends ServerForgePlugin{
//     private PropertiesFile propertiesFile;
// 
//     @Override
//     public void onServerStart(){
//         try {
//             Properties defaultProperties = new Properties();
//             defaultProperties.setProperty("enableVersion", String.valueOf(true));
//             defaultProperties.setProperty("enablePlugins", String.valueOf(true));
// 
//             propertiesFile = new PropertiesFile(wrapper, "serverforgeplugin.properties", defaultProperties);
// 
//             if((Boolean.parseBoolean(propertiesFile.getProperties().getProperty("enableVersion")))){
//                 ServerForge.instance.registerCommand("version", new VersionCommand());
//             }
// 
//             if((Boolean.parseBoolean(propertiesFile.getProperties().getProperty("enablePlugins")))){
//                 ServerForge.instance.registerCommand("plugins", new PluginsCommand());
//             }
//         }catch(IOException e){
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public void onServerStop(){
// 
//     }
// 
// }


import com.google.common.io.Files;
import src.john01dav.serverforge.ServerForge;
import src.john01dav.serverforge.api.ServerForgePlugin;
import src.john01dav.serverforge.plugin.ServerForgeDefaultPlugin;
import java.io.File;
import java.io.IOException;
import java.net.*;
import java.util.ArrayList;
package src.john01dav.serverforge.loader;


public class PluginLoader{
    private ArrayList<PluginFile> pluginFile;
    private ArrayList<PluginWrapper> pluginWrapper;
    private URLClassLoader loader;
    private File pluginsFolder;

    public void onServerStart(){
        pluginsFolder = new File("./plugins");

        try {
            if (!pluginsFolder.isDirectory()) {
                Files.move(pluginsFolder, new File("./plugins-file"));
                pluginsFolder.delete();
            }

            if (!pluginsFolder.exists()) {
                pluginsFolder.mkdir();
            }
        }catch(IOException e){
            e.printStackTrace();
            System.exit(0);
        }

        pluginFile = new ArrayList<PluginFile>();
        pluginWrapper = new ArrayList<PluginWrapper>();
        ArrayList<URL> pluginURL = new ArrayList<URL>();

// Path: src/main/java/src/john01dav/serverforge/ServerForge.java
// @Mod(modid = "ServerForge", name = "ServerForge", version = ServerForge.VERSION, acceptableRemoteVersions = "*")
// public class ServerForge{
//     public static final String VERSION = "PRE-ALPHA 0.0.1";
// 
//     private EventManager eventManager;
//     private PermissionsManager permissionsManager;
//     private PluginLoader pluginLoader;
// 
//     private FMLServerStartingEvent serverStartingEvent;
// 
//     @Mod.Instance("ServerForge")
//     public static ServerForge instance;
// 
//     public static void info(String info){
//         System.out.println("[SERVERFORGE INFO]: " + info);
//     }
// 
//     public static void error(String error){
//         System.out.println("[SERVERFORGE ERROR]: " + error);
//     }
// 
//     @Mod.EventHandler
//     public void serverStartingEvent(FMLServerStartingEvent e){
//         info("Starting ServerForge...");
//         this.serverStartingEvent = e;
// 
//         eventManager = new EventManager();
//         eventManager.onServerStart();
// 
//         permissionsManager = new PermissionsManager();
//         permissionsManager.onServerStart();
// 
//         pluginLoader = new PluginLoader();
//         pluginLoader.onServerStart();
// 
//         this.serverStartingEvent = null;
//         info("ServerForge started");
//     }
// 
//     /**
//      * Registers a command for use in the server, can only be called from onServerStart() or it's submethods
//      * @param name The name of the command to add, to be used as the name to execute (ie. name = "example", to type in chat = "/example")
//      * @param command The command object to register
//      * @param aliases Array containing the aliases for this command
//      */
//     public void registerCommand(String name, ServerForgeCommand command, String[] aliases){
//         CommandWrapper wrapper = new CommandWrapper(name, command, aliases);
//         serverStartingEvent.registerServerCommand(wrapper);
//     }
// 
//     /**
//      * Registers a command for use in the server, can only be called from onServerStart() or it's submethods
//      * @param name The name of the command to add, to be used as the name to execute (ie. name = "example", to type in chat = "/example")
//      * @param command The command object to register
//      */
//     public void registerCommand(String name, ServerForgeCommand command){
//         registerCommand(name, command, new String[0]);
//     }
// 
//     /**
//      * Returns the plugin loader (the class responsible for the loading and management of plugins)
//      * @return the plugin loader
//      */
//     public PluginLoader getPluginLoader(){
//         return pluginLoader;
//     }
// 
//     /**
//      * Returns the event manager (the class responsible for the registering and calling of events)
//      * @return The event manager
//      */
//     public EventManager getEventManager(){
//         return eventManager;
//     }
// 
//     /**
//      * Returns the permissions manager (the class responsible for the setting and getting of player's permissions)
//      * @return the permissions manager
//      */
//     public PermissionsManager getPermissionsManager(){
//         return permissionsManager;
//     }
// 
//     /**
//      * Returns the Minecraft version running this server
//      * @return The Minecraft version running this server
//      */
//     public String getMinecraftVersion(){
//         return MinecraftForge.MC_VERSION;
//     }
// 
//     /**
//      * Returns all online players
//      * @return All online players
//      */
//     public ArrayList<Player> getOnlinePlayers(){
//         ArrayList<Player> list = new ArrayList<Player>();
// 
//         for(World world : MinecraftServer.getServer().worldServers){
//             for(Object o : world.playerEntities){
//                 EntityPlayerMP playerMP = ((EntityPlayerMP) o);
//                 Player player = Player.get(playerMP);
//                 list.add(player);
//             }
//         }
// 
//         return list;
//     }
// 
// }
// 
// Path: src/main/java/src/john01dav/serverforge/api/ServerForgePlugin.java
// public abstract class ServerForgePlugin{
//     public PluginWrapper wrapper;
// 
//     /**
//      * Called when the server loads
//      */
//     public abstract void onServerStart();
// 
//     /**
//      * Called when the server unloads
//      */
//     public abstract void onServerStop();
// 
// }
// 
// Path: src/main/java/src/john01dav/serverforge/plugin/ServerForgeDefaultPlugin.java
// public class ServerForgeDefaultPlugin extends ServerForgePlugin{
//     private PropertiesFile propertiesFile;
// 
//     @Override
//     public void onServerStart(){
//         try {
//             Properties defaultProperties = new Properties();
//             defaultProperties.setProperty("enableVersion", String.valueOf(true));
//             defaultProperties.setProperty("enablePlugins", String.valueOf(true));
// 
//             propertiesFile = new PropertiesFile(wrapper, "serverforgeplugin.properties", defaultProperties);
// 
//             if((Boolean.parseBoolean(propertiesFile.getProperties().getProperty("enableVersion")))){
//                 ServerForge.instance.registerCommand("version", new VersionCommand());
//             }
// 
//             if((Boolean.parseBoolean(propertiesFile.getProperties().getProperty("enablePlugins")))){
//                 ServerForge.instance.registerCommand("plugins", new PluginsCommand());
//             }
//         }catch(IOException e){
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public void onServerStop(){
// 
//     }
// 
// }


// Path: src/main/java/src/john01dav/serverforge/loader/PluginLoader.java
import com.google.common.io.Files;
import src.john01dav.serverforge.ServerForge;
import src.john01dav.serverforge.api.ServerForgePlugin;
import src.john01dav.serverforge.plugin.ServerForgeDefaultPlugin;
import java.io.File;
import java.io.IOException;
import java.net.*;
import java.util.ArrayList;

package src.john01dav.serverforge.loader;


public class PluginLoader{
    private ArrayList<PluginFile> pluginFile;
    private ArrayList<PluginWrapper> pluginWrapper;
    private URLClassLoader loader;
    private File pluginsFolder;

    public void onServerStart(){
        pluginsFolder = new File("./plugins");

        try {
            if (!pluginsFolder.isDirectory()) {
                Files.move(pluginsFolder, new File("./plugins-file"));
                pluginsFolder.delete();
            }

            if (!pluginsFolder.exists()) {
                pluginsFolder.mkdir();
            }
        }catch(IOException e){
            e.printStackTrace();
            System.exit(0);
        }

        pluginFile = new ArrayList<PluginFile>();
        pluginWrapper = new ArrayList<PluginWrapper>();
        ArrayList<URL> pluginURL = new ArrayList<URL>();

        ServerForge.info("Loading plugins...");