for loop for config not working properly

Discussion in 'Plugin Development' started by Blackwing_Forged, Apr 3, 2018.

Thread Status:
Not open for further replies.
  1. When i run this command i get the first "test" message but not the second, its like it skips over the for loop entirely and i just get the message "That Cause doesn't exist!" and no errors in console and my config is perfectly fine

    Code:
    if(main.getConfig().getConfigurationSection("Death Messages") != null)
                            {
                                p.sendMessage("test");
                                for(String key : main.getConfig().getConfigurationSection("Death Messages").getKeys(false))
                                {
                                    p.sendMessage("test");
                                    if(key.equals(cause))
                                    {
                                        if(main.getConfig().getStringList("Death Messages."+key) != null)
                                        {
                                            List<String> list = main.getConfig().getStringList("Death Messages."+key);
                                            list.add(msg);
                                            main.getConfig().set("Death Messages."+key, list);
                                            main.saveConfig();
                                            main.reloadConfig();
                                            p.sendMessage(ChatColor.GREEN + "Message added!");
                                            return true;
                                        }
                                        else
                                        {
                                            List<String> list = new ArrayList<String>();
                                            list.add(msg);
                                            main.getConfig().set("Death Messages."+key, list);
                                            main.saveConfig();
                                            main.reloadConfig();
                                            p.sendMessage(ChatColor.GREEN + "Message added!");
                                            return true;
                                        }
                                    }
                                }
                                p.sendMessage(ChatColor.RED + "That Cause doesn't exist!");
                                return true;
                            }
    Code:
    #Placeholders: %killed% | %killer% | %main_hand% | %off_hand%
    Death Messages:
      BLOCK_EXPLOSION:
      #Damage caused by being in the area when a block explodes.
      CONTACT:
      #Damage caused when an entity contacts a block such as a Cactus.
      CRAMMING:
      #Damage caused when an entity is colliding with too many entities due to the maxEntityCramming game rule.
      DRAGON_BREATH:
      #Damage caused by a dragon breathing fire.
      DROWNING:
      #Damage caused by running out of air while in water
      ENTITY_ATTACK:
      #Damage caused when an entity attacks another entity.
      ENTITY_EXPLOSION:
      #Damage caused by being in the area when an entity, such as a Creeper, explodes.
      ENTITY_SWEEP_ATTACK:
      #Damage caused when an entity attacks another entity in a sweep attack.
      FALL: 
      #Damage caused when an entity falls a distance greater than 3 blocks
      FALLING_BLOCK:
      #Damage caused by being hit by a falling block which deals damage
      FIRE: 
      #Damage caused by direct exposure to fire
      FIRE_TICK:
      #Damage caused due to burns caused by fire
      FLY_INTO_WALL:
      #Damage caused when an entity runs into a wall.
      HOT_FLOOR:
      #Damage caused when an entity steps on Material.MAGMA.
      LAVA:
      #Damage caused by direct exposure to lava
      LIGHTNING:
      #Damage caused by being struck by lightning
      MAGIC:
      #Damage caused by being hit by a damage potion or spell
      MELTING:
      #Damage caused due to a snowman melting
      POISON:
      #Damage caused due to an ongoing poison effect
      PROJECTILE: 
      #Damage caused when attacked by a projectile.
      STARVATION: 
      #Damage caused by starving due to having an empty hunger bar
      SUFFOCATION:
      #Damage caused by being put in a block
      SUICIDE:
      #Damage caused by committing suicide using the command "/kill"
      THORNS:
      #Damage caused in retaliation to another attack by the Thorns enchantment.
      VOID:
      #Damage caused by falling into the void
      WITHER:
      #Damage caused by Wither potion effect
     
    Last edited by a moderator: Apr 3, 2018
  2. Offline

    timtower Administrator Administrator Moderator

  3. @timtower
    What do you mean? thats the config in the server files
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Blackwing_Forged
    main.getConfig().getConfigurationSection("Death Messages").getKeys(false)
    Print everything in there.
     
  5. @timtower
    oh, nothing prints in the for loop
    not even a set message like p.sendMessage("test");
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Blackwing_Forged Separate loop, at the beginning of the function, or at the end of the onEnable.
     
  7. @timtower
    i did this
    in onEnable
    for(String key : getConfig().getConfigurationSection("Death Messages").getKeys(false))
    {
    System.out.println(key);
    }

    but nothing printed
     
  8. Offline

    timtower Administrator Administrator Moderator

  9. @timtower
    I get the message Death Messages in console
    03.04 12:12:39 [Server] INFO Death Messages
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. @timtower
    i just tried that before you responded lol, still just prints out Death Messages
     
  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    timtower Administrator Administrator Moderator

    Locked
    Protocol hacks are not supported by Bukkit (ViaVersion)
     
Thread Status:
Not open for further replies.

Share This Page