Skip to content

Commit

Permalink
Add 2 new methods that detects if exist any challenge or level for gi…
Browse files Browse the repository at this point in the history
…ven world.
  • Loading branch information
BONNe committed Apr 24, 2019
1 parent 13faf47 commit f5cf5f5
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/world/bentobox/challenges/ChallengesManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1396,4 +1396,36 @@ public void deleteChallengeLevel(ChallengeLevel challengeLevel)
this.levelDatabase.deleteObject(challengeLevel);
}
}


/**
* This method returns if in given world has any stored challenge or level.
* @param world World that needs to be checked
* @return <code>true</code> if world has any challenge or level, otherwise <code>false</code>
*/
public boolean hasAnyChallengeData(@NonNull World world)
{
world = Util.getWorld(world);

if (world == null)
{
return false;
}

return this.hasAnyChallengeData(world.getName());
}


/**
* This method returns if in given world has any stored challenge or level.
* @param worldName World name that needs to be checked
* @return <code>true</code> if world has any challenge or level, otherwise <code>false</code>
*/
public boolean hasAnyChallengeData(@NonNull String worldName)
{
return this.challengeDatabase.loadObjects().stream().anyMatch(
challenge -> challenge.getUniqueId().startsWith(worldName)) ||
this.levelDatabase.loadObjects().stream().anyMatch(
level -> level.getUniqueId().startsWith(worldName));
}
}

0 comments on commit f5cf5f5

Please sign in to comment.