From 8a2226d483e60098f6b7446f8f5c261c60349ff6 Mon Sep 17 00:00:00 2001 From: Pahimar Date: Thu, 26 Jun 2014 15:19:59 -0400 Subject: [PATCH] When player data is loaded from disk, store the location it's reading the data from. Also, create a file for the player should one not already exist. --- .../ee3/handler/PlayerEventHandler.java | 48 ++++++++----------- .../com/pahimar/ee3/reference/Settings.java | 6 +++ 2 files changed, 25 insertions(+), 29 deletions(-) create mode 100644 src/main/java/com/pahimar/ee3/reference/Settings.java diff --git a/src/main/java/com/pahimar/ee3/handler/PlayerEventHandler.java b/src/main/java/com/pahimar/ee3/handler/PlayerEventHandler.java index 501a060a..62b2a6fe 100644 --- a/src/main/java/com/pahimar/ee3/handler/PlayerEventHandler.java +++ b/src/main/java/com/pahimar/ee3/handler/PlayerEventHandler.java @@ -1,6 +1,6 @@ package com.pahimar.ee3.handler; -import com.pahimar.ee3.util.LogHelper; +import com.pahimar.ee3.reference.Settings; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.event.entity.player.PlayerEvent; @@ -9,38 +9,28 @@ import java.io.IOException; public class PlayerEventHandler { - @SubscribeEvent - public void onPlayerSaveToFileEvent(PlayerEvent.SaveToFile event) - { - LogHelper.info("Save Event: " + event.playerUUID); - File playerFile = event.getPlayerFile("ee3"); - if (!playerFile.exists()) - { - LogHelper.info("Creating knowledge file for player with UUID: " + event.playerUUID); - try - { - playerFile.createNewFile(); - } - catch (IOException e) - { - e.printStackTrace(); - } - } - } - @SubscribeEvent public void onPlayerLoadFromFileEvent(PlayerEvent.LoadFromFile event) { - LogHelper.info("Load Event: " + event.playerUUID); + if (!event.entityPlayer.worldObj.isRemote) + { + if (Settings.PLAYER_DAT_LOCATION == null || Settings.PLAYER_DAT_LOCATION.length() == 0 || !Settings.PLAYER_DAT_LOCATION.equalsIgnoreCase(event.playerDirectory.getPath())) + { + Settings.PLAYER_DAT_LOCATION = event.playerDirectory.getPath(); + } - File playerFile = event.getPlayerFile("ee3"); - try - { - playerFile.createNewFile(); - } - catch (IOException e) - { - e.printStackTrace(); + File playerFile = event.getPlayerFile("ee3"); + if (!playerFile.exists()) + { + try + { + playerFile.createNewFile(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } } } } diff --git a/src/main/java/com/pahimar/ee3/reference/Settings.java b/src/main/java/com/pahimar/ee3/reference/Settings.java new file mode 100644 index 00000000..6537d0ee --- /dev/null +++ b/src/main/java/com/pahimar/ee3/reference/Settings.java @@ -0,0 +1,6 @@ +package com.pahimar.ee3.reference; + +public class Settings +{ + public static String PLAYER_DAT_LOCATION = ""; +}