// Path: src/main/java/com/endercrest/voidspawn/commands/VoidSpawnTabCompleter.java
// public class VoidSpawnTabCompleter implements TabCompleter {
// 
//     private CommandHandler handler;
// 
//     public VoidSpawnTabCompleter(CommandHandler handler) {
//         this.handler = handler;
//     }
// 
//     @Override
//     public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
//         if(!cmd.getName().equalsIgnoreCase("voidspawn") || !(sender instanceof Player)) {
//             return null;
//         }
//         List<String> output = new ArrayList<>();
//         Player player = (Player) sender;
//         // Send all sub-commands that user has perms for
//         if(args.length <= 1) {
//             for(Map.Entry<String, SubCommand> subCommand: handler.getCommands()) {
//                 String permission = subCommand.getValue().permission();
//                 if(permission == null || !player.hasPermission(permission))
//                     continue;
// 
//                 if(args.length == 0 || subCommand.getKey().startsWith(args[0])) {
//                     output.add(subCommand.getKey());
//                 }
//             }
// 
//             return output;
//         }
// 
//         SubCommand subCommand = handler.getSubCommand(args[0]);
//         return subCommand != null ? subCommand.getTabCompletion(player, Arrays.copyOfRange(args, 1, args.length)) : null;
//     }
// 
//     /////////////////////////////////////////////
//     ////        Common Auto Completes        ////
//     /////////////////////////////////////////////
// 
// 
//     static List<String> getBooleanWorldCompletion(String[] args) {
//         switch(args.length) {
//             case 1:
//                 return new ArrayList<String>() {{
//                     add("true");
//                     add("false");
//                 }}
//                 .stream()
//                 .filter(s -> s.startsWith(args[0].toLowerCase()))
//                 .collect(Collectors.toList());
//             case 2:
//                 return WorldUtil.getMatchingWorlds(args[1]);
//             default:
//                 return new ArrayList<>();
//         }
//     }
// }
// 
// Path: src/main/java/com/endercrest/voidspawn/utils/MessageUtil.java
// public class MessageUtil {
// 
//     /**
//      * Add Color to Messages
//      *
//      * @param str The String
//      * @return Coloured String
//      */
//     public static String colorize(String str){
//         return str.replaceAll("(?i)&([a-f0-9k-or])", "\u00a7$1");
//     }
// 
//     public static String colorize(String str, Object... args){
//         return colorize(String.format(str, args));
//     }
// }


import java.util.logging.Level;
import com.endercrest.voidspawn.commands.VoidSpawnTabCompleter;
import com.endercrest.voidspawn.utils.MessageUtil;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
package com.endercrest.voidspawn;



public class VoidSpawn extends JavaPlugin {
    public static String prefix = "[&6VS&f] ";

    public void onEnable(){
        try {
            // This is the class we check for as it was added in 1.13 and should remain in place for the long term.
            Class.forName("org.bukkit.Tag");
        } catch (ClassNotFoundException e) {
            log("&cERROR: Unsupported version of Spigot/Paper detected!");
            log("&cERROR: Disabling plugin! Please update to latest version");
            log("&cERROR: or use an unsupported version of VoidSpawn");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }

        /* if[PROD] */
        Metrics metrics = new Metrics(this, 3514);
        /* end[PROD] */

        loadConfiguration();
        ConfigManager.getInstance().setUp(this);
        TeleportManager.getInstance().setUp(this);
        ModeManager.getInstance().setUp(this);
        DetectorManager.getInstance().setUp();
        getServer().getPluginManager().registerEvents(new VoidListener(this), this);
        getServer().getPluginManager().registerEvents(new QuitListener(), this);

        PluginCommand command = getCommand("voidspawn");
        CommandHandler commandHandler = new CommandHandler(this);
        command.setExecutor(commandHandler);
        command.setTabCompleter(new VoidSpawnTabCompleter(commandHandler));

        Bukkit.getScheduler().runTaskTimer(this, new TouchTracker(), 5, 5);

        log("&ev" + getDescription().getVersion() + " by EnderCrest enabled");
    }

    public void onDisable(){
        log("&ev" + getDescription().getVersion() + " saving config");
        ConfigManager.getInstance().saveConfig();
        log("&ev" + getDescription().getVersion() + " disabled");
    }

    public void loadConfiguration(){
        if(!getConfig().contains("color-logs")){
            getConfig().addDefault("color-logs", true);
        }
        getConfig().options().copyDefaults(true);
        saveConfig();
    }

    /**
     * Sends Messages to Console
     *
     * @param obj The Obj(Message)
     */
    public void log(Object obj){
        if(getConfig().getBoolean("color-logs", true)){
// Path: src/main/java/com/endercrest/voidspawn/commands/VoidSpawnTabCompleter.java
// public class VoidSpawnTabCompleter implements TabCompleter {
// 
//     private CommandHandler handler;
// 
//     public VoidSpawnTabCompleter(CommandHandler handler) {
//         this.handler = handler;
//     }
// 
//     @Override
//     public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
//         if(!cmd.getName().equalsIgnoreCase("voidspawn") || !(sender instanceof Player)) {
//             return null;
//         }
//         List<String> output = new ArrayList<>();
//         Player player = (Player) sender;
//         // Send all sub-commands that user has perms for
//         if(args.length <= 1) {
//             for(Map.Entry<String, SubCommand> subCommand: handler.getCommands()) {
//                 String permission = subCommand.getValue().permission();
//                 if(permission == null || !player.hasPermission(permission))
//                     continue;
// 
//                 if(args.length == 0 || subCommand.getKey().startsWith(args[0])) {
//                     output.add(subCommand.getKey());
//                 }
//             }
// 
//             return output;
//         }
// 
//         SubCommand subCommand = handler.getSubCommand(args[0]);
//         return subCommand != null ? subCommand.getTabCompletion(player, Arrays.copyOfRange(args, 1, args.length)) : null;
//     }
// 
//     /////////////////////////////////////////////
//     ////        Common Auto Completes        ////
//     /////////////////////////////////////////////
// 
// 
//     static List<String> getBooleanWorldCompletion(String[] args) {
//         switch(args.length) {
//             case 1:
//                 return new ArrayList<String>() {{
//                     add("true");
//                     add("false");
//                 }}
//                 .stream()
//                 .filter(s -> s.startsWith(args[0].toLowerCase()))
//                 .collect(Collectors.toList());
//             case 2:
//                 return WorldUtil.getMatchingWorlds(args[1]);
//             default:
//                 return new ArrayList<>();
//         }
//     }
// }
// 
// Path: src/main/java/com/endercrest/voidspawn/utils/MessageUtil.java
// public class MessageUtil {
// 
//     /**
//      * Add Color to Messages
//      *
//      * @param str The String
//      * @return Coloured String
//      */
//     public static String colorize(String str){
//         return str.replaceAll("(?i)&([a-f0-9k-or])", "\u00a7$1");
//     }
// 
//     public static String colorize(String str, Object... args){
//         return colorize(String.format(str, args));
//     }
// }


// Path: src/main/java/com/endercrest/voidspawn/VoidSpawn.java
import java.util.logging.Level;
import com.endercrest.voidspawn.commands.VoidSpawnTabCompleter;
import com.endercrest.voidspawn.utils.MessageUtil;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

package com.endercrest.voidspawn;



public class VoidSpawn extends JavaPlugin {
    public static String prefix = "[&6VS&f] ";

    public void onEnable(){
        try {
            // This is the class we check for as it was added in 1.13 and should remain in place for the long term.
            Class.forName("org.bukkit.Tag");
        } catch (ClassNotFoundException e) {
            log("&cERROR: Unsupported version of Spigot/Paper detected!");
            log("&cERROR: Disabling plugin! Please update to latest version");
            log("&cERROR: or use an unsupported version of VoidSpawn");
            Bukkit.getPluginManager().disablePlugin(this);
            return;
        }

        /* if[PROD] */
        Metrics metrics = new Metrics(this, 3514);
        /* end[PROD] */

        loadConfiguration();
        ConfigManager.getInstance().setUp(this);
        TeleportManager.getInstance().setUp(this);
        ModeManager.getInstance().setUp(this);
        DetectorManager.getInstance().setUp();
        getServer().getPluginManager().registerEvents(new VoidListener(this), this);
        getServer().getPluginManager().registerEvents(new QuitListener(), this);

        PluginCommand command = getCommand("voidspawn");
        CommandHandler commandHandler = new CommandHandler(this);
        command.setExecutor(commandHandler);
        command.setTabCompleter(new VoidSpawnTabCompleter(commandHandler));

        Bukkit.getScheduler().runTaskTimer(this, new TouchTracker(), 5, 5);

        log("&ev" + getDescription().getVersion() + " by EnderCrest enabled");
    }

    public void onDisable(){
        log("&ev" + getDescription().getVersion() + " saving config");
        ConfigManager.getInstance().saveConfig();
        log("&ev" + getDescription().getVersion() + " disabled");
    }

    public void loadConfiguration(){
        if(!getConfig().contains("color-logs")){
            getConfig().addDefault("color-logs", true);
        }
        getConfig().options().copyDefaults(true);
        saveConfig();
    }

    /**
     * Sends Messages to Console
     *
     * @param obj The Obj(Message)
     */
    public void log(Object obj){
        if(getConfig().getBoolean("color-logs", true)){
            getServer().getConsoleSender().sendMessage(MessageUtil.colorize("&3[&d" + getName() + "&3] &r" + obj));