// Path: src/main/java/de/jeter/chatex/ChatEx.java
// public class ChatEx extends JavaPlugin {
// 
//     private static ChatEx INSTANCE;
//     private UpdateChecker updatechecker = null;
// 
//     @Override
//     public void onEnable() {
//         INSTANCE = this;
// 
//         Config.load();
//         Locales.load();
//         PluginManager.load();
//         ChatLogger.load();
//         RGBColors.load();
// 
//         getServer().getPluginManager().registerEvents(new ChatListener(), this);
//         getServer().getPluginManager().registerEvents(new PlayerListener(), this);
//         getCommand("chatex").setExecutor(new CommandHandler());
// 
//         if (Config.CHECK_UPDATE.getBoolean()) {
//             updatechecker = new UpdateChecker(this, 71041);
//         }
// 
//         ChannelHandler.load();
// 
//         if (Config.B_STATS.getBoolean()) {
//             Metrics metrics = new Metrics(this, 7744);
//             getLogger().info("Thanks for using bstats, it was enabled!");
//         }
// 
//         getLogger().info("is now enabled!");
//     }
// 
//     @Override
//     public void onDisable() {
//         ChatLogger.close();
//         getServer().getScheduler().cancelTasks(this);
//         getLogger().info("is now disabled!");
//     }
// 
//     public static ChatEx getInstance() {
//         return INSTANCE;
//     }
// 
//     public UpdateChecker getUpdateChecker() {
//         return this.updatechecker;
//     }
// }
// 
// Path: src/main/java/de/jeter/chatex/plugins/PluginManager.java
// public class PluginManager implements PermissionsPlugin {
// 
//     private static PermissionsPlugin handler;
//     private static PluginManager INSTANCE;
// 
//     public static PermissionsPlugin getInstance() {
//         return INSTANCE;
//     }
// 
//     public static void load() {
//         INSTANCE = new PluginManager();
//         if (HookManager.checkVault() && Vault.setupChat()) {
//             handler = new Vault();
//         } else {
//             handler = new Nothing();
//         }
//         ChatEx.getInstance().getLogger().info("Successfully hooked into: " + handler.getName());
// 
//         if (HookManager.checkPlaceholderAPI()) {
//             ChatEx.getInstance().getLogger().info("Hooked into PlaceholderAPI");
//         }
//     }
// 
//     @Override
//     public String getName() {
//         return handler.getName();
//     }
// 
//     @Override
//     public String getPrefix(Player p) {
//         return handler.getPrefix(p);
//     }
// 
//     @Override
//     public String getSuffix(Player p) {
//         return handler.getSuffix(p);
//     }
// 
//     @Override
//     public String[] getGroupNames(Player p) {
//         return handler.getGroupNames(p);
//     }
// 
//     @Override
//     public String getMessageFormat(Player p) {
//         return Utils.replaceColors(handler.getMessageFormat(p));
//     }
// 
//     @Override
//     public String getGlobalMessageFormat(Player p) {
//         return Utils.replaceColors(handler.getGlobalMessageFormat(p));
//     }
// }


import de.jeter.chatex.ChatEx;
import de.jeter.chatex.plugins.PluginManager;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
/*
 * This file is part of ChatEx
 * Copyright (C) 2020 ChatEx Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package de.jeter.chatex.utils;



public class Utils {

    public static String translateColorCodes(String string, Player p) {
        return p.hasPermission("chatex.chat.color") ? replaceColors(string) : string;
    }

    public static String replaceColors(String message) {
        message = RGBColors.translateCustomColorCodes(message);
        return ChatColor.translateAlternateColorCodes('&', message);
    }

    public static List<Player> getLocalRecipients(Player sender) {
        Location playerLocation = sender.getLocation();
        List<Player> recipients = new ArrayList<>();

        double squaredDistance = Math.pow(Config.RANGE.getInt(), 2);
        for (Player recipient : sender.getWorld().getPlayers()) {
            if (Config.RANGE.getInt() > 0 && (playerLocation.distanceSquared(recipient.getLocation()) > squaredDistance)) {
                continue;
            }
            recipients.add(recipient);
        }

        return recipients;
    }

    public static String replacePlayerPlaceholders(Player player, String format) {
        if (player == null) {
            return format;
        }
        String result = format;

        if (HookManager.checkPlaceholderAPI()) {
            result = PlaceholderAPI.setPlaceholders(player, result);
        }

        result = result.replace("%displayname", player.getDisplayName());
// Path: src/main/java/de/jeter/chatex/ChatEx.java
// public class ChatEx extends JavaPlugin {
// 
//     private static ChatEx INSTANCE;
//     private UpdateChecker updatechecker = null;
// 
//     @Override
//     public void onEnable() {
//         INSTANCE = this;
// 
//         Config.load();
//         Locales.load();
//         PluginManager.load();
//         ChatLogger.load();
//         RGBColors.load();
// 
//         getServer().getPluginManager().registerEvents(new ChatListener(), this);
//         getServer().getPluginManager().registerEvents(new PlayerListener(), this);
//         getCommand("chatex").setExecutor(new CommandHandler());
// 
//         if (Config.CHECK_UPDATE.getBoolean()) {
//             updatechecker = new UpdateChecker(this, 71041);
//         }
// 
//         ChannelHandler.load();
// 
//         if (Config.B_STATS.getBoolean()) {
//             Metrics metrics = new Metrics(this, 7744);
//             getLogger().info("Thanks for using bstats, it was enabled!");
//         }
// 
//         getLogger().info("is now enabled!");
//     }
// 
//     @Override
//     public void onDisable() {
//         ChatLogger.close();
//         getServer().getScheduler().cancelTasks(this);
//         getLogger().info("is now disabled!");
//     }
// 
//     public static ChatEx getInstance() {
//         return INSTANCE;
//     }
// 
//     public UpdateChecker getUpdateChecker() {
//         return this.updatechecker;
//     }
// }
// 
// Path: src/main/java/de/jeter/chatex/plugins/PluginManager.java
// public class PluginManager implements PermissionsPlugin {
// 
//     private static PermissionsPlugin handler;
//     private static PluginManager INSTANCE;
// 
//     public static PermissionsPlugin getInstance() {
//         return INSTANCE;
//     }
// 
//     public static void load() {
//         INSTANCE = new PluginManager();
//         if (HookManager.checkVault() && Vault.setupChat()) {
//             handler = new Vault();
//         } else {
//             handler = new Nothing();
//         }
//         ChatEx.getInstance().getLogger().info("Successfully hooked into: " + handler.getName());
// 
//         if (HookManager.checkPlaceholderAPI()) {
//             ChatEx.getInstance().getLogger().info("Hooked into PlaceholderAPI");
//         }
//     }
// 
//     @Override
//     public String getName() {
//         return handler.getName();
//     }
// 
//     @Override
//     public String getPrefix(Player p) {
//         return handler.getPrefix(p);
//     }
// 
//     @Override
//     public String getSuffix(Player p) {
//         return handler.getSuffix(p);
//     }
// 
//     @Override
//     public String[] getGroupNames(Player p) {
//         return handler.getGroupNames(p);
//     }
// 
//     @Override
//     public String getMessageFormat(Player p) {
//         return Utils.replaceColors(handler.getMessageFormat(p));
//     }
// 
//     @Override
//     public String getGlobalMessageFormat(Player p) {
//         return Utils.replaceColors(handler.getGlobalMessageFormat(p));
//     }
// }


// Path: src/main/java/de/jeter/chatex/utils/Utils.java
import de.jeter.chatex.ChatEx;
import de.jeter.chatex.plugins.PluginManager;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;

/*
 * This file is part of ChatEx
 * Copyright (C) 2020 ChatEx Team
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
package de.jeter.chatex.utils;



public class Utils {

    public static String translateColorCodes(String string, Player p) {
        return p.hasPermission("chatex.chat.color") ? replaceColors(string) : string;
    }

    public static String replaceColors(String message) {
        message = RGBColors.translateCustomColorCodes(message);
        return ChatColor.translateAlternateColorCodes('&', message);
    }

    public static List<Player> getLocalRecipients(Player sender) {
        Location playerLocation = sender.getLocation();
        List<Player> recipients = new ArrayList<>();

        double squaredDistance = Math.pow(Config.RANGE.getInt(), 2);
        for (Player recipient : sender.getWorld().getPlayers()) {
            if (Config.RANGE.getInt() > 0 && (playerLocation.distanceSquared(recipient.getLocation()) > squaredDistance)) {
                continue;
            }
            recipients.add(recipient);
        }

        return recipients;
    }

    public static String replacePlayerPlaceholders(Player player, String format) {
        if (player == null) {
            return format;
        }
        String result = format;

        if (HookManager.checkPlaceholderAPI()) {
            result = PlaceholderAPI.setPlaceholders(player, result);
        }

        result = result.replace("%displayname", player.getDisplayName());
        result = result.replace("%prefix", PluginManager.getInstance().getPrefix(player));