/*
 * Copyright (c) 2016 MCPhoton <http://mcphoton.org> and contributors.
 *
 * This file is part of the Photon Server Implementation <https://github.com/mcphoton/Photon-Server>.
 *
 * The Photon Server Implementation is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * The Photon Server Implementation is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.mcphoton;

import java.io.File;
import java.util.concurrent.ScheduledExecutorService;
import org.mcphoton.command.GlobalCommandRegistry;
import org.mcphoton.event.GlobalEventsManager;
import org.mcphoton.impl.GameRegistryImpl;
import org.mcphoton.impl.command.GlobalCommandRegistryImpl;
import org.mcphoton.impl.event.GlobalEventsManagerImpl;
import org.mcphoton.impl.permissions.GlobalPermissionsManagerImpl;
import org.mcphoton.impl.plugin.GlobalPluginsManagerImpl;
import org.mcphoton.impl.server.Main;
import org.mcphoton.permissions.GlobalPermissionsManager;
import org.mcphoton.plugin.GlobalPluginsManager;
import org.mcphoton.server.Server;

/**
 * Implementation of the Photon's class, which is the centralized API core.
 *
 * @author TheElectronWill
 */
public final class Photon {

	public static final File MAIN_DIR = new File(System.getProperty("user.dir")),
			PLUGINS_DIR = new File(MAIN_DIR, "plugins"),
			WORLDS_DIR = new File(MAIN_DIR, "worlds");
	private static final GameRegistry GAME_REGISTRY = new GameRegistryImpl();
	private static final GlobalCommandRegistry COMMAND_REGISTRY = new GlobalCommandRegistryImpl();
	private static final GlobalPluginsManager PLUGINS_MANAGER = new GlobalPluginsManagerImpl();
	private static final GlobalEventsManager EVENTS_MANAGER = new GlobalEventsManagerImpl();
	private static final GlobalPermissionsManager PERM_MANAGER = new GlobalPermissionsManagerImpl();
	private static final boolean CONSOLE_ADVANCED = !System.getProperty("os.name")
														   .toLowerCase()
														   .contains("windows");

	private Photon() {}

	/**
	 * Gets the Photon's ScheduledExecutorService, which is used to schedule tasks across multiple
	 * threads.
	 * <h2>What kind of task may be submitted to this ExecutorService?</h2>
	 * <p>
	 * To achieve better performance, the submitted tasks:
	 * <ol>
	 * <li>Musn't be IO-bound, in order to avoid delaying the other tasks. Use an asynchronous IO
	 * API instead of the ExecutorService.</li>
	 * <li>Musn't be too short, in order to avoid creating too much overhead. It is advised to group
	 * many small tasks together into one bigger task.</li>
	 * </ol>
	 * </p>
	 */
	public static ScheduledExecutorService getExecutorService() {
		return Main.SERVER.executorService.get();
	}

	public static GlobalPermissionsManager getGlobalPermissionsManager() {
		return PERM_MANAGER;
	}

	public static GlobalPluginsManager getGlobalPluginsManager() {
		return PLUGINS_MANAGER;
	}

	public static GlobalCommandRegistry getGlobalCommandRegistry() {
		return COMMAND_REGISTRY;
	}

	public static GlobalEventsManager getGlobalEventsManager() {
		return EVENTS_MANAGER;
	}

	public static GameRegistry getGameRegistry() {
		return GAME_REGISTRY;
	}

	public static boolean isClient() {
		return false;
	}

	public static boolean isServer() {
		return true;
	}

	public static boolean isConsoleAdvanced() {
		return CONSOLE_ADVANCED;
	}

	public static String getVersion() {
		return "dev-alpha";
	}

	public static String getMinecraftVersion() {
		return "1.11";
	}

	public static File getMainDirectory() {
		return MAIN_DIR;
	}

	public static File getPluginsDirectory() {
		return PLUGINS_DIR;
	}

	public static Server getServer() {
		return Main.SERVER;
	}
}
@@ -1402,16 +1402,60 @@
 r.Main;%0A
+import org.mcphoton.impl.server.ServerImpl;%0A
 import o
@@ -1496,32 +1496,32 @@
 issionsManager;%0A
-
 import org.mcpho
@@ -1556,43 +1556,8 @@
 ger;
-%0Aimport org.mcphoton.server.Server;
 %0A%0A/*
@@ -1697,16 +1697,149 @@
 oton %7B%0A%0A
+%09private static final boolean CONSOLE_ADVANCED = !System.getProperty(%22os.name%22).toLowerCase()%0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09   .contains(%22windows%22);%0A
 %09public 
@@ -2481,134 +2481,52 @@
 nal 
-boolean CONSOLE_ADV
+ServerImpl SERVER_INST
 ANCE
-D
  = 
-!System.getProperty(%22os.name%22)%0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09   .toLowerCase()%0A%09%09%09%09%09%09%09%09%09%09%09%09%09%09   .contains(%22windows%22
+new ServerImpl(
 );%0A%0A
@@ -3198,27 +3198,31 @@
 %09return 
-Main.
 SERVER
+_INSTANCE
 .executo
@@ -3233,14 +3233,8 @@
 vice
-.get()
 ;%0A%09%7D
@@ -4164,16 +4164,20 @@
 c Server
+Impl
  getServ
@@ -4196,19 +4196,23 @@
 urn 
-Main.
 SERVER
+_INSTANCE
 ;%0A%09%7D

Create the server instance in Photon.java (impl)