Skip to content

Commit

Permalink
Added API to work out which game modes Level is active in.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jun 5, 2021
1 parent 1246496 commit 452bf88
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/world/bentobox/level/Level.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.bukkit.Bukkit;
Expand All @@ -20,6 +22,7 @@
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
import world.bentobox.level.calculators.Pipeliner;
import world.bentobox.level.commands.AdminLevelCommand;
import world.bentobox.level.commands.AdminLevelStatusCommand;
Expand Down Expand Up @@ -53,6 +56,7 @@ public class Level extends Addon implements Listener {
private LevelsManager manager;
private boolean stackersEnabled;
private boolean advChestEnabled;
private final List<GameModeAddon> registeredGameModes = new ArrayList<>();

@Override
public void onLoad() {
Expand Down Expand Up @@ -85,12 +89,14 @@ public void onEnable() {
this.registerListener(new JoinLeaveListener(this));
this.registerListener(this);
// Register commands for GameModes
registeredGameModes.clear();
getPlugin().getAddonsManager().getGameModeAddons().stream()
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName()))
.forEach(gm -> {
log("Level hooking into " + gm.getDescription().getName());
registerCommands(gm);
registerPlaceholders(gm);
registeredGameModes.add(gm);
});
// Register request handlers
registerRequestHandler(new LevelRequestHandler(this));
Expand Down Expand Up @@ -399,4 +405,30 @@ public LevelsData getLevelsData(UUID targetPlayer) {
});
return ld;
}

/**
* @return the registeredGameModes
*/
public List<GameModeAddon> getRegisteredGameModes() {
return registeredGameModes;
}

/**
* Check if Level addon is active in game mode
* @param gm Game Mode Addon
* @return true if active, false if not
*/
public boolean isRegisteredGameMode(GameModeAddon gm) {
return registeredGameModes.contains(gm);
}

/**
* Checks if Level addon is active in world
* @param world world
* @return true if active, false if not
*/
public boolean isRegisteredGameModeWorld(World world) {
return registeredGameModes.stream().map(GameModeAddon::getOverWorld).anyMatch(w -> Util.sameWorld(world, w));
}

}

0 comments on commit 452bf88

Please sign in to comment.