From f5cf5f5867744467651a0e6a92531a6b12ae7dcb Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 24 Apr 2019 07:43:51 +0300 Subject: [PATCH] Add 2 new methods that detects if exist any challenge or level for given world. --- .../challenges/ChallengesManager.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 6d4a24d..8df185b 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -1396,4 +1396,36 @@ public class ChallengesManager 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 true if world has any challenge or level, otherwise false + */ + 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 true if world has any challenge or level, otherwise false + */ + 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)); + } } \ No newline at end of file