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 {

	private static NamelessPlugin instance;

	private String apiURL = "";
	private boolean hasSetUrl = false;

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

	@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!");
		}
	}

	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));
	}
	
	// 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;
	}

}
@@ -1647,373 +1647,8 @@
 %09%7D%0A%0A
-%09public void checkForUpdate() %7B%0A%09%09UpdateChecker updateChecker = new UpdateChecker(this);%0A%09%09if (updateChecker.updateNeeded()) %7B%0A%09%09%09for (String msg : updateChecker.getConsoleUpdateMessage()) %7B%0A%09%09%09%09NamelessChat.sendToLog(NamelessMessages.PREFIX_WARNING, msg);%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09%09%09NamelessChat.sendToLog(NamelessMessages.PREFIX_INFO, %22&aFound no new updates!%22);%0A%09%09%7D%0A%09%7D%0A%0A
 %09pub
@@ -3752,26 +3752,8 @@
 %7D%0A%09%0A
-%09// Gets instance%0A
 %09pub
@@ -3821,401 +3821,5 @@
 %09%7D%0A%0A
-%09// Gets the website api url.%0A%09public String getAPIUrl() %7B%0A%09%09return apiURL;%0A%09%7D%0A%0A%09// Gets the Plugin API%0A%09public NamelessAPI getAPI() %7B%0A%09%09return api;%0A%09%7D%0A%0A%09// Checks if hasSetUrl%0A%09public boolean hasSetUrl() %7B%0A%09%09return hasSetUrl;%0A%09%7D%0A%0A%09// Sets HasSetUrl%0A%09public void setHasSetUrl(boolean value) %7B%0A%09%09hasSetUrl = value;%0A%09%7D%0A%0A%09// Sets api url%0A%09public void setAPIUrl(String value) %7B%0A%09%09apiURL = value;%0A%09%7D%0A%0A
 %7D

Remove more useless code