67 lines
1.6 KiB
Java
67 lines
1.6 KiB
Java
package eu.univento.commons.player.profiles;
|
|
|
|
import com.mongodb.CursorType;
|
|
import com.mongodb.client.FindIterable;
|
|
import eu.univento.commons.player.DatabasePlayer;
|
|
import org.bson.Document;
|
|
|
|
import java.util.Collection;
|
|
import java.util.Date;
|
|
import java.util.LinkedList;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 0.1
|
|
*/
|
|
public class Profile {
|
|
|
|
private DatabasePlayer player;
|
|
private String id;
|
|
private String name;
|
|
private Date date;
|
|
private Save save;
|
|
private Collection<StoryItem> items;
|
|
|
|
public Profile(DatabasePlayer player, String id) {
|
|
this.id = id;
|
|
FindIterable<Document> cursor = player.getProfileCollection().find(new Document("_id", id));
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
Document doc = cursor.first();
|
|
|
|
this.name = doc.getString("name");
|
|
this.save = Save.valueOf(doc.getString("save"));
|
|
this.date = doc.getDate("date");
|
|
Collection<String> list = (Collection<String>) doc.get("items");
|
|
items = new LinkedList<>();
|
|
items.addAll(list.stream().map(StoryItem::valueOf).collect(Collectors.toList()));
|
|
}
|
|
|
|
public DatabasePlayer getPlayer() {
|
|
return player;
|
|
}
|
|
|
|
public String getId() {
|
|
return id;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public Save getSave() {
|
|
return save;
|
|
}
|
|
|
|
public Date getDate() {
|
|
return date;
|
|
}
|
|
|
|
public Collection<StoryItem> getItems() {
|
|
return items;
|
|
}
|
|
|
|
public String getURL() {
|
|
return "https://players.univento.eu/" + player.getUuid() + "/profile/" + id;
|
|
}
|
|
} |