Search in sources :

Example 1 with StatManager

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);
    });
}
Also used : StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) EventHandler(org.bukkit.event.EventHandler)

Example 2 with StatManager

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()))));
}
Also used : YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager)

Example 3 with StatManager

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());
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Example 4 with StatManager

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());
}
Also used : BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) EventHandler(org.bukkit.event.EventHandler)

Example 5 with StatManager

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);
}
Also used : StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) EventHandler(org.bukkit.event.EventHandler)

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