Added API to work out which game modes Level is active in.

This commit is contained in:
tastybento 2021-06-05 08:33:03 -07:00
parent 1246496373
commit 452bf88197

View File

@ -2,6 +2,8 @@ package world.bentobox.level;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -20,6 +22,7 @@ import world.bentobox.bentobox.api.configuration.Config;
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;
@ -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() {
@ -85,12 +89,14 @@ public class Level extends Addon implements Listener {
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));
@ -399,4 +405,30 @@ public class Level extends Addon implements Listener {
});
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));
}
}