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);
}
}
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);
}
}
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);
}
}
}
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();
}
}
}
}
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();
}
Aggregations