Config file not working?

Discussion in 'Spigot Plugin Development' started by ieatdiamond, Jun 26, 2016.

  1. Code (Text):
    package pl.kminer;

    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    import pl.events.BlockBreaking;
    import pl.events.PlayerJoin;

    public class KarmaMiner extends JavaPlugin {
       
        //FileConfiguration config = getConfig();
       
        //public void onEnable() {
            //registerEvents();
            ///registerConfig();
           
        //}

        //public void onDisable() {
           
        //}
       
        //public void registerEvents() {
        //    getServer().getPluginManager().registerEvents(new BlockBreaking(), this);
            //getServer().getPluginManager().registerEvents(new PlayerJoin(this), this);
        //}
       
        //private void registerConfig() {
            //config.addDefault("youAreAwesome", true);
            //config.options().copyDefaults(true);
            //saveConfig();
               
        //}
        FileConfiguration config = getConfig();

        public void onEnable() {
            config.addDefault("youAreAwesome", true);
            config.options().copyDefaults(true);
            saveConfig();
        }

        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();

            if (config.getBoolean("youAreAwesome")) {
                player.sendMessage("You are awesome!");
            } else {
                player.sendMessage("You are not awesome...");
            }
        }

    }
     
    same exact code from wiki, in config it says youAreAweomse: true like it should but its not sending the player on join any message.
     
    • Agree Agree x 1
  2. Im just doing as the tutorial stated, caused some confusion.
     
  3. Thanks for the more in depth wiki.
     
  4. @ieatdiamond why skip to configuration files before understanding events? Events are one of the first things you want to learn
     
  5. i already know what events are lol, thats why i was confused i didnt see how the src was working without registering the event,.