Search in sources :

Example 11 with StatManager

use of com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager in project buildinggame by stefvanschie.

the class Plot method addVote.

/**
 * Adds a vote to this plot
 *
 * @param vote the vote to be added
 * @since 2.1.0
 */
@Contract("null -> fail")
public void addVote(Vote vote) {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    YamlConfiguration messages = SettingsManager.getInstance().getMessages();
    if (arena.getState() != GameState.VOTING)
        return;
    Player sender = vote.getSender();
    // check if player votes on his/her own plot
    for (GamePlayer gamePlayer : getGamePlayers()) {
        if (gamePlayer.getPlayer().equals(sender)) {
            MessageManager.getInstance().send(sender, messages.getStringList("vote.own-plot"));
            return;
        }
    }
    // check how many times voted
    if (getTimesVoted(sender) == config.getInt("max-vote-change")) {
        messages.getStringList("vote.maximum-votes").forEach(message -> MessageManager.getInstance().send(sender, message.replace("%max_votes%", config.getInt("max-votes-change") + "")));
        return;
    }
    getTimesVoted().put(sender, getTimesVoted(sender) + 1);
    messages.getStringList("vote.message").forEach(message -> MessageManager.getInstance().send(sender, message.replace("%playerplot%", arena.getVotingPlot().getPlayerFormat()).replace("%points%", vote.getPoints() + "")));
    messages.getStringList("vote.receiver").forEach(message -> arena.getVotingPlot().getGamePlayers().forEach(player -> MessageManager.getInstance().send(player.getPlayer(), message.replace("%points%", vote.getPoints() + "").replace("%sender%", sender.getName()))));
    var senderArena = ArenaManager.getInstance().getArena(sender);
    if (senderArena != null)
        senderArena.getPlot(sender).getGamePlayers().forEach(player -> {
            player.addTitleAndSubtitle(messages.getString("vote.title").replace("%points%", vote.getPoints() + ""), messages.getString("vote.subtitle").replace("%points%", vote.getPoints() + ""));
            player.sendActionbar(messages.getString("vote.actionbar").replace("%points%", String.valueOf(vote.getPoints())));
        });
    int previousPoints = getPoints();
    if (hasVoted(sender))
        getVotes().remove(getVote(sender));
    votes.add(vote);
    if (!config.getBoolean("scoreboards.vote.text"))
        arena.getVoteScoreboard(this).setScore(getPlayerFormat(), getPoints());
    if (!config.getBoolean("names-after-voting") && config.getBoolean("scoreboards.vote.enable"))
        arena.getPlots().stream().filter(p -> !p.getGamePlayers().isEmpty()).flatMap(p -> getGamePlayers().stream()).forEach(player -> arena.getVoteScoreboard(this).show(player.getPlayer()));
    // point actions
    var configurationSection = config.getConfigurationSection("voting.point-actions");
    configurationSection.getKeys(false).forEach(key -> {
        int points;
        try {
            points = Integer.parseInt(key);
        } catch (NumberFormatException e) {
            if (config.getBoolean("debug"))
                Main.getInstance().getLogger().warning("Unsupported value found in config.yml in voting > point-actions > " + key);
            return;
        }
        // of points made the amount go over the minimum, it shouldn't already have been higher than the minimum)
        if (getPoints() < points || previousPoints >= points)
            return;
        configurationSection.getStringList(key).forEach(command -> {
            if (!command.isEmpty() && command.charAt(0) == '@') {
                String targetText = command.split(" ")[0];
                Target.parse(targetText).execute(command.substring(targetText.length() + 1));
            } else
                getGamePlayers().forEach(gamePlayer -> Bukkit.dispatchCommand(gamePlayer.getPlayer(), command));
        });
    });
    // track stats
    var statManager = StatManager.getInstance();
    getGamePlayers().forEach(gamePlayer -> {
        var player = gamePlayer.getPlayer();
        var stat = statManager.getStat(player, StatType.POINTS_RECEIVED);
        statManager.registerStat(player, StatType.POINTS_RECEIVED, (stat == null ? 0 : stat.getValue()) + vote.getPoints());
    });
    var stat = statManager.getStat(sender, StatType.POINTS_GIVEN);
    statManager.registerStat(sender, StatType.POINTS_GIVEN, (stat == null ? 0 : stat.getValue()) + vote.getPoints());
}
Also used : java.util(java.util) Player(org.bukkit.entity.Player) Biome(org.bukkit.block.Biome) org.bukkit(org.bukkit) Block(org.bukkit.block.Block) com.gmail.stefvanschiedev.buildinggame.utils(com.gmail.stefvanschiedev.buildinggame.utils) Main(com.gmail.stefvanschiedev.buildinggame.Main) GamePlayerType(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType) CommandSender(org.bukkit.command.CommandSender) Particle(com.gmail.stefvanschiedev.buildinggame.utils.particle.Particle) Entity(org.bukkit.entity.Entity) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation) ArenaMode(com.gmail.stefvanschiedev.buildinggame.utils.arena.ArenaMode) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) BlockState(org.bukkit.block.BlockState) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) LivingEntity(org.bukkit.entity.LivingEntity) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) Contract(org.jetbrains.annotations.Contract) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) BuildMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.buildmenu.BuildMenu) NotNull(org.jetbrains.annotations.NotNull) StatType(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) MainSpawnManager(com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager) SpectatorMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.spectatormenu.SpectatorMenu) Player(org.bukkit.entity.Player) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Contract(org.jetbrains.annotations.Contract)

Example 12 with StatManager

use of com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager in project buildinggame by stefvanschie.

the class GamePlayer method restore.

/**
 * This restores the player to before it joined an arena and applies any necessary statistic updates
 *
 * @since 2.1.0
 */
public void restore() {
    player.getInventory().setArmorContents(armor);
    setBlocksPlaced(0);
    player.setExp(exp);
    player.setFoodLevel(foodLevel);
    player.setFlySpeed(flySpeed);
    player.setGameMode(gameMode);
    player.getInventory().setContents(inventory);
    player.setLevel(levels);
    player.setScoreboard(scoreboard);
    // apply walked statistic
    StatManager instance = StatManager.getInstance();
    var stat = instance.getStat(player, StatType.WALKED);
    instance.registerStat(player, StatType.WALKED, (stat == null ? 0 : stat.getValue()) + (player.getStatistic(Statistic.WALK_ONE_CM) - walkOnceCM) / 100);
}
Also used : StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager)

Aggregations

StatManager (com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager)12 EventHandler (org.bukkit.event.EventHandler)8 StatType (com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType)3 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)3 Main (com.gmail.stefvanschiedev.buildinggame.Main)2 ArenaManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager)2 SettingsManager (com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager)2 MainSpawnManager (com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager)2 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)2 com.gmail.stefvanschiedev.buildinggame.utils (com.gmail.stefvanschiedev.buildinggame.utils)2 Arena (com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)2 ArenaMode (com.gmail.stefvanschiedev.buildinggame.utils.arena.ArenaMode)2 GamePlayer (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer)2 GamePlayerType (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType)2 PotentialLocation (com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation)2 Region (com.gmail.stefvanschiedev.buildinggame.utils.region.Region)2 org.bukkit (org.bukkit)2 CommandSender (org.bukkit.command.CommandSender)2 Player (org.bukkit.entity.Player)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2