diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-03-19 18:07:29 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-03-19 18:07:29 +1000 |
commit | 7a41bde88f8c2164d1bc5b23bc695ea7bb5e9cda (patch) | |
tree | 280e902ab66a1cdd2bf72ca4dc6e000fdae5dcc6 | |
parent | 73a8779a5f46eeb449005840fdf1b9120816e380 (diff) | |
download | GT5-Unofficial-7a41bde88f8c2164d1bc5b23bc695ea7bb5e9cda.tar.gz GT5-Unofficial-7a41bde88f8c2164d1bc5b23bc695ea7bb5e9cda.tar.bz2 GT5-Unofficial-7a41bde88f8c2164d1bc5b23bc695ea7bb5e9cda.zip |
Updated null checks and error messages related to the init & creation of the PlayerCache.dat
-rw-r--r-- | src/Java/miscutil/MiscUtils.java | 4 | ||||
-rw-r--r-- | src/Java/miscutil/core/util/PlayerCache.java | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/Java/miscutil/MiscUtils.java b/src/Java/miscutil/MiscUtils.java index d180cfb6c3..fa0f043675 100644 --- a/src/Java/miscutil/MiscUtils.java +++ b/src/Java/miscutil/MiscUtils.java @@ -9,6 +9,7 @@ import miscutil.core.creativetabs.AddToCreativeTab; import miscutil.core.handler.XEventHandler; import miscutil.core.lib.CORE; import miscutil.core.lib.LoadedMods; +import miscutil.core.util.PlayerCache; import miscutil.core.util.Utils; import net.minecraftforge.common.MinecraftForge; import cpw.mods.fml.common.FMLCommonHandler; @@ -63,7 +64,8 @@ implements ActionListener //Post-Init @Mod.EventHandler public void postInit(FMLPostInitializationEvent event) { - Utils.LOG_INFO("Cleaning up the banana on the floor."); + Utils.LOG_INFO("Cleaning up, doing postInit."); + PlayerCache.initCache(); proxy.postInit(event); } diff --git a/src/Java/miscutil/core/util/PlayerCache.java b/src/Java/miscutil/core/util/PlayerCache.java index 40f44e003a..e247646562 100644 --- a/src/Java/miscutil/core/util/PlayerCache.java +++ b/src/Java/miscutil/core/util/PlayerCache.java @@ -19,12 +19,26 @@ public class PlayerCache { private static final File cache = new File("PlayerCache.dat"); + public static final void initCache() { + if (CORE.PlayerCache == null || CORE.PlayerCache.equals(null)){ + try { + CORE.PlayerCache = PlayerCache.readPropertiesFileAsMap(); + Utils.LOG_INFO("Loaded PlayerCache.dat"); + } catch (Exception e) { + Utils.LOG_INFO("Failed to initialise PlayerCache.dat"); + PlayerCache.createPropertiesFile("CACHE FILE - ", "THIS CONTAINS PLAYERDATA"); + //e.printStackTrace(); + } + } + } + public static void createPropertiesFile(String playerName, String playerUUIDasString) { try { Properties props = new Properties(); props.setProperty(playerName, playerUUIDasString); OutputStream out = new FileOutputStream(cache); props.store(out, "Player Cache."); + Utils.LOG_INFO("Created an empty PlayerCache.dat for future use."); } catch (Exception e ) { e.printStackTrace(); @@ -66,7 +80,7 @@ public class PlayerCache { * @return The Map that contains the key/value pairs. * @throws Exception */ - private static Map<String, String> readPropertiesFileAsMap() throws Exception { + public static Map<String, String> readPropertiesFileAsMap() throws Exception { String filename = cache.getName(); String delimiter = ":"; @SuppressWarnings({ "rawtypes", "unchecked" }) |