Search in sources :

Example 6 with StatManager

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

the class CommandManager method onReload.

/**
 * Called whenever a command sender wants to reload the plugin
 *
 * @param sender the command sender
 * @since 5.8.0
 */
@Subcommand("reload")
@Description("Reload the plugin")
@CommandPermission("bg.reload")
public void onReload(CommandSender sender) {
    ArenaManager.getInstance().getArenas().stream().filter(arena -> arena.getPlayers() > 0).forEach(Arena::stop);
    StatManager instance = StatManager.getInstance();
    if (instance.getMySQLDatabase() == null)
        instance.saveToFile();
    else
        instance.saveToDatabase();
    FileCheckerTimer runnable = SettingsManager.getInstance().getRunnable();
    if (!runnable.isCancelled())
        runnable.cancel();
    Main.getInstance().loadPlugin(true);
    MessageManager.getInstance().send(sender, ChatColor.GREEN + "Reloaded the plugin!");
}
Also used : CommandHelp(co.aikar.commands.CommandHelp) Player(org.bukkit.entity.Player) ReportMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.ReportMenu) Action(org.bukkit.event.block.Action) Supplier(java.util.function.Supplier) org.bukkit(org.bukkit) Main(com.gmail.stefvanschiedev.buildinggame.Main) com.gmail.stefvanschiedev.buildinggame.utils(com.gmail.stefvanschiedev.buildinggame.utils) Locale(java.util.Locale) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) GamePlayerType(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayerType) CommandSender(org.bukkit.command.CommandSender) co.aikar.commands.annotation(co.aikar.commands.annotation) ArenaSelection(com.gmail.stefvanschiedev.buildinggame.utils.guis.ArenaSelection) BaseCommand(co.aikar.commands.BaseCommand) RegionFactory(com.gmail.stefvanschiedev.buildinggame.utils.region.RegionFactory) ArenaMode(com.gmail.stefvanschiedev.buildinggame.utils.arena.ArenaMode) GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) PotentialLocation(com.gmail.stefvanschiedev.buildinggame.utils.potential.PotentialLocation) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) SettingsManager(com.gmail.stefvanschiedev.buildinggame.managers.files.SettingsManager) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) Consumer(java.util.function.Consumer) List(java.util.List) Region(com.gmail.stefvanschiedev.buildinggame.utils.region.Region) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) com.gmail.stefvanschiedev.buildinggame.timers(com.gmail.stefvanschiedev.buildinggame.timers) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) StatType(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType) MainSpawnManager(com.gmail.stefvanschiedev.buildinggame.managers.mainspawn.MainSpawnManager) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) Arena(com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena)

Example 7 with StatManager

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

the class BreakStat method onBlockBreak.

/**
 * Handles statistics for broken blocks
 *
 * @param e an event representing a block being broken
 * @see BlockBreakEvent
 * @since 2.2.0
 */
@EventHandler
public void onBlockBreak(BlockBreakEvent e) {
    var player = e.getPlayer();
    if (ArenaManager.getInstance().getArena(player) == null)
        return;
    StatManager instance = StatManager.getInstance();
    var stat = instance.getStat(player, StatType.BROKEN);
    instance.registerStat(player, StatType.BROKEN, stat == null ? 1 : stat.getValue() + 1);
}
Also used : StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) EventHandler(org.bukkit.event.EventHandler)

Example 8 with StatManager

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

the class FirstStat method onPlayerWin.

/**
 * Handles statistics for players becoming first
 *
 * @param e an event that represents a player winning
 * @see PlayerWinEvent
 * @since 2.2.0
 */
@EventHandler
public void onPlayerWin(PlayerWinEvent e) {
    if (e.getWin() != Win.FIRST)
        return;
    StatManager instance = StatManager.getInstance();
    e.getPlayers().stream().map(GamePlayer::getPlayer).forEach(player -> {
        var stat = instance.getStat(player, StatType.FIRST);
        instance.registerStat(player, StatType.FIRST, stat == null ? 1 : stat.getValue() + 1);
    });
}
Also used : StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) EventHandler(org.bukkit.event.EventHandler)

Example 9 with StatManager

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

the class PlaysStat method onArenaStart.

/**
 * Handles statistics for games played
 *
 * @param e an event that represents an arena starting
 * @see ArenaStartEvent
 * @since 2.2.0
 */
@EventHandler
public static void onArenaStart(ArenaStartEvent e) {
    StatManager instance = StatManager.getInstance();
    e.getArena().getUsedPlots().stream().flatMap(plot -> plot.getGamePlayers().stream()).forEach(gamePlayer -> {
        var player = gamePlayer.getPlayer();
        var stat = instance.getStat(player, StatType.PLAYS);
        instance.registerStat(player, StatType.PLAYS, stat == null ? 1 : stat.getValue() + 1);
    });
}
Also used : EventHandler(org.bukkit.event.EventHandler) ArenaStartEvent(com.gmail.stefvanschiedev.buildinggame.api.events.ArenaStartEvent) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) StatType(com.gmail.stefvanschiedev.buildinggame.utils.stats.StatType) Listener(org.bukkit.event.Listener) StatManager(com.gmail.stefvanschiedev.buildinggame.managers.stats.StatManager) EventHandler(org.bukkit.event.EventHandler)

Example 10 with StatManager

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

the class ThirdStat method onPlayerWin.

/**
 * Handles statistics for players becoming third
 *
 * @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.THIRD)
        return;
    StatManager instance = StatManager.getInstance();
    e.getPlayers().stream().map(GamePlayer::getPlayer).forEach(player -> {
        var stat = instance.getStat(player, StatType.THIRD);
        instance.registerStat(player, StatType.THIRD, 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