2015-09-27 15:31:43 +02:00
|
|
|
/*
|
2016-08-02 13:08:22 +02:00
|
|
|
* This file ("PlayerData.java") is part of the Actually Additions mod for Minecraft.
|
2015-09-27 15:31:43 +02:00
|
|
|
* 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
|
2015-09-27 15:31:43 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-09-27 15:31:43 +02:00
|
|
|
*/
|
|
|
|
|
2016-06-04 13:51:06 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.data;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-11-12 13:54:49 +01:00
|
|
|
import de.ellpeck.actuallyadditions.api.booklet.IBookletPage;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.gui.GuiBooklet;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.booklet.misc.BookletUtils;
|
2015-09-27 15:31:43 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-11-12 13:54:49 +01:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
|
|
|
import net.minecraft.nbt.NBTTagString;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2017-02-18 00:54:58 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2016-07-14 20:25:12 +02:00
|
|
|
import java.util.UUID;
|
2016-11-22 18:26:29 +01:00
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-06-17 23:50:38 +02:00
|
|
|
public final class PlayerData{
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-12-28 14:55:03 +01:00
|
|
|
public static PlayerSave getDataFromPlayer(EntityPlayer player){
|
|
|
|
WorldData worldData = WorldData.get(player.getEntityWorld());
|
|
|
|
ConcurrentHashMap<UUID, PlayerSave> data = worldData.playerSaveData;
|
|
|
|
UUID id = player.getUniqueID();
|
|
|
|
|
2016-11-22 18:26:29 +01:00
|
|
|
if(data.containsKey(id)){
|
|
|
|
PlayerSave save = data.get(id);
|
|
|
|
if(save != null && save.id != null && save.id.equals(id)){
|
2016-06-15 17:15:26 +02:00
|
|
|
return save;
|
2015-10-22 22:18:33 +02:00
|
|
|
}
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
2015-10-22 22:18:33 +02:00
|
|
|
|
|
|
|
//Add Data if none is existant
|
2016-11-22 18:26:29 +01:00
|
|
|
PlayerSave save = new PlayerSave(id);
|
|
|
|
data.put(id, save);
|
2016-12-28 14:55:03 +01:00
|
|
|
worldData.markDirty();
|
2016-11-22 18:26:29 +01:00
|
|
|
return save;
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
2015-10-22 22:18:33 +02:00
|
|
|
public static class PlayerSave{
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-11-11 21:41:07 +01:00
|
|
|
public UUID id;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-11-11 21:41:07 +01:00
|
|
|
public boolean bookGottenAlready;
|
2016-11-12 15:09:30 +01:00
|
|
|
public boolean didBookTutorial;
|
2016-11-22 18:26:29 +01:00
|
|
|
public boolean hasBatWings;
|
2016-11-22 19:35:52 +01:00
|
|
|
public boolean shouldDisableBatWings;
|
2016-11-22 18:26:29 +01:00
|
|
|
public int batWingsFlyTime;
|
2015-09-27 15:31:43 +02:00
|
|
|
|
2016-11-12 13:54:49 +01:00
|
|
|
public IBookletPage[] bookmarks = new IBookletPage[12];
|
2017-02-18 00:54:58 +01:00
|
|
|
public List<String> completedTrials = new ArrayList<String>();
|
2016-11-12 13:54:49 +01:00
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public GuiBooklet lastOpenBooklet;
|
|
|
|
|
2016-11-11 21:41:07 +01:00
|
|
|
public PlayerSave(UUID id){
|
|
|
|
this.id = id;
|
2015-10-23 16:54:33 +02:00
|
|
|
}
|
|
|
|
|
2016-11-22 19:35:52 +01:00
|
|
|
public void readFromNBT(NBTTagCompound compound, boolean savingToFile){
|
2016-11-11 21:41:07 +01:00
|
|
|
this.bookGottenAlready = compound.getBoolean("BookGotten");
|
2016-11-12 15:09:30 +01:00
|
|
|
this.didBookTutorial = compound.getBoolean("DidTutorial");
|
2016-11-22 19:35:52 +01:00
|
|
|
|
2016-11-22 18:26:29 +01:00
|
|
|
this.hasBatWings = compound.getBoolean("HasBatWings");
|
|
|
|
this.batWingsFlyTime = compound.getInteger("BatWingsFlyTime");
|
2016-11-12 13:54:49 +01:00
|
|
|
|
|
|
|
NBTTagList bookmarks = compound.getTagList("Bookmarks", 8);
|
2017-02-13 15:23:28 +01:00
|
|
|
this.loadBookmarks(bookmarks);
|
2016-11-22 19:35:52 +01:00
|
|
|
|
2017-02-18 00:54:58 +01:00
|
|
|
NBTTagList trials = compound.getTagList("Trials", 8);
|
|
|
|
this.loadTrials(trials);
|
|
|
|
|
2016-11-22 19:35:52 +01:00
|
|
|
if(!savingToFile){
|
|
|
|
this.shouldDisableBatWings = compound.getBoolean("ShouldDisableWings");
|
|
|
|
}
|
2016-11-11 21:41:07 +01:00
|
|
|
}
|
2016-07-14 20:25:12 +02:00
|
|
|
|
2016-11-22 19:35:52 +01:00
|
|
|
public void writeToNBT(NBTTagCompound compound, boolean savingToFile){
|
2016-11-11 21:41:07 +01:00
|
|
|
compound.setBoolean("BookGotten", this.bookGottenAlready);
|
2016-11-12 15:09:30 +01:00
|
|
|
compound.setBoolean("DidTutorial", this.didBookTutorial);
|
2016-11-22 19:35:52 +01:00
|
|
|
|
2016-11-22 18:26:29 +01:00
|
|
|
compound.setBoolean("HasBatWings", this.hasBatWings);
|
|
|
|
compound.setInteger("BatWingsFlyTime", this.batWingsFlyTime);
|
2016-11-12 13:54:49 +01:00
|
|
|
|
2017-02-13 15:23:28 +01:00
|
|
|
compound.setTag("Bookmarks", this.saveBookmarks());
|
2017-02-18 00:54:58 +01:00
|
|
|
compound.setTag("Trials", this.saveTrials());
|
2017-02-13 15:23:28 +01:00
|
|
|
|
|
|
|
if(!savingToFile){
|
|
|
|
compound.setBoolean("ShouldDisableWings", this.shouldDisableBatWings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public NBTTagList saveBookmarks(){
|
2016-11-12 13:54:49 +01:00
|
|
|
NBTTagList bookmarks = new NBTTagList();
|
|
|
|
for(IBookletPage bookmark : this.bookmarks){
|
|
|
|
bookmarks.appendTag(new NBTTagString(bookmark == null ? "" : bookmark.getIdentifier()));
|
|
|
|
}
|
2017-02-13 15:23:28 +01:00
|
|
|
return bookmarks;
|
|
|
|
}
|
2016-11-22 19:35:52 +01:00
|
|
|
|
2017-02-13 15:23:28 +01:00
|
|
|
public void loadBookmarks(NBTTagList bookmarks){
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
this.bookmarks[i] = null;
|
|
|
|
}
|
2016-11-22 19:35:52 +01:00
|
|
|
}
|
2015-09-27 15:31:43 +02:00
|
|
|
}
|
2017-02-18 00:54:58 +01:00
|
|
|
|
|
|
|
public NBTTagList saveTrials(){
|
|
|
|
NBTTagList trials = new NBTTagList();
|
|
|
|
for(String trial : this.completedTrials){
|
|
|
|
trials.appendTag(new NBTTagString(trial));
|
|
|
|
}
|
|
|
|
return trials;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void loadTrials(NBTTagList trials){
|
|
|
|
this.completedTrials.clear();
|
|
|
|
|
|
|
|
for(int i = 0; i < trials.tagCount(); i++){
|
|
|
|
String strg = trials.getStringTagAt(i);
|
|
|
|
if(strg != null && !strg.isEmpty()){
|
|
|
|
this.completedTrials.add(strg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-27 15:31:43 +02:00
|
|
|
}
|
2015-10-22 22:18:33 +02:00
|
|
|
|
2016-07-14 20:25:12 +02:00
|
|
|
|
2015-09-27 15:31:43 +02:00
|
|
|
}
|