Add 2 new methods that detects if exist any challenge or level for given world.

This commit is contained in:
BONNe 2019-04-24 07:43:51 +03:00
parent 13faf478ee
commit f5cf5f5867

View File

@ -1396,4 +1396,36 @@ public class ChallengesManager
this.levelDatabase.deleteObject(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));
}
} }