mirror of
https://github.com/BentoBoxWorld/Level.git
synced 2024-12-27 11:37:39 +01:00
Added API to work out which game modes Level is active in.
This commit is contained in:
parent
1246496373
commit
452bf88197
@ -2,6 +2,8 @@ package world.bentobox.level;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
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.events.BentoBoxReadyEvent;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.database.objects.Island;
|
import world.bentobox.bentobox.database.objects.Island;
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
import world.bentobox.level.calculators.Pipeliner;
|
import world.bentobox.level.calculators.Pipeliner;
|
||||||
import world.bentobox.level.commands.AdminLevelCommand;
|
import world.bentobox.level.commands.AdminLevelCommand;
|
||||||
import world.bentobox.level.commands.AdminLevelStatusCommand;
|
import world.bentobox.level.commands.AdminLevelStatusCommand;
|
||||||
@ -53,6 +56,7 @@ public class Level extends Addon implements Listener {
|
|||||||
private LevelsManager manager;
|
private LevelsManager manager;
|
||||||
private boolean stackersEnabled;
|
private boolean stackersEnabled;
|
||||||
private boolean advChestEnabled;
|
private boolean advChestEnabled;
|
||||||
|
private final List<GameModeAddon> registeredGameModes = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
@ -85,12 +89,14 @@ public class Level extends Addon implements Listener {
|
|||||||
this.registerListener(new JoinLeaveListener(this));
|
this.registerListener(new JoinLeaveListener(this));
|
||||||
this.registerListener(this);
|
this.registerListener(this);
|
||||||
// Register commands for GameModes
|
// Register commands for GameModes
|
||||||
|
registeredGameModes.clear();
|
||||||
getPlugin().getAddonsManager().getGameModeAddons().stream()
|
getPlugin().getAddonsManager().getGameModeAddons().stream()
|
||||||
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName()))
|
.filter(gm -> !settings.getGameModes().contains(gm.getDescription().getName()))
|
||||||
.forEach(gm -> {
|
.forEach(gm -> {
|
||||||
log("Level hooking into " + gm.getDescription().getName());
|
log("Level hooking into " + gm.getDescription().getName());
|
||||||
registerCommands(gm);
|
registerCommands(gm);
|
||||||
registerPlaceholders(gm);
|
registerPlaceholders(gm);
|
||||||
|
registeredGameModes.add(gm);
|
||||||
});
|
});
|
||||||
// Register request handlers
|
// Register request handlers
|
||||||
registerRequestHandler(new LevelRequestHandler(this));
|
registerRequestHandler(new LevelRequestHandler(this));
|
||||||
@ -399,4 +405,30 @@ public class Level extends Addon implements Listener {
|
|||||||
});
|
});
|
||||||
return ld;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user