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){
//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(this.tryOpenMainPage && !data.getBoolean("BookAlreadyOpened")){
if(this.tryOpenMainPage && !data.theCompound.getBoolean("BookAlreadyOpened")){
BookletUtils.openIndexEntry(this, InitBooklet.chapterIntro.entry, 1, true);
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));
}
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
public void onGuiClosed(){
if(this.saveOnClose && this.changedPageSinceOpen){
System.out.println("SAVING");
NBTTagCompound bookletData = new NBTTagCompound();
BookletUtils.saveBookPage(this, bookletData);

View file

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

View file

@ -70,9 +70,9 @@ public class EntityLivingEvents{
public void livingDeathEvent(LivingDeathEvent event){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getEntityLiving() instanceof EntityPlayer){
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){
deaths.removeTag(0);
}
@ -83,7 +83,7 @@ public class EntityLivingEvents{
death.setDouble("Z", player.posZ);
deaths.appendTag(death);
data.setTag("Deaths", deaths);
data.theCompound.setTag("Deaths", deaths);
//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.util.ModUtil;
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.gameevent.PlayerEvent;
@ -30,12 +30,12 @@ public class PlayerConnectionEvents{
}
@SubscribeEvent
public void onLogInEvent(PlayerEvent.PlayerLoggedInEvent event){
if(!event.player.worldObj.isRemote && event.player instanceof EntityPlayerMP){
NBTTagCompound data = PlayerData.getDataFromPlayer(event.player);
if(!data.hasNoTags()){
PacketHandler.theNetwork.sendTo(new PacketServerToClient(data, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), (EntityPlayerMP)event.player);
ModUtil.LOGGER.info("Sending Player Data to player "+event.player.getName()+"!");
public void onLogInEvent(EntityJoinWorldEvent event){
if(!event.getEntity().worldObj.isRemote && event.getEntity() instanceof EntityPlayerMP){
EntityPlayerMP player = (EntityPlayerMP)event.getEntity();
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
if(!data.theCompound.hasNoTags()){
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();
if(name != null && name.toLowerCase(Locale.ROOT).contains(ModUtil.MOD_ID)){
NBTTagCompound compound = PlayerData.getDataFromPlayer(event.player);
if(compound != null && !compound.getBoolean("BookGottenAlready")){
compound.setBoolean("BookGottenAlready", true);
PlayerData.PlayerSave compound = PlayerData.getDataFromPlayer(event.player);
if(compound != null && !compound.theCompound.getBoolean("BookGottenAlready")){
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.setPickupDelay(0);

View file

@ -127,10 +127,10 @@ public final class PacketHandler{
EntityPlayer player = (EntityPlayer)world.getEntityByID(compound.getInteger("PlayerID"));
if(player != null){
NBTTagCompound playerData = PlayerData.getDataFromPlayer(player);
playerData.merge(data);
PlayerData.PlayerSave playerData = PlayerData.getDataFromPlayer(player);
playerData.theCompound.merge(data);
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)
public void handleData(NBTTagCompound compound){
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.RenderSmileyCloud;
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.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit;