Search in sources :

Example 11 with Configuration

use of net.md_5.bungee.config.Configuration in project DiscordBot by LXGaming.

the class Config method saveFile.

public void saveFile(String name, Configuration config) {
    try {
        File file = new File(DiscordBot.getInstance().getDataFolder(), name);
        ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
    } catch (IOException | NullPointerException | SecurityException ex) {
        DiscordBot.getInstance().getLogger().severe("Exception saving " + name);
        ex.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) File(java.io.File)

Example 12 with Configuration

use of net.md_5.bungee.config.Configuration in project FireAPI by FireBlade-Serv.

the class Events method onConnection.

@EventHandler
public void onConnection(PreLoginEvent e) {
    String name = e.getConnection().getName();
    String ip = e.getConnection().getAddress().getAddress().getHostAddress();
    this.instance.getBungeePlugin().getLogger().info("Tentative de connection de " + name + " avec l'adresse IP : " + ip + ".");
    try {
        this.instance.getWhitelistSystem().setDefault(name, ip);
        this.instance.getWhitelistSystem().loadConfiguration();
    } catch (IOException e2) {
        this.instance.getChatUtils().sendMessageToGroup(this.instance.getWhitelistSystem().getPrefix() + "§c Une erreur critique est survenue ! {name = " + name + ", " + e2.getMessage() + "}", VersionType.BUNGEECORD_VERSION, Rank.MODÉRATEUR);
        e.setCancelReason(new TextComponent("§cUne erreur critique est survenue ! Veuillez contacter Glowstoner ! (SpamBot ?)"));
        e.setCancelled(true);
        return;
    }
    if (this.instance.getWhitelistSystem().isEnable() == false) {
        return;
    }
    File file = new File(this.instance.getBungeePlugin().getDataFolder(), "whitelist.yml");
    Configuration config;
    try {
        config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
        boolean accepted = config.getBoolean("players." + name + ".accepted");
        if (config.getString("players." + name + ".ip").equals(ip) && accepted == true) {
            return;
        }
        e.setCancelReason(new TextComponent("§cLe serveur est en maintenance !\n§9Discord : https://discordapp.com/invite/H7acUcX"));
        e.setCancelled(true);
    } catch (IOException e1) {
        this.instance.getChatUtils().sendMessageToGroup(this.instance.getWhitelistSystem().getPrefix() + "§c Une erreur critique est survenue ! {name = " + name + ", " + e1.getMessage() + "}", VersionType.BUNGEECORD_VERSION, Rank.MODÉRATEUR);
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) IOException(java.io.IOException) File(java.io.File) EventHandler(net.md_5.bungee.event.EventHandler)

Example 13 with Configuration

use of net.md_5.bungee.config.Configuration in project FireAPI by FireBlade-Serv.

the class FireFriends method getOnlineFriends.

public List<ProxiedPlayer> getOnlineFriends(String pp) throws IOException {
    Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
    List<ProxiedPlayer> connected = new ArrayList<>();
    List<String> list = config.getStringList("data." + pp);
    for (String names : list) {
        try {
            ProxiedPlayer player = this.instance.getProxy().getPlayer(names);
            if (player != null) {
                connected.add(player);
            }
        } catch (Exception e) {
            continue;
        }
    }
    return connected;
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) ArrayList(java.util.ArrayList) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) IOException(java.io.IOException)

Example 14 with Configuration

use of net.md_5.bungee.config.Configuration in project FireAPI by FireBlade-Serv.

the class FireFriends method sendGeneratedListOther.

public void sendGeneratedListOther(CommandSender sender, String name) throws IOException {
    Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
    if (!this.instance.getSQL().hasFireAccount(name)) {
        sender.sendMessage(new TextComponent(this.pre + "§cErreur ce joueur n'existe pas !"));
        return;
    }
    if (hasFriends(name)) {
        if (getOnlineFriends(name).size() == 0) {
            sender.sendMessage(new TextComponent(this.pre + name + " n'a §caucun§r ami connecté sur le serveur"));
        } else if (getOnlineFriends(name).size() == 1) {
            sender.sendMessage(new TextComponent(this.pre + name + " a §eun§r ami connecté sur le serveur"));
        } else {
            sender.sendMessage(new TextComponent(this.pre + name + " a §e" + getOnlineFriends(name).size() + "§r amis connectés sur le serveur"));
        }
    } else {
        sender.sendMessage(new TextComponent(this.pre + "§c" + name + " n'a pas d'amis :("));
        return;
    }
    List<String> list = config.getStringList("data." + name);
    for (ProxiedPlayer connected : getOnlineFriends(name)) {
        sender.sendMessage(new TextComponent(this.pre + "§a" + connected.getName() + "§r est actuellement sur le §e" + connected.getServer().getInfo().getName()));
        list.remove(connected.getName());
    }
    for (String names : list) {
        sender.sendMessage(new TextComponent(this.pre + "§8" + names + "§r est actuellement §chors-ligne"));
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration)

Example 15 with Configuration

use of net.md_5.bungee.config.Configuration in project FireAPI by FireBlade-Serv.

the class FireFriends method addFriend.

public void addFriend(ProxiedPlayer p1, ProxiedPlayer p2) {
    if (this.enable) {
        try {
            Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(this.file);
            if (!config.contains("data." + p1.getName())) {
                List<String> list = new ArrayList<>();
                list.add(p2.getName());
                config.set("data." + p1.getName(), list);
            } else {
                List<String> list = config.getStringList("data." + p1.getName());
                list.add(p2.getName());
                config.set("data." + p1.getName(), list);
            }
            if (!config.contains("data." + p2.getName())) {
                List<String> list = new ArrayList<>();
                list.add(p1.getName());
                config.set("data." + p2.getName(), list);
            } else {
                List<String> list = config.getStringList("data." + p2.getName());
                list.add(p1.getName());
                config.set("data." + p2.getName(), list);
            }
            ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, this.file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Configuration(net.md_5.bungee.config.Configuration) ArrayList(java.util.ArrayList) IOException(java.io.IOException) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration)

Aggregations

YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)32 Configuration (net.md_5.bungee.config.Configuration)30 File (java.io.File)16 IOException (java.io.IOException)12 TextComponent (net.md_5.bungee.api.chat.TextComponent)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)5 Path (java.nio.file.Path)4 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)3 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 ServerInstallablePlugin (de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin)2 SimpledUser (de.dytanic.cloudnet.lib.user.SimpledUser)2 Document (de.dytanic.cloudnet.lib.utility.document.Document)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 URLConnection (java.net.URLConnection)2 Enumeration (java.util.Enumeration)2 Properties (java.util.Properties)2