Solved Configfile config.yml gets overwritten at reload/start

Discussion in 'Plugin Development' started by bennie3211, Jun 16, 2013.

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

    bennie3211

    Hi all, i have a little problem with my config file. 2 hours ago it worked fine, no problems or errors. After making a silktouchlistener, my plugin gets overwritten (in my silktouchlistenere i dont change anything from the config, i only get a boolean if the ability is enabled). This is what my config looks like in my donators.jar plugin:

    And this is how it looks like when I have reloaded/restarted the server:

    Even when i start my server, and then copy past it to the config again, and i do /reload, its gone again :L

    The way I load the config:

    onEnable() I call Load(). My Load() method is:

    Code:
    public void Load()
        {
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    I have never ever had any problems until now :( Who can help me?
     
  2. Offline

    the_merciless

    You dont need to load it, just check if it exists
     
  3. Offline

    bennie3211

    but i thought it did that already?

    EDIT:

    the_merciless

    I have solved the issue about overwritting the config, but now, when i use /dspawner for the first time after a reload/server restart, I get an error :(

    The first time i do /dspawner, I will get the error above, but the second time, it works perfectly :S What is the problem? I cant find the real problem from the error logg :(
     
  4. Offline

    the_merciless

    Show us your code for the command
     
  5. Offline

    bennie3211

    the_merciless

    This is what my ChangeSpawnerExecutor class looks like:

    Code:
    package me.dutch_kids.donators;
     
    import java.util.List;
    import java.util.Locale;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.CreatureSpawner;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
     
    public class ChangeSpawnerExecutor implements CommandExecutor
    {
        final static String prefix = ChatColor.WHITE + "[" + ChatColor.GOLD + "Donators" + ChatColor.WHITE + "]";
       
        public Donators plugin;
       
        public ChangeSpawnerExecutor(Donators plugin)
        {
            this.plugin = plugin;
        }
       
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String Label, String[] args)
        {
            if (sender instanceof Player)
            {
                Player pl = (Player) sender;
                List<String> mobs = plugin.getConfig().getStringList("mobspawner");
               
                if (args.length == 0)
                {
                    String names = "";
                   
                    for(int i = 0; i < mobs.size(); i++)
                    {
                        if (pl.hasPermission("donators.spawner." + mobs.get(i).toLowerCase(Locale.ENGLISH)))
                        {
                            names += ChatColor.GREEN + ", " + mobs.get(i).toString().toLowerCase();
                        }
                        else
                        {
                            names += ChatColor.GREEN + ", " + ChatColor.RED + mobs.get(i).toString().toLowerCase(Locale.ENGLISH);
                        }
                       
                    }
                   
                    pl.sendMessage(prefix + ChatColor.DARK_GREEN + " Usage: " + ChatColor.GREEN + " /dspawner <mobtype>");
                    pl.sendMessage(prefix + ChatColor.DARK_GREEN + " Available mobtypes: " + names);
                    return true;
                }
               
                else if (args.length > 0)
                {
                    final Location block = pl.getTargetBlock(null, 40).getLocation();
               
                    if ((block.getBlock().getType().equals(Material.MOB_SPAWNER)) && (block != null))
                    {
                        if (mobs.contains(args[0].toUpperCase()))
                        {
                            if (pl.hasPermission("donators.spawner." + args[0].toLowerCase()) || pl.isOp())
                            {
                                CreatureSpawner spawner = ((CreatureSpawner) block.getBlock().getState());
                                String mobname = args[0].toUpperCase();
                                spawner.setSpawnedType(EntityType.valueOf(mobname));
                                spawner.setDelay(0);
                               
                                pl.sendMessage(prefix + ChatColor.GREEN + " Mob spawner successfully changed to " + ChatColor.DARK_GREEN + args[0].toLowerCase().replace("_", " "));
                                return true;
                            }
                            else
                            {
                                pl.sendMessage(prefix + ChatColor.DARK_RED + " You have not the permission to change the mob spawner to " + ChatColor.RED + args[0].toLowerCase().replace("_", " "));
                                return true;
                            }
                        }
                        else
                        {
                            pl.sendMessage(prefix + ChatColor.DARK_RED + " Unknown mobtype " + ChatColor.RED + args[0].toLowerCase().replace("_", " "));
                            pl.sendMessage(prefix + ChatColor.DARK_RED + " Check all mobtypes with " + ChatColor.RED + "/dspawner");
                            return true;
                        }
                    }
                    else
                    {
                        pl.sendMessage(prefix + ChatColor.DARK_RED + " That block is not a mob spawner! Be sure there is a mob spawner at the place you are looking at!");
                        return true;
                    }
                }
                return false;
            }
            else
            {
                sender.sendMessage(prefix + ChatColor.DARK_RED + " Commands are only available for ingame players!");
                return true;
            }
        }
    }
    
    It works perfect, expect the error that i get :(
     
  6. Offline

    the_merciless

    Paste your config again, and your onenable method
     
    bennie3211 likes this.
  7. Offline

    bennie3211

    I solved it, i have added a new path in the config.yml, and i made a typ for the name, so it could not get the value of it. Thnx for your help :)
     
Thread Status:
Not open for further replies.

Share This Page