Solved Config.yml do not work

Discussion in 'Plugin Development' started by shadow5353, Apr 23, 2014.

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

    shadow5353

    I can not find out what I do wrong with this config.yml

    config.yml
    Code:
    # Enable/disable auto update for the plugin
    Auto-update: false
     
    # Set the gamemode for each world
    gamemode:
     
      # Set the gamemode to survival in a world
        survival:
        - world
        - world_nether
        - world_the_end
     
          # Enable message when a player join a creative world
          enable-message: true
          # Send them a custom message when they join a survival world
          message: &2You are now in the survival world
     
     
        # Set the gamemode to adventure in a world
        adventure:
        - adventure
     
          # Enable message when a player join a creative world
          enable-message: true
          # Send them a custom message when they join a survival world
          message: &2You are now in the adventure world
     
     
        # Set the gamemode to creative in a world
        creative:
        - creative
     
          # Enable message when a player join a creative world
          enable-message: true
          # Send them a custom message when they join a survival world
          message: &2You are now in the creative world
    Code:
    Code:
    public class WorldGamemode extends JavaPlugin implements Listener{
        FileConfiguration config;
        File cfile;
       
        public void onEnable() {
            if (getConfig().getString("Auto-update").contains("true")) {
                Updater updater = new Updater(this, 78765, this.getFile(),Updater.UpdateType.DEFAULT, true);
            }
            if (getConfig().getString("Auto-update").contains("false")) {
                Updater updater = new Updater(this, 78765, this.getFile(),Updater.UpdateType.NO_DOWNLOAD, true);
            }
           
            config = getConfig();
            config.options().copyDefaults(true);
            saveDefaultConfig();
            cfile = new File(getDataFolder(), "config.yml");
           
            // MCStats
                    try {
                        Metrics metrics = new Metrics(this);
                        metrics.start();
                    } catch (IOException e) {
                        // Failed to submit the stats :-(
                    }
           
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onPlayerChangedWorld(PlayerChangedWorldEvent e){
            if(!(e.getPlayer().hasPermission("wg.use"))){
               
            }
            if(config.getStringList("gamemode.adventrue").contains(e.getPlayer().getWorld())){
                e.getPlayer().setGameMode(GameMode.ADVENTURE);
                if(config.getString("gamemode.adventure.enable-message").contains("true")){
                    Player p = e.getPlayer();
                    String msg = getConfig().getString("gamemode.adventrue.message");
                    msg = msg.replaceAll("&", "§");
                    p.sendMessage(msg);
                }
            }
            if(config.getStringList("gamemode.creative").contains(e.getPlayer().getWorld())){
                e.getPlayer().setGameMode(GameMode.CREATIVE);
                if(config.getString("gamemode.creative.enable-message").contains("true")){
                    Player p = e.getPlayer();
                    String msg = getConfig().getString("gamemode.creative.message");
                    msg = msg.replaceAll("&", "§");
                    p.sendMessage(msg);
                }
            }
            if(config.getStringList("gamemode.survival").contains(e.getPlayer().getWorld())){
                e.getPlayer().setGameMode(GameMode.SURVIVAL);
                if(config.getString("gamemode.survival.enable-message").contains("true")){
                    Player p = e.getPlayer();
                    String msg = getConfig().getString("gamemode.survival.message");
                    msg = msg.replaceAll("&", "§");
                    p.sendMessage(msg);
                }
            }
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            Player p = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("wg")){
                if(args.length == 1){
                    if(args[0].equalsIgnoreCase("reload")){
                        if(!(sender.hasPermission("wg.admin"))){
                            mm.getInstance().severe(p, "You do not have permission");
                            return true;
                        }
                        config = YamlConfiguration.loadConfiguration(cfile);
                        mm.getInstance().good(p, "Reloaded config.yml!");
                        return true;
                    }
                }
            }
            return true;
        }
    }
    
    Error:
    http://pastebin.com/xzNsRxVr
     
  2. Offline

    tryy3

    shadow5353 likes this.
  3. Offline

    Etsijä

    Please use an YML validator, it will tell you straight away what is wrong with your YML. One parser here:
    http://yaml-online-parser.appspot.com/

    When I pasted your file, it gave straight away numerous errors, the first one being on line 8. Just work your way from there.

    And please note that YML is VERY choosy when it comes to spacing.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    Plo124

    shadow5353
    you need to compare the name of the world in the config to e.getPlayer().getWorld().getName(). you missed out the getName which gets the name of thw world. Also you spelt *adventrue* wrong in the code

    shadow5353 also as tryy3 said YAML is very picky when you are writing it.

    I think you need to initiallise the config.yml for bukkit In onenable with this.getConfig().options().copyDefaults(true);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    shadow5353

    tryy3 Thank you for your help :D
     
  6. Offline

    Plo124

    shadow5353
    if the problem is fixed mark thread as solved
     
    shadow5353 likes this.
  7. Offline

    shadow5353

    It should work now, thank you all for your help :D
     
Thread Status:
Not open for further replies.

Share This Page