mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-10-31 15:59:56 +01:00
Add history log to ChallengesPlayerData object.
Add @NonNull annotation to all population methods.
This commit is contained in:
parent
e6f2b9e0b7
commit
ca2b7e2ec6
@ -2,9 +2,14 @@ package world.bentobox.challenges.database.object;
|
||||
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import java.util.*;
|
||||
|
||||
import world.bentobox.bentobox.api.logs.LogEntry;
|
||||
import world.bentobox.bentobox.database.objects.DataObject;
|
||||
import world.bentobox.bentobox.database.objects.adapters.Adapter;
|
||||
import world.bentobox.bentobox.database.objects.adapters.LogEntryListAdapter;
|
||||
|
||||
|
||||
/**
|
||||
* Stores the player's challenge situation
|
||||
@ -63,6 +68,13 @@ public class ChallengesPlayerData implements DataObject
|
||||
@Expose
|
||||
private Set<String> levelsDone = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Stores history about challenge completion.
|
||||
*/
|
||||
@Adapter(LogEntryListAdapter.class)
|
||||
@Expose
|
||||
private List<LogEntry> history = new LinkedList<>();
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Getters
|
||||
@ -110,6 +122,16 @@ public class ChallengesPlayerData implements DataObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method returns the history object.
|
||||
* @return the history object.
|
||||
*/
|
||||
public List<LogEntry> getHistory()
|
||||
{
|
||||
return history;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Setters
|
||||
// ---------------------------------------------------------------------
|
||||
@ -159,6 +181,16 @@ public class ChallengesPlayerData implements DataObject
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method sets the history object value.
|
||||
* @param history the history object new value.
|
||||
*/
|
||||
public void setHistory(List<LogEntry> history)
|
||||
{
|
||||
this.history = history;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Section: Other Methods
|
||||
// ---------------------------------------------------------------------
|
||||
@ -169,7 +201,7 @@ public class ChallengesPlayerData implements DataObject
|
||||
*
|
||||
* @param worldName world which challenges must be reset.
|
||||
*/
|
||||
public void reset(String worldName)
|
||||
public void reset(@NonNull String worldName)
|
||||
{
|
||||
challengeStatus.keySet().removeIf(n -> n.startsWith(worldName));
|
||||
challengesTimestamp.keySet().removeIf(n -> n.startsWith(worldName));
|
||||
@ -183,7 +215,7 @@ public class ChallengesPlayerData implements DataObject
|
||||
*
|
||||
* @param challengeName - unique challenge name
|
||||
*/
|
||||
public void setChallengeDone(String challengeName)
|
||||
public void setChallengeDone(@NonNull String challengeName)
|
||||
{
|
||||
int times = challengeStatus.getOrDefault(challengeName, 0) + 1;
|
||||
challengeStatus.put(challengeName, times);
|
||||
@ -197,7 +229,7 @@ public class ChallengesPlayerData implements DataObject
|
||||
* @param challengeName - unique challenge name
|
||||
* @param times - the number of times to set
|
||||
*/
|
||||
public void setChallengeTimes(String challengeName, int times)
|
||||
public void setChallengeTimes(@NonNull String challengeName, @NonNull int times)
|
||||
{
|
||||
challengeStatus.put(challengeName, times);
|
||||
challengesTimestamp.put(challengeName, System.currentTimeMillis());
|
||||
@ -210,7 +242,7 @@ public class ChallengesPlayerData implements DataObject
|
||||
* @param challengeName - unique challenge name
|
||||
* @return true if done at least once
|
||||
*/
|
||||
public boolean isChallengeDone(String challengeName)
|
||||
public boolean isChallengeDone(@NonNull String challengeName)
|
||||
{
|
||||
return this.getTimes(challengeName) > 0;
|
||||
}
|
||||
@ -222,7 +254,7 @@ public class ChallengesPlayerData implements DataObject
|
||||
* @param challengeName - unique challenge name
|
||||
* @return - number of times
|
||||
*/
|
||||
public int getTimes(String challengeName)
|
||||
public int getTimes(@NonNull String challengeName)
|
||||
{
|
||||
return challengeStatus.getOrDefault(challengeName, 0);
|
||||
}
|
||||
@ -232,7 +264,7 @@ public class ChallengesPlayerData implements DataObject
|
||||
* This method adds given level id to completed level set.
|
||||
* @param uniqueId from ChallengeLevel object.
|
||||
*/
|
||||
public void addCompletedLevel(String uniqueId)
|
||||
public void addCompletedLevel(@NonNull String uniqueId)
|
||||
{
|
||||
this.levelsDone.add(uniqueId);
|
||||
}
|
||||
@ -243,12 +275,23 @@ public class ChallengesPlayerData implements DataObject
|
||||
* @param uniqueId of ChallengeLevel object.
|
||||
* @return <code>true</code> if level is completed, otherwise <code>false</code>
|
||||
*/
|
||||
public boolean isLevelDone(String uniqueId)
|
||||
public boolean isLevelDone(@NonNull String uniqueId)
|
||||
{
|
||||
return !this.levelsDone.isEmpty() && this.levelsDone.contains(uniqueId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method adds given LogEntry to history.
|
||||
*
|
||||
* @param entry of type LogEntry
|
||||
*/
|
||||
public void addHistoryRecord(@NonNull LogEntry entry)
|
||||
{
|
||||
this.history.add(entry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see Object#hashCode()
|
||||
* @return object hashCode value.
|
||||
|
Loading…
Reference in New Issue
Block a user