Search in sources :

Example 1 with BattleSession

use of com.gmail.goosius.siegewar.objects.BattleSession in project SiegeWar by TownyAdvanced.

the class SiegeWarAdminCommand method parseSiegeWarBattleSessionCommand.

private void parseSiegeWarBattleSessionCommand(CommandSender sender, String[] args) {
    if (args.length == 0) {
        showBattleSessionHelp(sender);
        return;
    }
    BattleSession battleSession = BattleSession.getBattleSession();
    if (args[0].equalsIgnoreCase("start")) {
        if (battleSession.isActive()) {
            Messaging.sendMsg(sender, Translatable.of("msg_err_battle_session_active"));
            return;
        }
        SiegeWarBattleSessionUtil.startBattleSession();
        Messaging.sendMsg(sender, Translatable.of("msg_battle_session_force_start"));
    } else if (args[0].equalsIgnoreCase("end")) {
        if (!battleSession.isActive()) {
            Messaging.sendMsg(sender, Translatable.of("msg_err_battle_session_inactive"));
            return;
        }
        SiegeWarBattleSessionUtil.endBattleSession();
        Messaging.sendMsg(sender, Translatable.of("msg_battle_session_force_end"));
    } else {
        showBattleSessionHelp(sender);
    }
}
Also used : BattleSession(com.gmail.goosius.siegewar.objects.BattleSession)

Example 2 with BattleSession

use of com.gmail.goosius.siegewar.objects.BattleSession in project SiegeWar by TownyAdvanced.

the class SiegeWarCommand method parseSiegeWarNextSessionCommand.

private void parseSiegeWarNextSessionCommand(Player player) {
    BattleSession session = BattleSession.getBattleSession();
    if (session.isActive())
        Messaging.sendMsg(player, Translatable.of("msg_session_is_active_now"));
    else {
        Translatable message = Translatable.of("msg_next_session_cannot_be_determined");
        if (session.getScheduledStartTime() != null) {
            long timeRemaining = session.getScheduledStartTime() - System.currentTimeMillis();
            message = Translatable.of("msg_next_siege_session_in_minutes", TimeMgmt.getFormattedTimeValue(timeRemaining));
        }
        Messaging.sendMsg(player, message);
    }
}
Also used : BattleSession(com.gmail.goosius.siegewar.objects.BattleSession) Translatable(com.palmergames.bukkit.towny.object.Translatable)

Example 3 with BattleSession

use of com.gmail.goosius.siegewar.objects.BattleSession in project SiegeWar by TownyAdvanced.

the class BossBarUtil method updateBattleSessionBossBar.

public static void updateBattleSessionBossBar() {
    BattleSession session = BattleSession.getBattleSession();
    TextComponent comp = Component.text(Translation.of("bossbar_msg_battle_time_remaining", session.getFormattedTimeRemainingUntilBattleSessionEnds()));
    float remaining = getRemainder(session.getScheduledEndTime(), SiegeWarSettings.getWarSiegeBattleSessionsDurationMinutes() * 60000);
    for (Player player : Bukkit.getOnlinePlayers()) {
        Resident resident = TownyAPI.getInstance().getResident(player);
        if (resident == null || ResidentMetaDataController.getBossBarsDisabled(resident))
            continue;
        BossBar bossBar = bossBarBattleSessionMap.containsKey(player) ? bossBarBattleSessionMap.get(player) : BossBar.bossBar(comp, 0, Color.WHITE, Overlay.PROGRESS);
        bossBar.progress((float) (remaining / 100.0));
        bossBar.name(comp);
        if (!bossBarBattleSessionMap.containsKey(player)) {
            bossBarBattleSessionMap.put(player, bossBar);
            Towny.getAdventure().player(player).showBossBar(bossBar);
        }
    }
}
Also used : BattleSession(com.gmail.goosius.siegewar.objects.BattleSession) TextComponent(com.palmergames.adventure.text.TextComponent) Player(org.bukkit.entity.Player) Resident(com.palmergames.bukkit.towny.object.Resident) BossBar(com.palmergames.adventure.bossbar.BossBar)

Example 4 with BattleSession

use of com.gmail.goosius.siegewar.objects.BattleSession in project SiegeWar by TownyAdvanced.

the class SiegeWarBattleSessionUtil method evaluateBattleSessions.

public static void evaluateBattleSessions() {
    BattleSession battleSession = BattleSession.getBattleSession();
    if (battleSession.isActive()) {
        if (System.currentTimeMillis() > battleSession.getScheduledEndTime()) {
            // Finish battle session
            endBattleSession();
        } else {
            // Update battle session boss bars.
            BossBarUtil.updateBattleSessionBossBar();
        }
    } else {
        // If there is no battle session scheduled, attempt to schedule session now.
        if (battleSession.getScheduledStartTime() == null) {
            scheduleNextBattleSession();
        }
        // If a battle session is scheduled, start it if we hit the scheduled time
        if (battleSession.getScheduledStartTime() != null) {
            if (System.currentTimeMillis() > battleSession.getScheduledStartTime()) {
                // Send up the Bukkit event for other plugins to listen for and potentially cancel.
                BattleSessionPreStartEvent event = new BattleSessionPreStartEvent();
                Bukkit.getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                    // Null the next scheduled time, so it can be reset on the next ShortTime.
                    battleSession.setScheduledStartTime(null);
                    // Broadcast a cancelled BatterlSession message.
                    Messaging.sendGlobalMessage(event.getCancellationMsg());
                    return;
                }
                // Activate the session
                startBattleSession();
            }
        }
    }
}
Also used : BattleSession(com.gmail.goosius.siegewar.objects.BattleSession) BattleSessionPreStartEvent(com.gmail.goosius.siegewar.events.BattleSessionPreStartEvent)

Example 5 with BattleSession

use of com.gmail.goosius.siegewar.objects.BattleSession in project SiegeWar by TownyAdvanced.

the class SiegeWarBattleSessionUtil method endBattleSession.

public static void endBattleSession() {
    BattleSession battleSession = BattleSession.getBattleSession();
    battleSession.setActive(false);
    battleResults.clear();
    /*
		 * Gather the results of all battles
		 * End any active battles
		 */
    for (Siege siege : SiegeController.getSieges()) endBattleSessionForSiege(siege);
    Bukkit.getPluginManager().callEvent(new BattleSessionEndedEvent());
    // Send message
    sendBattleSessionEndedMessage(battleResults);
    // Remove Battle Session Boss-Bars
    BossBarUtil.removeBattleSessionBossBars();
}
Also used : BattleSession(com.gmail.goosius.siegewar.objects.BattleSession) BattleSessionEndedEvent(com.gmail.goosius.siegewar.events.BattleSessionEndedEvent) Siege(com.gmail.goosius.siegewar.objects.Siege)

Aggregations

BattleSession (com.gmail.goosius.siegewar.objects.BattleSession)6 BattleSessionEndedEvent (com.gmail.goosius.siegewar.events.BattleSessionEndedEvent)1 BattleSessionPreStartEvent (com.gmail.goosius.siegewar.events.BattleSessionPreStartEvent)1 BattleSessionStartedEvent (com.gmail.goosius.siegewar.events.BattleSessionStartedEvent)1 Siege (com.gmail.goosius.siegewar.objects.Siege)1 BossBar (com.palmergames.adventure.bossbar.BossBar)1 TextComponent (com.palmergames.adventure.text.TextComponent)1 Resident (com.palmergames.bukkit.towny.object.Resident)1 Translatable (com.palmergames.bukkit.towny.object.Translatable)1 Player (org.bukkit.entity.Player)1