Config Problems (or reading from them)

Discussion in 'Plugin Development' started by Typhoon5, Dec 20, 2011.

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

    Typhoon5

    This is probably a rookie mistake, but what am i doing wrong here? i'm not getting errors in eclipse but when i run it it it just spams console.

    Code:
    package me.typhoon5.dailybonus.listeners;
    
    import java.util.logging.Logger;
    
    import org.bukkit.event.player.PlayerListener;
    
    import org.bukkit.event.player.PlayerJoinEvent;
    
    import me.typhoon5.dailybonus.DailyBonus;
    
    public class Listener_Player extends PlayerListener {
        @SuppressWarnings("unused")
        private DailyBonus plugin;
    
        public Listener_Player(DailyBonus plugin){
            this.plugin = plugin;
        }
            public boolean getConfig_giveonjoin(){
                return getConfig_giveonjoin();
            }
    
        @Override
         public void onPlayerJoin(PlayerJoinEvent event){
    
        if (getConfig_giveonjoin() == true){
              Logger log = Logger.getLogger("Minecraft");
              log.info("A player has gotten their bonus");
          // Do stuff here if its true
    
         }
        }
    }
    *To clarify, my problem is getting the Boolean from the config and applying it in my code
     
  2. Offline

    Chiller

    Because it always true so it goes on for ever!
     
  3. Offline

    Typhoon5

    o.o oops, but how would i properly get it from the config then?
     
  4. Offline

    Chiller

    Ive never used a config so idk?
     
  5. Offline

    Typhoon5

    Still need help please, anyone got any tips?
     
  6. Heh, I got some tips. Get it? My name is tips48! Hilarious!
    Anyway, I could give you a big long tutorial, but some basics are:
    Get the default config.yml:
    Code:java
    1.  
    2. YamlConfiguration = this.getConfig();
    3.  

    To make a custom config:
    Code:java
    1.  
    2. YamlConfiguration config = YamlConfiguration.loadConfig(file);
    3.  

    To copy the defaults from a config. Basically, this should be when the configuration file doesn't exist. You define it in the plugin root, and Bukkit will copy it over, comments and all!
    Code:java
    1.  
    2. config.options().copyDefaults(true);
    3.  

    To get or set a String
    Code:java
    1.  
    2. String value = config.getString("The.Path.To.My.Value", "DefaultValue");
    3. // To set it
    4. config.setProperty("The.Path.To.My.Value", "Value");
    5.  

    For other things, like boolean's, replace getString with the name...So for example, to get a boolean you would replace getString with getBoolean
    Full tutorial: http://forums.bukkit.org/threads/tutorial-intermediate-configuration-yaml-make-configs.45383/ or http://forums.bukkit.org/threads/logger-and-configuration-class-examples.44818/
    I haven't read nor used either of them, but they look promising! Hope this helps :)
     
  7. Offline

    Typhoon5

    Thanks, i'll try it out
     
Thread Status:
Not open for further replies.

Share This Page