Skip to content

Commit

Permalink
Add siege status to sieges on dynmap. (#25)
Browse files Browse the repository at this point in the history
* Add siege status to sieges on dynmap.

* Add dynmap siege translations

* Switch to translations, remove null check

* Switch to using new functions

* Remove unneeded setSiegeName
  • Loading branch information
Warriorrrr authored Jan 14, 2021
1 parent bcb56f2 commit 723072c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public static boolean saveSieges() {

public static void saveSiege(Siege siege) {
Town town = siege.getDefendingTown();
SiegeMetaDataController.setSiegeName(town, siege.getName());
SiegeMetaDataController.setNationUUID(town, siege.getAttackingNation().getUUID().toString());
SiegeMetaDataController.setTownUUID(town, siege.getDefendingTown().getUUID().toString());
SiegeMetaDataController.setFlagLocation(town, siege.getFlagLocation().getWorld().getName()
Expand Down
44 changes: 20 additions & 24 deletions src/main/java/com/gmail/goosius/siegewar/tasks/DynmapTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@

import com.gmail.goosius.siegewar.SiegeController;
import com.gmail.goosius.siegewar.SiegeWar;
import com.gmail.goosius.siegewar.enums.SiegeStatus;
import com.gmail.goosius.siegewar.objects.Siege;
import com.gmail.goosius.siegewar.settings.SiegeWarSettings;
import com.gmail.goosius.siegewar.settings.Translation;
import com.gmail.goosius.siegewar.utils.SiegeWarDynmapUtil;
import com.palmergames.bukkit.towny.TownyEconomyHandler;
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.util.StringMgmt;
import com.palmergames.util.TimeMgmt;

public class DynmapTask {

Expand Down Expand Up @@ -69,38 +68,35 @@ public static void endDynmapTask() {
}

private static void displaySieges() {
markerMap.clear();
for (Siege siege : SiegeController.getSieges()) {
String name = "Siege: " + siege.getName().replace("#", " ");
String name = Translation.of("dynmap_siege_title", siege.getName().replace("#", " "));
try {
if (siege.getStatus() == SiegeStatus.IN_PROGRESS) {
if (siege.getStatus().isActive()) {
MarkerIcon siegeIcon = markerapi.getMarkerIcon("fire");
List<String> lines = new ArrayList<>();
lines.add("Attacker: " + siege.getAttackingNation().getName());
lines.add("Defender: " + siege.getDefendingTown().getName());
lines.add("Points: " + siege.getSiegePoints());
lines.add("Banner Control: " + siege.getBannerControllingSide());
lines.add("Time left: " + TimeMgmt.getFormattedTimeValue(siege.getTimeUntilCompletionMillis()));
lines.add(Translation.of("dynmap_siege_attacker", siege.getAttackingNation().getName()));
lines.add(Translation.of("dynmap_siege_defender", siege.getDefendingTown().getName()));
lines.add(Translation.of("dynmap_siege_points", siege.getSiegePoints()));
lines.add(Translation.of("dynmap_siege_banner_control", siege.getBannerControllingSide().name().charAt(0) + siege.getBannerControllingSide().name().substring(1).toLowerCase()));
lines.add(Translation.of("dynmap_siege_status", siege.getStatus().getName()));
lines.add(Translation.of("dynmap_siege_time_left", siege.getTimeRemaining()));

if (TownySettings.isUsingEconomy() && TownyEconomyHandler.isActive())
lines.add("War Chest: " + TownyEconomyHandler.getFormattedBalance(siege.getWarChestAmount()));
lines.add(Translation.of("dynmap_siege_war_chest", TownyEconomyHandler.getFormattedBalance(siege.getWarChestAmount())));
String desc = "<b>" + name + "</b><hr>" + StringMgmt.join(lines, "<br>");
Location siegeLoc = siege.getFlagLocation();
double siegeX = siegeLoc.getX();
double siegeZ = siegeLoc.getZ();
String siegeMarkerId = siege.getName();
Marker siegeMarker = markerMap.get(siegeMarkerId);
if (siegeMarker == null) {
siegeMarker = set.createMarker(siegeMarkerId, name, siegeLoc.getWorld().getName(), siegeX, 64,
siegeZ, siegeIcon, false);
} else {
siegeMarker.setLocation(siegeLoc.getWorld().getName(), siegeX, 64, siegeZ);
siegeMarker.setLabel(name);
siegeMarker.setDescription(desc);
siegeMarker.setMarkerIcon(siegeIcon);
}

if (siegeMarker != null)
markerMap.put(siegeMarkerId, siegeMarker);

set.createMarker(siegeMarkerId, name, siegeLoc.getWorld().getName(), siegeX, 64,
siegeZ, siegeIcon, false);

Marker siegeMarker = set.findMarker(siegeMarkerId);
siegeMarker.setLabel(name);
siegeMarker.setDescription(desc);

markerMap.put(siegeMarkerId, siegeMarker);
}
} catch (Exception ex) {
System.err.println(SiegeWar.prefix + "Problem adding siege marker for siege: " + name);
Expand Down
14 changes: 13 additions & 1 deletion src/main/resources/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,16 @@ siege_status_attacker_abandon: 'Attacker Abandon'
siege_status_defender_surrender: 'Defender Surrender'
siege_status_pending_attacker_abandon: 'Pending Attacker Abandon'
siege_status_pending_defender_surrender: 'Pending Defender Surrender'
siege_status_unknown: 'Unknown'
siege_status_unknown: 'Unknown'

dynmap_siege_title: 'Siege: %s'
dynmap_siege_attacker: 'Attacker: %s'
dynmap_siege_defender: 'Defender: %s'
dynmap_siege_points: 'Points: %d'
dynmap_siege_banner_control: 'Banner Control: %s'
dynmap_siege_status: 'Status: %s'
dynmap_siege_status_in_progress: 'In Progress'
dynmap_siege_status_pending_surrender: 'Pending Surrender'
dynmap_siege_status_pending_abandon: 'Pending Abandon'
dynmap_siege_time_left: 'Time Left: %s'
dynmap_siege_war_chest: 'War Chest: %s'

0 comments on commit 723072c

Please sign in to comment.