use of com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager in project buildinggame by stefvanschie.
the class SecondStat method onPlayerWin.
/**
* Handles statistics for players becoming second
*
* @param e an event representing a player winning
* @see PlayerWinEvent
* @since 2.2.0
*/
@EventHandler
public static void onPlayerWin(PlayerWinEvent e) {
if (e.getWin() != Win.SECOND)
return;
StatManager instance = StatManager.getInstance();
e.getPlayers().stream().map(GamePlayer::getPlayer).forEach(player -> {
var stat = instance.getStat(player, StatType.SECOND);
instance.registerStat(player, StatType.SECOND, stat == null ? 1 : stat.getValue() + 1);
});
}
use of com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager in project buildinggame by stefvanschie.
the class CommandManager method onStats.
/**
* Called whenever a player wants to view his/her statistics
*
* @param player the player
* @since 5.8.0
*/
@Subcommand("stats")
@Description("Show your stats")
@CommandPermission("bg.stats")
public void onStats(Player player) {
YamlConfiguration messages = SettingsManager.getInstance().getMessages();
StatManager statManager = StatManager.getInstance();
var playsStat = statManager.getStat(player, StatType.PLAYS);
var firstStat = statManager.getStat(player, StatType.FIRST);
var secondStat = statManager.getStat(player, StatType.SECOND);
var thirdStat = statManager.getStat(player, StatType.THIRD);
var placedStat = statManager.getStat(player, StatType.PLACED);
var brokenStat = statManager.getStat(player, StatType.BROKEN);
var walkedStat = statManager.getStat(player, StatType.WALKED);
var pointsGivenStat = statManager.getStat(player, StatType.POINTS_GIVEN);
var pointsReceivedStat = statManager.getStat(player, StatType.POINTS_RECEIVED);
MessageManager.translate(messages.getStringList("commands.stats.success")).forEach(message -> MessageManager.getInstance().send(player, message.replace("%stat_plays%", playsStat == null ? "0" : String.valueOf(playsStat.getValue())).replace("%stat_first%", firstStat == null ? "0" : String.valueOf(firstStat.getValue())).replace("%stat_second%", secondStat == null ? "0" : String.valueOf(secondStat.getValue())).replace("%stat_third%", thirdStat == null ? "0" : String.valueOf(thirdStat.getValue())).replace("%stat_placed%", placedStat == null ? "0" : String.valueOf(placedStat.getValue())).replace("%stat_broken%", brokenStat == null ? "0" : String.valueOf(brokenStat.getValue())).replace("%stat_walked%", walkedStat == null ? "0" : String.valueOf(walkedStat.getValue())).replace("%stat_points_given%", pointsGivenStat == null ? "0" : String.valueOf(pointsGivenStat.getValue())).replace("%stat_points_received%", pointsReceivedStat == null ? "0" : String.valueOf(pointsReceivedStat.getValue()))));
}
use of com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager in project buildinggame by stefvanschie.
the class JoinPlayerStats method onJoin.
/**
* Handles MySQL statistic loading for new players
*
* @author TomVerschueren
* @param event an event representing a player joining
* @see PlayerJoinEvent
* @since 4.0.0
*/
@EventHandler
public void onJoin(PlayerJoinEvent event) {
final var player = event.getPlayer();
new BukkitRunnable() {
@Override
public void run() {
StatManager instance = StatManager.getInstance();
UUID uniqueId = player.getUniqueId();
String uuidString = uniqueId.toString();
if (!instance.containsUUID(uniqueId) && instance.getMySQLDatabase() != null)
instance.getMySQLDatabase().insertPlayer(uuidString);
for (var statType : StatType.values()) instance.registerStat(player, statType, instance.getMySQLDatabase().getStat(uuidString, statType.toString().toLowerCase(Locale.getDefault())));
}
}.runTaskAsynchronously(Main.getInstance());
}
use of com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager in project buildinggame by stefvanschie.
the class QuitPlayerStats method onPlayerQuit.
/**
* Handles MySQL statistic saving for disconnecting players
*
* @author TomVerschueren
* @param event an event representing a player disconnecting
* @see PlayerQuitEvent
* @since 4.0.0
*/
@EventHandler
public static void onPlayerQuit(PlayerQuitEvent event) {
final var player = event.getPlayer();
new BukkitRunnable() {
@Override
public void run() {
StatManager instance = StatManager.getInstance();
for (var type : StatType.values()) {
var stat = instance.getStat(player, type);
int value = stat == null ? 0 : stat.getValue();
instance.getMySQLDatabase().setStat(player.getUniqueId().toString(), type, value);
}
}
}.runTaskAsynchronously(Main.getInstance());
}
use of com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager in project buildinggame by stefvanschie.
the class PlaceStat method onBlockPlace.
/**
* Handles statistics for placed blocks
*
* @param e an event that represents a block being placed
* @see BlockPlaceEvent
* @since 2.2.0
*/
@EventHandler
public void onBlockPlace(BlockPlaceEvent e) {
var player = e.getPlayer();
if (ArenaManager.getInstance().getArena(player) == null)
return;
StatManager instance = StatManager.getInstance();
var stat = instance.getStat(player, StatType.PLACED);
instance.registerStat(player, StatType.PLACED, stat == null ? 1 : stat.getValue() + 1);
}
Aggregations