Posted June 18, 201510 yr I would like to know if there is a way to edit a config file via command and if so could someone explain to me how to do it.
June 18, 201510 yr Hey, if you are interested in an easier way to edit configFiles.(and actualy ingame through for example a command) I would suggest to take a look at my api. I made especialy for these purposes https://github.com/N247S/N2Configuration Projects: Discontinued: - N2ConfigAPI - Meachanical Crafting Table Latest: - CollectionUtils Coöperations: - InGameConfigManager
June 18, 201510 yr Author Sorry for making it unclear but what i meant was i want to implement this feature into my mod and i already have the commands and the config file but i dont know how to link them.
June 18, 201510 yr What do you mean commands? Sorry, I'm a bit confused. Do you mean command block kind commands?
June 19, 201510 yr It can be rather simple. You got a configFile already, so have you written the code to update your configFile yet? If so, you would only have to call the responsoble method when the command is typed in. Projects: Discontinued: - N2ConfigAPI - Meachanical Crafting Table Latest: - CollectionUtils Coöperations: - InGameConfigManager
June 19, 201510 yr Like what others have said, if you have a reference to your Config object stored somewhere, such as your Main class, then writing to it from a command is as simple as using that reference to access a value in the file like you do when you first load the config. However, what would be the point of this? Do you just want the command to change the config setting that is currently being used in the game? If so, you need to change THAT reference, not write to the config file - the only reason you would write to the config file is to save the change for the next time the player loads the game, but you'd still have to change the current value of the config setting for it to have any immediate effect. http://i.imgur.com/NdrFdld.png[/img]
June 19, 201510 yr However, what would be the point of this? Do you just want the command to change the config setting that is currently being used in the game? If so, you need to change THAT reference, not write to the config file - the only reason you would write to the config file is to save the change for the next time the player loads the game, but you'd still have to change the current value of the config setting for it to have any immediate effect. To clarify a bit more. While it is possible to read from the actual config file every time you need one of the config settings, that causes a file read access which can affect performance. So best practice is to read the config file once during the mod initialization and store the values in public fields that can then be accessed in your code. So assuming you have it set up that way, in the command processing code what you want to invoke is a config "sync" method which both writes to the config file but also updates any fields that are supposed to hold values read from the config file. Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.