Solved get a String in a config

Discussion in 'Plugin Development' started by idkG0D, Jan 28, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    idkG0D

    I'am trying to get the args[0](group) of the player in the config file, idk how to do that... Someone can help me?

    Jogadores:
    idkG0D:
    Cargo: dono <--- I want to pick this string(args[0])
    Here is the code:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("addgroup")){
                if(!sender.hasPermission("flash.groupset")) {
                    sender.sendMessage("§c§lFLASH§3GROUPS  §cVocê não tem permissão para executar esse comando!");
                    return true;
                }
                if(args.length == 0) {
                    sender.sendMessage("§c§lFLASH§3GROUPS  §cComando inválido! Consulte o guia de ajuda!");
                    return true;
                }else if(args.length == 1) {
                    sender.sendMessage("§c§lFLASH§3GROUPS  §cVocê precisa selecionar um jogador!");
                    return true;
                }else if(args.length > 1) {
                    Player target = (Player)Bukkit.getServer().getPlayer(args[1]);
                  
                    if(target == null) {
                        sender.sendMessage("§c§lFLASH§3GROUPS  §cJogador não encontrado!");
                        return true;
                    }
                    if(!(args[0].toUpperCase().contentEquals("DONO") || args[0].toUpperCase().equals("SUBDONO") || args[0].toUpperCase().equals("ADMIN") || args[0].toUpperCase().equals("MODERADOR") || args[0].toUpperCase().equals("TRIAL") || args[0].toUpperCase().equals("BUILDER") || args[0].toUpperCase().equals("YOUTUBER") || args[0].toUpperCase().equals("DIAMANTE") || args[0].toUpperCase().equals("ESMERALDA") || args[0].toUpperCase().equals("OURO"))) {
                        sender.sendMessage("§c§lFLASH§3GROUPS  §cGrupo não existente!");
                        return true;
                    }else
                      
                        if(args[0].toUpperCase().equals("DONO")) {
                            if(!sender.hasPermission("flash.dono")) {
                                sender.sendMessage("§c§lFLASH§3GROUPS  §cVocê não tem permissão para adicionar/remover jogadores desse grupo!");
                                return true;
                            }
                            if(!Main.pLugin.getConfig().getList(target.getName()).contains(args[0])) {
                                sender.sendMessage("§c§lFLASH§3GROUPS  §dO jogador já pertence ao grupo em questão!");
                                return true;
                            }
                            Main.pLugin.getConfig().get("Jogadores."+target.getName()+".Cargo", args[0]);
                            Main.pLugin.saveConfig();
                            sender.sendMessage("§c§lFLASH§3GROUPS  §dJogador adicionado com sucesso ao grupo!");
                            target.kickPlayer("§c§lFLASH§fMC" + "\n" + "§6§lVocê foi expulso de nosso servidor!"+"\n"+"§f§lMotivo: §aAdicionado a um novo grupo!");
                        }
                  
                  
                }
              
            }
          
          
            return false;
        }
     
  2. Online

    timtower Administrator Administrator Moderator

    @idkG0D Are you trying to set the config or get a value from it? Because using the args[0] on a value will only be useful for setting
     
    KarimAKL likes this.
  3. Offline

    KarimAKL

    @idkG0D If this is in your main class you can use 'getConfig().getString()', if it's not in your main class then pass an instance of your main class to that class and then you can use 'instance.getConfig().getString()'
     
Thread Status:
Not open for further replies.

Share This Page