Solved Data only gets updated when i /reload

Discussion in 'Spigot Plugin Development' started by NegativeExpert9, Jan 11, 2019.

  1. Idk if I'm having a brain fart or what.

    I have a command that kicks a player from a "Kingdom" when someone types /kd kick <player>. When a new player comes, just to test, I add their uuid to the France kingdom, and i change their stats.players.uuid.kingdom to France as well. The first time I do it, the command works, but when I add all that info again to test the kick command, it doesn't work. It only works once I /reload. Are the local variables not getting updated onCommand?



    Here's my config file from where the data gets removed:

    Code (YAML):
    data:
      France
    :
        king
    : a7547ccc-eb0b-4420-9fc3-983cea0d6bc9
        points
    : 0
        influence
    : 0
        players
    :
          normal
    :
         - Test1UUID
          - Test2UUID
          mod
    :
         - Test1UUID
          - Test2UUID
          general
    :
         - Test1UUID
    stats
    :
      players
    :
        a7547ccc-eb0b-4420-9fc3-983cea0d6bc9
    :
          name
    : Emperio
          kills
    : 0
          deaths
    : 0
          kingdom
    : France
          confirmed
    : 'no'
    chooser
    :
      x
    : 0.0
      y
    : -25.88140983351316
      z
    : 1.2567760907296321
     

    Here's my code: this doesn't contain the line if(command.getName().equals("kd"){}
    Code (Java):
    else if(args[0].equals("kick")){
                    String sendersKingdom = getConfig().getString(getConfigPath(player) + ".kingdom");

                    if(getConfig().getString("data." + sendersKingdom + ".king").equals(player.getUniqueId().toString())){
                        player.sendMessage("King ->> True");

                        if(args.length > 2){
                            player.sendMessage(getMessage("&cToo many arguments specified. Correct usage: &6/kd kick <player>"));
                            return true;
                        }
                        else if(args.length == 1){
                            player.sendMessage(getMessage("&cArgument &6<player>&c missing. Correct usage: &6/kd kick <player>"));
                            return true;
                        }
                        else if(args.length == 2){

                            Player toBeKicked = Bukkit.getPlayerExact(args[1]);
                            if(toBeKicked == null){
                                player.sendMessage(getMessage("Player not found"));
                                return true;
                            }
                            player.sendMessage("Player is valid --->>> true");
                            String playerKingdom = getConfig().getString(getConfigPath(toBeKicked) + ".kingdom");
                            player.sendMessage("if you've seen this then all logic breaks here");
                            if(playerKingdom.equals(sendersKingdom)){
                                player.sendMessage("player's and kings kingdom mathch ->> true");
                                List<String> normalplayers = (List<String>) getConfig().getList("data." + sendersKingdom +".players.normal");
                                List<String> modplayers = (List<String>) getConfig().getList("data." + sendersKingdom +".players.mod");
                                List<String> generalplayers = (List<String>) getConfig().getList("data." + sendersKingdom +".players.general");
                                if(normalplayers.contains(toBeKicked.getUniqueId().toString())){
                                    normalplayers.remove(toBeKicked.getUniqueId().toString());
                                    getConfig().set(getConfigPath(toBeKicked) + ".kingdom", "none");
                                    saveConfig();
                                    toBeKicked.sendMessage(getMessage("&6You have been kicked from your kingdom!"));
                                    return true;
                                }
                                else if(modplayers.contains(toBeKicked.getUniqueId().toString())){
                                    modplayers.remove(toBeKicked.getUniqueId().toString());
                                    getConfig().set(getConfigPath(toBeKicked) + ".kingdom", "none");
                                    saveConfig();
                                    toBeKicked.sendMessage(getMessage("&6You have been kicked from your kingdom!"));
                                    return true;
                                }
                                else if(generalplayers.contains(toBeKicked.getUniqueId().toString())){
                                    generalplayers.remove(toBeKicked.getUniqueId().toString());
                                    getConfig().set(getConfigPath(toBeKicked) + ".kingdom", "none");
                                    saveConfig();
                                    toBeKicked.sendMessage(getMessage("&6You have been kicked from your Kingdom!"));
                                    return true;
                                }
                                else if(player.getName().equals(toBeKicked.getName())){
                                    player.sendMessage(getMessage("&6Since when could a king &ckick &6him/herself?"));
                                }
                                else{
                                    player.sendMessage(getMessage("&cAn unknown error occurred"));
                                }




                            }
                            else{
                                player.sendMessage("Player is not part of your kingdom");
                            }



                        }
                        else{
                            player.sendMessage("wut");
                        }


                    }
                    else{
                        player.sendMessage(getMessage("6You don't have permission to run that command"));
                    }




                }
     
  2. Where are you adding them to the kingdom? In the config file? Or do you have a separate (sub)command for that?
    If you do it manually in the config, you'd need to do JavaPlugin#reloadConfig to reload it.
    If you've got a command for it, seeing the command would help.
     
  3. Thanks, I thought that the config automatically gets reloaded
     
  4. Set the thread prefix to solved
     

Share This Page