Posted November 5, 201212 yr I am trying to make a money mod, but I need a way to store and change the variables like the player name and money amount in a external file. What would I use to do this? I made the night vision mining hats mod. http://www.minecraftforum.net/topic/1830713-152forge-night-vision-mining-hats/
November 6, 201212 yr The easiest would be to create an xml file or yaml which alot of other mods use. If ur not sure how to write to an xml or yaml file you can just search for java tutorials tyere are quite a few out there. Hooe that helps u out, good luck
November 6, 201212 yr Author Whats better xml or yaml? I made the night vision mining hats mod. http://www.minecraftforum.net/topic/1830713-152forge-night-vision-mining-hats/
November 7, 201212 yr YAML. It's simpler and easier for everyone. Protip: try and find answers yourself before asking on the forum. It's pretty likely that there is an answer. Was I helpful? Give me a thank you! http://bit.ly/HZ03zy[/img] Tired of waiting for mods to port to bukkit? use BukkitForge! (now with a working version of WorldEdit!)
November 7, 201212 yr Author Do I import the src or the jar into the project for yaml? I made the night vision mining hats mod. http://www.minecraftforum.net/topic/1830713-152forge-night-vision-mining-hats/
November 7, 201212 yr Or if you don't need the player to be able to modify these values, just compress and export the map with the mappings directly. You can do this like this: Saving: File savedirectory = new File(world.getSaveHandler().getSaveDirectoryName().concat("/MySaveInfo.dat")); savedirectory.createNewFile(); ObjectOutputStream os = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(savedirectory))); os.writeObject(MapContainingPlayerMappedVariables); Loading: File savedirectory = new File(world.getSaveHandler().getSaveDirectoryName().concat("/MySaveInfo.dat")); if(savedirectory.exists()){ ObjectInputStream os = new ObjectInputStream(new GZIPInputStream(new FileInputStream(savedirectory))); MapContainingPlayerMappedVariables.putAll((Map)os.readObject()); } Remember to encompass file saving/loading in a try catch block in case there are write errors.
November 8, 201212 yr Author Im just going to use yaml. I made the night vision mining hats mod. http://www.minecraftforum.net/topic/1830713-152forge-night-vision-mining-hats/
November 8, 201212 yr Author I got the save function to work but im having some trouble with the load function, curently I have package economy.common; import java.io.*; import java.util.*; import org.yaml.snakeyaml.Yaml; public class Data { public static String LoadData(String player) throws IOException { File file = new File("config/EconomyAcounts.yml"); if(!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } //TODO: Load file Yaml yaml = new Yaml(); List<String> list = (List<String>) yaml.load(document); //TODO: find the amount of money the player has //return amount } public static void SaveData(String player, String amount) throws FileNotFoundException { File file = new File("config/EconomyAcounts.yml"); if(!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } Map<String, Object> data = new HashMap<String, Object>(); data.put(player, amount); Yaml yaml = new Yaml(); String output = yaml.dump(data); PrintWriter out = new PrintWriter(file); out.println(output); out.close(); } } I made the night vision mining hats mod. http://www.minecraftforum.net/topic/1830713-152forge-night-vision-mining-hats/
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.