Add some NPE protection to saving player data to disk

This commit is contained in:
Pahimar 2015-02-07 13:31:50 -05:00
parent e9db1db54d
commit dce8ea6af3
2 changed files with 4 additions and 2 deletions

View file

@ -34,8 +34,9 @@ public class PlayerEventHandler
}
@SubscribeEvent
public void syncEnergyValuesOnLogin(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event)
public void onPlayerLoggedIn(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent event)
{
TransmutationKnowledgeRegistry.getInstance().loadPlayerFromDiskIfNeeded(event.player);
PacketHandler.INSTANCE.sendTo(new MessageSyncEnergyValues(EnergyValueRegistry.getInstance()), (EntityPlayerMP) event.player);
}

View file

@ -275,12 +275,13 @@ public class TransmutationKnowledgeRegistry
{
if (entityPlayer != null && entityPlayer.getUniqueID() != null)
{
if (playerKnowledgeMap.containsKey(entityPlayer.getUniqueID()) && playerKnowledgeMap.get(entityPlayer.getUniqueID()).hasBeenModified())
if (playerKnowledgeMap.containsKey(entityPlayer.getUniqueID()) && playerKnowledgeMap.get(entityPlayer.getUniqueID()) != null && playerKnowledgeMap.get(entityPlayer.getUniqueID()).hasBeenModified())
{
SerializationHelper.writeTransmutationKnowledgeToFile(playerKnowledgeDirectory, entityPlayer.getUniqueID().toString() + ".json", playerKnowledgeMap.get(entityPlayer.getUniqueID()));
}
else
{
loadPlayerFromDiskIfNeeded(entityPlayer);
SerializationHelper.writeTransmutationKnowledgeToFile(playerKnowledgeDirectory, entityPlayer.getUniqueID().toString() + ".json", new TransmutationKnowledge());
}
}