ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/data/PlayerData.java

101 lines
3.5 KiB
Java
Raw Normal View History

/*
2016-08-02 13:08:22 +02:00
* This file ("PlayerData.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.data;
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
import de.ellpeck.actuallyadditions.mod.booklet.misc.BookletUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
2016-06-17 23:50:38 +02:00
public final class PlayerData{
public static PlayerSave getDataFromPlayer(UUID id){
ConcurrentHashMap<UUID, PlayerSave> data = WorldData.getWorldUnspecificData().playerSaveData;
if(data.containsKey(id)){
PlayerSave save = data.get(id);
if(save != null && save.id != null && save.id.equals(id)){
return save;
}
2015-10-03 10:16:18 +02:00
}
//Add Data if none is existant
PlayerSave save = new PlayerSave(id);
data.put(id, save);
return save;
2015-10-03 10:16:18 +02:00
}
public static PlayerSave getDataFromPlayer(EntityPlayer player){
return getDataFromPlayer(player.getUniqueID());
}
public static class PlayerSave{
public UUID id;
public boolean displayTesla;
public boolean bookGottenAlready;
2016-11-12 15:09:30 +01:00
public boolean didBookTutorial;
public boolean hasBatWings;
public int batWingsFlyTime;
public IBookletPage[] bookmarks = new IBookletPage[12];
@SideOnly(Side.CLIENT)
public GuiBooklet lastOpenBooklet;
public PlayerSave(UUID id){
this.id = id;
2015-10-23 16:54:33 +02:00
}
public void readFromNBT(NBTTagCompound compound){
this.displayTesla = compound.getBoolean("DisplayTesla");
this.bookGottenAlready = compound.getBoolean("BookGotten");
2016-11-12 15:09:30 +01:00
this.didBookTutorial = compound.getBoolean("DidTutorial");
this.hasBatWings = compound.getBoolean("HasBatWings");
this.batWingsFlyTime = compound.getInteger("BatWingsFlyTime");
NBTTagList bookmarks = compound.getTagList("Bookmarks", 8);
for(int i = 0; i < bookmarks.tagCount(); i++){
String strg = bookmarks.getStringTagAt(i);
if(strg != null && !strg.isEmpty()){
IBookletPage page = BookletUtils.getBookletPageById(strg);
this.bookmarks[i] = page;
}
}
}
public void writeToNBT(NBTTagCompound compound){
compound.setBoolean("DisplayTesla", this.displayTesla);
compound.setBoolean("BookGotten", this.bookGottenAlready);
2016-11-12 15:09:30 +01:00
compound.setBoolean("DidTutorial", this.didBookTutorial);
compound.setBoolean("HasBatWings", this.hasBatWings);
compound.setInteger("BatWingsFlyTime", this.batWingsFlyTime);
NBTTagList bookmarks = new NBTTagList();
for(IBookletPage bookmark : this.bookmarks){
bookmarks.appendTag(new NBTTagString(bookmark == null ? "" : bookmark.getIdentifier()));
}
compound.setTag("Bookmarks", bookmarks);
}
}
}