Clarinetncleats3 Posted February 7, 2014 Posted February 7, 2014 HI, In the mod I'm making, I want the user to be able to type "SLEnable" to enable the mod and "SLDisable to disable the mod. This works fine while ingame, but when you exit the game and rejoin, it goes back to the default state of being enabled. After looking in the forge/mcp/jars/config directory, I found that the configuration file is simply not changing when these "commands" are being run. I looked at this post: http://www.minecraftforge.net/forum/index.php/topic,7746.0.html. I changed my boolean "Enabled" variable to a Property and used the Property.set() method but the config file is still not changing. My Body Class (SLMain.java): package comaolevbelcher.ShedLight; import comaolevbelcher.WhatStuff.WSPlayerDeathHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; import net.minecraft.src.ModLoader; import net.minecraftforge.common.Configuration; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.Property; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.registry.TickRegistry; import cpw.mods.fml.relauncher.Side; @Mod(modid = SLInfo.ID, name = SLInfo.NAME, version = SLInfo.VERSION) @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class SLMain { public static int MaxLightLevel; public static boolean InNether; public static Property Enabled; static Configuration config; @EventHandler public static void preInit(FMLPreInitializationEvent event) { config = new Configuration(event.getSuggestedConfigurationFile()); config.load(); MaxLightLevel = config.get(Configuration.CATEGORY_GENERAL, "Maximum Light Level", 7).getInt(); InNether = config.get(Configuration.CATEGORY_GENERAL, "Place torches in Nether?", false).getBoolean(false); Enabled = config.get(Configuration.CATEGORY_GENERAL, "Enable this mod?", true); config.save(); } /*public static void saveConfig(){ config.save(); } public static void loadConfig(){ config.load(); }*/ @EventHandler public void load(FMLInitializationEvent event) { TickRegistry.registerTickHandler(new SLGameTickHandler(), Side.CLIENT); } @EventHandler public void postInit(FMLPostInitializationEvent event) { System.out.println("You are running " + SLInfo.NAME + " made by " + SLInfo.CREATORS); MinecraftForge.EVENT_BUS.register(new SLChatHandler()); } } My ChatHandler class (SLChatHandler.java): package comaolevbelcher.ShedLight; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ServerChatEvent; public class SLChatHandler { @ForgeSubscribe public void onChat(ServerChatEvent event){ if (event.player instanceof EntityPlayer){ if (event.message.contentEquals("SLEnable")){ SLMain.Enabled.set(true); EntityPlayer player = (EntityPlayer) event.player; player.addChatMessage("Shed Light has been enabled."); event.setCanceled(true); } if (event.message.contentEquals("SLDisable")){ SLMain.Enabled.set(false); EntityPlayer player = (EntityPlayer) event.player; player.addChatMessage("Shed Light has been disabled."); event.setCanceled(true); } } } } Why is the Enabled property not changing in the configuration file? By the way, disregard the fact that the MinecraftForge.EVENT_BUS.register(new SLChatHandler()); was in the postInit instead of the load. I did that in an attempt to troubleshoot something earlier. Thanks, Clarinetncleats3 Quote
Draco18s Posted February 7, 2014 Posted February 7, 2014 Configuration config = new Configuration(some_file_reference);//you'll have to figure this out for yourself config.get(Configuration.CATEGORY_GENERAL, "Enable this mod?", true).set(false); Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Clarinetncleats3 Posted February 7, 2014 Author Posted February 7, 2014 Is this what you meant? package comaolevbelcher.ShedLight; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.Configuration; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.ServerChatEvent; public class SLChatHandler { @ForgeSubscribe public void onChat(ServerChatEvent event){ if (event.player instanceof EntityPlayer){ if (event.message.contentEquals("SLEnable")){ SLMain.config.get(Configuration.CATEGORY_GENERAL, "Enable this mod?", false).set(true); EntityPlayer player = (EntityPlayer) event.player; player.addChatMessage("Shed Light has been enabled."); event.setCanceled(true); } if (event.message.contentEquals("SLDisable")){ SLMain.config.get(Configuration.CATEGORY_GENERAL, "Enable this mod?", true).set(false); EntityPlayer player = (EntityPlayer) event.player; player.addChatMessage("Shed Light has been disabled."); event.setCanceled(true); } } } } ... Because it doesn't work. Quote
coolboy4531 Posted February 7, 2014 Posted February 7, 2014 I don't know, not into Entities. Try something like EntityPlayer, EntityClientPlayerMP, etc. i really don't know tbh Quote
Clarinetncleats3 Posted February 7, 2014 Author Posted February 7, 2014 I don't know, not into Entities. Try something like EntityPlayer, EntityClientPlayerMP, etc. i really don't know tbh Uhhh... did you comment on the wrong post? Because your post makes no sense in this context. Quote
Draco18s Posted February 7, 2014 Posted February 7, 2014 Here's some working code that I use Property cw = config.get("WorldGen","dimensionWhitelistList", new int[] {0}); Property cb = config.get("WorldGen","dimensionBlacklistList", new int[] {-1,1}); int[] white = cw.getIntList(); int[] black = cb.getIntList(); Arrays.sort(white); Arrays.sort(black); String a=Arrays.toString(white); String whitestring[]=a.substring(1,a.length()-1).split(", "); String b=Arrays.toString(black); String blackstring[]=b.substring(1,b.length()-1).split(", "); cw.set(whitestring); cb.set(blackstring); It sorts two lists of dimensions so that they're in numerical order. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.