package com.namelessmc.NamelessBungee;

import com.namelessmc.namelessplugin.bungeecord.API.NamelessAPI;
import com.namelessmc.namelessplugin.bungeecord.API.UpdateChecker;
import com.namelessmc.namelessplugin.bungeecord.API.Utils.NamelessChat;
import com.namelessmc.namelessplugin.bungeecord.API.Utils.NamelessMessages;
import com.namelessmc.namelessplugin.bungeecord.commands.CommandWithArgs;
import com.namelessmc.namelessplugin.bungeecord.commands.alone.GetNotificationsCommand;
import com.namelessmc.namelessplugin.bungeecord.commands.alone.GetUserCommand;
import com.namelessmc.namelessplugin.bungeecord.commands.alone.RegisterCommand;
import com.namelessmc.namelessplugin.bungeecord.commands.alone.ReportCommand;
import com.namelessmc.namelessplugin.bungeecord.commands.alone.SetGroupCommand;
import com.namelessmc.namelessplugin.bungeecord.player.PlayerEventListener;

import net.md_5.bungee.api.plugin.Plugin;

public class NamelessPlugin extends Plugin {

	/*
	 * Instance
	 */
	private static NamelessPlugin instance;

	/*
	 * Plugin API
	 */
	private NamelessAPI api;

	/*
	 * API URL
	 */
	private String apiURL = "";
	private boolean hasSetUrl = false;

	/*
	 * NamelessMC permission string.
	 */

	public static final String permission = "namelessmc";
	public static final String permissionAdmin = "namelessmc.admin";

	@Override
	public void onLoad() {
		NamelessPlugin.instance = this;
	}

	/*
	 * OnEnable method
	 */
	@Override
	public void onEnable() {
		instance = this;

		// Register the API
		api = new NamelessAPI(this);

		// Init config files.
		api.getConfigManager().initializeFiles();

		if (hasSetUrl) {
			registerListeners();
		}
		if (getAPI().getConfigManager().getConfig().getBoolean("update-checker")) {
			checkForUpdate();
		} else {
			NamelessChat.sendToLog(NamelessMessages.PREFIX_WARNING, "&CIt is recommended to enable update checker.");
		}

	}

	public void checkForUpdate() {
		UpdateChecker updateChecker = new UpdateChecker(this);
		if (updateChecker.updateNeeded()) {
			for (String msg : updateChecker.getConsoleUpdateMessage()) {
				NamelessChat.sendToLog(NamelessMessages.PREFIX_WARNING, msg);
			}
		} else {
			NamelessChat.sendToLog(NamelessMessages.PREFIX_INFO, "&aFound no new updates!");
		}
	}

	/*
	 * Register Commands/Events
	 */
	public void registerListeners() {
		if (api.getConfigManager().getCommandsConfig().getBoolean("Commands.Alone.Use")
				&& api.getConfigManager().getCommandsConfig().getBoolean("Commands.SubCommand.Use")) {
			NamelessChat.sendToLog(NamelessMessages.PREFIX_WARNING,
					"&4ERROR REGISTERING COMMANDS! BOUTH IS SET TO TRUE!");
		} else if (api.getConfigManager().getCommandsConfig().getBoolean("Commands.Alone.Use")) {
			String register = api.getConfigManager().getCommandsConfig().getString("Commands.Alone.Register");
			String getUser = api.getConfigManager().getCommandsConfig().getString("Commands.Alone.GetUser");
			String getNotifications = api.getConfigManager().getCommandsConfig()
					.getString("Commands.Alone.GetNotifications");
			String setGroup = api.getConfigManager().getCommandsConfig().getString("Commands.Alone.SetGroup");
			String report = api.getConfigManager().getCommandsConfig().getString("Commands.Alone.Report");
			if (api.getConfigManager().getConfig().getBoolean("enable-registration")) {
				getProxy().getPluginManager().registerCommand(this, new RegisterCommand(this, register));
			}
			getProxy().getPluginManager().registerCommand(this, new GetUserCommand(this, getUser));
			getProxy().getPluginManager().registerCommand(this, new GetNotificationsCommand(this, getNotifications));
			getProxy().getPluginManager().registerCommand(this, new SetGroupCommand(this, setGroup));
			if (api.getConfigManager().getConfig().getBoolean("enable-reports")) {
				getProxy().getPluginManager().registerCommand(this, new ReportCommand(this, report));
			}
		} else if (api.getConfigManager().getCommandsConfig().getBoolean("Commands.SubCommand.Use")) {
			String subCommand = api.getConfigManager().getCommandsConfig().getString("Commands.SubCommand.Main");
			getProxy().getPluginManager().registerCommand(this, new CommandWithArgs(this, subCommand));
		} else {
			NamelessChat.sendToLog(NamelessMessages.PREFIX_WARNING, "&4ERROR REGISTERING COMMANDS!");
		}

		// Register events
		getProxy().getPluginManager().registerListener(this, new PlayerEventListener(this));
	}

	/*
	 * Get / Has / Set
	 */

	// Gets instance
	public static NamelessPlugin getInstance() {
		return instance;
	}

	// Gets the website api url.
	public String getAPIUrl() {
		return apiURL;
	}

	// Gets the Plugin API
	public NamelessAPI getAPI() {
		return api;
	}

	// Checks if hasSetUrl
	public boolean hasSetUrl() {
		return hasSetUrl;
	}

	// Sets HasSetUrl
	public void setHasSetUrl(boolean value) {
		hasSetUrl = value;
	}

	// Sets api url
	public void setAPIUrl(String value) {
		apiURL = value;
	}

}
@@ -962,30 +962,8 @@
  %7B%0A%0A
-%09/*%0A%09 * Instance%0A%09 */%0A
 %09pri
@@ -1004,80 +1004,8 @@
 e;%0A%0A
-%09/*%0A%09 * Plugin API%0A%09 */%0A%09private NamelessAPI api;%0A%0A%09/*%0A%09 * API URL%0A%09 */%0A
 %09pri
@@ -1070,52 +1070,8 @@
 e;%0A%0A
-%09/*%0A%09 * NamelessMC permission string.%0A%09 */%0A%0A
 %09pub
@@ -1265,37 +1265,8 @@
 %09%7D%0A%0A
-%09/*%0A%09 * OnEnable method%0A%09 */%0A
 %09@Ov
@@ -2085,46 +2085,8 @@
 %09%7D%0A%0A
-%09/*%0A%09 * Register Commands/Events%0A%09 */%0A
 %09pub
@@ -4188,38 +4188,9 @@
 %0A%09%7D%0A
-%0A%09/*%0A%09 * Get / Has / Set%0A%09 */%0A
+%09
 %0A%09//

Remove useless comments and api instance