Solved Calling strings from the config.yml

Discussion in 'Plugin Development' started by ReflectionCraft, Jul 6, 2019.

  1. Offline

    ReflectionCraft

    I want to call a string from my config.yml but its a child of two other parents
    Code:
    Users:
      USER1:
        Balance: 1
    If I wanted to call the balance variable how would I go about doing that?
    What I got so far is, player.sendMessage(Main.getPlugin(Main.class).getConfig().getString("Users"));
    Any input?
     
  2. Online

    KarimAKL

    @ReflectionCraft You can get to the next configuration section by seperating the names with a '.' character.
    Example:
    Code:Java
    1. getConfig().getInt("Users.USER1.Balance")
     
  3. Offline

    ReflectionCraft

    Lets say I have a command that says the balance, how would I target the command senders ID in the config

    Nevermind, I did some tinkering and came up with this
    Code:
    UUID playerID = player.getUniqueID();
    
    Main.getPlugin(Main.class).getConfig().getString("Users."+playerID+".Balance");
    I have a command /dbal and when I do it, in game it prints the message "MemorySection[path='Users', root='YAMLConfiguration'].
    Im unsure why but heres my code for the command
    Code:
    if(cmd.getName().equalsIgnoreCase("dbal")) //permission node is "dust.bal"
            {
               
                Inventory dustGUI = Bukkit.createInventory(null, 27, ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Magic Dust");
               
                ItemStack dust1 = new ItemStack(Material.GLOWSTONE_DUST);
                ItemMeta dust1Meta = dust1.getItemMeta();
               
                dust1Meta.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Magic Dust Balance");
               
                ArrayList<String> dust1lore = new ArrayList<String>();
                //dust1lore.add(ChatColor.WHITE + "" + ChatColor.ITALIC + ec.getDustMap());
                dust1lore.add(ChatColor.WHITE + "" + ChatColor.ITALIC + Main.getPlugin(Main.class).getConfig().getString("Users."+playerID+".Balance"));
                dust1Meta.setLore(dust1lore);
               
                dust1.setItemMeta(dust1Meta);
               
                dustGUI.setItem(13, dust1);
                player.openInventory(dustGUI);
            }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 6, 2019
  4. Online

    KarimAKL

    @ReflectionCraft Where exactly does it say that? In the chat? In the console? In the item's lore? Could you be a little more specific?
     
  5. Offline

    ReflectionCraft

    Yes its sent to the player in chat
     
  6. Online

    KarimAKL

    @ReflectionCraft The code you showed doesn't send any message to the player though.
    EDIT: Do you mean the code you had in the OG post? If so then it's probably because 'Users' isn't a string; it's a configuration section. The code you used to set the lore is correct, send that message to them.
     
  7. Offline

    ReflectionCraft

    I'm unsure why it's sending, earlier I had the message get sent to the player to test something but once I removed that line of code when you do /dbal it sends that message still.
    The line I added for testing but that is now removed is this
    Code:
    player.sendMessage(Main.getPlugin(Main.class).getConfig().getString("Users"))
     
  8. Online

    KarimAKL

  9. Offline

    ReflectionCraft

    I commented out the line of code and I just deleted it and it fixed the problem
     
  10. Online

    KarimAKL

    @ReflectionCraft Sounds weird, commented code is ignored, you must've done something wrong. Anyway, glad you got it solved. :) Remember to set the title prefix.
     

Share This Page