use of au.com.mineauz.minigames.objects.ModulePlaceHolderProvider in project Minigames by AddstarMC.
the class PlaceHolderManager method onPlaceholderRequest.
@Override
public String onPlaceholderRequest(Player player, String identifier) {
if (player == null) {
return "";
}
if (!identifiers.containsKey(identifier)) {
return null;
}
Set<String> games = plugin.getMinigameManager().getAllMinigames().keySet();
if (identifier.contains("_")) {
String[] parts = identifier.split("_");
String gameName = parts[0];
if (games.contains(gameName)) {
Minigame minigame = plugin.getMinigameManager().getMinigame(gameName);
try {
switch(parts[1]) {
case "enabled":
return Boolean.toString(minigame.isEnabled());
case "maxPlayers":
return Integer.toString(minigame.getMaxPlayers());
case "currentPlayers":
return Integer.toString(minigame.getPlayers().size());
case "type":
return minigame.getType().getName();
case "mechanic":
return minigame.getMechanicName();
case "state":
return minigame.getState().name();
case "objective":
return minigame.getObjective();
case "gameType":
return minigame.getGametypeName();
case "timeLeft":
return Integer.toString(minigame.getMinigameTimer().getTimeLeft());
case "name":
return minigame.getName(true);
default:
for (ModulePlaceHolderProvider provider : providers) {
if (provider.hasPlaceHolder(parts[1])) {
return provider.onPlaceHolderRequest(player, gameName, parts[1]);
}
}
return null;
}
} catch (Exception e) {
plugin.getLogger().warning("Error processing PAPI:" + identifier);
plugin.getLogger().warning(e.getMessage());
if (plugin.isDebugging()) {
e.printStackTrace();
}
return null;
}
} else {
// this means the first part is not a gameName ?? what else could it be
return null;
}
} else {
switch(identifier) {
case "gameCount":
return Integer.toString(plugin.getMinigameManager().getAllMinigames().size());
case "enabledGameCount":
return Long.toString(plugin.getMinigameManager().getAllMinigames().values().stream().filter(Minigame::isEnabled).count());
case "totalPlaying":
return Long.toString(plugin.getPlayerManager().getAllMinigamePlayers().stream().filter(MinigamePlayer::isInMinigame).count());
default:
return null;
}
}
}
use of au.com.mineauz.minigames.objects.ModulePlaceHolderProvider in project Minigames by AddstarMC.
the class PlaceHolderManager method addGameIdentifiers.
public void addGameIdentifiers(Minigame game) {
String name = game.getName(false);
for (GameOptions o : GameOptions.values()) {
identifiers.put(name + "_" + o.name, "GAME_" + name);
}
for (MinigameModule module : game.getModules()) {
ModulePlaceHolderProvider provider = module.getModulePlaceHolders();
if (provider != null) {
registerModulePlaceholders(game.getName(false), provider);
}
}
plugin.getLogger().info("PAPI hooked for " + game.getName(true));
}
Aggregations