Skip to content

Commit

Permalink
Add history log to ChallengesPlayerData object.
Browse files Browse the repository at this point in the history
Add @nonnull annotation to all population methods.
  • Loading branch information
BONNe committed Feb 18, 2019
1 parent e6f2b9e commit ca2b7e2
Showing 1 changed file with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@


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
Expand Down Expand Up @@ -63,6 +68,13 @@ public ChallengesPlayerData(String uniqueId)
@Expose
private Set<String> levelsDone = new HashSet<>();

/**
* Stores history about challenge completion.
*/
@Adapter(LogEntryListAdapter.class)
@Expose
private List<LogEntry> history = new LinkedList<>();


// ---------------------------------------------------------------------
// Section: Getters
Expand Down Expand Up @@ -110,6 +122,16 @@ public Set<String> getLevelsDone()
}


/**
* This method returns the history object.
* @return the history object.
*/
public List<LogEntry> getHistory()
{
return history;
}


// ---------------------------------------------------------------------
// Section: Setters
// ---------------------------------------------------------------------
Expand Down Expand Up @@ -159,6 +181,16 @@ public void setLevelsDone(Set<String> levelsDone)
}


/**
* 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
// ---------------------------------------------------------------------
Expand All @@ -169,7 +201,7 @@ public void setLevelsDone(Set<String> levelsDone)
*
* @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));
Expand All @@ -183,7 +215,7 @@ public void reset(String worldName)
*
* @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);
Expand All @@ -197,7 +229,7 @@ public void setChallengeDone(String challengeName)
* @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());
Expand All @@ -210,7 +242,7 @@ public void setChallengeTimes(String challengeName, int times)
* @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;
}
Expand All @@ -222,7 +254,7 @@ public boolean isChallengeDone(String challengeName)
* @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);
}
Expand All @@ -232,7 +264,7 @@ public int getTimes(String challengeName)
* 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);
}
Expand All @@ -243,12 +275,23 @@ public void addCompletedLevel(String uniqueId)
* @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.
Expand Down

0 comments on commit ca2b7e2

Please sign in to comment.