Solved Problem with getting keys

Discussion in 'Spigot Plugin Development' started by MrIvanPlays, Aug 9, 2018.

Thread Status:
Not open for further replies.
  1. I am sure that this thingy here loops only thru the first premade announcement defined in the configuration and doesnt loop the other ones. The configuration: https://hastebin.com/itanayawiw.shell when i test it only sends the testbar the others say that the premade announcement cannot be found. So how i need to change my code to loop thru all and not only the first. Also when i change the type of the first one defined in the configuration to CHAT or TITLE its working correctly, but the other ones under the 1st defined doesnt work and i dont know why. Please help!
     
  2. 1. Use the built in "Code" tool to post code.
    2. Only send the part in question.
    3. Your signature is trying to be clever but its comparing a player object to a string.
     
  3. Why you are looking at my signature man? Also the links are hastebin, so i cannot get on your computer "weird virus" or something. Also why to send only the part in question? Other parts are information, man -_-
     
  4. TheJavaHacker

    Supporter

    1. Don't do that, there's too much code.
    2. Don't do that, we need as much information as possible.
    3. That is irrelevant, don't be stupid.
     
  5. Code (Text):
    if(args.length == 1){
                        for(String name : preConfig.getPre().getConfigurationSection("announcements").getKeys(false)){
                            String getType = preConfig.getPre().getString("announcements." + name + ".type");
                            String getMessage = preConfig.getPre().getString("announcements." + name + ".message");
                            String getPermission = preConfig.getPre().getString("announcements." + name + ".permission");
                            if(args[0].equalsIgnoreCase(name)){
                                if(getType.equalsIgnoreCase("ACTION_BAR")){
                                    if(getPermission.equalsIgnoreCase("none")){
                                        if(pm.isPluginEnabled("ActionBarAPI")){
                                            ActionBarAPI.sendActionBarToAllPlayers(plugin.color(getMessage));
                                        }else{
                                            sender.sendMessage(plugin.color(plugin.getLangString("actionbarapi-not-found")));
                                            return true;
                                        }
                                        return true;
                                    }
                                    for(Player online : Bukkit.getOnlinePlayers()){
                                        if(online.hasPermission(getPermission)){
                                            if(pm.isPluginEnabled("ActionBarAPI")){
                                                ActionBarAPI.sendActionBar(online, plugin.color(getMessage));
                                            }else{
                                                sender.sendMessage(plugin.color(plugin.getLangString("actionbarapi-not-found")));
                                                return true;
                                            }
                                            return true;
                                        }
                                    }
                                    return true;
                                }
                                if(getType.equalsIgnoreCase("TITLE")){
                                    for(Player online : Bukkit.getOnlinePlayers()){
                                        if(getPermission.equalsIgnoreCase("none")){
                                            online.sendTitle(plugin.color(getMessage), "");
                                            return true;
                                        }
                                        if(online.hasPermission(getPermission)){
                                            online.sendTitle(plugin.color(getMessage), "");
                                            return true;
                                        }
                                    }
                                    return true;
                                }
                                if(getType.equalsIgnoreCase("CHAT")){
                                    if(getPermission.equalsIgnoreCase("none")){
                                        Bukkit.broadcastMessage(plugin.color(plugin.getLangString("broadcast-format").replaceAll("%message%", plugin.color(getMessage))));
                                        return true;
                                    }
                                    for(Player online : Bukkit.getOnlinePlayers()){
                                        if(online.hasPermission(getPermission)){
                                            online.sendMessage(plugin.color(plugin.getLangString("broadcast-format").replaceAll("%message%", plugin.color(getMessage))));
                                            return true;
                                        }
                                    }
                                    return true;
                                }
                            }else{
                                sender.sendMessage(plugin.color(plugin.getLangString("preannouncement-not-found")));
                                return true;
                            }
                        }
    Wow that was difficult.
     
  6. TheJavaHacker

    Supporter

    You realise we need as much code as possible to accurately determine the problem. We don't need a snippet.
     
  7. Its not only that code lol. Also the signatures are made to be fun or something and they're not thinked to be a real java :p
     
  8. Change getKeys(false) to getKeys(true).Put the . at the beginning of the string instead of the end

    Edit:
    Code (Text):
    [code] String getType = preConfig.getPre().getString("announcements" + "." + name + ".type");
     
  9. Edited. happy?

    Edit: did it solve the issue
     
  10. I am gonna test it now, we'll see
    Edit: It didnt
     
    • Agree Agree x 1
  11. So is the config null? put debug messages
     
  12. Its not the config, if it was the config the 1st one defined will not work, but its working. The code is working, but idk y it doesnt want to go under the 1st one defined in the config. How i said before, when i change the type of the 1st one to TITLE or CHAT its working, but the other ones under 1st arent working (saying that cannot be find).

    Edit: just look at the config :p
     
  13. remove return true; from line 61
     
  14. Its not from theese thingies or from the returns that i am placing because the code is working. As i said before when i change the type of the 1st defined premade announcement in the configuration to TITLE or CHAT its working. Idk why the plugin cant get the other premade announcements under the 1st one.
     
  15. Ehm, can i have some help or ill be ignored?
     
  16. i am really struggling to understand what the problem really is here but from a glance at your code you really should have a
    Code (Java):
    return true
    after line 46 (after this):
    Code (Java):
    if(getPermission.equalsIgnoreCase("none")){
                                        if(pm.isPluginEnabled("ActionBarAPI")){
                                            ActionBarAPI.sendActionBarToAllPlayers(plugin.color(getMessage));
     
    if you explain the problem very explicitly as to what you do and what the exact effect is i might be able to help you more.
     
  17. The returns are not the problem here because as i said before the problem is that the code doesnt go downwards from the 1st premade announcement defined in the configuration. When i change the first premade announcement's type its working
     
  18. Ehm, can i get help today?
     
Thread Status:
Not open for further replies.