use of com.gmail.goosius.siegewar.enums.SiegeStatus in project SiegeWar by TownyAdvanced.
the class SiegeWarStatusScreenListener method onTownStatusScreen.
/*
* SiegeWar will add lines to towns which have a siege
*/
@EventHandler
public void onTownStatusScreen(TownStatusScreenEvent event) {
if (SiegeWarSettings.getWarSiegeEnabled()) {
final Translator translator = Translator.locale(Translation.getLocale(event.getCommandSender()));
Town town = event.getTown();
// Occupying Nation: Empire of the Fluffy Bunnies
if (SiegeWarSettings.getWarSiegeInvadeEnabled() && TownOccupationController.isTownOccupied(town)) {
Nation townOccupier = TownOccupationController.getTownOccupier(town);
event.getStatusScreen().addComponentOf("siegeWar_townOccupier", translator.of("status_town_occupying_nation", townOccupier.getFormattedName()));
}
// Revolt Immunity Timer: 71.8 hours
long immunity = TownMetaDataController.getRevoltImmunityEndTime(town);
if (SiegeWarSettings.getRevoltSiegesEnabled() && immunity == -1l || System.currentTimeMillis() < immunity) {
String time = immunity == -1l ? translator.of("msg_permanent") : TimeMgmt.getFormattedTimeValue(immunity - System.currentTimeMillis());
event.getStatusScreen().addComponentOf("siegeWar_revoltImmunityTimer", translator.of("status_town_revolt_immunity_timer", time));
}
immunity = TownMetaDataController.getSiegeImmunityEndTime(town);
if (SiegeController.hasSiege(town)) {
List<String> out = new ArrayList<>();
Siege siege = SiegeController.getSiege(town);
SiegeStatus siegeStatus = siege.getStatus();
String time = immunity == -1l ? translator.of("msg_permanent") : TimeMgmt.getFormattedTimeValue(immunity - System.currentTimeMillis());
// > Type: Conquest
out.add(translator.of("status_town_siege_type", siege.getSiegeType().getTranslatedName()));
// > Status: In Progress
out.add(translator.of("status_town_siege_status", getStatusTownSiegeSummary(siege, translator)));
// > Attacker: Darkness
out.add(translator.of("status_town_siege_attacker", siege.getAttackerNameForDisplay()));
// > Defender: Light
out.add(translator.of("status_town_siege_defender", siege.getDefenderNameForDisplay()));
switch(siegeStatus) {
case IN_PROGRESS:
// > Balance: 530
String balanceLine = translator.of("status_town_siege_status_siege_balance", siege.getSiegeBalance());
// > Balance: 530 | Pending: +130
int pending = SiegeWarBattleSessionUtil.calculateSiegeBalanceAdjustment(siege);
if (pending != 0)
balanceLine += translator.of("status_town_siege_pending_balance_adjustment", ((pending > 0 ? "+" : "") + pending));
out.add(balanceLine);
if (SiegeWarSettings.isBannerXYZTextEnabled()) {
// > Banner XYZ: {2223,82,9877}
out.add(translator.of("status_town_siege_status_banner_xyz", siege.getFlagLocation().getBlockX(), siege.getFlagLocation().getBlockY(), siege.getFlagLocation().getBlockZ()));
}
// > Victory Timer: 5.3 hours
String victoryTimer = translator.of("status_town_siege_victory_timer", siege.getFormattedHoursUntilScheduledCompletion());
out.add(victoryTimer);
// > War Chest: $12,800
if (TownyEconomyHandler.isActive()) {
String warChest = TownyEconomyHandler.getFormattedBalance(siege.getWarChestAmount());
out.add(translator.of("status_town_siege_status_warchest", warChest));
}
// Battle:
String battle = translator.of("status_town_siege_battle");
out.add(battle);
// > Banner Control: Attackers [4] Killbot401x, NerfeyMcNerferson, WarCriminal80372
if (siege.getBannerControllingSide() == SiegeSide.NOBODY) {
out.add(translator.of("status_town_banner_control_nobody", siege.getBannerControllingSide().getFormattedName().forLocale(event.getCommandSender())));
} else {
String[] bannerControllingResidents = TownyFormatter.getFormattedNames(siege.getBannerControllingResidents().toArray(new Resident[0]));
if (bannerControllingResidents.length > 34) {
String[] entire = bannerControllingResidents;
bannerControllingResidents = new String[36];
System.arraycopy(entire, 0, bannerControllingResidents, 0, 35);
bannerControllingResidents[35] = translator.of("status_town_reslist_overlength");
}
out.addAll(ChatTools.listArr(bannerControllingResidents, translator.of("status_town_banner_control", siege.getBannerControllingSide().getFormattedName().forLocale(event.getCommandSender()), siege.getBannerControllingResidents().size())));
}
// > Points: +90 / -220
out.add(translator.of("status_town_siege_battle_points", siege.getFormattedAttackerBattlePoints(), siege.getFormattedDefenderBattlePoints()));
// > Time Remaining: 22 minutes
out.add(translator.of("status_town_siege_battle_time_remaining", siege.getFormattedBattleTimeRemaining(translator)));
// > Breach Points: 15
if (SiegeWarSettings.isWallBreachingEnabled() && SiegeWarSettings.getWallBreachBonusBattlePoints() != 0)
out.add(translator.of("status_town_siege_breach_points", siege.getFormattedBreachPoints()));
break;
case ATTACKER_WIN:
case DEFENDER_SURRENDER:
case DEFENDER_WIN:
case ATTACKER_ABANDON:
String invadedPlunderedStatus = getInvadedPlunderedStatusLine(siege, translator);
if (!invadedPlunderedStatus.isEmpty())
out.add(invadedPlunderedStatus);
String siegeImmunityTimer = translator.of("status_town_siege_immunity_timer", time);
out.add(siegeImmunityTimer);
break;
case PENDING_DEFENDER_SURRENDER:
case PENDING_ATTACKER_ABANDON:
case UNKNOWN:
break;
}
TextComponent hoverText = Component.empty();
for (String line : out) {
hoverText = hoverText.append(Component.text(line).append(Component.newline()));
}
event.getStatusScreen().addComponentOf("siegeWar_siegeHover", hoverFormat(translator.of("status_sieged")), HoverEvent.showText(hoverText));
} else {
if (!SiegeController.hasActiveSiege(town) && (System.currentTimeMillis() < immunity) || immunity == -1l) {
// Siege:
// > Immunity Timer: 40.8 hours
String time = immunity == -1l ? Translation.of("msg_permanent") : TimeMgmt.getFormattedTimeValue(immunity - System.currentTimeMillis());
TextComponent immunityComp = Component.newline().append(Component.text(Translation.of("status_town_siege"))).append(Component.newline()).append(Component.text(Translation.of("status_town_siege_immunity_timer", time)));
event.getStatusScreen().addComponentOf("siegeWar_siegeImmunity", immunityComp);
}
}
}
}
Aggregations