use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.
the class SiegeWarStatusScreenListener method onResidentStatusScreen.
/*
* SiegeWar will show a resident if they can collect money due to them,
* via the resident status screen. Components are clickable to
* claim monies owed.
*/
@EventHandler
public void onResidentStatusScreen(ResidentStatusScreenEvent event) {
int salary = ResidentMetaDataController.getMilitarySalaryAmount(event.getResident());
if (salary > 0) {
final Translator translator = Translator.locale(Translation.getLocale(event.getCommandSender()));
event.getStatusScreen().addComponentOf("siegeWarNationSalary", formatKeyValue(translator.of("status_military_salary"), formatMoney(salary)), HoverEvent.showText(Component.text(translator.of("hover_message_click_to_claim"))), ClickEvent.runCommand("/sw collect"));
}
}
use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.
the class SiegeWarHud method updateInfo.
public static void updateInfo(Player p, Siege siege) {
Scoreboard board = p.getScoreboard();
if (board == null) {
toggleOn(p, siege);
return;
}
final Translator translator = Translator.locale(Translation.getLocale(p));
board.getObjective("WAR_HUD_OBJ").setDisplayName(SiegeHUDManager.checkLength(Colors.Gold + "§l" + siege.getTown().getName()) + " " + translator.of("hud_title"));
board.getTeam("siegeType").setSuffix(SiegeHUDManager.checkLength(siege.getSiegeType().getTranslatedName().forLocale(p)));
board.getTeam("attackers").setSuffix(SiegeHUDManager.checkLength(siege.getAttackerNameForDisplay()));
board.getTeam("defenders").setSuffix(SiegeHUDManager.checkLength(siege.getDefenderNameForDisplay()));
board.getTeam("balance").setSuffix(siege.getSiegeBalance().toString());
board.getTeam("timeRemaining").setSuffix(siege.getTimeRemaining());
if (TownyEconomyHandler.isActive()) {
board.getTeam("warchest").setSuffix(TownyEconomyHandler.getFormattedBalance(siege.getWarChestAmount()));
} else {
board.getTeam("warchest").setSuffix("-");
}
board.getTeam("bannerControl").setSuffix(siege.getBannerControllingSide().getFormattedName().forLocale(p) + (siege.getBannerControllingSide() == SiegeSide.NOBODY ? "" : " (" + siege.getBannerControllingResidents().size() + ")"));
board.getTeam("btAttackerPoints").setSuffix(siege.getFormattedAttackerBattlePoints());
board.getTeam("btDefenderPoints").setSuffix(siege.getFormattedDefenderBattlePoints());
board.getTeam("btTimeRemaining").setSuffix(siege.getFormattedBattleTimeRemaining(translator));
boolean displayBreachPoints = SiegeWarSettings.isWallBreachingEnabled() && SiegeWarSettings.getWallBreachBonusBattlePoints() != 0;
if (displayBreachPoints)
board.getTeam("breachPoints").setSuffix(siege.getFormattedBreachPoints());
}
use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.
the class SiegeWarHud method toggleOn.
public static void toggleOn(Player p, Siege siege) {
final Translator translator = Translator.locale(Translation.getLocale(p));
Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
Objective objective = board.registerNewObjective("WAR_HUD_OBJ", "", translator.of("hud_title"));
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
Team siegeType = board.registerNewTeam("siegeType"), attackers = board.registerNewTeam("attackers"), defenders = board.registerNewTeam("defenders"), balance = board.registerNewTeam("balance"), timeRemaining = board.registerNewTeam("timeRemaining"), warchest = board.registerNewTeam("warchest"), bannerControl = board.registerNewTeam("bannerControl"), battleAttackerScore = board.registerNewTeam("btAttackerPoints"), battleDefenderScore = board.registerNewTeam("btDefenderPoints"), battleTimeRemaining = board.registerNewTeam("btTimeRemaining");
String siegeType_entry = Colors.LightGray + translator.of("hud_siege_type"), attackers_entry = Colors.LightGray + translator.of("hud_attackers"), defenders_entry = Colors.LightGray + translator.of("hud_defenders"), balance_entry = Colors.LightGray + translator.of("hud_siege_balance"), timeRemaining_entry = Colors.LightGray + translator.of("hud_time_remaining"), warchest_entry = Colors.LightGray + translator.of("hud_warchest"), bannerControl_entry = Colors.LightGray + translator.of("hud_banner_control"), battleAttackerScore_entry = Colors.LightGray + translator.of("hud_battle_attacker_points"), battleDefenderScore_entry = Colors.LightGray + translator.of("hud_battle_defender_points"), battleTimeRemaining_entry = Colors.LightGray + translator.of("hud_battle_time_remaining");
siegeType.addEntry(siegeType_entry);
attackers.addEntry(attackers_entry);
defenders.addEntry(defenders_entry);
balance.addEntry(balance_entry);
bannerControl.addEntry(bannerControl_entry);
timeRemaining.addEntry(timeRemaining_entry);
warchest.addEntry(warchest_entry);
battleDefenderScore.addEntry(battleDefenderScore_entry);
battleAttackerScore.addEntry(battleAttackerScore_entry);
battleTimeRemaining.addEntry(battleTimeRemaining_entry);
int topScore;
boolean displayBreachPoints = SiegeWarSettings.isWallBreachingEnabled() && SiegeWarSettings.getWallBreachBonusBattlePoints() != 0;
if (displayBreachPoints)
topScore = 11;
else
topScore = 10;
objective.getScore(siegeType_entry).setScore(topScore--);
objective.getScore(attackers_entry).setScore(topScore--);
objective.getScore(defenders_entry).setScore(topScore--);
objective.getScore(balance_entry).setScore(topScore--);
objective.getScore(timeRemaining_entry).setScore(topScore--);
objective.getScore(warchest_entry).setScore(topScore--);
objective.getScore(bannerControl_entry).setScore(topScore--);
objective.getScore(battleAttackerScore_entry).setScore(topScore--);
objective.getScore(battleDefenderScore_entry).setScore(topScore--);
objective.getScore(battleTimeRemaining_entry).setScore(topScore--);
if (displayBreachPoints) {
Team breachPoints = board.registerNewTeam("breachPoints");
String breachPoints_entry = Colors.LightGray + translator.of("hud_breach_points");
breachPoints.addEntry(breachPoints_entry);
objective.getScore(breachPoints_entry).setScore(topScore--);
}
p.setScoreboard(board);
updateInfo(p, siege);
}
use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.
the class DestroyBlock method evaluateSiegeWarDestroyBlockRequest.
/**
* Evaluates a block destroy request.
*
* @param event The event object
* @throws TownyException if something is misconfigured
*/
public static void evaluateSiegeWarDestroyBlockRequest(TownyDestroyEvent event) throws TownyException {
// Ensure siege is enabled in this world
Block block = event.getBlock();
if (!TownyAPI.getInstance().getTownyWorld(block.getWorld()).isWarAllowed())
return;
final Translator translator = Translator.locale(Translation.getLocale(event.getPlayer()));
// If the event has already been cancelled by Towny...
if (event.isCancelled()) {
if (!SiegeWarSettings.isWallBreachingEnabled())
// Without wall breaching, SW doesn't un-cancel events
return;
Town town = TownyAPI.getInstance().getTown(block.getLocation());
if (town == null)
// SW doesn't un-cancel wilderness events
return;
if (!SiegeController.hasActiveSiege(town))
// SW doesn't un-cancel events in unsieged towns
return;
// Ensure player has permission
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(event.getPlayer(), SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_USE_BREACH_POINTS.getNode())) {
event.setMessage(translator.of("msg_err_action_disable"));
return;
}
// No wall breaching outside battle sessions
if (!BattleSession.getBattleSession().isActive()) {
event.setMessage(translator.of("msg_err_cannot_breach_without_battle_session"));
return;
}
// Ensure player is on the town-hostile siege side
Resident resident = TownyAPI.getInstance().getResident(event.getPlayer());
if (resident == null)
return;
Siege siege = SiegeController.getSiege(town);
if (!SiegeWarAllegianceUtil.isPlayerOnTownHostileSide(event.getPlayer(), resident, siege))
return;
// Ensure there are enough breach points
if (siege.getWallBreachPoints() < SiegeWarSettings.getWallBreachingBlockDestructionCost()) {
event.setMessage(translator.of("msg_err_not_enough_breach_points_for_action", SiegeWarSettings.getWallBreachingBlockDestructionCost(), siege.getFormattedBreachPoints()));
return;
}
// Ensure height is ok
if (!SiegeWarWallBreachUtil.validateBreachHeight(block, town, siege)) {
event.setMessage(translator.of("msg_err_cannot_breach_at_this_height", SiegeWarSettings.getWallBreachingHomeblockBreachHeightLimitMin(), SiegeWarSettings.getWallBreachingHomeblockBreachHeightLimitMax()));
return;
}
// Ensure material is ok
if (!SiegeWarWallBreachUtil.validateDestroyMaterial(block, event.getLocation())) {
event.setMessage(translator.of("msg_err_cannot_destroy_at_this_height", SiegeWarSettings.getWallBreachingHomeblockBreachHeightLimitMin(), SiegeWarSettings.getWallBreachingHomeblockBreachHeightLimitMax()));
return;
}
// IF we get here, it is a wall breach!!
// Reduce breach points
siege.setWallBreachPoints(siege.getWallBreachPoints() - SiegeWarSettings.getWallBreachingBlockDestructionCost());
// Un-cancel the event
event.setCancelled(false);
// Send message to player
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.RED + translator.of("msg_wall_breach_successful")));
return;
}
// Trap warfare block protection
if (SiegeWarSettings.isTrapWarfareMitigationEnabled() && SiegeWarDistanceUtil.isLocationInActiveTimedPointZoneAndBelowSiegeBannerAltitude(event.getBlock().getLocation())) {
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.DARK_RED + translator.of("msg_err_cannot_alter_blocks_below_banner_in_timed_point_zone")));
event.setCancelled(true);
return;
}
// Prevent destruction of siege-banner or support block
if (SiegeWarBlockUtil.isBlockNearAnActiveSiegeBanner(event.getBlock()) || SiegeWarBlockUtil.isBlockNearAnActiveSiegeCampBanner(event.getBlock())) {
event.setMessage(translator.of("msg_err_siege_war_cannot_destroy_siege_banner"));
event.setCancelled(true);
return;
}
}
use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.
the class PeacefullyRevolt method processActionRequest.
/**
* Process a request by a town member to peacefully revolt.
*
* @param player the player
* @param targetTown the revolting peaceful town, where we already know the player is a resident
* @throws TownyException if the revolt request fails.
*/
public static void processActionRequest(Player player, Town targetTown) throws TownyException {
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!SiegeWarSettings.isPeacefulTownsRevoltEnabled())
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.SIEGEWAR_TOWN_REVOLT_PEACEFULLY.getNode()))
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownOccupationController.isTownOccupied(targetTown))
throw new TownyException(translator.of("msg_err_cannot_peacefully_revolt_because_unoccupied"));
if (SiegeController.hasActiveSiege(targetTown)) {
throw new TownyException(translator.of("msg_err_cannot_change_occupation_of_besieged_town"));
}
verifyThatOccupierHasZeroTownyInfluence(targetTown);
peacefullyRevolt(targetTown);
}
Aggregations