Posted March 12, 20169 yr I am trying to save information to a file on server side. My save method is getting triggered by WorldEvent.Save I am getting this error when the world try's to save: 23:50:13] [server thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.world.WorldEvent$Save@7100ac37: java.lang.ExceptionInInitializerError at lidr.common.LiDrEvents.worldSave(LiDrEvents.java:32) ~[LiDrEvents.class:?] ... Caused by: java.lang.NullPointerException at lidr.common.DraftableReg.SaveDraftables(DraftableReg.java:57) and my WorldSave Method: @SubscribeEvent public void worldSave(WorldEvent.Save e){ if(!e.world.isRemote) DraftableReg.SaveDraftables(); // this is line 32 } DraftableReg is a java "static" class meaning every field and method is static, private instructor with another field that instantiates it. public final class DraftableReg { public static final DraftableReg draftableReg = new DraftableReg(); private static final URL LOCATION = draftableReg.getClass().getClassLoader().getResource("Draftables.json"); private DraftableReg(){ DraftableMap dMap = new DraftableMap(); dMap.AddPart(new TriTuple(0,0,0), new EdgePart(LuxinReg.RegisteredLuxin.get("Blue"), Purity.Base)); RegisterDraftable(CoreFactory.GenerateFrom("test", CoreType.Sword, dMap)); //Testing items } public static void SaveDraftables(){ try { GsonBuilder builder = new GsonBuilder(); builder.registerTypeHierarchyAdapter(IDraftable.class, new DraftableAdapter<DraftingItemCore>()); builder.enableComplexMapKeySerialization(); builder.setPrettyPrinting(); Gson gson = builder.create(); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(LOCATION.getFile()), "UTF-8")); gson.toJson(knowledgeBase, out); // this is line 57 } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } So obviously my URL is faulty. How should I be choosing a location to save to? Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures
March 12, 20169 yr Yes, your save location is faulty because it is inside the JAR file. You need to point to a location that has write access. 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.
March 12, 20169 yr Author Thats what I can't figure out how to get. Lets say this is the folder structure: / mods/ LightDrafter.jar ... config/ LightDrafter/ Draftables.json How do I get the path/URL of Draftables.json Current Project: Armerger Planned mods: Light Drafter | Ore Swords Looking for help getting a mod off the ground? Coding | Textures
March 12, 20169 yr Client-side you can get the game directory from Minecraft#mcDataDir, server-side from MinecraftServer#getDataDirectory(), or you can get it in pre-init with FMLPreInitializationEvent#getModConfigurationDirectory().
March 12, 20169 yr You can also use FMLInitializationEvent#getSuggestedConfigurationFile() which you could manipulate to get the config directory There's also Loader.instance().getConfigDir() 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.
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.