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());
}
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);
}
Aggregations