Skip to content

Commit

Permalink
Reputation and quests can sometimes be lost #103
Browse files Browse the repository at this point in the history
  • Loading branch information
frodare committed Feb 1, 2017
1 parent a687e02 commit e35dc81
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public void handleEnterProvince(CivilizationEvent.Enter event) {
public void handleLeaveProvince(CivilizationEvent.Leave event) {

}

/*
* -1360 40 342
*/

@SubscribeEvent
public void onDeath(PlayerEvent.Clone event) {
Expand All @@ -80,9 +84,15 @@ public void onDeath(PlayerEvent.Clone event) {
PlayerCivilizationCapability newCap = PlayerCivilizationCapabilityImpl.get(event.getEntityPlayer());
PlayerCivilizationCapability originalCap = PlayerCivilizationCapabilityImpl.get(event.getOriginal());

if (newCap == null || originalCap == null) {
if (originalCap == null) {
return;
}

if(newCap == null){
throw new NullPointerException("missing player capability during clone");
}

//System.out.println("CLONE: " + originalCap.writeNBT());

newCap.readNBT(originalCap.writeNBT());
}
Expand All @@ -99,8 +109,10 @@ public void onSave(PlayerEvent.SaveToFile event) {

NBTTagCompound civData = cap.writeNBT();

if (civData == null || civData.getTag("reputations") == null || ((NBTTagList) civData.getTag("reputations")).tagCount() < 1) {
System.out.println("Not writing empty ToroQuest data for player " + event.getEntityPlayer().getName());
//System.out.println("SAVE: " + civData);

if (civData == null || civData.getTag("reputations") == null || ((NBTTagList) civData.getTag("reputations")).tagCount() < 1) {
//System.out.println("******************Not writing empty ToroQuest data for player " + event.getEntityPlayer().getName());
return;
}

Expand All @@ -117,7 +129,16 @@ public void onLoad(PlayerEvent.LoadFromFile event) {
if (cap == null) {
return;
}
cap.readNBT((NBTTagCompound) event.getEntityPlayer().getEntityData().getTag(ToroQuest.MODID + ".playerCivilization"));

NBTTagCompound c = event.getEntityPlayer().getEntityData().getCompoundTag(ToroQuest.MODID + ".playerCivilization");

if(c == null){
//System.out.println("******************Missing civ data on load");
}else{
System.out.println("LOAD: " + c.toString());
}

cap.readNBT(c);
}

@SubscribeEvent
Expand Down

0 comments on commit e35dc81

Please sign in to comment.