Config.yml Help Please

Discussion in 'Plugin Development' started by TGMGamingzz1, Apr 6, 2014.

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

    TGMGamingzz1

    Hello, I am quite new to configs. I am trying to make a plugin that needs to get information from the config more than once but i cannot seem to figure it out, i know my config is properly isn't very efficient as for some reason when it runs the events from the config it some times runs a different one or it just uses what it has run before.

    This is my config.
    Code:
    # Config File For the SimpleFortune Plugin.
    Five: 5
    Ten: 12
    Fiften: 15
    Twenty: 20
    Twentyfive: 25
    Thirty: 30
    
    I really hope that someone can help me to get this to work thanks.
     
  2. Offline

    triger545

    Post the code, not the config...
     
  3. Offline

    TGMGamingzz1

    I dont have code to set the config.yml
     
  4. Offline

    BillyBobJoe168

    How do you expect us to help you if we can't see what your code is? How do you know it doesn't work if you have no code? Post your main class. Also, shouldn't it be ten: 10 in your config not ten: 12?
     
  5. Offline

    1Achmed1

    Code:java
    1. getConfig().getString("stringHere");
     
  6. Offline

    coasterman10

    I could help if you could explain what you're trying to do with the config, whether it be set values, get values, etc.
     
  7. Offline

    TGMGamingzz1

    My code is very long and very UN efficient.
     
  8. Offline

    BillyBobJoe168

    Well can you post it? You can't expect us just to write you a brand new plugin without telling us what you want to do and just by saying your code is unefficient...
     
  9. Offline

    triger545

    Your config won't load if your code doesn't tell it to...
     
  10. Offline

    TGMGamingzz1

  11. Offline

    triger545

    First of all, you want to only use the "CopyFromDefaults(true)" when you first launch the plugin, otherwise whatever you change in the config will be overwritten everytime you start your server. You can fix this by putting it in an if statement like this:

    Code:java
    1. if(!getDataFolder().exists()) { //Checks to see if the folder has been created yet. If not, lets create the default config
    2. getConfig().options().copyDefaults(true);
    3. saveConfig();
    4. reloadConfig();
    5. }
    6.  


    To get the information from the config, use
    Code:
    getConfig().getString("Five");
    Code:java
    1. if(getConfig().getString("Five").equalsIgnoreCase("five")) {
    2. do this;
    3. }
     
  12. Offline

    TGMGamingzz1

    triger545 What does do this; mean is that just my code?
    Also This
    Code:java
    1. if(getConfig().getString("Five").equalsIgnoreCase("five")) {


    wouldnt work because my code is to get the config as the config sets the amount of items droppedi and its near the end of the event
    Code:java
    1. if (event.getBlock().getType() == Material.IRON_ORE) {
    2. event.getBlock().getWorld()
    3. .getBlockAt(event.getBlock().getLocation())
    4. .setType(Material.AIR);
    5. event.getBlock()
    6. .getWorld()
    7. .dropItemNaturally(
    8. loc,
    9. new ItemStack(Material.IRON_INGOT,
    10. getConfig().getInt("Five")));
     
  13. Offline

    triger545

    TGMGamingzz1 Yes, replace "do this" with whatever code you want there.
     
  14. Offline

    TGMGamingzz1

    I have edited my last post a bit so can you re read it please?
     
  15. Offline

    ToastHelmi

    does someone know how tu use getItemStack from the config?
    do I have to use the id or name or what
    1Achmed1
     
  16. Offline

    TGMGamingzz1

  17. Offline

    TGMGamingzz1

    I guess nobody can help me?
     
  18. Offline

    TGMGamingzz1

Thread Status:
Not open for further replies.

Share This Page