Erreur sauvegarde configuration (accès refusé) [1.12.2]



  • Bonjour à tous et à toutes,
    J'ai un problème assez énervant : quand je modifie en jeu la configuration du mod, ca ne se save pas et j'ai à la place un joli message d'erreur :

    [21:05:49] [main/ERROR] [FML]: Error while loading config /config/gunsofchickens.
    java.io.FileNotFoundException: C:\Users\coutu\AUBIN\JEUX\Minecraft\MODDING\Guns of Chickens\run\client\config\gunsofchickens (Accès refusé)
    	at java.io.FileInputStream.open0(Native Method) ~[?:1.8.0_221]
    	at java.io.FileInputStream.open(FileInputStream.java:195) ~[?:1.8.0_221]
    	at java.io.FileInputStream.<init>(FileInputStream.java:138) ~[?:1.8.0_221]
    	at net.minecraftforge.common.config.Configuration.load(Configuration.java:836) [Configuration.class:?]
    	at net.minecraftforge.common.config.Configuration.runConfiguration(Configuration.java:129) [Configuration.class:?]
    	at net.minecraftforge.common.config.Configuration.<init>(Configuration.java:146) [Configuration.class:?]
    	at net.minecraftforge.common.config.Configuration.<init>(Configuration.java:107) [Configuration.class:?]
    	at fr.flowarg.gunsofchickens.utils.handlers.ConfigHandler.syncConfig(ConfigHandler.java:47) [ConfigHandler.class:?]
    	at fr.flowarg.gunsofchickens.utils.handlers.RegistryHandler.onConfigChangedEvent(RegistryHandler.java:173) [RegistryHandler.class:?]
    	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_10_RegistryHandler_onConfigChangedEvent_OnConfigChangedEvent.invoke(.dynamic) [?:?]
    	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) [ASMEventHandler.class:?]
    	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) [EventBus.class:?]
    	at net.minecraftforge.fml.client.config.GuiConfig.actionPerformed(GuiConfig.java:332) [GuiConfig.class:?]
    	at net.minecraft.client.gui.GuiScreen.mouseClicked(GuiScreen.java:494) [GuiScreen.class:?]
    	at net.minecraftforge.fml.client.config.GuiConfig.mouseClicked(GuiConfig.java:385) [GuiConfig.class:?]
    	at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:611) [GuiScreen.class:?]
    	at net.minecraftforge.fml.client.config.GuiConfig.handleMouseInput(GuiConfig.java:372) [GuiConfig.class:?]
    	at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) [GuiScreen.class:?]
    	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1885) [Minecraft.class:?]
    	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1187) [Minecraft.class:?]
    	at net.minecraft.client.Minecraft.run(Minecraft.java:441) [Minecraft.class:?]
    	at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_221]
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_221]
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_221]
    	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_221]
    	at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    	at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_221]
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_221]
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_221]
    	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_221]
    	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    	at GradleStart.main(GradleStart.java:25) [start/:?]
    

    Je me suis donc renseigné sur l'erreur, j'ai testé des solutions comme :

            if(!configFile.canWrite())
            {
                configFile.setWritable(true);
            }
            if (!configFile.canRead())
            {
                configFile.setReadable(true);
            }
    

    sans succès 😕 .

    Si vous avez une solution, je la prendrais avec plaisir 🙂 !
    Merci à tous !

    Flow



  • Bon en fait, c'était tout simple, lors de l'event onConfigChangedEvent
    au lieu de sync la config, on la save, c'est tout 🙂 .
    Pour ceux que ca intéresse :

        @SubscribeEvent
        public static void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
        {
            if (event.getModID().equals(References.MODID))
            {
                if (ConfigHandler.config.hasChanged())
                {
                    ConfigHandler.config.save();
                }
            }
        }
    

    Voilà voilà, encore MErci à @robin4002 de l'aide apportée 🙂

    Flow



  • Je n'aime pas trop ça lais bon : Up ?


  • Moddeurs confirmés Rédacteurs Administrateurs

    Bonsoir,
    C'est assez étonnant comme résultat, tu as quelque chose qui restraint les droits d'accès au fichier gunsofchickens ?



  • Je ne pense pas, j'aime même essayé dans Windows de voir si les dossiers : config/gunsofchickens et à l'jntérieur le gunsofchickens.cfg si ils étaient en lecture seule. Ce n'était pas le cas.
    Voici la classe de configuration, peut être qu'elle aidera 🤷

    package fr.flowarg.gunsofchickens.utils.handlers;
    
    import fr.flowarg.gunsofchickens.utils.References;
    import net.minecraftforge.common.config.Configuration;
    import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
    
    import java.io.File;
    
    /**
     * @author FlowArg
     * @see net.minecraftforge.common.config.Configuration
     */
    public class ConfigHandler
    {
        public static File configFile;
        private static Configuration config;
    
        public static int GUI_CHICKEN_FURNACE = 5;
        public static int GUI_CHICKEN_CHEST = 1;
        public static int KIKI = 120;
        public static int CHICKEN_TNT = 121;
        public static int CHICKEN_DIM = 2;
        public static double spawnX = 0;
        public static double spawnY = 80;
        public static double spawnZ = 0;
        public static int tntReachDistance = 25;
        public static int tntReachDistancechDistancePlus = 25;
        static String welcomeMessage = "";
        static boolean showWelcomeMessage = true;
        public static float strength = 5f;
    
        public static void registerConfig(FMLPreInitializationEvent event)
        {
            configFile = new File(event.getModConfigurationDirectory() + "/" + References.MODID);
            if(!configFile.canWrite())
            {
                configFile.setWritable(true);
            }
            if (!configFile.canRead())
            {
                configFile.setReadable(true);
            }
            configFile.mkdirs();
            syncConfig(new File(configFile.getPath(), References.MODID + ".cfg"));
        }
    
        public static Configuration getConfig()
        {
            return config;
        }
        public static void syncConfig(File file)
        {
            config = new Configuration(file);
    
            String category;
    
            category = "Locations";
            config.addCustomCategoryComment(category, "Set the location of the world spawn");
            spawnX = (double)config.getInt("X Spawn", category, 0, 0, 29999999, "X coordinate for the world spawn");
            spawnY = (double)config.getInt("Y Spawn", category, 80, 0, 256, "Y coordinate for the world spawn");
            spawnZ = (double)config.getInt("Z Spawn", category, 0, 0, 29999999, "Z coordinate for the world spawn");
    
            category = "IDs";
            config.addCustomCategoryComment(category, "Set the different IDs for Entities and GUIs");
            KIKI = config.getInt("Kiki ID", category, 120, 120, 999, "ID for the kiki entity");
            CHICKEN_TNT = config.getInt("Chicken TNT ID", category, 121, 120, 999, "ID for the Chicken TNT entity");
            GUI_CHICKEN_CHEST = config.getInt("Chicken Chest GUI ID", category, 1, 1, 999, "ID for the Chicken Chest GUI");
            GUI_CHICKEN_FURNACE = config.getInt("Chicken Furnace ID", category, 5, 5, 999, "ID for the Chicken Furnace GUI");
            CHICKEN_DIM = config.getInt("Chicken Dimension ID", category, 2, 2, 999, "ID for the Chicken Dimension");
    
            category = "Other";
            config.addCustomCategoryComment(category, "Set other variables");
            tntReachDistance = config.getInt("TNT Reach Distance", category, 25, 5, 999, "Minimal distance of the launcher and the `Destination` of the TNT");
            tntReachDistancechDistancePlus = config.getInt("TNT Reach Distance + ", category, 25, 0, 999, "Supplemental distance of the launcher and the `Destination` of the TNT");
            welcomeMessage = config.getString("Welcome Message", category, "Welcome %player%", "The code %player% will be replaced by player's name");
            showWelcomeMessage = config.getBoolean("Enable/Disable the Welcome Message", category, true, "Set false to disable this");
            strength = config.getFloat("Chicken TNT strength", category, 15f, 1f, Float.MAX_VALUE, "Set the tnt strength when it explode");
    
            if (config.hasChanged())
            {
                config.save();
            }
        }
    
    }
    

    Ainsi que l'event qui enregistre la config a chaque fois qu'elle est modifiée (présente dans le RegistryHandler, elle est bien appelée car ça produit l'erreur)

    @SubscribeEvent
        public static void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
        {
            if (event.getModID().equals(References.MODID))
            {
                ConfigHandler.syncConfig(ConfigHandler.configFile);
            }
        }
    

    Voilà, je précise aussi que quand je modifie le fichier à la main, tout se passe bien, c'est via le gui de minecraft que ça fait le message d'erreur.

    J'espère t'avoir un peu plus éclairé sur mon soucis 🙂
    Flow



  • @robin4002 Boon, je viens de modifier 2/3 trucs et j'ai un truc qui marche a 50% :
    J'ai plus le soucis d'accès refusé MAIS, quand je synchronise la configuration, ca remet tout par défaut.
    Voici ma classe + l'event onConfigChangedEvent:

    package fr.flowarg.gunsofchickens.utils.handlers;
    
    import fr.flowarg.gunsofchickens.Main;
    import fr.flowarg.gunsofchickens.utils.References;
    import net.minecraftforge.common.config.Configuration;
    import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
    
    import java.io.File;
    
    /**
     * @author FlowArg
     * @see net.minecraftforge.common.config.Configuration
     */
    public class ConfigHandler
    {
        public static File configFile;
        private static Configuration config;
    
        public static int GUI_CHICKEN_FURNACE = 5;
        public static int GUI_CHICKEN_CHEST = 1;
        public static int KIKI = 120;
        public static int CHICKEN_TNT = 121;
        public static int CHICKEN_DIM = 2;
        public static double spawnX = 0;
        public static double spawnY = 80;
        public static double spawnZ = 0;
        public static int tntReachDistance = 25;
        public static int tntReachDistancechDistancePlus = 25;
        public static String welcomeMessage = "";
        public static boolean showWelcomeMessage = true;
        public static float strength = 5f;
    
        public static void registerConfig(FMLPreInitializationEvent event)
        {
            Main.LOGGER.debug("Registering config...");
            Main.LOGGER.debug("Creating config directory...");
            configFile = new File(event.getModConfigurationDirectory() + "/" + References.MODID);
            if (!configFile.canRead())
            {
                configFile.setReadable(true);
            }
            if (!configFile.canWrite())
            {
                configFile.setWritable(true);
            }
            configFile.mkdirs();
            Main.LOGGER.debug("Created config directory.");
            Main.LOGGER.debug("Creating config file...");
            //config = new Configuration(event.getSuggestedConfigurationFile());
            Main.LOGGER.debug("Created config file.");
            syncConfig(new File(configFile.getPath(), References.MODID + ".cfg"));
            Main.LOGGER.debug("Registered config.");
        }
    
        public static Configuration getConfig()
        {
            return config;
        }
        public static void syncConfig(File file)
        {
            config = new Configuration(file);
            config.load();
            Main.LOGGER.debug("Synchronising config...");
            String category;
    
            category = "Locations";
            config.addCustomCategoryComment(category, "Set the location of the world spawn");
            spawnX = (double)config.getInt("X Spawn", category, 0, 0, 29999999, "X coordinate for the world spawn");
            spawnY = (double)config.getInt("Y Spawn", category, 80, 0, 256, "Y coordinate for the world spawn");
            spawnZ = (double)config.getInt("Z Spawn", category, 0, 0, 29999999, "Z coordinate for the world spawn");
    
            category = "IDs";
            config.addCustomCategoryComment(category, "Set the different IDs for Entities and GUIs");
            KIKI = config.getInt("Kiki ID", category, 120, 120, 999, "ID for the kiki entity");
            CHICKEN_TNT = config.getInt("Chicken TNT ID", category, 121, 120, 999, "ID for the Chicken TNT entity");
            GUI_CHICKEN_CHEST = config.getInt("Chicken Chest GUI ID", category, 1, 1, 999, "ID for the Chicken Chest GUI");
            GUI_CHICKEN_FURNACE = config.getInt("Chicken Furnace ID", category, 5, 5, 999, "ID for the Chicken Furnace GUI");
            CHICKEN_DIM = config.getInt("Chicken Dimension ID", category, 2, 2, 999, "ID for the Chicken Dimension");
    
            category = "Other";
            config.addCustomCategoryComment(category, "Set other variables");
            tntReachDistance = config.getInt("TNT Reach Distance", category, 25, 5, 999, "Minimal distance of the launcher and the `Destination` of the TNT");
            tntReachDistancechDistancePlus = config.getInt("TNT Reach Distance + ", category, 25, 0, 999, "Supplemental distance of the launcher and the `Destination` of the TNT");
            welcomeMessage = config.getString("Welcome Message", category, "Welcome %player%", "The code %player% will be replaced by player's name");
            showWelcomeMessage = config.getBoolean("Enable/Disable the Welcome Message", category, true, "Set false to disable this");
            strength = config.getFloat("Chicken TNT strength", category, 15f, 1f, Float.MAX_VALUE, "Set the tnt strength when it explode");
    
            if (config.hasChanged())
            {
                config.save();
            }
        }
    
    }
    

    l'event :

        @SubscribeEvent
        public static void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
        {
            if (event.getModID().equals(References.MODID))
            {
                ConfigHandler.syncConfig(new File(ConfigHandler.configFile.getPath(), References.MODID + "cfg"));
                Main.LOGGER.debug("Synchronised config.");
            }
        }
    

    Voilà voilà, j'espère de tout coeur que tu auras une solution, merci beaucoup 🙂

    Flow


  • Moddeurs confirmés Rédacteurs Administrateurs

    Tu lis la configuration depuis le fichier de config au début de ta fonction syncConfig, donc forcement ça réécrit le contenu du fichier et tes paramètres modifiés sont perdu.



  • @robin4002 Yep, mais je n'ai pas trop d'idée pour éviter ce soucis, pourrais tu m'éclairer ma lanterne ? Merci 🙂

    Flow



  • Bon en fait, c'était tout simple, lors de l'event onConfigChangedEvent
    au lieu de sync la config, on la save, c'est tout 🙂 .
    Pour ceux que ca intéresse :

        @SubscribeEvent
        public static void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event)
        {
            if (event.getModID().equals(References.MODID))
            {
                if (ConfigHandler.config.hasChanged())
                {
                    ConfigHandler.config.save();
                }
            }
        }
    

    Voilà voilà, encore MErci à @robin4002 de l'aide apportée 🙂

    Flow


Log in to reply