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.
This commit is contained in:
parent
89abfee9f6
commit
8a2226d483
2 changed files with 25 additions and 29 deletions
|
@ -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;
|
||||
|
||||
|
@ -10,13 +10,18 @@ import java.io.IOException;
|
|||
public class PlayerEventHandler
|
||||
{
|
||||
@SubscribeEvent
|
||||
public void onPlayerSaveToFileEvent(PlayerEvent.SaveToFile event)
|
||||
public void onPlayerLoadFromFileEvent(PlayerEvent.LoadFromFile event)
|
||||
{
|
||||
LogHelper.info("Save 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");
|
||||
if (!playerFile.exists())
|
||||
{
|
||||
LogHelper.info("Creating knowledge file for player with UUID: " + event.playerUUID);
|
||||
try
|
||||
{
|
||||
playerFile.createNewFile();
|
||||
|
@ -27,20 +32,5 @@ public class PlayerEventHandler
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLoadFromFileEvent(PlayerEvent.LoadFromFile event)
|
||||
{
|
||||
LogHelper.info("Load Event: " + event.playerUUID);
|
||||
|
||||
File playerFile = event.getPlayerFile("ee3");
|
||||
try
|
||||
{
|
||||
playerFile.createNewFile();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
src/main/java/com/pahimar/ee3/reference/Settings.java
Normal file
6
src/main/java/com/pahimar/ee3/reference/Settings.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package com.pahimar.ee3.reference;
|
||||
|
||||
public class Settings
|
||||
{
|
||||
public static String PLAYER_DAT_LOCATION = "";
|
||||
}
|
Loading…
Reference in a new issue