Return null if Level addon is not operating in world

This commit is contained in:
tastybento 2021-06-05 08:37:42 -07:00
parent 757a39e7f9
commit fc4f6c634a
2 changed files with 11 additions and 3 deletions

View File

@ -60,7 +60,7 @@
<!-- More visible way how to change dependency versions -->
<spigot.version>1.16.3-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.15.4</bentobox.version>
<level.version>1.5.0</level.version>
<level.version>2.7.0-SNAPSHOT</level.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->

View File

@ -210,10 +210,18 @@ public class Warp extends Addon {
* Get the island level
* @param world - world
* @param uniqueId - player's UUID
* @return island level or null if there is no level plugin
* @return island level or null if there is no level plugin or Level is not operating in this world
*/
public Long getLevel(World world, UUID uniqueId) {
return this.getPlugin().getAddonsManager().getAddonByName(LEVEL_ADDON_NAME).map(l -> ((Level) l).getIslandLevel(world, uniqueId)).orElse(null);
// Get name of the game mode
String name = this.getPlugin().getIWM().getAddon(world).map(g -> g.getDescription().getName()).orElse("");
return this.getPlugin().getAddonsManager().getAddonByName(LEVEL_ADDON_NAME)
.map(l -> {
if (!name.isEmpty() && ((Level) l).getSettings().getGameModes().contains(name)) {
return ((Level) l).getIslandLevel(world, uniqueId);
}
return null;
}).orElse(null);
}
/* (non-Javadoc)