From e35dc815a7f8c45035997ec1645e45052f6f5ea5 Mon Sep 17 00:00:00 2001 From: Charles Howard Date: Tue, 31 Jan 2017 19:32:14 -0500 Subject: [PATCH] Reputation and quests can sometimes be lost #103 --- .../civilization/CivilizationHandlers.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/java/net/torocraft/toroquest/civilization/CivilizationHandlers.java b/java/net/torocraft/toroquest/civilization/CivilizationHandlers.java index b28ff9a..c9e0445 100644 --- a/java/net/torocraft/toroquest/civilization/CivilizationHandlers.java +++ b/java/net/torocraft/toroquest/civilization/CivilizationHandlers.java @@ -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) { @@ -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()); } @@ -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; } @@ -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