Fixed crash on singleplayer joining with the new system >_>

This commit is contained in:
Ellpeck 2016-06-15 17:15:26 +02:00
parent daaad16a32
commit 03215e3b5b
7 changed files with 26 additions and 27 deletions

View file

@ -378,9 +378,9 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{
if(ItemBooklet.forcedEntry == null){ if(ItemBooklet.forcedEntry == null){
//Open last entry or introductory entry //Open last entry or introductory entry
NBTTagCompound data = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().thePlayer); PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(Minecraft.getMinecraft().thePlayer);
if(data != null){ if(data != null){
if(this.tryOpenMainPage && !data.getBoolean("BookAlreadyOpened")){ if(this.tryOpenMainPage && !data.theCompound.getBoolean("BookAlreadyOpened")){
BookletUtils.openIndexEntry(this, InitBooklet.chapterIntro.entry, 1, true); BookletUtils.openIndexEntry(this, InitBooklet.chapterIntro.entry, 1, true);
BookletUtils.openChapter(this, InitBooklet.chapterIntro, null); BookletUtils.openChapter(this, InitBooklet.chapterIntro, null);
@ -393,7 +393,7 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{
PacketHandler.theNetwork.sendToServer(new PacketClientToServer(dataToSend, PacketHandler.CHANGE_PLAYER_DATA_HANDLER)); PacketHandler.theNetwork.sendToServer(new PacketClientToServer(dataToSend, PacketHandler.CHANGE_PLAYER_DATA_HANDLER));
} }
else{ else{
BookletUtils.openLastBookPage(this, data.getCompoundTag("BookletData")); BookletUtils.openLastBookPage(this, data.theCompound.getCompoundTag("BookletData"));
} }
} }
} }
@ -446,8 +446,6 @@ public class GuiBooklet extends GuiScreen implements IBookletGui{
@Override @Override
public void onGuiClosed(){ public void onGuiClosed(){
if(this.saveOnClose && this.changedPageSinceOpen){ if(this.saveOnClose && this.changedPageSinceOpen){
System.out.println("SAVING");
NBTTagCompound bookletData = new NBTTagCompound(); NBTTagCompound bookletData = new NBTTagCompound();
BookletUtils.saveBookPage(this, bookletData); BookletUtils.saveBookPage(this, bookletData);

View file

@ -18,25 +18,25 @@ import java.util.UUID;
public class PlayerData{ public class PlayerData{
public static NBTTagCompound getDataFromPlayer(EntityPlayer player){ public static PlayerSave getDataFromPlayer(EntityPlayer player){
ArrayList<PlayerSave> data = WorldData.PLAYER_SAVE_DATA; ArrayList<PlayerSave> data = WorldData.PLAYER_SAVE_DATA;
//Get Data from existing data //Get Data from existing data
for(PlayerSave save : data){ for(PlayerSave save : data){
if(save.thePlayerUUID.equals(player.getUniqueID())){ if(save.thePlayerUUID.equals(player.getUniqueID())){
return save.theCompound; return save;
} }
} }
//Add Data if none is existant //Add Data if none is existant
PlayerSave aSave = new PlayerSave(player.getUniqueID(), new NBTTagCompound()); PlayerSave aSave = new PlayerSave(player.getUniqueID(), new NBTTagCompound());
data.add(aSave); data.add(aSave);
return aSave.theCompound; return aSave;
} }
public static class PlayerSave{ public static class PlayerSave{
public final UUID thePlayerUUID; public final UUID thePlayerUUID;
public final NBTTagCompound theCompound; public NBTTagCompound theCompound;
public PlayerSave(UUID theUUID, NBTTagCompound theCompound){ public PlayerSave(UUID theUUID, NBTTagCompound theCompound){
this.thePlayerUUID = theUUID; this.thePlayerUUID = theUUID;

View file

@ -70,9 +70,9 @@ public class EntityLivingEvents{
public void livingDeathEvent(LivingDeathEvent event){ public void livingDeathEvent(LivingDeathEvent event){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getEntityLiving() instanceof EntityPlayer){ if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getEntityLiving() instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)event.getEntityLiving(); EntityPlayer player = (EntityPlayer)event.getEntityLiving();
NBTTagCompound data = PlayerData.getDataFromPlayer(player); PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
NBTTagList deaths = data.getTagList("Deaths", 10); NBTTagList deaths = data.theCompound.getTagList("Deaths", 10);
while(deaths.tagCount() >= 5){ while(deaths.tagCount() >= 5){
deaths.removeTag(0); deaths.removeTag(0);
} }
@ -83,7 +83,7 @@ public class EntityLivingEvents{
death.setDouble("Z", player.posZ); death.setDouble("Z", player.posZ);
deaths.appendTag(death); deaths.appendTag(death);
data.setTag("Deaths", deaths); data.theCompound.setTag("Deaths", deaths);
//player.addChatComponentMessage(new TextComponentTranslation("info."+ModUtil.MOD_ID+".deathRecorded")); //player.addChatComponentMessage(new TextComponentTranslation("info."+ModUtil.MOD_ID+".deathRecorded"));
} }

View file

@ -16,7 +16,7 @@ import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient; import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent;
@ -30,12 +30,12 @@ public class PlayerConnectionEvents{
} }
@SubscribeEvent @SubscribeEvent
public void onLogInEvent(PlayerEvent.PlayerLoggedInEvent event){ public void onLogInEvent(EntityJoinWorldEvent event){
if(!event.player.worldObj.isRemote && event.player instanceof EntityPlayerMP){ if(!event.getEntity().worldObj.isRemote && event.getEntity() instanceof EntityPlayerMP){
NBTTagCompound data = PlayerData.getDataFromPlayer(event.player); EntityPlayerMP player = (EntityPlayerMP)event.getEntity();
if(!data.hasNoTags()){ PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
PacketHandler.theNetwork.sendTo(new PacketServerToClient(data, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)event.player); if(!data.theCompound.hasNoTags()){
ModUtil.LOGGER.info("Sending Player Data to player "+event.player.getName()+"!"); PacketHandler.theNetwork.sendTo(new PacketServerToClient(data.theCompound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), player);
} }
} }
} }

View file

@ -48,9 +48,9 @@ public class PlayerObtainEvents{
String name = event.crafting.getItem().getRegistryName().toString(); String name = event.crafting.getItem().getRegistryName().toString();
if(name != null && name.toLowerCase(Locale.ROOT).contains(ModUtil.MOD_ID)){ if(name != null && name.toLowerCase(Locale.ROOT).contains(ModUtil.MOD_ID)){
NBTTagCompound compound = PlayerData.getDataFromPlayer(event.player); PlayerData.PlayerSave compound = PlayerData.getDataFromPlayer(event.player);
if(compound != null && !compound.getBoolean("BookGottenAlready")){ if(compound != null && !compound.theCompound.getBoolean("BookGottenAlready")){
compound.setBoolean("BookGottenAlready", true); compound.theCompound.setBoolean("BookGottenAlready", true);
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemBooklet)); EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemBooklet));
entityItem.setPickupDelay(0); entityItem.setPickupDelay(0);

View file

@ -127,10 +127,10 @@ public final class PacketHandler{
EntityPlayer player = (EntityPlayer)world.getEntityByID(compound.getInteger("PlayerID")); EntityPlayer player = (EntityPlayer)world.getEntityByID(compound.getInteger("PlayerID"));
if(player != null){ if(player != null){
NBTTagCompound playerData = PlayerData.getDataFromPlayer(player); PlayerData.PlayerSave playerData = PlayerData.getDataFromPlayer(player);
playerData.merge(data); playerData.theCompound.merge(data);
if(player instanceof EntityPlayerMP){ if(player instanceof EntityPlayerMP){
PacketHandler.theNetwork.sendTo(new PacketServerToClient(playerData, PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player); PacketHandler.theNetwork.sendTo(new PacketServerToClient(playerData.theCompound, PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)player);
} }
} }
} }
@ -141,7 +141,9 @@ public final class PacketHandler{
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void handleData(NBTTagCompound compound){ public void handleData(NBTTagCompound compound){
EntityPlayer player = Minecraft.getMinecraft().thePlayer; EntityPlayer player = Minecraft.getMinecraft().thePlayer;
PlayerData.getDataFromPlayer(player).merge(compound); if(player != null){
PlayerData.getDataFromPlayer(player).theCompound = compound;
}
} }
}; };

View file

@ -20,7 +20,6 @@ import de.ellpeck.actuallyadditions.mod.blocks.render.RenderDisplayStand;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderReconstructorLens; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderReconstructorLens;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderSmileyCloud; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderSmileyCloud;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.ExtraClientData;
import de.ellpeck.actuallyadditions.mod.event.InitEvents; import de.ellpeck.actuallyadditions.mod.event.InitEvents;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit; import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit;