Search in sources :

Example 1 with MinigameTimerTickEvent

use of au.com.mineauz.minigames.events.MinigameTimerTickEvent in project Minigames by AddstarMC.

the class MinigameTimer method startTimer.

public void startTimer() {
    if (taskID != -1)
        stopTimer();
    taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {

        @Override
        public void run() {
            time -= 1;
            if (minigame.isUsingXPBarTimer()) {
                float timeper = ((Integer) time).floatValue() / ((Integer) otime).floatValue();
                int level = 0;
                if (time / 60 > 0)
                    level = time / 60;
                else
                    level = time;
                for (MinigamePlayer ply : minigame.getPlayers()) {
                    ply.getPlayer().setExp(timeper);
                    ply.getPlayer().setLevel(level);
                }
            }
            if (timeMsg.contains(time) && broadcastTime) {
                PlayMGSound.playSound(minigame, MGSounds.getSound("timerTick"));
                plugin.mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("minigame.timeLeft", MinigameUtils.convertTime(time)), null, null);
            }
            if (time == 0) {
                Bukkit.getServer().getPluginManager().callEvent(new TimerExpireEvent(minigame));
                stopTimer();
            }
            if (time != 0)
                Bukkit.getPluginManager().callEvent(new MinigameTimerTickEvent(minigame, minigame.getMinigameTimer()));
        }
    }, 0, 20);
}
Also used : TimerExpireEvent(au.com.mineauz.minigames.events.TimerExpireEvent) MinigameTimerTickEvent(au.com.mineauz.minigames.events.MinigameTimerTickEvent)

Example 2 with MinigameTimerTickEvent

use of au.com.mineauz.minigames.events.MinigameTimerTickEvent in project Minigames by AddstarMC.

the class MinigameTimer method runTimer.

private void runTimer() {
    time -= 1;
    if (minigame.isUsingXPBarTimer()) {
        float timeper = ((Integer) time).floatValue() / ((Integer) otime).floatValue();
        int level = 0;
        if (time / 60 > 0)
            level = time / 60;
        else
            level = time;
        for (MinigamePlayer ply : minigame.getPlayers()) {
            if (timeper < 0) {
                ply.getPlayer().setExp(0);
                ply.getPlayer().setLevel(0);
            } else {
                ply.getPlayer().setExp(timeper);
                ply.getPlayer().setLevel(level);
            }
        }
    }
    if (timeMsg.contains(time) && broadcastTime) {
        PlayMGSound.playSound(minigame, MGSounds.getSound("timerTick"));
        plugin.getMinigameManager().sendMinigameMessage(minigame, MinigameUtils.formStr("minigame.timeLeft", MinigameUtils.convertTime(time)));
    }
    if (time <= 0) {
        Bukkit.getServer().getPluginManager().callEvent(new TimerExpireEvent(minigame));
        stopTimer();
    }
    if (time > 0)
        Bukkit.getPluginManager().callEvent(new MinigameTimerTickEvent(minigame, minigame.getMinigameTimer()));
}
Also used : TimerExpireEvent(au.com.mineauz.minigames.events.TimerExpireEvent) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) MinigameTimerTickEvent(au.com.mineauz.minigames.events.MinigameTimerTickEvent)

Aggregations

MinigameTimerTickEvent (au.com.mineauz.minigames.events.MinigameTimerTickEvent)2 TimerExpireEvent (au.com.mineauz.minigames.events.TimerExpireEvent)2 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)1