public class Config {

	public static List<Component> getAdventureMessages(String category, String message) {
		MethodInterface mi = Universal.get().getMethods();
		return getAdventureMessages(category, message, mi.getMessagesConfig());
	}

	public static List<Component> getAdventureMessages(String category, String message, Object fileConfiguration) {
		MethodInterface mi = Universal.get().getMethods();
		List<Component> componentList = new ArrayList<>();
		for (String individualMessage : mi.getOldMessages(category, message, fileConfiguration)) {
			Component a = LegacyComponentSerializer.legacy(mi.getChatComponentChar()).deserialize(individualMessage);
			componentList.add(MiniMessage.get().parse(MiniMessage.get().serialize(a)));
		}
		return componentList;
	}

	public static Component getAdventureMessage(String category, String message) {
		Component result = null;
		for (Component component : getAdventureMessages(category, message)) {
			result = component;
			break;
		}
		return result;
	}

} public class Log {

	public static void addLog(MethodInterface mi, String s) {
		try {
			List<String> log = getLog(mi);
			if (log == null) {
				mi.log(s);
				mi.log("&cTrey's Command Blocker: Could not access log.txt!");
				return;
			}
			Path file = Paths.get(mi.getDataFolder() + "/log.txt");
			LocalDateTime time = LocalDateTime.now();
			String month = time.getMonth().toString().substring(0, 3);
			int year = time.getYear();
			int day = time.getDayOfMonth();
			String hour = time.getHour() + "";
			if (hour.length() == 1) {
				hour = "0" + hour;
			}
			String minute = time.getMinute() + "";
			if (minute.length() == 1) {
				minute = "0" + minute;
			}
			String second = time.getSecond() + "";
			if (second.length() == 1) {
				second = "0" + second;
			}
			log.add("[" + month + " " + day + ", " + year + " | " + hour + ":" + minute + ":" + second + "] " + s);
			Files.write(file, log, StandardCharsets.UTF_8);
			return;
		} catch (IOException e) {
			e.printStackTrace();
		}
		mi.log(s);
		mi.log("&cTrey's Command Blocker: Could not access log.txt!");

	}
	
	public static List<String> getLog(MethodInterface mi) {
		try {
			File log = new File(mi.getDataFolder(), "log.txt");
			if (!log.exists()) {
				log.createNewFile();
			}
			Path file = Paths.get(mi.getDataFolder() + "/log.txt");
			return Files.readAllLines(file, StandardCharsets.UTF_8);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
} public interface MethodInterface {

	Object getPlugin();

	Object getConfig();
	Object getDisabledCommandsConfig();
	Object getMessagesConfig();
	Object getOpBlockConfig();

	void saveConfig();
	void saveDisabledCommandsConfig();
	void saveMessagesConfig();
	void saveOpBlockConfig();

	File getConfigFile(Object configurationFile);

	String getVersion();
	
	String getServerType();
	
	File getDataFolder();
	
    void setupMetrics();

	void executeCommand(String cmd);

    void sendMessage(Object commandSender, Component message);

    List<String> getOldMessages(String category, String message);
    List<String> getOldMessages(String category, String message, Object configurationFile);

    Character getChatComponentChar();

    String getOldMessage(String category, String message);
    String getOldMessage(String category, String message, Object configurationFile);
	
    void log(String msg);
} public class Universal {

	private static Universal instance = null;
	private MethodInterface mi;
	
	public static Universal get() {
		return instance == null ? instance = new Universal() : instance;
	}
	
	public void setup(MethodInterface mi) {
		this.mi = mi;
		
		mi.setupMetrics();
	}
	
	public MethodInterface getMethods() {
        return mi;
    }
	
} public class BukkitMain extends JavaPlugin {

	private static BukkitMain instance;

	public static BukkitMain get() {
		return instance;
	}

	private static BukkitAudiences adventure;

	public static @NotNull BukkitAudiences adventure() {
		if (adventure == null) {
			throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
		}
		return adventure;
	}

	@Override
	public void onEnable() {
		if (needGson())
			return;
		if (!sendOldMessages())
			adventure = BukkitAudiences.create(this);
		instance = this;
		Universal.get().setup(new BukkitMethods());

		getServer().getPluginManager().registerEvents(new Update(), this);
		getServer().getPluginManager().registerEvents(new BukkitBlock(), this);
		getServer().getPluginManager().registerEvents(new CommandValueListener(), this);
		getServer().getPluginManager().registerEvents(new DisabledGui(), this);
    	if (newBlocks()) {
      		getServer().getPluginManager().registerEvents(new NewTabCompletionListener(), this);
		}
		loadConfigManager();

		new BukkitUpdateConfig().setup();
		Objects.requireNonNull(getCommand("cb")).setExecutor(new CommandBlockerCmd());
		Objects.requireNonNull(getCommand("cb")).setTabCompleter(new CommandBlockerTabComplete());
		Objects.requireNonNull(getCommand("commandblocker")).setExecutor(new CommandBlockerCmd());
		Objects.requireNonNull(getCommand("commandblocker")).setTabCompleter(new CommandBlockerTabComplete());
		if (Bukkit.getPluginManager().isPluginEnabled("ProtocolLib")) {
			Packets.protocol(this);
		}
		new UpdateManager().setup();
		Update.updateCheck();
		fixCommands();
	}

	@Override
	public void onDisable() {
		if (adventure != null) {
			adventure.close();
			adventure = null;
		}
	}

	public static Boolean isPapiEnabled() {
		return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI");
	}
	
	public void loadConfigManager() {
		if (!oldConfig()) {
			ConfigManager.reloadConfig();
			ConfigManager.reloadDisabled();
			ConfigManager.reloadOpDisabled();
			ConfigManager.reloadMessages();
		} else {
			OldConfigManager.reloadConfig();
			OldConfigManager.reloadDisabled();
			OldConfigManager.reloadOpDisabled();
			OldConfigManager.reloadMessages();
		}
	}

	public static String getBukkitVersion() {
		return Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
	}

	public static void fixCommands() {
		ConfigurationSection configuration = oldConfig() ? OldConfigManager.getDisabled().getConfigurationSection(
				"DisabledCommands") : ConfigManager.getDisabled().getConfigurationSection("DisabledCommands");
		if (configuration != null) {
			for (String cmds : configuration.getKeys(false)) {
				String path = cmds.substring(0, 1).toUpperCase() + cmds.substring(1).toLowerCase();
				if (!Character.isLetter(cmds.charAt(0))) {
					return;
				}
				if (!Character.isUpperCase(cmds.charAt(0))) {
					configuration.set(path, configuration.get(cmds));
					configuration.set(cmds, null);
					if (oldConfig()) {
						OldConfigManager.saveDisabled();
					} else {
						ConfigManager.saveDisabled();
					}
				}
				if (!cmds.substring(1).equals(cmds.substring(1).toLowerCase())) {
					configuration.set(path, configuration.get(cmds));
					configuration.set(cmds, null);
					if (oldConfig()) {
						OldConfigManager.saveDisabled();
					} else {
						ConfigManager.saveDisabled();
					}
				}
			}
		}
		ConfigurationSection opBlockConfiguration = oldConfig() ?
				OldConfigManager.getOpDisabled().getConfigurationSection(
				"DisabledOpCommands") : ConfigManager.getOpDisabled().getConfigurationSection("DisabledOpCommands");
		if (opBlockConfiguration != null) {
			for (String cmds : opBlockConfiguration.getKeys(false)) {
				String path = cmds.substring(0, 1).toUpperCase() + cmds.substring(1).toLowerCase();
				if (!Character.isLetter(cmds.charAt(0))) {
					return;
				}
				if (!Character.isUpperCase(cmds.charAt(0))) {
					opBlockConfiguration.set(path, opBlockConfiguration.get(cmds));
					opBlockConfiguration.set(cmds, null);
					if (oldConfig()) {
						OldConfigManager.saveOpDisabled();
					} else {
						ConfigManager.saveOpDisabled();
					}
				}
				if (!cmds.substring(1).equals(cmds.substring(1).toLowerCase())) {
					opBlockConfiguration.set(path, opBlockConfiguration.get(cmds));
					opBlockConfiguration.set(cmds, null);
					if (oldConfig()) {
						OldConfigManager.saveOpDisabled();
					} else {
						ConfigManager.saveOpDisabled();
					}
				}
			}
		}
	}

	public static boolean newBlocks() {
		if (legacyVersion()) return false;
		switch (getBukkitVersion()) {
			case "v1_7_R1":
			case "v1_7_R2":
			case "v1_7_R3":
			case "v1_7_R4":
			case "v1_8_R1":
			case "v1_8_R2":
			case "v1_8_R3":
			case "v1_9_R1":
			case "v1_9_R2":
			case "v1_10_R1":
			case "v1_11_R1":
			case "v1_12_R1":
				return false;
			default:
				return true;
		}
	}

	public static boolean oldConfig() {
		if (legacyVersion()) return true;
		if (getBukkitVersion().equals("v1_7_R1")) {
			return true;
		}
		return false;
	}

	public static boolean sendOldMessages() {
		if (legacyVersion())
			return true;
		switch (getBukkitVersion()) {
			case "v1_7_R1":
			case "v1_7_R2":
			case "v1_7_R3":
				return true;
			default:
				return false;
		}
	}

	public static boolean customSkulls() {
		if (sendOldMessages())
			return false;
		if (getBukkitVersion().equals("v1_7_R4"))
			return false;
		return true;
	}

	private static boolean legacyVersion() {
		switch (getBukkitVersion()) {
			case "v1_4_R1":
			case "v1_5_R1":
			case "v1_5_R2":
			case "v1_5_R3":
			case "v1_6_R1":
			case "v1_6_R2":
			case "v1_6_R3":
				return true;
			default:
				return false;
		}
	}

	public static boolean coloredGlassPane() {
		return !legacyVersion();
	}

	private boolean needGson() {
		try {
			Class.forName("com.google.gson.JsonElement");
			if (oldConfig())
				Class.forName("me.treyruffy.commandblockerlegacy.OldConfigManager");
			return false;
		} catch (ClassNotFoundException ignored) {
		}
		Bukkit.getLogger().log(Level.SEVERE,
				"Trey's Command Blocker needs Trey's Command Blocker Legacy to run on your server version" +
						". Please download at https://www.spigotmc.org/resources/command-blocker-legacy.82948/");
		getPluginLoader().disablePlugin(this);
		return true;
	}

} public class Variables {

	public static String translateVariablesToString(String msg, CommandSender commandSender,
													HashMap<String, String> additionalPlaceholders,
													boolean excludePlayerPlaceholder) {
		if (commandSender instanceof Player) {
			Player p = (Player) commandSender;
			if (!excludePlayerPlaceholder) {
				msg = msg.replace("%player%", p.getName())
						.replace("%username%", p.getDisplayName())
						.replace("%displayname%", p.getDisplayName());
			}
			msg = msg.replace("%uuid%", p.getUniqueId().toString())
					.replace("%isop%", String.valueOf(p.isOp()))
					.replace("%server_name%", p.getServer().getName())
					.replace("%server_ip%", p.getServer().getIp())
					.replace("%server_port%", String.valueOf(p.getServer().getPort()))
					.replace("%world%", p.getWorld().getName());
			if (BukkitMain.isPapiEnabled()) {
				msg = PlaceholderAPI.setPlaceholders((Player) commandSender, msg);
			}
		} else {
			msg = msg.replace("%server_name%", BukkitMain.get().getServer().getName())
					.replace("%server_ip%", BukkitMain.get().getServer().getIp())
					.replace("%server_port%", String.valueOf(BukkitMain.get().getServer().getPort()));
		}

		if (additionalPlaceholders != null) {
			for (String placeholder : additionalPlaceholders.keySet()) {
				msg = msg.replace(placeholder, additionalPlaceholders.get(placeholder));
			}
		}
		return msg;
	}

	public static String translateVariablesToString(String msg, CommandSender commandSender) {
		return translateVariablesToString(msg, commandSender, null, false);
	}

	public static Component translateVariables(String msg, CommandSender commandSender,
											   HashMap<String, String> additionalPlaceholders,
											   boolean excludePlayerPlaceholder) {

		msg = translateVariablesToString(msg, commandSender, additionalPlaceholders, excludePlayerPlaceholder);
		return MiniMessage.get().parse(msg);
	}

	public static Component translateVariables(String msg, CommandSender commandSender,
											   HashMap<String, String> additionalPlaceholders) {
		return translateVariables(msg, commandSender, additionalPlaceholders, false);
	}

	public static Component translateVariables(String msg, CommandSender commandSender) {
		return translateVariables(msg, commandSender, null, false);
	}

	public static Component translateVariablesWithComponentPlaceholders(String msg, CommandSender commandSender,
																		HashMap<String, String> additionalPlaceholders,
																		HashMap<String, Component> additionalComponentPlaceholders) {
		msg = translateVariablesToString(msg, commandSender, additionalPlaceholders, false);
		if (additionalComponentPlaceholders != null) {
			for (String placeholder : additionalComponentPlaceholders.keySet()) {
				msg = msg.replace(placeholder,
						MiniMessage.get().serialize(additionalComponentPlaceholders.get(placeholder)) + "<reset>");
			}
		}
		return MiniMessage.get().parse(msg);
	}


	public static String translateVariablesToLegacyString(String msg, CommandSender commandSender) {
		Component translatedComponent = translateVariables(msg, commandSender);
		return LegacyComponentSerializer.legacy(ChatColor.COLOR_CHAR).serialize(translatedComponent);
	}

} @SuppressWarnings("unused")
public class BlockedCommands {

	/**
	 *  Allows you to save the blocked command list
	 * @return If the blocked command list was saved
	 */
	public static boolean saveBlockedCommandList() {
		try {
			if (BukkitMain.oldConfig())
				OldConfigManager.saveDisabled();
			else
				ConfigManager.saveDisabled();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * Allows you to add a command to be blocked
	 * @param command The command name without "/"
	 * @param permission The permission for players to have the command unblocked for them
	 * @param message The message displayed when the player executes the command
	 * @param worlds The worlds that the command should be blocked in. Can be all
	 * @param playerCommands Any commands to be executed by the player if they execute the command
	 * @param consoleCommands Any commands to be executed by the console if a player executes the command
	 * @return If the command was successfully added to the block list
	 */
	public static boolean addBlockedCommand(String command, String permission, String message, List<String> worlds, List<String> playerCommands, List<String> consoleCommands) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}

		if (!disabled.contains("DisabledCommands." + cmd)) {
			if (permission != null) {
				disabled.set("DisabledCommands." + cmd + ".Permission", permission);
			}
			if (message != null) {
				disabled.set("DisabledCommands." + cmd + ".Message", message.replace(ChatColor.COLOR_CHAR, '&'));
			}
			if (worlds != null) {
				disabled.set("DisabledCommands." + cmd + ".Worlds", worlds);
			}
			if (playerCommands != null) {
				disabled.set("DisabledCommands." + cmd + ".PlayerCommands", playerCommands);
			}
			if(consoleCommands != null) {
				disabled.set("DisabledCommands." + cmd + ".ConsoleCommands", consoleCommands);
			}
			
			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to edit the permission of the blocked command
	 * @param command The command to change the permission of without /
	 * @param permission The new permission
	 * @return If the permission was successfully changed
	 */
	public static boolean editBlockedCommandPermission(String command, String permission) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd) && permission != null) {
			disabled.set("DisabledCommands." + cmd + ".Permission", permission);
			
			saveBlockedCommandList();
			return true;
		} 
		return false;
	}

	/**
	 * Allows you to edit the message displayed when a player types the blocked command
	 * @param command The command to change the message of without the /
	 * @param message The new message to be displayed when a player types the command
	 * @return If the message was successfully changed
	 */
	public static boolean editBlockedCommandMessage(String command, String message) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		if (disabled.contains("DisabledCommands." + cmd) && message != null) {
			disabled.set("DisabledCommands." + cmd + ".Message", message.replace(ChatColor.COLOR_CHAR, '&'));

			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to edit the worlds which the blocked command will be blocked
	 * @param command The command without /
	 * @param worlds The worlds which the command will be blocked in
	 * @return If the worlds were successfully changed
	 */
	public static boolean editBlockedCommandWorlds(String command, List<String> worlds) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd) && worlds != null) {
			disabled.set("DisabledCommands." + cmd + ".Worlds", worlds);

			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to change the player commands executed when the player executes the blocked command
	 * @param command The command without /
	 * @param playerCommands The player commands without / to execute when the player executes the blocked command
	 * @return If the player commands were successfully changed
	 */
	public static boolean editBlockedCommandPlayerCommands(String command, List<String> playerCommands) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd) && playerCommands != null) {
			disabled.set("DisabledCommands." + cmd + ".PlayerCommands", playerCommands);

			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to change the console commands executed when the player executes the blocked command
	 * @param command The command without /
	 * @param consoleCommands The console commands without / to execute when the player executes the blocked command
	 * @return If the console commands were successfully changed
	 */
	public static boolean editBlockedCommandConsoleCommands(String command, List<String> consoleCommands) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd) && consoleCommands != null) {
			disabled.set("DisabledCommands." + cmd + ".ConsoleCommands", consoleCommands);

			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to get the permission of a blocked command
	 * @param command The blocked command without /
	 * @return The permission
	 */
	public static String getBlockedCommandPermission(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd)) {
			FileConfiguration getDisabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
			if ((getDisabled.getString("DisabledCommands." + cmd + ".Permission") != null) && !(getDisabled.getString("DisabledCommands." + cmd + ".Permission").equalsIgnoreCase("default"))) {
				return getDisabled.getString("DisabledCommands." + cmd + ".Permission");
			}
			FileConfiguration getConfig = BukkitMain.oldConfig() ? OldConfigManager.getConfig() : ConfigManager.getConfig();
			return (getConfig.getString("Default.Permission")).replace("%command%", cmd.toLowerCase());
		}
		return null;
	}

	/**
	 * Allows you to get the message of a blocked command
	 * @param command The blocked command without /
	 * @return The message
	 */
	public static String getBlockedCommandMessage(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd)) {
			FileConfiguration getDisabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
			if ((getDisabled.getString("DisabledCommands." + cmd + ".Message") != null) && !(getDisabled.getString("DisabledCommands." + cmd + ".Message").equalsIgnoreCase("default"))) {
				return getDisabled.getString("DisabledCommands." + cmd + ".Message");
			}
			FileConfiguration getConfig = BukkitMain.oldConfig() ? OldConfigManager.getConfig() : ConfigManager.getConfig();
			return getConfig.getString("Default.Message");
		}
		return null;
	}

	/**
	 * Allows you to get the worlds of a blocked command
	 * @param command The blocked command without /
	 * @return The worlds
	 */
	public static List<String> getBlockedCommandWorlds(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd)) {
			FileConfiguration getDisabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
			if (getDisabled.getString("DisabledCommands." + cmd + ".Worlds") != null) {
				return getDisabled.getStringList("DisabledCommands." + cmd + ".Worlds");
			}
			List<String> worlds = new ArrayList<>();
			worlds.add("all");
			return worlds;
		}
		return null;
	}

	/**
	 * Allows you to get the player commands executed of a blocked command
	 * @param command The blocked command without /
	 * @return The player commands
	 */
	public static List<String> getBlockedCommandPlayerCommands(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd)) {
			FileConfiguration getDisabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
			if (getDisabled.getString("DisabledCommands." + cmd + ".PlayerCommands") != null) {
				return getDisabled.getStringList("DisabledCommands." + cmd + ".PlayerCommands");
			}
			List<String> cmds = new ArrayList<>();
			cmds.add("none");
			return cmds;
		}
		return null;
	}

	/**
	 * Allows you to get the console commands executed of a blocked command
	 * @param command The blocked command without /
	 * @return The console commands
	 */
	public static List<String> getBlockedCommandConsoleCommands(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd)) {
			FileConfiguration getDisabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
			if (getDisabled.getString("DisabledCommands." + cmd + ".ConsoleCommands") != null) {
				return getDisabled.getStringList("DisabledCommands." + cmd + ".ConsoleCommands");
			}
			List<String> cmds = new ArrayList<>();
			cmds.add("none");
			return cmds;
		}
		return null;
	}

	/**
	 * Allows you to remove a blocked command
	 * @param command The command to be removed
	 * @return If the command was removed successfully
	 */
	public static boolean removeBlockedCommand(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledCommands." + cmd)) {
			disabled.set("DisabledCommands." + cmd, null);
			
			if (!BukkitMain.oldConfig()) {
				ConfigManager.saveDisabled();
			} else {
				OldConfigManager.saveDisabled();
			}
			return true;
		}
		return false;
	}

	/**
	 * Gets all blocked commands
	 * @return The blocked commands
	 */
	public static Set<String> getBlockedCommands() {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getDisabled() : ConfigManager.getDisabled();
		ConfigurationSection cs = disabled.getConfigurationSection("DisabledCommands");
		assert cs != null;
		return cs.getKeys(false);
	}
} public class BlockedOpCommands {

	/**
	 *  Allows you to save the op blocked command list
	 * @return If the op blocked command list was saved
	 */
	public static boolean saveBlockedCommandList() {
		try {
			if (BukkitMain.oldConfig())
				OldConfigManager.saveOpDisabled();
			else
				ConfigManager.saveOpDisabled();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	/**
	 * Allows you to add a command to be blocked for operators
	 * @param command The command name without "/"
	 * @param message The message displayed when the player executes the command
	 * @param worlds The worlds that the command should be blocked in. Can be all
	 * @param playerCommands Any commands to be executed by the player if they execute the command
	 * @param consoleCommands Any commands to be executed by the console if a player executes the command
	 * @return If the command was successfully added to the block list
	 */
	public static boolean addBlockedCommand(String command, String message, List<String> worlds, List<String> playerCommands, List<String> consoleCommands) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}

		if (!disabled.contains("DisabledOpCommands." + cmd)) {
			if (message != null) {
				disabled.set("DisabledOpCommands." + cmd + ".Message", message.replace("§", "&"));
			}
			if (worlds != null) {
				disabled.set("DisabledOpCommands." + cmd + ".Worlds", worlds);
			}
			if (playerCommands != null) {
				disabled.set("DisabledOpCommands." + cmd + ".PlayerCommands", playerCommands);
			}
			if(consoleCommands != null) {
				disabled.set("DisabledOpCommands." + cmd + ".ConsoleCommands", consoleCommands);
			}
			
			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to edit the message displayed when a operator types the blocked command
	 * @param command The command to change the message of without the /
	 * @param message The new message to be displayed when a operator types the command
	 * @return If the message was successfully changed
	 */
	public static boolean editBlockedCommandMessage(String command, String message) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		if (disabled.contains("DisabledOpCommands." + cmd) && message != null) {
			disabled.set("DisabledOpCommands." + cmd + ".Message", message.replace("§", "&"));

			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to edit the worlds which the blocked command will be blocked
	 * @param command The command without /
	 * @param worlds The worlds which the command will be blocked in
	 * @return If the worlds were successfully changed
	 */
	public static boolean editBlockedCommandWorlds(String command, List<String> worlds) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}

		if (disabled.contains("DisabledOpCommands." + cmd) && worlds != null) {
			disabled.set("DisabledOpCommands." + cmd + ".Worlds", worlds);

			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to change the player commands executed when the operator executes the blocked command
	 * @param command The command without /
	 * @param playerCommands The player commands without / to execute when the operator executes the blocked command
	 * @return If the player commands were successfully changed
	 */
	public static boolean editBlockedCommandPlayerCommands(String command, List<String> playerCommands) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledOpCommands." + cmd) && playerCommands != null) {
			disabled.set("DisabledOpCommands." + cmd + ".PlayerCommands", playerCommands);

			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to change the console commands executed when the operator executes the blocked command
	 * @param command The command without /
	 * @param consoleCommands The console commands without / to execute when the operator executes the blocked command
	 * @return If the console commands were successfully changed
	 */
	public static boolean editBlockedCommandConsoleCommands(String command, List<String> consoleCommands) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledOpCommands." + cmd) && consoleCommands != null) {
			disabled.set("DisabledOpCommands." + cmd + ".ConsoleCommands", consoleCommands);

			saveBlockedCommandList();
			return true;
		}
		return false;
	}

	/**
	 * Allows you to get the message of a blocked command
	 * @param command The blocked command without /
	 * @return The message
	 */
	public static String getBlockedCommandMessage(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledOpCommands." + cmd)) {
			if ((disabled.getString("DisabledOpCommands." + cmd + ".Message") != null) && !(disabled.getString("DisabledOpCommands." + cmd + ".Message").equalsIgnoreCase("default"))) {
				return disabled.getString("DisabledOpCommands." + cmd + ".Message");
			}
			FileConfiguration getConfig = BukkitMain.oldConfig() ? OldConfigManager.getConfig() : ConfigManager.getConfig();
			return getConfig.getString("Default.Message");
		}
		return null;
	}

	/**
	 * Allows you to get the worlds of a blocked command
	 * @param command The blocked command without /
	 * @return The worlds
	 */
	public static List<String> getBlockedCommandWorlds(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledOpCommands." + cmd)) {
			if (disabled.getString("DisabledOpCommands." + cmd + ".Worlds") != null) {
				return disabled.getStringList("DisabledOpCommands." + cmd + ".Worlds");
			}
			List<String> worlds = new ArrayList<>();
			worlds.add("all");
			return worlds;
		}
		return null;
	}

	/**
	 * Allows you to get the player commands executed of a blocked command
	 * @param command The blocked command without /
	 * @return The player commands
	 */
	public static List<String> getBlockedCommandPlayerCommands(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledOpCommands." + cmd)) {
			if (disabled.getString("DisabledOpCommands." + cmd + ".PlayerCommands") != null) {
				return disabled.getStringList("DisabledOpCommands." + cmd + ".PlayerCommands");
			}
			List<String> cmds = new ArrayList<>();
			cmds.add("none");
			return cmds;
		}
		return null;
	}

	/**
	 * Allows you to get the console commands executed of a blocked command
	 * @param command The blocked command without /
	 * @return The console commands
	 */
	public static List<String> getBlockedCommandConsoleCommands(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledOpCommands." + cmd)) {
			if (disabled.getString("DisabledOpCommands." + cmd + ".ConsoleCommands") != null) {
				return disabled.getStringList("DisabledOpCommands." + cmd + ".ConsoleCommands");
			}
			List<String> cmds = new ArrayList<>();
			cmds.add("none");
			return cmds;
		}
		return null;
	}

	/**
	 * Allows you to remove a blocked command
	 * @param command The command to be removed
	 * @return If the command was removed successfully
	 */
	public static boolean removeBlockedCommand(String command) {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		String cmd = command;
		if (Character.isLetter(command.charAt(0))) {
			cmd = command.substring(0, 1).toUpperCase() + command.substring(1).toLowerCase();
		}
		
		if (disabled.contains("DisabledOpCommands." + cmd)) {
			disabled.set("DisabledOpCommands." + cmd, null);
			
			if (!BukkitMain.oldConfig()) {
				ConfigManager.saveOpDisabled();
			} else {
				OldConfigManager.saveOpDisabled();
			}
			return true;
		}
		return false;
	}

	/**
	 * Gets all blocked commands for operators
	 * @return The blocked commands
	 */
	public static Set<String> getBlockedCommands() {
		FileConfiguration disabled = BukkitMain.oldConfig() ? OldConfigManager.getOpDisabled() : ConfigManager.getOpDisabled();
		ConfigurationSection cs = disabled.getConfigurationSection("DisabledOpCommands");
		assert cs != null;
		return cs.getKeys(false);
	}
} public class ConfigManager {

	private static final BukkitMain plugin = BukkitMain.get();

	public static FileConfiguration MainConfig;
	public static File MainConfigFile;

	public static FileConfiguration MainDisabled;
	public static File MainDisabledFile;

	public static FileConfiguration OpDisabled;
	public static File OpDisabledFile;

	public static FileConfiguration Messages;
	public static File MessagesFile;

	public static File getFileFromConfig(FileConfiguration configuration) {
		if (configuration.equals(MainConfig)) {
			return MainConfigFile;
		}
		if (configuration.equals(MainDisabled)) {
			return MainDisabledFile;
		}
		if (configuration.equals(OpDisabled)) {
			return OpDisabledFile;
		}
		if (configuration.equals(Messages)) {
			return MessagesFile;
		}
		return null;
	}

	public static FileConfiguration getConfig() {
		if (MainConfig == null) {
			reloadConfig();
		}
		return MainConfig; 
	}
	public static FileConfiguration getDisabled() {
		if (MainDisabled == null) {
			reloadDisabled();
		}
		return MainDisabled;
	}

	public static FileConfiguration getOpDisabled() {
		if (OpDisabled == null) {
			reloadOpDisabled();
		}
		return OpDisabled;
	}

	public static FileConfiguration getMessages() {
		if (Messages == null) {
			reloadMessages();
		}
		return Messages;
	}

	public static void saveConfig() {
		if (MainConfig == null) {
			throw new NullArgumentException("Cannot save a non-existent file!");
		}
		try {
			MainConfig.save(MainConfigFile);
		} catch (IOException e) {
			Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save " + MainConfigFile + ".", e);
		}
	}
	public static void saveDisabled() {
		if (MainDisabled == null) {
			throw new NullArgumentException("Cannot save a non-existent file!");
		}
		try {
			MainDisabled.save(MainDisabledFile);
		} catch (IOException e) {
			Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save " + MainDisabledFile + ".", e);
		}
	}

	public static void saveOpDisabled() {
		if (OpDisabled == null) {
			throw new NullArgumentException("Cannot save a non-existent file!");
		}
		try {
			OpDisabled.save(OpDisabledFile);
		} catch (IOException e) {
			Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save " + OpDisabledFile + ".", e);
		}
	}

	public static void saveMessages() {
		if (Messages == null) {
			throw new NullArgumentException("Cannot save a non-existent file!");
		}
		try {
			Messages.save(MessagesFile);
		} catch (IOException e) {
			Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save " + MessagesFile + ".", e);
		}
	}

	public static void reloadConfig() {
		MainConfigFile = new File(plugin.getDataFolder(), "config.yml");
		if (!MainConfigFile.exists()) {
			plugin.saveResource("config.yml", false);
		}
		MainConfig = YamlConfiguration.loadConfiguration(MainConfigFile);
		InputStream configData = plugin.getResource("config.yml");
		if (configData != null) {
			try {
				MainConfig.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(configData)));
			} catch (NoSuchMethodError e) {
				MainConfig.setDefaults(YamlConfiguration.loadConfiguration(MainConfigFile));
			}
		}
	}
	public static void reloadDisabled() {
		MainDisabledFile = new File(plugin.getDataFolder(), "disabled.yml");
		if (!MainDisabledFile.exists()) {
			plugin.saveResource("disabled.yml", false);
		}
		MainDisabled = YamlConfiguration.loadConfiguration(MainDisabledFile);
		InputStream disabledData = plugin.getResource("disabled.yml");
		if (disabledData != null) {
			try {
				MainDisabled.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(disabledData)));
			} catch (NoSuchMethodError e) {
				MainDisabled.setDefaults(YamlConfiguration.loadConfiguration(MainDisabledFile));
			}
		}
	}
	public static void reloadOpDisabled() {
		OpDisabledFile = new File(plugin.getDataFolder(), "opblock.yml");
		if (!OpDisabledFile.exists()) {
			plugin.saveResource("opblock.yml", false);
		}
		OpDisabled = YamlConfiguration.loadConfiguration(OpDisabledFile);
		InputStream opData = plugin.getResource("opblock.yml");
		if (opData != null) {
			try {
				OpDisabled.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(opData)));
			} catch (NoSuchMethodError e) {
				OpDisabled.setDefaults(YamlConfiguration.loadConfiguration(OpDisabledFile));
			}
		}
	}

	public static void reloadMessages() {
		MessagesFile = new File(plugin.getDataFolder(), "messages.yml");
		if (!MessagesFile.exists()) {
			plugin.saveResource("messages.yml", false);
		}
		Messages = YamlConfiguration.loadConfiguration(MessagesFile);
		InputStream messagesData = plugin.getResource("messages.yml");
		if (messagesData != null) {
			try {
				Messages.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(messagesData)));
			} catch (NoSuchMethodError e) {
				Messages.setDefaults(YamlConfiguration.loadConfiguration(MessagesFile));
			}
		}
	}


} public class DisabledGui implements Listener {

	private final HashMap<String, String> lookingFor = new HashMap<>();
	private final HashMap<String, Boolean> lookingForOp = new HashMap<>();
	private final HashMap<String, String> command = new HashMap<>();

	@SuppressWarnings("deprecation")
	public void openGui(Player p, String args, boolean op) {
		if (!p.hasPermission("cb.edit") && !op) {
			return;
		} else if (!p.hasPermission("cb.editop") && op) {
			return;
		}
		MethodInterface mi = Universal.get().getMethods();
		Inventory inv;
		if (op) {
			inv = Bukkit.createInventory(null, 27,
					Variables.translateVariablesToLegacyString(mi.getOldMessage("EditOpGui",
							"EditCommandInventoryName"), p));
		} else {
			inv = Bukkit.createInventory(null, 36,
				Variables.translateVariablesToLegacyString(mi.getOldMessage("EditGui", "EditCommandInventoryName"), p));
		}
		SharedGui.setupWool();
		ItemStack commandSlot = new ItemStack(Material.valueOf(SharedGui.pinkGlassBlock), 1, (byte) SharedGui.pinkGlassBlockId);

		if (BukkitMain.coloredGlassPane()) {
			String magentaGlass = new LegacyBlocks().getBlock("MAGENTA_GLASS_PANE");

			String pinkGlass = new LegacyBlocks().getBlock("PINK_GLASS_PANE");

			ItemStack magentaGlassSlots = new ItemStack(Material.valueOf(magentaGlass), 1, (byte) SharedGui.magentaId);
			ItemStack pinkGlassSlots = new ItemStack(Material.valueOf(pinkGlass), 1, (byte) SharedGui.pinkId);

			magentaPinkItemSlots(magentaGlassSlots, pinkGlassSlots);

			for (int i = 0; i <= 8; i += 2) {
				inv.setItem(i, pinkGlassSlots);
				if (op) {
					if ((i + 18) < 26) {
						inv.setItem(i + 18, pinkGlassSlots);
					}
				} else {
					inv.setItem(i + 26, pinkGlassSlots);
				}
			}
			for (int i = 1; i <= 9; i += 2) {
				inv.setItem(i, magentaGlassSlots);
				if (op) {
					if ((i + 18) < 26) {
						inv.setItem(i + 18, magentaGlassSlots);
					}
				} else {
					inv.setItem(i + 26, magentaGlassSlots);
				}
			}
			inv.setItem(17, magentaGlassSlots);
			inv.setItem(18, pinkGlassSlots);
		}

		ItemStack firstSlot = null;
		if (!op) {
			firstSlot = new ItemStack(Material.valueOf(SharedGui.pinkWool), 1, (byte) SharedGui.pinkId);
		}
		ItemStack secondSlot = new ItemStack(Material.valueOf(SharedGui.magentaWool), 1, (byte) SharedGui.magentaId);
		ItemStack thirdSlot = new ItemStack(Material.valueOf(SharedGui.worldsItem), 1, (byte) SharedGui.worldsItemId);
		ItemStack fourthSlot = new ItemStack(Material.valueOf(SharedGui.blueWool), 1, (byte) SharedGui.blueId);
		ItemStack fifthSlot = new ItemStack(Material.valueOf(SharedGui.lightBlueWool), 1, (byte) SharedGui.lightBlueId);
		ItemStack sixthSlot;

		FileConfiguration getDisabledConfig = op ? (FileConfiguration) mi.getOpBlockConfig() :
				(FileConfiguration) mi.getDisabledCommandsConfig();
		String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
		String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";

		if (getDisabledConfig.getString(configurationSectionName + "." + args + ".NoTabComplete") == null) {
			getDisabledConfig.set(configurationSectionName + "." + args + ".NoTabComplete", true);
			if (op) {
				mi.saveOpBlockConfig();
			} else {
				mi.saveDisabledCommandsConfig();
			}

		}
		if (!getDisabledConfig.getBoolean(configurationSectionName + "." + args + ".NoTabComplete")) {
			sixthSlot = new ItemStack(Material.valueOf(SharedGui.redWool), 1, (byte) SharedGui.redWoolId);
		} else {
			sixthSlot = new ItemStack(Material.valueOf(SharedGui.greenWool), 1, (byte) SharedGui.greenWoolId);
		}

		commandSlotItem(mi, p, args, inv, commandSlot, op);


		if (!op) {
			ItemMeta firstSlotMeta = firstSlot.getItemMeta();
			assert firstSlotMeta != null;
			firstSlotMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
							Messages.getMessage(mi, editConfigurationSectionName, "PermissionItemName")), p));

			String currentPermission = ChatColor.WHITE + mi.getOldMessage(configurationSectionName, args +
					".Permission", getDisabledConfig);

			List<String> firstSlotLore = new ArrayList<>();
			for (String message : mi.getOldMessages(editConfigurationSectionName, "PermissionItemLore")) {
				if (message.contains("%m") && (!getDisabledConfig.getStringList(
						configurationSectionName + "." + args + ".Permission").isEmpty())) {
					if (!ChatColor.stripColor(message.replace("%p", "")).equalsIgnoreCase(""))
						firstSlotLore.add(message.replace("%p", ""));
					firstSlotLore.add(ChatColor.WHITE + mi.getOldMessage(configurationSectionName, args +
							".Permission", getDisabledConfig));
				} else {
					firstSlotLore.add(message.replace("%p",
							ChatColor.WHITE + mi.getOldMessage(configurationSectionName, args +
							".Permission", getDisabledConfig)));
				}
			}
			firstSlotMeta.setLore(firstSlotLore);
			firstSlot.setItemMeta(firstSlotMeta);
			if (SharedGui.pinkWool.equalsIgnoreCase("SKULL_ITEM") || SharedGui.pinkWool.equalsIgnoreCase("PLAYER_HEAD")) {
				SkullMeta meta = (SkullMeta) firstSlot.getItemMeta();
				GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
				String playerCommandValue =
						"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTY3MTY1MjI4ZWNlN2FhYzg3NmExMTA4ZjczYzJiNzYwNDQ0MGJlMWRmZjQzZWJkMmZhODQxOTU0ODkxZDhjIn19fQ==";
				gameProfile.getProperties().put("textures", new Property("textures", playerCommandValue));
				Field profileField;
				try {
					profileField = meta.getClass().getDeclaredField("profile");
					profileField.setAccessible(true);
					profileField.set(meta, gameProfile);
				} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
					e.printStackTrace();
				}
				firstSlot.setItemMeta(meta);
			}
			inv.setItem(11, firstSlot);
		}


		ItemMeta secondSlotMeta = secondSlot.getItemMeta();
		assert secondSlotMeta != null;
		secondSlotMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "MessageItemName")), p));

		List<String> secondSlotLore = new ArrayList<>();
		for (String message : mi.getOldMessages(editConfigurationSectionName, "MessageItemLore")) {
			if (message.contains("%m") && (!getDisabledConfig.getStringList(
					configurationSectionName + "." + args + ".Message").isEmpty())) {
				if (!ChatColor.stripColor(message.replace("%m", "")).equalsIgnoreCase(""))
					secondSlotLore.add(message.replace("%m", ""));
				for (String messageList : mi.getOldMessages(configurationSectionName, args +
						".Message", getDisabledConfig)) {
					messageList = ChatColor.WHITE + messageList;
					secondSlotLore.add(messageList);
				}
			} else {
				secondSlotLore.add(message.replace("%m", ChatColor.WHITE + mi.getOldMessage(configurationSectionName, args +
						".Message", getDisabledConfig)));
			}
		}
		secondSlotMeta.setLore(secondSlotLore);
		secondSlot.setItemMeta(secondSlotMeta);
		if (SharedGui.magentaWool.equalsIgnoreCase("SKULL_ITEM") || SharedGui.magentaWool.equalsIgnoreCase("PLAYER_HEAD")) {
			SkullMeta meta = (SkullMeta) secondSlot.getItemMeta();
			GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
			String playerCommandValue =
					"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjAyYWYzY2EyZDVhMTYwY2ExMTE0MDQ4Yjc5NDc1OTQyNjlhZmUyYjFiNWVjMjU1ZWU3MmI2ODNiNjBiOTliOSJ9fX0=";
			gameProfile.getProperties().put("textures", new Property("textures", playerCommandValue));
			Field profileField;
			try {
				profileField = meta.getClass().getDeclaredField("profile");
				profileField.setAccessible(true);
				profileField.set(meta, gameProfile);
			} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
				e.printStackTrace();
			}
			secondSlot.setItemMeta(meta);
		}
		if (op) {
			inv.setItem(11, secondSlot);
		} else {
			inv.setItem(12, secondSlot);
		}


		ItemMeta thirdSlotMeta = thirdSlot.getItemMeta();
		assert thirdSlotMeta != null;
		thirdSlotMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "WorldsItemName")), p));
		thirdSlot.setItemMeta(thirdSlotMeta);
		if (SharedGui.worldsItem.equalsIgnoreCase("SKULL_ITEM") || SharedGui.worldsItem.equalsIgnoreCase("PLAYER_HEAD")) {
			SkullMeta meta = (SkullMeta) thirdSlot.getItemMeta();
			GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
			String worldHeadValue =
					"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDJmMDMyMTk5NjRlOTY2N2ZhMWY0ZDdhNWRlYTA1ODQwZTg5YTRkODgyNDAzNjQxYTMwMTE2MjNkOTUifX19";
			gameProfile.getProperties().put("textures", new Property("textures", worldHeadValue));
			Field profileField;
			try {
				profileField = meta.getClass().getDeclaredField("profile");
				profileField.setAccessible(true);
				profileField.set(meta, gameProfile);
			} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
				e.printStackTrace();
			}
			thirdSlot.setItemMeta(meta);
		}
		if (op) {
			inv.setItem(12, thirdSlot);
		} else {
			inv.setItem(13, thirdSlot);
		}


		ItemMeta fourthSlotMeta = fourthSlot.getItemMeta();
		assert fourthSlotMeta != null;
		fourthSlotMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "PlayerCommandsItemName")), p));
		fourthSlot.setItemMeta(fourthSlotMeta);
		if (op) {
			inv.setItem(13, fourthSlot);
		} else {
			inv.setItem(14, fourthSlot);
		}


		ItemMeta fifthSlotMeta = fifthSlot.getItemMeta();
		assert fifthSlotMeta != null;
		fifthSlotMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "ConsoleCommandsItemName")), p));
		fifthSlot.setItemMeta(fifthSlotMeta);
		if (SharedGui.lightBlueWool.equalsIgnoreCase("SKULL_ITEM") || SharedGui.lightBlueWool.equalsIgnoreCase("PLAYER_HEAD")) {
			SkullMeta meta = (SkullMeta) fifthSlot.getItemMeta();
			GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
			String playerCommandValue =
					"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDdkOTc3ZTI4ODlhMWY1MGJiYjIzZDQyMjI3NWFiOWRhYTNjMTUwYzg5ODMxZTc5ODRiNDliNDA5ZGIwNjcifX19";
			gameProfile.getProperties().put("textures", new Property("textures", playerCommandValue));
			Field profileField;
			try {
				profileField = meta.getClass().getDeclaredField("profile");
				profileField.setAccessible(true);
				profileField.set(meta, gameProfile);
			} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
				e.printStackTrace();
			}
			fifthSlot.setItemMeta(meta);
		}
		if (op) {
			inv.setItem(14, fifthSlot);
		} else {
			inv.setItem(15, fifthSlot);
		}


		ItemMeta sixthSlotMeta = sixthSlot.getItemMeta();
		assert sixthSlotMeta != null;
		sixthSlotMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, "EditGui", "NoTabCompletion")), p));
		sixthSlot.setItemMeta(sixthSlotMeta);
		if (op) {
			inv.setItem(15, sixthSlot);
		} else {
			inv.setItem(22, sixthSlot);
		}


		Bukkit.getScheduler().runTaskLater(BukkitMain.get(), () -> p.openInventory(inv), 1);
	}

	private void commandSlotItem(MethodInterface mi, Player p, String args, Inventory inv, ItemStack commandSlot,
								 boolean op) {
		String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";
		ItemMeta commandSlotMeta = commandSlot.getItemMeta();
		assert commandSlotMeta != null;
		commandSlotMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "InventoryCommandName").replace("%c", args)), p));
		commandSlot.setItemMeta(commandSlotMeta);
		inv.setItem(4, commandSlot);
	}

	static void magentaPinkItemSlots(ItemStack magentaGlassSlots, ItemStack pinkGlassSlots) {
		ItemMeta magentaGlassMeta = magentaGlassSlots.getItemMeta();
		assert magentaGlassMeta != null;
		magentaGlassMeta.setDisplayName(" ");
		magentaGlassSlots.setItemMeta(magentaGlassMeta);

		ItemMeta pinkGlassMeta = pinkGlassSlots.getItemMeta();
		assert pinkGlassMeta != null;
		pinkGlassMeta.setDisplayName(" ");
		pinkGlassSlots.setItemMeta(pinkGlassMeta);
	}

	@EventHandler
	public void onInventoryClick(InventoryClickEvent e) {
		if (e.getInventory().getHolder() != null) {
			return;
		}
		if (e.getCurrentItem() == null) {
			return;
		}
		if (e.getCurrentItem().getItemMeta() == null) {
			return;
		}

		MethodInterface mi = Universal.get().getMethods();

		if (e.getView().getTitle().equals(Variables.translateVariablesToLegacyString(mi.getOldMessage("EditGui",
				"EditCommandInventoryName"), e.getWhoClicked())) || e.getView().getTitle().equals(
						Variables.translateVariablesToLegacyString(mi.getOldMessage("EditOpGui",
				"EditCommandInventoryName"), e.getWhoClicked()))) {
			boolean op = !e.getView().getTitle().equals(Variables.translateVariablesToLegacyString(mi.getOldMessage(
					"EditGui", "EditCommandInventoryName"), e.getWhoClicked()));

			FileConfiguration getDisabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
					(FileConfiguration) mi.getDisabledCommandsConfig();
			if (!op && !e.getWhoClicked().hasPermission("cb.edit")) {
				return;
			} else if (op && !e.getWhoClicked().hasPermission("cb.editop")) {
				return;
			}
			String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
			String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";

			if (e.getRawSlot() < 0 || e.getRawSlot() >= 54 || (!e.getCurrentItem().getItemMeta().hasDisplayName()) || e.getCurrentItem() == null) {
				e.setCancelled(true);
				return;
			}
			String cmd = ChatColor.stripColor(Objects.requireNonNull(Objects.requireNonNull(e.getInventory().getItem(4)).getItemMeta()).getDisplayName()).substring(1);
			Player p = (Player) e.getWhoClicked();
			if (!op && e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "PermissionItemName")), p))) {
				p.closeInventory();

				for (String msgToSend : mi.getOldMessages(editConfigurationSectionName, "ChangePermission")) {
					HashMap<String, String> placeholders = new HashMap<>();
					placeholders.put("%c", cmd);
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
				}
				lookingFor.put(p.getUniqueId().toString(), "permission");
				lookingForOp.put(p.getUniqueId().toString(), true);
				command.put(p.getUniqueId().toString(), cmd);
			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "MessageItemName")), p))) {
				p.closeInventory();

				for (String msgToSend : mi.getOldMessages(editConfigurationSectionName, "ChangeMessage")) {
					HashMap<String, String> placeholders = new HashMap<>();
					placeholders.put("%c", cmd);
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
				}
				lookingFor.put(p.getUniqueId().toString(), "message");
				lookingForOp.put(p.getUniqueId().toString(), op);
				command.put(p.getUniqueId().toString(), cmd);
			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "WorldsItemName")), p))) {
				openWorldGui(mi, p, cmd, op);

			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "PlayerCommandsItemName")), p))) {
				openPCommandsGui(mi, p, cmd, op);

			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "ConsoleCommandsItemName")), p))) {
				openCCommandsGui(mi, p, cmd, op);

			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "NoTabCompletion")), p))) {
				if (!getDisabled.getBoolean(configurationSectionName + "." + cmd + ".NoTabComplete")) {
					getDisabled.set(configurationSectionName + "." + cmd + ".NoTabComplete", true);
					if (op) {
						mi.saveOpBlockConfig();
					} else {
						mi.saveDisabledCommandsConfig();
					}
					Log.addLog(mi, p.getName() + ": Changed tab completion for /" + cmd + " from off to on in " +
							(op ? "opblock.yml" : "disabled.yml"));
				} else {
					getDisabled.set(configurationSectionName + "." + cmd + ".NoTabComplete", false);
					if (op) {
						mi.saveOpBlockConfig();
					} else {
						mi.saveDisabledCommandsConfig();
					}
					Log.addLog(mi, p.getName() + ": Changed tab completion for /" + cmd + " from on to off in " +
							(op ? "opblock.yml" : "disabled.yml"));
				}

				openGui(p, cmd, op);

			}
			e.setCancelled(true);
		} else if (e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, "EditGui", "EditWorldsInventoryName")), e.getWhoClicked())) ||
				e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, "EditOpGui", "EditWorldsInventoryName")), e.getWhoClicked()))) {

			boolean op = !e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, "EditGui", "EditWorldsInventoryName")), e.getWhoClicked()));

			FileConfiguration disabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
					(FileConfiguration) mi.getDisabledCommandsConfig();
			if (!op && !e.getWhoClicked().hasPermission("cb.edit")) {
				return;
			} else if (op && !e.getWhoClicked().hasPermission("cb.editop")) {
				return;
			}
			String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
			String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";

			if (e.getRawSlot() < 0 || e.getRawSlot() >= 54 || (!e.getCurrentItem().getItemMeta().hasDisplayName())) {
				e.setCancelled(true);
				return;
			}
			String cmd = ChatColor.stripColor(Objects.requireNonNull(Objects.requireNonNull(e.getInventory().getItem(4)).getItemMeta()).getDisplayName()).substring(1);
			Player p = (Player) e.getWhoClicked();

			if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "GoBackItemName")), p))) {
				openGui(p, cmd, op);

			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "AddWorldItem")), p))) {

				command.put(p.getUniqueId().toString(), cmd);
				lookingFor.put(p.getUniqueId().toString(), "world");
				lookingForOp.put(p.getUniqueId().toString(), op);
				for (String msgToSend : mi.getOldMessages(editConfigurationSectionName, "AddWorldMessage")) {
					HashMap<String, String> placeholders = new HashMap<>();
					placeholders.put("%c", cmd);
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
				}

				p.closeInventory();
			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(" ")) {
				e.setCancelled(true);
			} else if (!(e.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "InventoryCommandName").replace("%c", cmd)), p))) {

				if (disabled.getStringList(configurationSectionName + "." + cmd + ".Worlds").indexOf("all") != -1) {
					List<String> worlds = new ArrayList<>();
					for (World w : Bukkit.getWorlds()) {
						worlds.add(w.getName());
					}
					disabled.set(configurationSectionName + "." + cmd + ".Worlds", worlds);
					if (op) {
						mi.saveOpBlockConfig();
					} else {
						mi.saveDisabledCommandsConfig();
					}
				}
				List<String> newWorldList = disabled.getStringList(configurationSectionName + "." + cmd + ".Worlds");
				if (disabled.getStringList(configurationSectionName + "." + cmd + ".Worlds").indexOf(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName())) != -1) {
					newWorldList.remove(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
					Log.addLog(Universal.get().getMethods(), p.getName() + ": Removed world " + e.getCurrentItem().getItemMeta().getDisplayName() + " from /" + cmd +
							" in " + (op ? "opblock.yml" : "disabled.yml"));
				} else {
					newWorldList.add(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
					Log.addLog(Universal.get().getMethods(), p.getName() + ": Added world " + e.getCurrentItem().getItemMeta().getDisplayName() + " to /" + cmd +
							" in " + (op ? "opblock.yml" : "disabled.yml"));
				}

				disabled.set(configurationSectionName + "." + cmd + ".Worlds", newWorldList);
				if (op) {
					mi.saveOpBlockConfig();
				} else {
					mi.saveDisabledCommandsConfig();
				}
				openWorldGui(mi, p, cmd, op);
			}
			e.setCancelled(true);
		} else if (e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, "EditGui", "EditPlayerCommandsInventoryName")), e.getWhoClicked())) ||
				e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, "EditOpGui", "EditPlayerCommandsInventoryName")), e.getWhoClicked()))) {
			boolean op =
					!e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, "EditGui", "EditPlayerCommandsInventoryName")), e.getWhoClicked()));

			FileConfiguration disabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
					(FileConfiguration) mi.getDisabledCommandsConfig();
			if (!op && !e.getWhoClicked().hasPermission("cb.edit")) {
				return;
			} else if (op && !e.getWhoClicked().hasPermission("cb.editop")) {
				return;
			}
			String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
			String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";

			if (e.getRawSlot() < 0 || e.getRawSlot() >= 54 || (!e.getCurrentItem().getItemMeta().hasDisplayName())) {
				e.setCancelled(true);
				return;
			}
			String cmd = ChatColor.stripColor(Objects.requireNonNull(Objects.requireNonNull(e.getInventory().getItem(4)).getItemMeta()).getDisplayName()).substring(1);
			Player p = (Player) e.getWhoClicked();
			if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "GoBackItemName")), p))) {
				openGui(p, cmd, op);
			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "AddPlayerCommandItem")), p))) {
				command.put(p.getUniqueId().toString(), cmd);
				lookingFor.put(p.getUniqueId().toString(), "playercommand");
				lookingForOp.put(p.getUniqueId().toString(), op);
				for (String msgToSend : mi.getOldMessages(editConfigurationSectionName, "AddPlayerCommandMessage")) {
					HashMap<String, String> placeholders = new HashMap<>();
					placeholders.put("%c", cmd);
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders, true));
				}
				p.closeInventory();
			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(" ")) {
				e.setCancelled(true);
			} else if (!(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "InventoryCommandName").replace("%c", cmd)), p)))) {

				List<String> newPCommandList = disabled.getStringList(configurationSectionName + "." + cmd +
						".PlayerCommands");
				if (!ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase("none")) {
					newPCommandList.remove(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()).substring(1));
					Log.addLog(Universal.get().getMethods(),
							p.getName() + ": Removed player command " + e.getCurrentItem().getItemMeta().getDisplayName()
									+ " from /" + cmd + " in " + (op ? "opblock.yml" : "disabled.yml"));
				} else {
					newPCommandList.remove(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
					Log.addLog(Universal.get().getMethods(),
							p.getName() + ": Removed none tag from player commands " + "for /" + cmd + " in " + (op ?
									"opblock.yml" : "disabled.yml"));
				}

				disabled.set(configurationSectionName + "." + cmd + ".PlayerCommands", newPCommandList);
				if (op) {
					mi.saveOpBlockConfig();
				} else {
					mi.saveDisabledCommandsConfig();
				}
				openPCommandsGui(mi, p, cmd, op);
			}
			e.setCancelled(true);
		} else if (e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, "EditGui", "EditConsoleCommandsInventoryName")), e.getWhoClicked())) ||
				e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, "EditOpGui", "EditConsoleCommandsInventoryName")), e.getWhoClicked()))) {

			boolean op = !e.getView().getTitle().equals(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, "EditGui", "EditConsoleCommandsInventoryName")), e.getWhoClicked()));

			FileConfiguration disabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
					(FileConfiguration) mi.getDisabledCommandsConfig();
			if (!op && !e.getWhoClicked().hasPermission("cb.edit")) {
				return;
			} else if (op && !e.getWhoClicked().hasPermission("cb.editop")) {
				return;
			}
			String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
			String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";

			if (e.getRawSlot() < 0 || e.getRawSlot() >= 54 || (!e.getCurrentItem().getItemMeta().hasDisplayName())) {
				e.setCancelled(true);
				return;
			}
			String cmd = ChatColor.stripColor(Objects.requireNonNull(Objects.requireNonNull(e.getInventory().getItem(4)).getItemMeta()).getDisplayName()).substring(1);
			Player p = (Player) e.getWhoClicked();
			if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "GoBackItemName")), p))) {
				openGui(p, cmd, op);
			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "AddConsoleCommandItem")), p))) {
				command.put(p.getUniqueId().toString(), cmd);
				lookingFor.put(p.getUniqueId().toString(), "consolecommand");
				lookingForOp.put(p.getUniqueId().toString(), op);
				for (String msgToSend : mi.getOldMessages(editConfigurationSectionName, "AddConsoleCommandMessage")) {
					HashMap<String, String> placeholders = new HashMap<>();
					placeholders.put("%c", cmd);
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders, true));
				}
				p.closeInventory();
			} else if (e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(" ")) {
				e.setCancelled(true);
			} else if (!(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
					Messages.getMessage(mi, editConfigurationSectionName, "InventoryCommandName").replace("%c", cmd)), p)))) {

				List<String> newPCommandList = disabled.getStringList(configurationSectionName + "." + cmd +
						".ConsoleCommands");
				if (!ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()).equalsIgnoreCase("none")) {
					newPCommandList.remove(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()).substring(1));
					Log.addLog(Universal.get().getMethods(),
							p.getName() + ": Removed console command " + e.getCurrentItem().getItemMeta().getDisplayName() +
									" from /" + cmd + " in " + (op ? "opblock.yml" : "disabled.yml"));
				} else {
					newPCommandList.remove(ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName()));
					Log.addLog(Universal.get().getMethods(),
							p.getName() + ": Removed none tag from console commands " + "for /" + cmd + " in " + (op ?
									"opblock.yml" : "disabled.yml"));
				}
				
				disabled.set(configurationSectionName + "." + cmd + ".ConsoleCommands", newPCommandList);
				if (op) {
					mi.saveOpBlockConfig();
				} else {
					mi.saveDisabledCommandsConfig();
				}
				openCCommandsGui(mi, p, cmd, op);
			}
			e.setCancelled(true);
		}
	}
	
	@EventHandler
	public void onChat(AsyncPlayerChatEvent e) {
		Player p = e.getPlayer();
		if (!lookingForOp.containsKey(p.getUniqueId().toString())) {
			return;
		}
		if ((!p.hasPermission("cb.edit") && !lookingForOp.get(p.getUniqueId().toString())) || (!p.hasPermission("cb" +
				".editop") && lookingForOp.get(p.getUniqueId().toString()))) {
			return;
		}
		if (!lookingFor.containsKey(p.getUniqueId().toString())) {
			return;
		}

		MethodInterface mi = Universal.get().getMethods();

		boolean op = lookingForOp.get(p.getUniqueId().toString());

		FileConfiguration disabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
				(FileConfiguration) mi.getDisabledCommandsConfig();
		String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";

		if (e.getMessage().replace(" ", "").equalsIgnoreCase("cancel")) {
			lookingFor.remove(p.getUniqueId().toString());
			lookingForOp.remove(p.getUniqueId().toString());
			command.remove(p.getUniqueId().toString());
			for (String msgToSend : mi.getOldMessages("Main", "Cancelled", mi.getMessagesConfig())) {
				mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
			}
			e.setCancelled(true);
			return;
		}

		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("permission")) {

			Log.addLog(Universal.get().getMethods(), p.getName() + ": Changed permission from " +
					disabled.getString(configurationSectionName + "." + command.get(p.getUniqueId().toString()) +
							".Permission") + " to "+ e.getMessage()	+ "for /" + command.get(p.getUniqueId().toString()) +
					" in " + (op ? "opblock.yml" : "disabled.yml"));
			
			disabled.set(configurationSectionName + "." + command.get(p.getUniqueId().toString()) + ".Permission",
					e.getMessage());

			if (op) {
				mi.saveOpBlockConfig();
			} else {
				mi.saveDisabledCommandsConfig();
			}
			lookingFor.remove(p.getUniqueId().toString());
			lookingForOp.remove(p.getUniqueId().toString());

			openGui(p, command.get(p.getUniqueId().toString()), op);
			command.remove(p.getUniqueId().toString());
		} else if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("message")) {

			Log.addLog(Universal.get().getMethods(), p.getName() + ": Changed message from " +
					disabled.getString(configurationSectionName + "." + command.get(p.getUniqueId().toString()) +
							".Message") + " to "+ e.getMessage() + "for /" + command.get(p.getUniqueId().toString()) + " in " + (op ? "opblock.yml" : "disabled.yml"));
			
			disabled.set(configurationSectionName + "." + command.get(p.getUniqueId().toString()) + ".Message",
					e.getMessage());

			if (op) {
				mi.saveOpBlockConfig();
			} else {
				mi.saveDisabledCommandsConfig();
			}
			lookingFor.remove(p.getUniqueId().toString());
			lookingForOp.remove(p.getUniqueId().toString());

			openGui(p, command.get(p.getUniqueId().toString()), op);
			command.remove(p.getUniqueId().toString());
		} else if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("world")) {
			Log.addLog(Universal.get().getMethods(),
					p.getName() + ": Added world " + e.getMessage() + " for /" + command.get(p.getUniqueId().toString()) + " in " + (op ? "opblock.yml" : "disabled.yml"));
			
			List<String> worldList =
					disabled.getStringList(configurationSectionName + "." + command.get(p.getUniqueId().toString()) +
							".Worlds");
			worldList.add(e.getMessage());
			disabled.set(configurationSectionName + "." + command.get(p.getUniqueId().toString()) + ".Worlds",
					worldList);

			if (op) {
				mi.saveOpBlockConfig();
			} else {
				mi.saveDisabledCommandsConfig();
			}
			lookingFor.remove(p.getUniqueId().toString());
			lookingForOp.remove(p.getUniqueId().toString());
			
			openWorldGui(mi, p, command.get(p.getUniqueId().toString()), op);
			command.remove(p.getUniqueId().toString());
		} else if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("playercommand")) {
			Log.addLog(Universal.get().getMethods(), p.getName() + ": Added player command /" + e.getMessage() + " " +
					"for /" + command.get(p.getUniqueId().toString()) + " in " + (op ? "opblock.yml" : "disabled.yml"));
			
			List<String> pCmdList =
					disabled.getStringList(configurationSectionName + "." + command.get(p.getUniqueId().toString()) +
					".PlayerCommands");
			pCmdList.add(e.getMessage());
			addCmd(mi, p, disabled, pCmdList, op);
		} else if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("consolecommand")) {
			Log.addLog(Universal.get().getMethods(), p.getName() + ": Added console command /" + e.getMessage() + " " +
					"for /" + command.get(p.getUniqueId().toString()) + " in " + (op ? "opblock.yml" : "disabled.yml"));
			
			List<String> cCmdList =
					disabled.getStringList(configurationSectionName + "." + command.get(p.getUniqueId().toString()) +
					".ConsoleCommands");
			cCmdList.add(e.getMessage());
			addConsoleCmd(mi, p, disabled, cCmdList, op);
		}
		e.setCancelled(true);
	}

	private void addConsoleCmd(MethodInterface mi, Player p, FileConfiguration disabled, List<String> cCmdList,
							   boolean op) {
		String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
		disabled.set(configurationSectionName + "." + command.get(p.getUniqueId().toString()) + ".ConsoleCommands",
				cCmdList);
		if (op) {
			mi.saveOpBlockConfig();
		} else {
			mi.saveDisabledCommandsConfig();
		}
		lookingFor.remove(p.getUniqueId().toString());
		lookingForOp.remove(p.getUniqueId().toString());
		openCCommandsGui(mi, p, command.get(p.getUniqueId().toString()), op);
		command.remove(p.getUniqueId().toString());
	}

	private void addCmd(MethodInterface mi, Player p, FileConfiguration disabled, List<String> pCmdList, boolean op) {
		String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
		disabled.set(configurationSectionName + "." + command.get(p.getUniqueId().toString()) + ".PlayerCommands",
				pCmdList);
		if (op) {
			mi.saveOpBlockConfig();
		} else {
			mi.saveDisabledCommandsConfig();
		}
		lookingFor.remove(p.getUniqueId().toString());
		lookingForOp.remove(p.getUniqueId().toString());
		openPCommandsGui(mi, p, command.get(p.getUniqueId().toString()), op);
		command.remove(p.getUniqueId().toString());
	}

	@EventHandler
	public void onCmd(PlayerCommandPreprocessEvent e) {
		Player p = e.getPlayer();

		if (!lookingForOp.containsKey(p.getUniqueId().toString())) {
			return;
		}

		if ((!p.hasPermission("cb.edit") && !lookingForOp.get(p.getUniqueId().toString())) || (!p.hasPermission("cb" +
				".editop") && lookingForOp.get(p.getUniqueId().toString()))) {
			return;
		}
		if (!lookingFor.containsKey(p.getUniqueId().toString())) {
			return;
		}
		MethodInterface mi = Universal.get().getMethods();
		boolean op = lookingForOp.get(p.getUniqueId().toString());

		FileConfiguration disabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
				(FileConfiguration) mi.getDisabledCommandsConfig();
		String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
		String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";
		
		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("permission")) {
			for (String msgToSend : mi.getOldMessages(editConfigurationSectionName, "CannotUseCommand")) {
				mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
			}
		} else if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("message")) {
			for (String msgToSend : mi.getOldMessages(editConfigurationSectionName, "CannotUseCommand")) {
				mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
			}
		} else if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("world")) {
			for (String msgToSend : mi.getOldMessages(editConfigurationSectionName, "CannotUseCommand")) {
				mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
			}
		} else if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("playercommand")) {

			Log.addLog(Universal.get().getMethods(), p.getName() + ": Added player command " + e.getMessage() + " for" +
					" /" + command.get(p.getUniqueId().toString()) + " in " + (op ? "opblock.yml" : "disabled.yml"));
			
			List<String> pCmdList =
					disabled.getStringList(configurationSectionName + "." + command.get(p.getUniqueId().toString()) +
					".PlayerCommands");
			pCmdList.add(e.getMessage().substring(1));
			addCmd(mi, p, disabled, pCmdList, op);
		} else if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("consolecommand")) {

			Log.addLog(Universal.get().getMethods(), p.getName() + ": Added console command " + e.getMessage() + " " +
					"for /" + command.get(p.getUniqueId().toString()) + " in " + (op ? "opblock.yml" : "disabled.yml"));
			
			List<String> cCmdList =
					disabled.getStringList(configurationSectionName + "." + command.get(p.getUniqueId().toString()) +
					".ConsoleCommands");
			cCmdList.add(e.getMessage().substring(1));
			addConsoleCmd(mi, p, disabled, cCmdList, op);
		}
		e.setCancelled(true);
	}

	@SuppressWarnings("deprecation")
	public void openWorldGui(MethodInterface mi, Player p, String args, boolean op) {
		if ((!p.hasPermission("cb.edit") && !op) || (!p.hasPermission("cb.editop") && op) ) {
			return;
		}
		FileConfiguration disabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
				(FileConfiguration) mi.getDisabledCommandsConfig();
		String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
		String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";

		Inventory inv = Bukkit.createInventory(null, 54, Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "EditWorldsInventoryName")), p));

		worldGui(mi, p, args, inv, op);

		if (disabled.getString(configurationSectionName + "." + args + ".Worlds") == null) {
			List<String> list = new ArrayList<>();
			for (World w : Bukkit.getWorlds()) {
				list.add(w.getName());
			}
			disabled.set(configurationSectionName + "." + args + ".Worlds", list);
			if (op) {
				mi.saveOpBlockConfig();
			} else {
				mi.saveDisabledCommandsConfig();
			}
		}

		int worldCount = 10;
		for (World w : Bukkit.getWorlds()) {
			ItemStack world;
			ItemMeta worldMeta;
			if ((disabled.getStringList(configurationSectionName + "." + args + ".Worlds").indexOf(w.getName()) != -1) ||
					(disabled.getStringList(configurationSectionName + "." + args + ".Worlds").indexOf("all") != -1)) {
				String limeWool = new LegacyBlocks().getBlock("LIME_WOOL");
				int limeWoolId = 0;
				if (limeWool.equalsIgnoreCase("wool")) {
					limeWoolId = new LegacyBlocks().getLegacyId("LIME");
				}

				world = new ItemStack(Material.valueOf(limeWool), 1, (byte) limeWoolId);
				worldMeta = world.getItemMeta();
				assert worldMeta != null;
				worldMeta.setDisplayName(ChatColor.GREEN + w.getName());
			} else {
				String redWool = new LegacyBlocks().getBlock("RED_WOOL");
				int redWoolId = 0;
				if (redWool.equalsIgnoreCase("wool")) {
					redWoolId = new LegacyBlocks().getLegacyId("RED");
				}

				world = new ItemStack(Material.valueOf(redWool), 1, (byte) redWoolId);
				worldMeta = world.getItemMeta();
				assert worldMeta != null;
				worldMeta.setDisplayName(ChatColor.RED + w.getName());
			}
			world.setItemMeta(worldMeta);
			if (worldCount == 17) worldCount += 2;
			if (worldCount == 26) worldCount += 2;
			if (worldCount == 35) worldCount += 2;
			if (worldCount == 43) break;
			inv.setItem(worldCount, world);
			worldCount++;
			
		}
		for (String s : disabled.getStringList(configurationSectionName + "." + args + ".Worlds")) {
			if (Bukkit.getWorld(s) == null) {
				if (!s.equalsIgnoreCase("all")) {
					String limeWool = new LegacyBlocks().getBlock("LIME_WOOL");
					int limeWoolId = 0;
					if (limeWool.equalsIgnoreCase("wool")) {
						limeWoolId = new LegacyBlocks().getLegacyId("LIME");
					}

					ItemStack world = new ItemStack(Material.valueOf(limeWool), 1, (byte) limeWoolId);
					ItemMeta worldMeta = world.getItemMeta();
					assert worldMeta != null;
					worldMeta.setDisplayName(ChatColor.GREEN + s);
					world.setItemMeta(worldMeta);
					if (worldCount == 17) worldCount += 2;
					if (worldCount == 26) worldCount += 2;
					if (worldCount == 35) worldCount += 2;
					if (worldCount == 43) break;
					inv.setItem(worldCount, world);
					worldCount++;
				}
			}
		}
		String magentaWool;
		if (BukkitMain.customSkulls()) {
			if (BukkitMain.newBlocks()) {
				magentaWool = "PLAYER_HEAD";
			} else {
				magentaWool = "SKULL_ITEM";
			}
		} else {
			magentaWool = new LegacyBlocks().getBlock("MAGENTA_WOOL");
		}
		int magentaWoolId = 0;
		if (magentaWool.equalsIgnoreCase("wool")) {
			magentaWoolId = new LegacyBlocks().getLegacyId("MAGENTA");
		} else if (magentaWool.equalsIgnoreCase("skull_item")) {
			magentaWoolId = 3;
		}

		ItemStack world = new ItemStack(Material.valueOf(magentaWool), 1, (byte) magentaWoolId);
		ItemMeta worldMeta = world.getItemMeta();
		assert worldMeta != null;
		worldMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "AddWorldItem")), p));
		world.setItemMeta(worldMeta);
		if (magentaWool.equalsIgnoreCase("SKULL_ITEM") || magentaWool.equalsIgnoreCase("PLAYER_HEAD")) {
			SkullMeta meta = (SkullMeta) world.getItemMeta();
			GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
			String playerCommandValue =
					"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTE3MTViZWNjNGI3ZWIxNzY4ZDRhMDM3NmY3NzU5ZmZiY2M1NzkwOWY4ZmQ0MTRkMDVhNDA5NGI2YjNhYmYwIn19fQ==";
			gameProfile.getProperties().put("textures", new Property("textures", playerCommandValue));
			Field profileField;
			try {
				profileField = meta.getClass().getDeclaredField("profile");
				profileField.setAccessible(true);
				profileField.set(meta, gameProfile);
			} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
				e.printStackTrace();
			}
			world.setItemMeta(meta);
		}
		setSlots(p, inv, worldCount, world);

	}

	@SuppressWarnings("deprecation")
	private void worldGui(MethodInterface mi, Player p, String args, Inventory inv, boolean op) {
		String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";
		String pinkGlassBlock = new LegacyBlocks().getBlock("GLASS");
		int pinkGlassBlockId = 0;
		if (BukkitMain.coloredGlassPane()) {
			pinkGlassBlock = new LegacyBlocks().getBlock("PINK_GLASS");
			if (pinkGlassBlock.equalsIgnoreCase("stained_glass")) {
				pinkGlassBlockId = new LegacyBlocks().getLegacyId("PINK");
			}
		}

		ItemStack commandSlot = new ItemStack(Material.valueOf(pinkGlassBlock), 1, (byte) pinkGlassBlockId);

		if (BukkitMain.coloredGlassPane()) {
			String magentaGlass = new LegacyBlocks().getBlock("MAGENTA_GLASS_PANE");
			String pinkGlass = new LegacyBlocks().getBlock("PINK_GLASS_PANE");

			int magentaId = 0;
			int pinkId = 0;
			if (magentaGlass.equalsIgnoreCase("stained_glass_pane")) {
				magentaId = new LegacyBlocks().getLegacyId("MAGENTA");
			}
			if (pinkGlass.equalsIgnoreCase("stained_glass_pane")) {
				pinkId = new LegacyBlocks().getLegacyId("PINK");
			}

			ItemStack magentaGlassSlots = new ItemStack(Material.valueOf(magentaGlass), 1, (byte) magentaId);
			ItemStack pinkGlassSlots = new ItemStack(Material.valueOf(pinkGlass), 1, (byte) pinkId);

			magentaPinkItemSlots(magentaGlassSlots, pinkGlassSlots);

			setSlot(inv, magentaGlassSlots, pinkGlassSlots);
		}

		String pinkDye = new LegacyBlocks().getBlock("PINK_DYE");

		int pinkId = 0;
		if (pinkDye.equalsIgnoreCase("ink_sack")) {
			pinkId = 9;
		}
		ItemStack backSlot = new ItemStack(Material.valueOf(pinkDye), 1, (byte) pinkId);
		ItemMeta backSlotMeta = backSlot.getItemMeta();
		assert backSlotMeta != null;
		backSlotMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "GoBackItemName")), p));
		backSlot.setItemMeta(backSlotMeta);
		inv.setItem(49, backSlot);

		commandSlotItem(mi, p, args, inv, commandSlot, op);
	}

	static void setSlot(Inventory inv, ItemStack magentaGlassSlots, ItemStack pinkGlassSlots) {
		for (int i = 0; i <= 8; i += 2) {
			inv.setItem(i, pinkGlassSlots);
			inv.setItem(i + 44, pinkGlassSlots);
		}
		for (int i = 1; i <= 9; i += 2) {
			inv.setItem(i, magentaGlassSlots);
			inv.setItem(i + 44, magentaGlassSlots);
		}
		inv.setItem(17, magentaGlassSlots);
		inv.setItem(18, pinkGlassSlots);
		inv.setItem(26, pinkGlassSlots);
		inv.setItem(27, magentaGlassSlots);
		inv.setItem(35, magentaGlassSlots);
		inv.setItem(36, pinkGlassSlots);
	}

	@SuppressWarnings("deprecation")
	public void openPCommandsGui(MethodInterface mi, Player p, String args, boolean op) {
		if ((!p.hasPermission("cb.edit") && !op) || (!p.hasPermission("cb.editop") && op) ) {
			return;
		}
		FileConfiguration disabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
				(FileConfiguration) mi.getDisabledCommandsConfig();
		String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
		String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";

		Inventory inv = Bukkit.createInventory(null, 54, Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "EditPlayerCommandsInventoryName")), p));
		worldGui(mi, p, args, inv, op);

		int cmdCount = 10;
		if (!disabled.getStringList(configurationSectionName + "." + args + ".PlayerCommands").contains("none")) {
			for (String s : disabled.getStringList(configurationSectionName + "." + args + ".PlayerCommands")) {
				String limeWool = new LegacyBlocks().getBlock("LIME_WOOL");
				int limeWoolId = 0;
				if (limeWool.equalsIgnoreCase("wool")) {
					limeWoolId = new LegacyBlocks().getLegacyId("LIME");
				}

				ItemStack cmd = new ItemStack(Material.valueOf(limeWool), 1, (byte) limeWoolId);
				ItemMeta cmdMeta = cmd.getItemMeta();
				assert cmdMeta != null;
				cmdMeta.setDisplayName("/" + s);
				cmd.setItemMeta(cmdMeta);
				if (cmdCount == 17) cmdCount += 2;
				if (cmdCount == 26) cmdCount += 2;
				if (cmdCount == 35) cmdCount += 2;
				if (cmdCount == 43) break;
				inv.setItem(cmdCount, cmd);
				cmdCount++;
			}
		} else {
			for (String s : disabled.getStringList(configurationSectionName + "." + args + ".PlayerCommands")) {
				ItemStack cmd;
				ItemMeta cmdMeta;
				if (!s.equalsIgnoreCase("none")) {
					String redWool = new LegacyBlocks().getBlock("RED_WOOL");
					int redWoolId = 0;
					if (redWool.equalsIgnoreCase("wool")) {
						redWoolId = new LegacyBlocks().getLegacyId("RED");
					}

					cmd = new ItemStack(Material.valueOf(redWool), 1, (byte) redWoolId);
					cmdMeta = cmd.getItemMeta();
					assert cmdMeta != null;
					cmdMeta.setDisplayName("/" + s);
				} else {
					String limeWool = new LegacyBlocks().getBlock("LIME_WOOL");
					int limeWoolId = 0;
					if (limeWool.equalsIgnoreCase("wool")) {
						limeWoolId = new LegacyBlocks().getLegacyId("LIME");
					}

					cmd = new ItemStack(Material.valueOf(limeWool), 1, (byte) limeWoolId);
					cmdMeta = cmd.getItemMeta();
					assert cmdMeta != null;
					cmdMeta.setDisplayName("none");
				}
				cmd.setItemMeta(cmdMeta);
				if (cmdCount == 17) cmdCount += 2;
				if (cmdCount == 26) cmdCount += 2;
				if (cmdCount == 35) cmdCount += 2;
				if (cmdCount == 43) break;
				inv.setItem(cmdCount, cmd);
				cmdCount++;
			}
		}
		String magentaWool;
		if (BukkitMain.customSkulls()) {
			if (BukkitMain.newBlocks()) {
				magentaWool = "PLAYER_HEAD";
			} else {
				magentaWool = "SKULL_ITEM";
			}
		} else {
			magentaWool = new LegacyBlocks().getBlock("MAGENTA_WOOL");
		}
		int magentaWoolId = 0;
		if (magentaWool.equalsIgnoreCase("wool")) {
			magentaWoolId = new LegacyBlocks().getLegacyId("MAGENTA");
		} else if (magentaWool.equalsIgnoreCase("skull_item")) {
			magentaWoolId = 3;
		}

		ItemStack cmd = new ItemStack(Material.valueOf(magentaWool), 1, (byte) magentaWoolId);
		ItemMeta cmdMeta = cmd.getItemMeta();
		assert cmdMeta != null;
		cmdMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "AddPlayerCommandItem")), p));
		cmd.setItemMeta(cmdMeta);
		if (magentaWool.equalsIgnoreCase("SKULL_ITEM") || magentaWool.equalsIgnoreCase("PLAYER_HEAD")) {
			SkullMeta meta = (SkullMeta) cmd.getItemMeta();
			GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
			String playerCommandValue =
					"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTE3MTViZWNjNGI3ZWIxNzY4ZDRhMDM3NmY3NzU5ZmZiY2M1NzkwOWY4ZmQ0MTRkMDVhNDA5NGI2YjNhYmYwIn19fQ==";
			gameProfile.getProperties().put("textures", new Property("textures", playerCommandValue));
			Field profileField;
			try {
				profileField = meta.getClass().getDeclaredField("profile");
				profileField.setAccessible(true);
				profileField.set(meta, gameProfile);
			} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
				e.printStackTrace();
			}
			cmd.setItemMeta(meta);
		}
		setSlots(p, inv, cmdCount, cmd);

	}

	static void setSlots(Player p, Inventory inv, int cmdCount, ItemStack cmd) {
		if (cmdCount == 17) cmdCount += 2;
		if (cmdCount == 26) cmdCount += 2;
		if (cmdCount == 35) cmdCount += 2;
		if (cmdCount == 44) cmdCount -= 1;
		inv.setItem(cmdCount, cmd);

		Bukkit.getScheduler().runTaskLater(BukkitMain.get(), () -> p.openInventory(inv), 1);
	}

	@SuppressWarnings("deprecation")
	public void openCCommandsGui(MethodInterface mi, Player p, String args, boolean op) {
		if ((!p.hasPermission("cb.edit") && !op) || (!p.hasPermission("cb.editop") && op) ) {
			return;
		}
		FileConfiguration disabled = op ? (FileConfiguration) mi.getOpBlockConfig() :
				(FileConfiguration) mi.getDisabledCommandsConfig();
		String configurationSectionName = op ? "DisabledOpCommands" : "DisabledCommands";
		String editConfigurationSectionName = op ? "EditOpGui" : "EditGui";

		Inventory inv = Bukkit.createInventory(null, 54, Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "EditConsoleCommandsInventoryName")), p));
		worldGui(mi, p, args, inv, op);

		int cmdCount = 10;
		if (!disabled.getStringList(configurationSectionName + "." + args + ".ConsoleCommands").contains("none")) {
			for (String s : disabled.getStringList(configurationSectionName + "." + args + ".ConsoleCommands")) {
				String limeWool = new LegacyBlocks().getBlock("LIME_WOOL");
				int limeWoolId = 0;
				if (limeWool.equalsIgnoreCase("wool")) {
					limeWoolId = new LegacyBlocks().getLegacyId("LIME");
				}

				ItemStack cmd = new ItemStack(Material.valueOf(limeWool), 1, (byte) limeWoolId);
				ItemMeta cmdMeta = cmd.getItemMeta();
				assert cmdMeta != null;
				cmdMeta.setDisplayName("/" + s);
				cmd.setItemMeta(cmdMeta);
				if (cmdCount == 17) cmdCount += 2;
				if (cmdCount == 26) cmdCount += 2;
				if (cmdCount == 35) cmdCount += 2;
				if (cmdCount == 43) break;
				inv.setItem(cmdCount, cmd);
				cmdCount++;
			}
		} else {
			for (String s : disabled.getStringList(configurationSectionName + "." + args + ".ConsoleCommands")) {
				ItemStack cmd;
				ItemMeta cmdMeta;
				if (!s.equalsIgnoreCase("none")) {
					String redWool = new LegacyBlocks().getBlock("RED_WOOL");
					int redWoolId = 0;
					if (redWool.equalsIgnoreCase("wool")) {
						redWoolId = new LegacyBlocks().getLegacyId("RED");
					}

					cmd = new ItemStack(Material.valueOf(redWool), 1, (byte) redWoolId);
					cmdMeta = cmd.getItemMeta();
					assert cmdMeta != null;
					cmdMeta.setDisplayName("/" + s);
				} else {
					String limeWool = new LegacyBlocks().getBlock("LIME_WOOL");
					int limeWoolId = 0;
					if (limeWool.equalsIgnoreCase("wool")) {
						limeWoolId = new LegacyBlocks().getLegacyId("LIME");
					}

					cmd = new ItemStack(Material.valueOf(limeWool), 1, (byte) limeWoolId);
					cmdMeta = cmd.getItemMeta();
					assert cmdMeta != null;
					cmdMeta.setDisplayName("none");
				}
				cmd.setItemMeta(cmdMeta);
				if (cmdCount == 17) cmdCount += 2;
				if (cmdCount == 26) cmdCount += 2;
				if (cmdCount == 35) cmdCount += 2;
				if (cmdCount == 43) break;
				inv.setItem(cmdCount, cmd);
				cmdCount++;
			}
		}
		String magentaWool;
		if (BukkitMain.customSkulls()) {
			if (BukkitMain.newBlocks()) {
				magentaWool = "PLAYER_HEAD";
			} else {
				magentaWool = "SKULL_ITEM";
			}
		} else {
			magentaWool = new LegacyBlocks().getBlock("MAGENTA_WOOL");
		}
		int magentaWoolId = 0;
		if (magentaWool.equalsIgnoreCase("wool")) {
			magentaWoolId = new LegacyBlocks().getLegacyId("MAGENTA");
		} else if (magentaWool.equalsIgnoreCase("skull_item")) {
			magentaWoolId = 3;
		}

		ItemStack cmd = new ItemStack(Material.valueOf(magentaWool), 1, (byte) magentaWoolId);
		ItemMeta cmdMeta = cmd.getItemMeta();
		assert cmdMeta != null;
		cmdMeta.setDisplayName(Variables.translateVariablesToString(ChatColor.translateAlternateColorCodes('&',
				Messages.getMessage(mi, editConfigurationSectionName, "AddConsoleCommandItem")), p));
		cmd.setItemMeta(cmdMeta);
		if (magentaWool.equalsIgnoreCase("SKULL_ITEM") || magentaWool.equalsIgnoreCase("PLAYER_HEAD")) {
			SkullMeta meta = (SkullMeta) cmd.getItemMeta();
			GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
			String playerCommandValue =
					"eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTE3MTViZWNjNGI3ZWIxNzY4ZDRhMDM3NmY3NzU5ZmZiY2M1NzkwOWY4ZmQ0MTRkMDVhNDA5NGI2YjNhYmYwIn19fQ==";
			gameProfile.getProperties().put("textures", new Property("textures", playerCommandValue));
			Field profileField;
			try {
				profileField = meta.getClass().getDeclaredField("profile");
				profileField.setAccessible(true);
				profileField.set(meta, gameProfile);
			} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
				e.printStackTrace();
			}
			cmd.setItemMeta(meta);
		}
		setSlots(p, inv, cmdCount, cmd);

	}
	
} public class CommandValueListener implements Listener {

	public static HashMap<String, String> lookingFor = new HashMap<>();
	public static HashMap<String, JsonObject> partsHad = new HashMap<>();
	public static HashMap<String, BossBar> bossBar = new HashMap<>();
	
	@EventHandler(priority = EventPriority.HIGHEST)
	public void readChat(AsyncPlayerChatEvent e) {
		MethodInterface mi = Universal.get().getMethods();
		Player p = e.getPlayer();
		if (!lookingFor.containsKey(p.getUniqueId().toString())) {
			return;
		}
		if (!(p.hasPermission("cb.add") || p.hasPermission("cb.remove") || p.hasPermission("cb.addop") || p.hasPermission("cb.removeop"))) {
			return;
		}

		if (e.getMessage().equalsIgnoreCase("cancel")) {
			lookingFor.remove(p.getUniqueId().toString());
			partsHad.remove(p.getUniqueId().toString());
			if (bossBar.containsKey(p.getUniqueId().toString()))
				if (!BukkitMain.sendOldMessages())
					BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
			bossBar.remove(p.getUniqueId().toString());
			for (String msgToSend : mi.getOldMessages("Main", "Cancelled")) {
				mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
			}
			/*
			 * Send message that the event was cancelled
			 */
			e.setCancelled(true);
			return;
		}

		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("add")) {
			
			if (!p.hasPermission("cb.add")) {
				lookingFor.remove(p.getUniqueId().toString());
				partsHad.remove(p.getUniqueId().toString());
				if (bossBar.containsKey(p.getUniqueId().toString()))
					if (!BukkitMain.sendOldMessages())
						BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
				bossBar.remove(p.getUniqueId().toString());
				CommandBlockerCmd.noPermissions(mi, p);
				return;
			}
			
			if (!partsHad.get(p.getUniqueId().toString()).has("command")) {
				FileConfiguration disabled = (FileConfiguration) mi.getDisabledCommandsConfig();
				String message = e.getMessage().substring(0, 1).toUpperCase() + e.getMessage().substring(1).toLowerCase();
				if (disabled.contains("DisabledCommands." + message)) {
					for (String msgToSend : mi.getOldMessages("Main", "CommandAlreadyBlocked")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", e.getMessage());
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
					lookingFor.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						if (!BukkitMain.sendOldMessages())
							BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					e.setCancelled(true);
					return;
				}

				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("command", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);
				HashMap<String, String> placeholders = new HashMap<>();
				placeholders.put("%c", e.getMessage());
				BossBar bar = BossBar.bossBar(Variables.translateVariables(mi.getOldMessage("Main", "AddBossBar"), p,
						placeholders)
						, 1f, BossBar.Color.PURPLE, BossBar.Overlay.PROGRESS);
				bossBar.put(p.getUniqueId().toString(), bar);
				if (!BukkitMain.sendOldMessages())
					BukkitMain.adventure().player(p).showBossBar(bar);

				for (String msgToSend : mi.getOldMessages("Main", "AddPermission")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a permission
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("permission")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("permission", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddMessage")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a message
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("message")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("message", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddWorld")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add worlds. Allow for all.
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("worlds")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("worlds", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddPlayerCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add player commands. Allow for none.
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("playercommands")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("playercommands", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddConsoleCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add console commands. Allow for none.
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("consolecommands")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("consolecommands", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddConfirmation")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to confirm if the command is right
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("confirmation")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				if (e.getMessage().equalsIgnoreCase("no")) {
					object.addProperty("confirmation", false);
				} else if (e.getMessage().equalsIgnoreCase("yes")) {
					object.addProperty("confirmation", true);
				} else {
					for (String msgToSend : mi.getOldMessages("Main", "CanOnlyBeYesOrNo")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
					e.setCancelled(true);
					return;
				}
				
				partsHad.put(p.getUniqueId().toString(), object);
				
				Gson gson = new Gson();
				AddCommand addcommand = gson.fromJson(partsHad.get(p.getUniqueId().toString()), AddCommand.class);
				
				if (!addcommand.getConfirmation()) {
					lookingFor.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						if (!BukkitMain.sendOldMessages())
							BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					for (String msgToSend : mi.getOldMessages("Main", "Cancelled")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
					e.setCancelled(true);
					return;
				}
				String cmd = addcommand.getCommand().substring(0, 1).toUpperCase() + addcommand.getCommand().substring(1).toLowerCase();
				
				List<String> worlds = new ArrayList<>();
				Collections.addAll(worlds, addcommand.getWorlds().split(","));
				
				List<String> pCmds = new ArrayList<>();
				for (String s : addcommand.getPlayerCommands().split(",")) {
					pCmds.add("/" + s);
				}
				for (String s : pCmds) {
					if (s.startsWith("/")) {
						pCmds.set(pCmds.indexOf(s), s.substring(1));
					}
				}

				List<String> cCmds = new ArrayList<>();
				for (String s : addcommand.getConsoleCommands().split(",")) {
					cCmds.add("/" + s);
				}

				for (String s : cCmds) {
					if (s.startsWith("/")) {
						cCmds.set(cCmds.indexOf(s), s.substring(1));
					}
				}

				if (BlockedCommands.addBlockedCommand(cmd, addcommand.getPermission(), addcommand.getMessage(), worlds
						, pCmds, cCmds)) {
					Log.addLog(Universal.get().getMethods(),
							p.getName() + ": Added command /" + addcommand.getCommand() + " in disabled.yml with " +
									"permission " + addcommand.getPermission() + " and message " + addcommand.getMessage() + " in worlds: " + addcommand.getWorlds() + ". When executed, it runs " + addcommand.getPlayerCommands() + " as the player and " + addcommand.getConsoleCommands() + " as console.");
					for (String msgToSend : mi.getOldMessages("Main", "AddedCommandOutput")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", addcommand.getCommand());
						placeholders.put("%p", addcommand.getPermission());
						placeholders.put("%m", addcommand.getMessage());
						placeholders.put("%w", addcommand.getWorlds());
						placeholders.put("%x", addcommand.getPlayerCommands());
						placeholders.put("%z", addcommand.getConsoleCommands());
						placeholders.put("%y", String.valueOf(addcommand.getConfirmation()));
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
				} else {
					for (String msgToSend : mi.getOldMessages("Main", "CouldNotAddCommandToConfig")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
				}
				lookingFor.remove(p.getUniqueId().toString());
				partsHad.remove(p.getUniqueId().toString());
				if (bossBar.containsKey(p.getUniqueId().toString()))
					if (!BukkitMain.sendOldMessages())
						BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
				bossBar.remove(p.getUniqueId().toString());
			}
			e.setCancelled(true);
			return;
		}
		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("remove")) {
			if (!p.hasPermission("cb.remove")) {
				CommandBlockerCmd.noPermissions(mi, p);
				lookingFor.remove(p.getUniqueId().toString());
				if (bossBar.containsKey(p.getUniqueId().toString()))
					if (!BukkitMain.sendOldMessages())
						BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
				bossBar.remove(p.getUniqueId().toString());
				partsHad.remove(p.getUniqueId().toString());
				return;
			}
			
			if (!partsHad.get(p.getUniqueId().toString()).has("command")) {
				FileConfiguration disabled = (FileConfiguration) mi.getDisabledCommandsConfig();
				String message = e.getMessage().substring(0, 1).toUpperCase() + e.getMessage().substring(1).toLowerCase();
				if (!disabled.contains("DisabledCommands." + message)) {
					for (String msgToSend : mi.getOldMessages("Main", "UnblockCancelledBecauseNotBlocked")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", e.getMessage());
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
					lookingFor.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						if (!BukkitMain.sendOldMessages())
							BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					e.setCancelled(true);
					return;
				}
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("command", message);
				partsHad.put(p.getUniqueId().toString(), object);
				HashMap<String, String> placeholders = new HashMap<>();
				placeholders.put("%c", e.getMessage());
				BossBar bar = BossBar.bossBar(Variables.translateVariables(mi.getOldMessage("Main", "RemoveBossBar"), p,
						placeholders)
						, 1f, BossBar.Color.PURPLE, BossBar.Overlay.PROGRESS);
				bossBar.put(p.getUniqueId().toString(), bar);
				if (!BukkitMain.sendOldMessages())
					BukkitMain.adventure().player(p).showBossBar(bar);

				for (String msgToSend : mi.getOldMessages("Main", "RemoveCommandQuestion")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
				}
				e.setCancelled(true);
				/*
				 * Send message to confirm
				 */
			} else if (!partsHad.get(p.getUniqueId().toString()).has("confirmation")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				/*
				 * For the confirmation, make a config option for yes or no options (different languages?)
				 */
				if (e.getMessage().equalsIgnoreCase("no")) {
					object.addProperty("confirmation", false);
				} else if (e.getMessage().equalsIgnoreCase("yes")) {
					object.addProperty("confirmation", true);
				} else {
					for (String msgToSend : mi.getOldMessages("Main", "CanOnlyBeYesOrNo")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
					e.setCancelled(true);
					return;
				}
				partsHad.put(p.getUniqueId().toString(), object);
				
				Gson gson = new Gson();
				RemoveCommand removecommand = gson.fromJson(partsHad.get(p.getUniqueId().toString()), RemoveCommand.class);

				if (!removecommand.getConfirmation()) {
					lookingFor.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						if (!BukkitMain.sendOldMessages())
							BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					for (String msgToSend : mi.getOldMessages("Main", "Cancelled")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
					e.setCancelled(true);
					return;
				}

				if (BlockedCommands.removeBlockedCommand(removecommand.getCommand())) {
					Log.addLog(Universal.get().getMethods(),
							p.getName() + ": Removed command /" + removecommand.getCommand() + " in disabled.yml");

					for (String msgToSend : mi.getOldMessages("Main", "RemovedCommandOutput")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", removecommand.getCommand());
						placeholders.put("%y", String.valueOf(removecommand.getConfirmation()));
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
				} else {
					for (String msgToSend : mi.getOldMessages("Main", "UnblockCancelledBecauseNotBlocked")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", removecommand.getCommand());
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
				}

				partsHad.remove(p.getUniqueId().toString());
				lookingFor.remove(p.getUniqueId().toString());
				if (bossBar.containsKey(p.getUniqueId().toString()))
					if (!BukkitMain.sendOldMessages())
						BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
				bossBar.remove(p.getUniqueId().toString());
			}
			e.setCancelled(true);
			return;
		}
		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("addop")) {
			if (!p.hasPermission("cb.addop")) {
				CommandBlockerCmd.noPermissions(mi, p);
				lookingFor.remove(p.getUniqueId().toString());
				partsHad.remove(p.getUniqueId().toString());
				if (bossBar.containsKey(p.getUniqueId().toString()))
					if (!BukkitMain.sendOldMessages())
						BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
				bossBar.remove(p.getUniqueId().toString());
				return;
			}
			
			if (!partsHad.get(p.getUniqueId().toString()).has("command")) {
				FileConfiguration disabled = (FileConfiguration) mi.getOpBlockConfig();
				String message = e.getMessage().substring(0, 1).toUpperCase() + e.getMessage().substring(1).toLowerCase();
				if (disabled.contains("DisabledOpCommands." + message)) {
					for (String msgToSend : mi.getOldMessages("Main", "CommandAlreadyBlocked")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", e.getMessage());
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
					lookingFor.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						if (!BukkitMain.sendOldMessages())
							BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					e.setCancelled(true);
					return;
				}
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("command", e.getMessage());
				HashMap<String, String> placeholders = new HashMap<>();
				placeholders.put("%c", e.getMessage());
				BossBar bar = BossBar.bossBar(Variables.translateVariables(mi.getOldMessage("Main", "AddOpBossBar"), p,
						placeholders)
						, 1f, BossBar.Color.PURPLE, BossBar.Overlay.PROGRESS);
				bossBar.put(p.getUniqueId().toString(), bar);
				if (!BukkitMain.sendOldMessages())
					BukkitMain.adventure().player(p).showBossBar(bar);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddOpAddMessage")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a message
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("message")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("message", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddOpAddWorld")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add worlds. Allow for all.
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("worlds")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("worlds", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddOpAddPlayerCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add player commands. Allow for none.
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("playercommands")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("playercommands", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddOpAddConsoleCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add console commands. Allow for none.
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("consolecommands")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("consolecommands", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddOpConfirmation")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to confirm if the command is right
				 */
			} else if (!partsHad.get(p.getUniqueId().toString()).has("confirmation")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				if (e.getMessage().equalsIgnoreCase("no")) {
					object.addProperty("confirmation", false);
				} else if (e.getMessage().equalsIgnoreCase("yes")) {
					object.addProperty("confirmation", true);
				} else {
					for (String msgToSend : mi.getOldMessages("Main", "CanOnlyBeYesOrNo")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
					e.setCancelled(true);
					return;
				}
				
				partsHad.put(p.getUniqueId().toString(), object);
				
				Gson gson = new Gson();
				AddOpCommand addopcommand = gson.fromJson(partsHad.get(p.getUniqueId().toString()), AddOpCommand.class);

				if (!addopcommand.getConfirmation()) {
					lookingFor.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						if (!BukkitMain.sendOldMessages())
							BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					for (String msgToSend : mi.getOldMessages("Main", "Cancelled")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
					e.setCancelled(true);
					return;
				}
				String cmd =
						addopcommand.getCommand().substring(0, 1).toUpperCase() + addopcommand.getCommand().substring(1).toLowerCase();

				List<String> worlds = Arrays.asList(addopcommand.getWorlds().split(","));

				List<String> pCmds = Arrays.asList(addopcommand.getPlayerCommands().split(","));
				for (String s : pCmds) {
					if (s.startsWith("/")) {
						pCmds.set(pCmds.indexOf(s), s.substring(1));
					}
				}
				List<String> cCmds = Arrays.asList(addopcommand.getConsoleCommands().split(","));
				for (String s : cCmds) {
					if (s.startsWith("/")) {
						cCmds.set(cCmds.indexOf(s), s.substring(1));
					}
				}

				if (BlockedOpCommands.addBlockedCommand(cmd, addopcommand.getMessage(), worlds, pCmds, cCmds)) {
					Log.addLog(Universal.get().getMethods(),
							p.getName() + ": Added command /" + addopcommand.getCommand() + " in opblock.yml with " +
									"message " + addopcommand.getMessage() + " in worlds: " + addopcommand.getWorlds() + ". When executed, it runs " + addopcommand.getPlayerCommands() + " as the player and " + addopcommand.getConsoleCommands() + " as console.");

					for (String msgToSend : mi.getOldMessages("Main", "AddedOpCommandOutput")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", addopcommand.getCommand());
						placeholders.put("%m", addopcommand.getMessage());
						placeholders.put("%w", addopcommand.getWorlds());
						placeholders.put("%x", addopcommand.getPlayerCommands());
						placeholders.put("%z", addopcommand.getConsoleCommands());
						placeholders.put("%y", String.valueOf(addopcommand.getConfirmation()));
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
				} else {
					for (String msgToSend : mi.getOldMessages("Main", "CouldNotAddCommandToOpConfig")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", addopcommand.getCommand());
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
				}
				/*
				 * Send message saying if it was completed or not
				 *
				 * Add to disabled here
				 * With partsHad
				 *
				 * Deserialize json and put into disabled.yml
				 */
				
				lookingFor.remove(p.getUniqueId().toString());
				partsHad.remove(p.getUniqueId().toString());
				if (bossBar.containsKey(p.getUniqueId().toString()))
					if (!BukkitMain.sendOldMessages())
						BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
				bossBar.remove(p.getUniqueId().toString());
			}
			e.setCancelled(true);
			return;
		}
		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("removeop")) {
			if (!p.hasPermission("cb.removeop")) {
				CommandBlockerCmd.noPermissions(mi, p);
				lookingFor.remove(p.getUniqueId().toString());
				partsHad.remove(p.getUniqueId().toString());
				if (bossBar.containsKey(p.getUniqueId().toString()))
					if (!BukkitMain.sendOldMessages())
						BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
				bossBar.remove(p.getUniqueId().toString());
				return;
			}
			
			if (!partsHad.get(p.getUniqueId().toString()).has("command")) {
				FileConfiguration disabled = (FileConfiguration) mi.getOpBlockConfig();
				String message = e.getMessage().substring(0, 1).toUpperCase() + e.getMessage().substring(1).toLowerCase();
				if (!disabled.contains("DisabledOpCommands." + message)) {
					for (String msgToSend : mi.getOldMessages("Main", "RemoveOpCouldNotRemove")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", e.getMessage());
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
					lookingFor.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						if (!BukkitMain.sendOldMessages())
							BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					e.setCancelled(true);
					return;
				}
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("command", e.getMessage());
				partsHad.put(p.getUniqueId().toString(), object);
				HashMap<String, String> placeholders = new HashMap<>();
				placeholders.put("%c", e.getMessage());
				BossBar bar = BossBar.bossBar(Variables.translateVariables(mi.getOldMessage("Main", "RemoveOpBossBar")
						, p,
						placeholders)
						, 1f, BossBar.Color.PURPLE, BossBar.Overlay.PROGRESS);
				bossBar.put(p.getUniqueId().toString(), bar);
				if (!BukkitMain.sendOldMessages())
					BukkitMain.adventure().player(p).showBossBar(bar);

				for (String msgToSend : mi.getOldMessages("Main", "RemoveOpQuestion")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
				}
				/*
				 * Send message to confirm
				 */
			} else if (!partsHad.get(p.getUniqueId().toString()).has("confirmation")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				/*
				 * For the confirmation, make a config option for yes or no options (different languages?)
				 */
				if (e.getMessage().equalsIgnoreCase("no")) {
					object.addProperty("confirmation", false);
				} else if (e.getMessage().equalsIgnoreCase("yes")) {
					object.addProperty("confirmation", true);
				} else {
					for (String msgToSend : mi.getOldMessages("Main", "CanOnlyBeYesOrNo")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
					e.setCancelled(true);
					return;
				}
				
				partsHad.put(p.getUniqueId().toString(), object);
				
				Gson gson = new Gson();
				RemoveOpCommand removeopcommand = gson.fromJson(partsHad.get(p.getUniqueId().toString()), RemoveOpCommand.class);

				if (!removeopcommand.getConfirmation()) {
					lookingFor.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						if (!BukkitMain.sendOldMessages())
							BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					for (String msgToSend : mi.getOldMessages("Main", "Cancelled")) {
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
					}
					e.setCancelled(true);
					return;
				}

				if (BlockedOpCommands.removeBlockedCommand(removeopcommand.getCommand())) {
					Log.addLog(Universal.get().getMethods(),
							p.getName() + ": Removed command /" + removeopcommand.getCommand() + " in opblock.yml");

					for (String msgToSend : mi.getOldMessages("Main", "RemovedOpCommandOutput")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", removeopcommand.getCommand());
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
				} else {
					for (String msgToSend : mi.getOldMessages("Main", "RemoveOpCouldNotRemove")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", removeopcommand.getCommand());
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
				}

				partsHad.remove(p.getUniqueId().toString());
				lookingFor.remove(p.getUniqueId().toString());
				if (bossBar.containsKey(p.getUniqueId().toString()))
					if (!BukkitMain.sendOldMessages())
						BukkitMain.adventure().player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
				bossBar.remove(p.getUniqueId().toString());
			}
		}
		
		e.setCancelled(true);
	}
	
	@EventHandler
	public void removeOnLeave(PlayerQuitEvent e) {
		lookingFor.remove(e.getPlayer().getUniqueId().toString());
		partsHad.remove(e.getPlayer().getUniqueId().toString());
		if (bossBar.containsKey(e.getPlayer().getUniqueId().toString()))
			if (!BukkitMain.sendOldMessages())
				BukkitMain.adventure().player(e.getPlayer()).hideBossBar(bossBar.get(e.getPlayer().getUniqueId().toString()));
		bossBar.remove(e.getPlayer().getUniqueId().toString());
	}
	
	@EventHandler (priority = EventPriority.HIGHEST)
	public void readCommandsSent(PlayerCommandPreprocessEvent e) {
		MethodInterface mi = Universal.get().getMethods();
		Player p = e.getPlayer();
		BukkitAudiences adventure = BukkitMain.adventure();
		if (!(p.hasPermission("cb.add") || p.hasPermission("cb.remove") || p.hasPermission("cb.addop") || p.hasPermission("cb.removeop"))) {
			return;
		}
		if (!lookingFor.containsKey(p.getUniqueId().toString())) {
			return;
		}
		String message = e.getMessage().substring(1);
		Bukkit.getConsoleSender().sendMessage("Trey's Command Blocker: " + p.getName() + " executed /" + message + " but it was not actually executed.");

		String msg = message.substring(0, 1).toUpperCase() + message.substring(1).toLowerCase();
		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("add")) {
			
			if (!p.hasPermission("cb.add")) {
				CommandBlockerCmd.noPermissions(mi, p);
				return;
			}
			
			if (!partsHad.get(p.getUniqueId().toString()).has("command")) {
				FileConfiguration disabled = (FileConfiguration) mi.getDisabledCommandsConfig();
				if (disabled.contains("DisabledCommands." + msg)) {
					for (String msgToSend : mi.getOldMessages("Main", "CommandAlreadyBlocked")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", message);
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
					lookingFor.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						adventure.player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					e.setCancelled(true);
					return;
				}

				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("command", message);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddPermission")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a permission
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("permission")) {

				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			} else if (!partsHad.get(p.getUniqueId().toString()).has("message")) {

				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			} else if (!partsHad.get(p.getUniqueId().toString()).has("worlds")) {

				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			} else if (!partsHad.get(p.getUniqueId().toString()).has("playercommands")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("playercommands", message);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddConsoleCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a console command
				 */
			} else if (!partsHad.get(p.getUniqueId().toString()).has("consolecommands")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("consolecommands", message);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "Confirmation")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a confirmation
				 */
			} else if (!partsHad.get(p.getUniqueId().toString()).has("confirmation")) {
				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			}
		} 
		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("remove")) {
			
			if (!p.hasPermission("cb.remove")) {
				CommandBlockerCmd.noPermissions(mi, p);
				return;
			}
			
			if (!partsHad.get(p.getUniqueId().toString()).has("command")) {
				FileConfiguration disabled = (FileConfiguration) mi.getDisabledCommandsConfig();
				if (!disabled.contains("DisabledCommands." + msg)) {
					for (String msgToSend : mi.getOldMessages("Main", "UnblockCancelledBecauseNotBlocked")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", message);
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
					lookingFor.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						adventure.player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					e.setCancelled(true);
					return;
				}
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("command", message);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "RemoveCommandQuestion")) {
					HashMap<String, String> placeholders = new HashMap<>();
					placeholders.put("%c", message);
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
				}

			} else if (!partsHad.get(p.getUniqueId().toString()).has("confirmation")) {
				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			}
		}
		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("addop")) {
			
			if (!p.hasPermission("cb.addop")) {
				CommandBlockerCmd.noPermissions(mi, p);
				return;
			}
			
			if (!partsHad.get(p.getUniqueId().toString()).has("command")) {
				FileConfiguration disabled = (FileConfiguration) mi.getOpBlockConfig();
				if (disabled.contains("DisabledOpCommands." + msg)) {
					for (String msgToSend : mi.getOldMessages("Main", "CommandAlreadyBlocked")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", message);
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
					lookingFor.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						adventure.player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					e.setCancelled(true);
					return;
				}
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("command", message);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddOpAddMessage")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a permission
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("message")) {

				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			} else if (!partsHad.get(p.getUniqueId().toString()).has("worlds")) {

				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			} else if (!partsHad.get(p.getUniqueId().toString()).has("playercommands")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("playercommands", message);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "AddOpAddConsoleCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a permission
				 */
			} else if (!partsHad.get(p.getUniqueId().toString()).has("consolecommands")) {
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("consolecommands", message);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "Confirmation")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}
				/*
				 * Send message to add a permission
				 */
			} else if (!partsHad.get(p.getUniqueId().toString()).has("confirmation")) {
				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			}
		} 
		if (lookingFor.get(p.getUniqueId().toString()).equalsIgnoreCase("removeop")) {
			
			if (!p.hasPermission("cb.removeop")) {
				CommandBlockerCmd.noPermissions(mi, p);
				return;
			}
			if (!partsHad.get(p.getUniqueId().toString()).has("command")) {
				FileConfiguration disabled = (FileConfiguration) mi.getOpBlockConfig();
				if (!disabled.contains("DisabledOpCommands." + msg)) {
					for (String msgToSend : mi.getOldMessages("Main", "RemoveOpCouldNotRemove")) {
						HashMap<String, String> placeholders = new HashMap<>();
						placeholders.put("%c", message);
						mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
					}
					lookingFor.remove(p.getUniqueId().toString());
					partsHad.remove(p.getUniqueId().toString());
					if (bossBar.containsKey(p.getUniqueId().toString()))
						adventure.player(p).hideBossBar(bossBar.get(p.getUniqueId().toString()));
					bossBar.remove(p.getUniqueId().toString());
					e.setCancelled(true);
					return;
				}
				JsonObject object = partsHad.get(p.getUniqueId().toString());
				object.addProperty("command", message);
				partsHad.put(p.getUniqueId().toString(), object);

				for (String msgToSend : mi.getOldMessages("Main", "RemoveOpQuestion")) {
					HashMap<String, String> placeholders = new HashMap<>();
					placeholders.put("%c", message);
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p, placeholders));
				}
				/*
				 * Send message to add a permission
				 */

			} else if (!partsHad.get(p.getUniqueId().toString()).has("confirmation")) {
				/*
				 * Send message that you can't use a command
				 */
				for (String msgToSend : mi.getOldMessages("Main", "CantUseCommand")) {
					mi.sendMessage(p, Variables.translateVariables(msgToSend, p));
				}

				e.setCancelled(true);
				return;
			}
		}
		e.setCancelled(true);
	}
} public class OldConfigManager {

	public static FileConfiguration MainConfig;
	public static File MainConfigFile;

	public static FileConfiguration MainDisabled;
	public static File MainDisabledFile;

	public static FileConfiguration OpDisabled;
	public static File OpDisabledFile;

	public static FileConfiguration Messages;
	public static File MessagesFile;

	public static File getFileFromConfig(FileConfiguration configuration) {
		if (configuration.equals(MainConfig)) {
			return MainConfigFile;
		}
		if (configuration.equals(MainDisabled)) {
			return MainDisabledFile;
		}
		if (configuration.equals(OpDisabled)) {
			return OpDisabledFile;
		}
		if (configuration.equals(Messages)) {
			return MessagesFile;
		}
		return null;
	}

	public static FileConfiguration getConfig() {
		if (MainConfig == null) {
			reloadConfig();
		}
		return MainConfig; 
	}
	public static FileConfiguration getDisabled() {
		if (MainDisabled == null) {
			reloadDisabled();
		}
		return MainDisabled;
	}

	public static FileConfiguration getOpDisabled() {
		if (OpDisabled == null) {
			reloadOpDisabled();
		}
		return OpDisabled;
	}

	public static FileConfiguration getMessages() {
		if (Messages == null) {
			reloadMessages();
		}
		return Messages;
	}

	public static void saveConfig() {
		if (MainConfig == null) {
			throw new NullArgumentException("Cannot save a non-existent file!");
		}
		try {
			MainConfig.save(MainConfigFile);
		} catch (IOException e) {
			Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save " + MainConfigFile + ".", e);
		}
	}
	public static void saveDisabled() {
		if (MainDisabled == null) {
			throw new NullArgumentException("Cannot save a non-existent file!");
		}
		try {
			MainDisabled.save(MainDisabledFile);
		} catch (IOException e) {
			Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save " + MainDisabledFile + ".", e);
		}
	}

	public static void saveOpDisabled() {
		if (OpDisabled == null) {
			throw new NullArgumentException("Cannot save a non-existent file!");
		}
		try {
			OpDisabled.save(OpDisabledFile);
		} catch (IOException e) {
			Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save " + OpDisabledFile + ".", e);
		}
	}

	public static void saveMessages() {
		if (Messages == null) {
			throw new NullArgumentException("Cannot save a non-existent file!");
		}
		try {
			Messages.save(MessagesFile);
		} catch (IOException e) {
			Bukkit.getServer().getLogger().log(Level.SEVERE, "Could not save " + MessagesFile + ".", e);
		}
	}

	public static void reloadConfig() {
		MainConfigFile = new File(Bukkit.getPluginManager().getPlugin("CommandBlocker").getDataFolder(), "config.yml");
		if (!MainConfigFile.exists()) {
			Bukkit.getPluginManager().getPlugin("CommandBlocker").saveResource("config.yml", false);
		}
		MainConfig = YamlConfiguration.loadConfiguration(MainConfigFile);
		InputStream configData = Bukkit.getPluginManager().getPlugin("CommandBlocker").getResource("config.yml");
		if (configData != null) {
			try {
				MainConfig.setDefaults(YamlConfiguration.loadConfiguration(configData));
			} catch (NoSuchMethodError e) {
				MainConfig.setDefaults(YamlConfiguration.loadConfiguration(MainConfigFile));
			}
		}
	}
	public static void reloadDisabled() {
		MainDisabledFile = new File(Bukkit.getPluginManager().getPlugin("CommandBlocker").getDataFolder(), "disabled.yml");
		if (!MainDisabledFile.exists()) {
			Bukkit.getPluginManager().getPlugin("CommandBlocker").saveResource("disabled.yml", false);
		}
		MainDisabled = YamlConfiguration.loadConfiguration(MainDisabledFile);
		InputStream disabledData = Bukkit.getPluginManager().getPlugin("CommandBlocker").getResource("disabled.yml");
		if (disabledData != null) {
			try {
				MainDisabled.setDefaults(YamlConfiguration.loadConfiguration(disabledData));
			} catch (NoSuchMethodError e) {
				MainDisabled.setDefaults(YamlConfiguration.loadConfiguration(MainDisabledFile));
			}
		}
	}
	public static void reloadOpDisabled() {
		OpDisabledFile = new File(Bukkit.getPluginManager().getPlugin("CommandBlocker").getDataFolder(), "opblock.yml");
		if (!OpDisabledFile.exists()) {
			Bukkit.getPluginManager().getPlugin("CommandBlocker").saveResource("opblock.yml", false);
		}
		OpDisabled = YamlConfiguration.loadConfiguration(OpDisabledFile);
		InputStream opData = Bukkit.getPluginManager().getPlugin("CommandBlocker").getResource("opblock.yml");
		if (opData != null) {
			try {
				OpDisabled.setDefaults(YamlConfiguration.loadConfiguration(opData));
			} catch (NoSuchMethodError e) {
				OpDisabled.setDefaults(YamlConfiguration.loadConfiguration(OpDisabledFile));
			}
		}
	}

	public static void reloadMessages() {
		MessagesFile = new File(Bukkit.getPluginManager().getPlugin("CommandBlocker").getDataFolder(), "messages.yml");
		if (!MessagesFile.exists()) {
			Bukkit.getPluginManager().getPlugin("CommandBlocker").saveResource("messages.yml", false);
		}
		Messages = YamlConfiguration.loadConfiguration(MessagesFile);
		InputStream messagesData = Bukkit.getPluginManager().getPlugin("CommandBlocker").getResource("messages.yml");
		if (messagesData != null) {
			try {
				Messages.setDefaults(YamlConfiguration.loadConfiguration(messagesData));
			} catch (NoSuchMethodError e) {
				Messages.setDefaults(YamlConfiguration.loadConfiguration(MessagesFile));
			}
		}
	}
}
import com.google.gson.JsonObject;
import me.treyruffy.commandblocker.Config;
import me.treyruffy.commandblocker.Log;
import me.treyruffy.commandblocker.MethodInterface;
import me.treyruffy.commandblocker.Universal;
import me.treyruffy.commandblocker.bukkit.BukkitMain;
import me.treyruffy.commandblocker.bukkit.Variables;
import me.treyruffy.commandblocker.bukkit.api.BlockedCommands;
import me.treyruffy.commandblocker.bukkit.api.BlockedOpCommands;
import me.treyruffy.commandblocker.bukkit.config.ConfigManager;
import me.treyruffy.commandblocker.bukkit.gui.DisabledGui;
import me.treyruffy.commandblocker.bukkit.listeners.CommandValueListener;
import me.treyruffy.commandblockerlegacy.OldConfigManager;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
package me.treyruffy.commandblocker.bukkit.commands;



public class CommandBlockerCmd implements CommandExecutor {

	@Override
	public boolean onCommand(@NotNull CommandSender sender, Command cmd, @NotNull String label, String[] args) {
		if (!cmd.getName().equalsIgnoreCase("cb")) {
			return false;
		}

		MethodInterface mi = Universal.get().getMethods();

		// Player does not have permission to execute the command
		if (!(sender.hasPermission("cb.add") || sender.hasPermission("cb.reload") || sender.hasPermission("cb" +
				".remove") || sender.hasPermission("cb.edit") || sender.hasPermission("cb.editop") || sender.hasPermission("cb.addop") || sender.hasPermission("cb.removeop")) && (sender instanceof Player)) {
			noPermissions(mi, sender);
			return true;
		}

		// No arguments
		if (args.length == 0) {
			for (Component component : Config.getAdventureMessages("Main", "NoArguments")) {
				mi.sendMessage(sender, component);
			}
			return true;
		}

		// Add argument
		if (args[0].equalsIgnoreCase("add")) {

			// Player doesn't have permissions to do /cb add
			if (!sender.hasPermission("cb.add") && (sender instanceof Player)) {
				noPermissions(mi, sender);
				return true;
			}

			if (args.length == 1) {

				if (sender instanceof Player) {
					Player p = (Player) sender;
					CommandValueListener.lookingFor.put(p.getUniqueId().toString(), "add");
					CommandValueListener.partsHad.put(p.getUniqueId().toString(), new JsonObject());

					/*
					 * Send message to input a command
					 */
					for (String msg : mi.getOldMessages("Main", "AddCommandToBlock")) {
						mi.sendMessage(p, Variables.translateVariables(msg, p));