Search in sources :

Example 1 with TextComponent

use of com.palmergames.adventure.text.TextComponent 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 2 with TextComponent

use of com.palmergames.adventure.text.TextComponent in project SiegeWar by TownyAdvanced.

the class BossBarUtil method updateBannerCapBossBar.

public static void updateBannerCapBossBar(Player player, String msg, BannerControlSession bannerControlSession) {
    Resident resident = TownyAPI.getInstance().getResident(player);
    if (resident == null || ResidentMetaDataController.getBossBarsDisabled(resident))
        return;
    TextComponent comp = Component.text(msg);
    float remaining = getRemainder(bannerControlSession.getSessionEndTime(), SiegeWarSettings.getWarSiegeBannerControlSessionDurationMinutes());
    BossBar bossBar = bossBarBannerCapMap.containsKey(player) ? bossBarBannerCapMap.get(player) : BossBar.bossBar(comp, 0, Color.WHITE, Overlay.PROGRESS);
    bossBar.progress(remaining);
    bossBar.name(comp);
    if (!bossBarBannerCapMap.containsKey(player)) {
        bossBarBannerCapMap.put(player, bossBar);
        Towny.getAdventure().player(player).showBossBar(bossBar);
    }
}
Also used : TextComponent(com.palmergames.adventure.text.TextComponent) Resident(com.palmergames.bukkit.towny.object.Resident) BossBar(com.palmergames.adventure.bossbar.BossBar)

Example 3 with TextComponent

use of com.palmergames.adventure.text.TextComponent in project SiegeWar by TownyAdvanced.

the class SiegeWarStatusScreenListener method onNationStatusScreen.

/*
	 * SiegeWar will add lines to Nation which have a siege
	 */
@EventHandler
public void onNationStatusScreen(NationStatusScreenEvent event) {
    if (SiegeWarSettings.getWarSiegeEnabled()) {
        final Translator translator = Translator.locale(Translation.getLocale(event.getCommandSender()));
        Nation nation = event.getNation();
        List<String> out = new ArrayList<>();
        // Occupied Home Towns[3]: Town1, Town2, Town3
        List<Town> occupiedHomeTowns = TownOccupationController.getOccupiedHomeTowns(nation);
        if (occupiedHomeTowns.size() > 0) {
            TextComponent comp = Component.newline().append(Component.text(translator.of("status_nation_occupied_home_towns", occupiedHomeTowns.size()) + getFormattedTownList(occupiedHomeTowns)).clickEvent(ClickEvent.runCommand("/nation siegewar occupiedhometowns " + nation.getName())).hoverEvent(HoverEvent.showText(Component.text(translator.of("status_hover_click_for_more")))));
            event.getStatusScreen().addComponentOf("siegeWarNationOccupiedHomeTowns", comp);
        }
        // Occupied Foreign Towns[3]: Town4, Town5, Town6
        List<Town> occupiedForeignTowns = TownOccupationController.getOccupiedForeignTowns(nation);
        if (occupiedForeignTowns.size() > 0) {
            TextComponent comp = Component.newline().append(Component.text(translator.of("status_nation_occupied_foreign_towns", occupiedForeignTowns.size()) + getFormattedTownList(occupiedForeignTowns)).clickEvent(ClickEvent.runCommand("/nation siegewar occupiedforeigntowns " + nation.getName())).hoverEvent(HoverEvent.showText(Component.text(translator.of("status_hover_click_for_more")))));
            event.getStatusScreen().addComponentOf("siegeWarNationOccupiedForeignTowns", comp);
        }
        // Offensive Sieges [3]: TownA, TownB, TownC
        List<Town> siegeAttacks = new ArrayList<>(SiegeController.getActiveOffensiveSieges(nation).values());
        if (siegeAttacks.size() > 0)
            out.add(translator.of("status_nation_offensive_sieges", siegeAttacks.size()) + getFormattedTownList(siegeAttacks));
        // Defensive Sieges [3]: TownX, TownY, TownZ
        List<Town> siegeDefences = new ArrayList<>(SiegeController.getActiveDefensiveSieges(nation).values());
        if (siegeDefences.size() > 0)
            out.add(translator.of("status_nation_defensive_sieges", siegeDefences.size()) + getFormattedTownList(siegeDefences));
        if (SiegeWarSettings.getWarSiegeNationStatisticsEnabled()) {
            out.add(translator.of("status_nation_town_stats", NationMetaDataController.getTotalTownsGained(nation), NationMetaDataController.getTotalTownsLost(nation)));
            out.add(translator.of("status_nation_plunder_stats", NationMetaDataController.getTotalPlunderGained(nation), NationMetaDataController.getTotalPlunderLost(nation)));
        }
        TextComponent comp = Component.empty();
        for (String line : out) comp = comp.append(Component.text(line)).append(Component.newline());
        event.getStatusScreen().addComponentOf("siegeWarNation", comp);
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) TextComponent(com.palmergames.adventure.text.TextComponent) Translator(com.palmergames.bukkit.towny.object.Translator) Town(com.palmergames.bukkit.towny.object.Town) ArrayList(java.util.ArrayList) EventHandler(org.bukkit.event.EventHandler)

Example 4 with TextComponent

use of com.palmergames.adventure.text.TextComponent 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);
            }
        }
    }
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) TextComponent(com.palmergames.adventure.text.TextComponent) ArrayList(java.util.ArrayList) Siege(com.gmail.goosius.siegewar.objects.Siege) Translator(com.palmergames.bukkit.towny.object.Translator) Town(com.palmergames.bukkit.towny.object.Town) SiegeStatus(com.gmail.goosius.siegewar.enums.SiegeStatus) Resident(com.palmergames.bukkit.towny.object.Resident) EventHandler(org.bukkit.event.EventHandler)

Aggregations

TextComponent (com.palmergames.adventure.text.TextComponent)4 Resident (com.palmergames.bukkit.towny.object.Resident)3 BossBar (com.palmergames.adventure.bossbar.BossBar)2 Nation (com.palmergames.bukkit.towny.object.Nation)2 Town (com.palmergames.bukkit.towny.object.Town)2 Translator (com.palmergames.bukkit.towny.object.Translator)2 ArrayList (java.util.ArrayList)2 EventHandler (org.bukkit.event.EventHandler)2 SiegeStatus (com.gmail.goosius.siegewar.enums.SiegeStatus)1 BattleSession (com.gmail.goosius.siegewar.objects.BattleSession)1 Siege (com.gmail.goosius.siegewar.objects.Siege)1 Player (org.bukkit.entity.Player)1