Search in sources :

Example 1 with ModulePlaceHolderProvider

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;
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) ModulePlaceHolderProvider(au.com.mineauz.minigames.objects.ModulePlaceHolderProvider) Minigame(au.com.mineauz.minigames.minigame.Minigame)

Example 2 with ModulePlaceHolderProvider

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));
}
Also used : MinigameModule(au.com.mineauz.minigames.minigame.modules.MinigameModule) ModulePlaceHolderProvider(au.com.mineauz.minigames.objects.ModulePlaceHolderProvider)

Aggregations

ModulePlaceHolderProvider (au.com.mineauz.minigames.objects.ModulePlaceHolderProvider)2 Minigame (au.com.mineauz.minigames.minigame.Minigame)1 MinigameModule (au.com.mineauz.minigames.minigame.modules.MinigameModule)1 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)1