Search in sources :

Example 6 with Translator

use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.

the class PlaceBlock method evaluatePlaceWhiteBannerNearTown.

/**
 * Evaluates placing a white banner near a town
 *
 * Effects depend on the nature of the siege (if any) and the allegiances of the banner placer
 *
 * @param player the player placing the banner
 * @param residentsTown the town of the player placing the banner
 * @param residentsNation the nation of the player placing the banner (can be null)
 * @param nearbyTown the nearby town
 */
private static void evaluatePlaceWhiteBannerNearTown(Player player, Town residentsTown, Nation residentsNation, Town nearbyTown) throws TownyException {
    final Translator translator = Translator.locale(Translation.getLocale(player));
    // Ensure that there is a siege
    if (!SiegeController.hasSiege(nearbyTown))
        throw new TownyException(translator.of("msg_err_town_cannot_end_siege_as_no_siege"));
    // Get siege
    Siege siege = SiegeController.getSiege(nearbyTown);
    if (siege.getStatus() != SiegeStatus.IN_PROGRESS)
        throw new TownyException(translator.of("msg_err_town_cannot_end_siege_as_finished"));
    /*
		 * Check what type of action this qualifies as.
		 * Depending on the scenario, it may be 'abandonAttack' or 'surrenderDefence'
		 */
    switch(siege.getSiegeType()) {
        case CONQUEST:
            if (residentsNation != null && residentsNation == siege.getAttacker()) {
                AbandonAttack.processAbandonAttackRequest(player, siege);
            } else if (residentsTown == nearbyTown) {
                SurrenderDefence.processSurrenderDefenceRequest(player, siege);
            } else {
                throw new TownyException(translator.of("msg_err_action_disable"));
            }
            break;
        case LIBERATION:
            if (residentsNation != null && residentsNation == siege.getAttacker()) {
                AbandonAttack.processAbandonAttackRequest(player, siege);
            } else if (residentsNation != null && TownOccupationController.isTownOccupied(nearbyTown) && TownOccupationController.getTownOccupier(nearbyTown) == residentsNation) {
                SurrenderDefence.processSurrenderDefenceRequest(player, siege);
            } else {
                throw new TownyException(translator.of("msg_err_action_disable"));
            }
            break;
        case REVOLT:
            if (residentsTown == nearbyTown) {
                AbandonAttack.processAbandonAttackRequest(player, siege);
            } else if (residentsNation != null && TownOccupationController.isTownOccupied(nearbyTown) && TownOccupationController.getTownOccupier(nearbyTown) == residentsNation) {
                SurrenderDefence.processSurrenderDefenceRequest(player, siege);
            } else {
                throw new TownyException(translator.of("msg_err_action_disable"));
            }
            break;
        case SUPPRESSION:
            if (residentsNation != null && TownOccupationController.isTownOccupied(nearbyTown) && TownOccupationController.getTownOccupier(nearbyTown) == residentsNation) {
                AbandonAttack.processAbandonAttackRequest(player, siege);
            } else if (residentsTown == nearbyTown) {
                SurrenderDefence.processSurrenderDefenceRequest(player, siege);
            } else {
                throw new TownyException(translator.of("msg_err_action_disable"));
            }
            break;
    }
}
Also used : Translator(com.palmergames.bukkit.towny.object.Translator) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException) Siege(com.gmail.goosius.siegewar.objects.Siege)

Example 7 with Translator

use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.

the class StartConquestSiege method processStartSiegeRequest.

/**
 * Process a start conquest siege request.
 *
 * At this point we know that the resident has a nation and the town is not occupied
 *
 * This method does some final checks and if they pass, the siege is initiated.
 *
 * @param player the player
 * @param townOfSiegeStarter town
 * @param nationOfSiegeStarter nation which is attacking.
 * @param townBlock the townblock where the attack is taking place.
 * @param targetTown the town about to be attacked
 * @param bannerBlock the banner block
 *
 * @throws TownyException when attack cannot be made.
 */
public static void processStartSiegeRequest(Player player, Town townOfSiegeStarter, Nation nationOfSiegeStarter, TownBlock townBlock, Town targetTown, Block bannerBlock) throws TownyException {
    final Translator translator = Translator.locale(Translation.getLocale(player));
    if (!SiegeWarSettings.getConquestSiegesEnabled())
        throw new TownyException(translator.of("msg_err_action_disable"));
    if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.getPermissionNodeToStartSiege(SiegeType.CONQUEST)))
        throw new TownyException(translator.of("msg_err_action_disable"));
    if (targetTown.hasNation()) {
        Nation nationOfDefendingTown = targetTown.getNation();
        if (nationOfSiegeStarter == nationOfDefendingTown)
            throw new TownyException(translator.of("msg_err_siege_war_cannot_attack_town_in_own_nation"));
        if (!nationOfSiegeStarter.hasEnemy(nationOfDefendingTown))
            throw new TownyException(translator.of("msg_err_siege_war_cannot_attack_non_enemy_nation"));
    }
    if (TownySettings.getNationRequiresProximity() > 0) {
        Coord capitalCoord = nationOfSiegeStarter.getCapital().getHomeBlock().getCoord();
        Coord townCoord = targetTown.getHomeBlock().getCoord();
        if (!nationOfSiegeStarter.getCapital().getHomeBlock().getWorld().getName().equals(targetTown.getHomeBlock().getWorld().getName())) {
            throw new TownyException(translator.of("msg_err_nation_homeblock_in_another_world"));
        }
        double distance;
        distance = Math.sqrt(Math.pow(capitalCoord.getX() - townCoord.getX(), 2) + Math.pow(capitalCoord.getZ() - townCoord.getZ(), 2));
        if (distance > TownySettings.getNationRequiresProximity()) {
            throw new TownyException(translator.of("msg_err_siege_war_town_not_close_enough_to_nation"));
        }
    }
    SiegeCamp camp = new SiegeCamp(player, bannerBlock, SiegeType.CONQUEST, targetTown, nationOfSiegeStarter, targetTown, townOfSiegeStarter, townBlock);
    PreSiegeCampEvent event = new PreSiegeCampEvent(camp);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        throw new TownyException(event.getCancellationMsg());
    if (SiegeWarSettings.areSiegeCampsEnabled())
        // Launch a SiegeCamp, a (by default) 10 minute minigame. If successful the Siege will be initiated in ernest.
        SiegeController.beginSiegeCamp(camp);
    else
        // SiegeCamps are disabled, just do the Siege.
        camp.startSiege();
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Coord(com.palmergames.bukkit.towny.object.Coord) Translator(com.palmergames.bukkit.towny.object.Translator) PreSiegeCampEvent(com.gmail.goosius.siegewar.events.PreSiegeCampEvent) SiegeCamp(com.gmail.goosius.siegewar.objects.SiegeCamp) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 8 with Translator

use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.

the class StartLiberationSiege method processStartSiegeRequest.

/**
 * Process a start liberation siege request.
 * <p>
 * At this point we know that
 * - the resident has a nation
 * - the town is occupied,
 * - the player's nation is not the occupier.
 * <p>
 * This method does some final checks and if they pass, the siege is initiated.
 *
 * @param player               the player
 * @param townOfSiegeStarter   town
 * @param nationOfSiegeStarter nation which is attacking.
 * @param townBlock            the townblock where the attack is taking place.
 * @param targetTown           the town about to be attacked
 * @param bannerBlock          the banner block
 * @throws TownyException when attack cannot be made.
 */
public static void processStartSiegeRequest(Player player, Town townOfSiegeStarter, Nation nationOfSiegeStarter, TownBlock townBlock, Town targetTown, Block bannerBlock) throws TownyException {
    final Translator translator = Translator.locale(Translation.getLocale(player));
    if (!SiegeWarSettings.getLiberationSiegesEnabled())
        throw new TownyException(translator.of("msg_err_action_disable"));
    if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.getPermissionNodeToStartSiege(SiegeType.LIBERATION)))
        throw new TownyException(translator.of("msg_err_action_disable"));
    Nation occupierNation = TownOccupationController.getTownOccupier(targetTown);
    if (!nationOfSiegeStarter.hasEnemy(occupierNation))
        throw new TownyException(translator.of("msg_err_siege_war_cannot_attack_occupied_town_non_enemy_nation"));
    Nation naturalNationOfTown = targetTown.getNationOrNull();
    if (naturalNationOfTown != null && !naturalNationOfTown.hasMutualAlly(nationOfSiegeStarter))
        throw new TownyException(translator.of("msg_err_siege_war_cannot_start_liberation_siege_at_unallied_town"));
    if (TownySettings.getNationRequiresProximity() > 0) {
        Coord capitalCoord = nationOfSiegeStarter.getCapital().getHomeBlock().getCoord();
        Coord townCoord = targetTown.getHomeBlock().getCoord();
        if (!nationOfSiegeStarter.getCapital().getHomeBlock().getWorld().getName().equals(targetTown.getHomeBlock().getWorld().getName())) {
            throw new TownyException(translator.of("msg_err_nation_homeblock_in_another_world"));
        }
        double distance;
        distance = Math.sqrt(Math.pow(capitalCoord.getX() - townCoord.getX(), 2) + Math.pow(capitalCoord.getZ() - townCoord.getZ(), 2));
        if (distance > TownySettings.getNationRequiresProximity()) {
            throw new TownyException(translator.of("msg_err_siege_war_town_not_close_enough_to_nation"));
        }
    }
    SiegeCamp camp = new SiegeCamp(player, bannerBlock, SiegeType.LIBERATION, targetTown, nationOfSiegeStarter, occupierNation, townOfSiegeStarter, townBlock);
    PreSiegeCampEvent event = new PreSiegeCampEvent(camp);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled())
        throw new TownyException(event.getCancellationMsg());
    if (SiegeWarSettings.areSiegeCampsEnabled())
        // Launch a SiegeCamp, a (by default) 10 minute minigame. If successful the Siege will be initiated in ernest.
        SiegeController.beginSiegeCamp(camp);
    else
        // SiegeCamps are disabled, just do the Siege.
        camp.startSiege();
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Coord(com.palmergames.bukkit.towny.object.Coord) Translator(com.palmergames.bukkit.towny.object.Translator) PreSiegeCampEvent(com.gmail.goosius.siegewar.events.PreSiegeCampEvent) SiegeCamp(com.gmail.goosius.siegewar.objects.SiegeCamp) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 9 with Translator

use of com.palmergames.bukkit.towny.object.Translator in project Towny by TownyAdvanced.

the class TownyCommand method getUniverseStats.

public List<String> getUniverseStats(Locale locale) {
    TownyUniverse townyUniverse = TownyUniverse.getInstance();
    List<String> output = new ArrayList<>();
    final Translator translator = Translator.locale(locale);
    // Intentionally left blank
    output.add("");
    output.add("\u00A70-\u00A74###\u00A70---\u00A74###\u00A70-   " + Colors.Gold + "[" + Colors.Yellow + "Towny " + Colors.Green + plugin.getVersion() + Colors.Gold + "]");
    output.add("\u00A74#\u00A7c###\u00A74#\u00A70-\u00A74#\u00A7c###\u00A74#\u00A70   " + Colors.Blue + translator.of("msg_universe_attribution") + Colors.LightBlue + "Chris H (Shade), ElgarL, LlmDl");
    output.add("\u00A74#\u00A7c####\u00A74#\u00A7c####\u00A74#   " + Colors.LightBlue + translator.of("msg_universe_contributors") + Colors.Rose + translator.of("msg_universe_heart"));
    output.add("\u00A70-\u00A74#\u00A7c#######\u00A74#\u00A70-");
    output.add("\u00A70--\u00A74##\u00A7c###\u00A74##\u00A70--   " + Colors.Blue + translator.of("res_list") + ": " + Colors.LightBlue + townyUniverse.getNumResidents() + Colors.Gray + " | " + Colors.Blue + translator.of("town_plu") + ": " + Colors.LightBlue + townyUniverse.getTowns().size() + Colors.Gray + " | " + Colors.Blue + translator.of("nation_plu") + ": " + Colors.LightBlue + townyUniverse.getNumNations());
    output.add("\u00A70----\u00A74#\u00A7c#\u00A74#\u00A70----   " + Colors.Blue + translator.of("world_plu") + ": " + Colors.LightBlue + townyUniverse.getTownyWorlds().size() + Colors.Gray + " | " + Colors.Blue + translator.of("townblock_plu") + ": " + Colors.LightBlue + townyUniverse.getTownBlocks().size());
    output.add("\u00A70-----\u00A74#\u00A70-----   " + Colors.LightGreen + "https://TownyAdvanced.github.io/");
    // Intentionally left blank
    output.add("");
    // Other TownyAdvanced plugins to report versions
    int plugins = 0;
    String townyPlugins = Colors.Gold + "[";
    // LlmDl Sponsor exclusive
    Plugin tCamps = Bukkit.getServer().getPluginManager().getPlugin("TownyCamps");
    if (tCamps != null) {
        townyPlugins += Colors.Yellow + "TownyCamps " + Colors.Green + tCamps.getDescription().getVersion() + " ";
        plugins++;
    }
    Plugin townyChat = Bukkit.getServer().getPluginManager().getPlugin("TownyChat");
    if (townyChat != null) {
        townyPlugins += Colors.Yellow + "TownyChat " + Colors.Green + townyChat.getDescription().getVersion() + " ";
        plugins++;
    }
    Plugin tCult = Bukkit.getServer().getPluginManager().getPlugin("TownyCultures");
    if (tCult != null) {
        townyPlugins += Colors.Yellow + "TownyCultures " + Colors.Green + tCult.getDescription().getVersion() + " ";
        plugins++;
    }
    Plugin tFlight = Bukkit.getServer().getPluginManager().getPlugin("TownyFlight");
    if (tFlight != null) {
        townyPlugins += Colors.Yellow + "TownyFlight " + Colors.Green + tFlight.getDescription().getVersion() + " ";
        plugins++;
    }
    // LlmDl Sponsor exclusive
    Plugin tHist = Bukkit.getServer().getPluginManager().getPlugin("TownyHistories");
    if (tHist != null) {
        townyPlugins += Colors.Yellow + "TownyHistories " + Colors.Green + tHist.getDescription().getVersion() + " ";
        plugins++;
    }
    Plugin flagWar = Bukkit.getServer().getPluginManager().getPlugin("FlagWar");
    if (flagWar != null) {
        townyPlugins += Colors.Yellow + "FlagWar " + Colors.Green + flagWar.getDescription().getVersion() + " ";
        plugins++;
    }
    Plugin siegeWar = Bukkit.getServer().getPluginManager().getPlugin("SiegeWar");
    if (siegeWar != null) {
        townyPlugins += Colors.Yellow + "SiegeWar " + Colors.Green + siegeWar.getDescription().getVersion() + " ";
        plugins++;
    }
    if (plugins > 0)
        output.add(townyPlugins + Colors.Gold + "]");
    return output;
}
Also used : Translator(com.palmergames.bukkit.towny.object.Translator) ArrayList(java.util.ArrayList) TownyUniverse(com.palmergames.bukkit.towny.TownyUniverse) Plugin(org.bukkit.plugin.Plugin)

Example 10 with Translator

use of com.palmergames.bukkit.towny.object.Translator in project Towny by TownyAdvanced.

the class JailUtil method sendJailedBookToResident.

/**
 * A wonderful little handbook to help out the sorry jailed person.
 *
 * @param player Player who will receive a book.
 * @param reason JailReason the player is in jail for.
 */
private static void sendJailedBookToResident(Player player, JailReason reason) {
    final Translator translator = Translator.locale(Translation.getLocale(player));
    /*
		 * A nice little book for the not so nice person in jail.
		 */
    String pages = translator.of("msg_jailed_handbook_1", translator.of(reason.getCause()));
    pages += translator.of("msg_jailed_handbook_2") + "\n\n";
    pages += translator.of("msg_jailed_handbook_3", reason.getHours()) + "\n\n";
    pages += TownySettings.JailDeniesTownLeave() ? translator.of("msg_jailed_handbook_4_cant") : translator.of("msg_jailed_handbook_4_can") + "\n";
    if (TownySettings.isAllowingBail() && TownyEconomyHandler.isActive()) {
        pages += translator.of("msg_jailed_handbook_bail_1");
        double cost = TownySettings.getBailAmount();
        Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
        if (resident.isMayor())
            cost = TownySettings.getBailAmountMayor();
        if (resident.isKing())
            cost = TownySettings.getBailAmountKing();
        pages += translator.of("msg_jailed_handbook_bail_2", TownyEconomyHandler.getFormattedBalance(cost)) + "\n\n";
    }
    pages += translator.of("msg_jailed_handbook_5");
    pages += translator.of("msg_jailed_handbook_6");
    if (TownySettings.JailAllowsTeleportItems())
        pages += translator.of("msg_jailed_teleport");
    pages += "\n\n";
    if (reason.equals(JailReason.PRISONER_OF_WAR))
        pages += translator.of("msg_jailed_war_prisoner");
    /*
		 * Send the book off to the BookFactory to be made.
		 */
    player.getInventory().addItem(new ItemStack(BookFactory.makeBook(translator.of("msg_jailed_title"), translator.of("msg_jailed_author"), pages)));
}
Also used : Translator(com.palmergames.bukkit.towny.object.Translator) Resident(com.palmergames.bukkit.towny.object.Resident) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

Translator (com.palmergames.bukkit.towny.object.Translator)21 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)12 Nation (com.palmergames.bukkit.towny.object.Nation)9 Siege (com.gmail.goosius.siegewar.objects.Siege)6 Resident (com.palmergames.bukkit.towny.object.Resident)6 Town (com.palmergames.bukkit.towny.object.Town)6 Coord (com.palmergames.bukkit.towny.object.Coord)5 PreSiegeCampEvent (com.gmail.goosius.siegewar.events.PreSiegeCampEvent)4 SiegeCamp (com.gmail.goosius.siegewar.objects.SiegeCamp)4 ArrayList (java.util.ArrayList)4 EventHandler (org.bukkit.event.EventHandler)3 TextComponent (com.palmergames.adventure.text.TextComponent)2 TownyUniverse (com.palmergames.bukkit.towny.TownyUniverse)2 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 Scoreboard (org.bukkit.scoreboard.Scoreboard)2 SiegeStatus (com.gmail.goosius.siegewar.enums.SiegeStatus)1 TownBlock (com.palmergames.bukkit.towny.object.TownBlock)1 TownBlockType (com.palmergames.bukkit.towny.object.TownBlockType)1 DecimalFormat (java.text.DecimalFormat)1 Material (org.bukkit.Material)1