Skip to content

Commit

Permalink
Move outpost details from permhud to maphud.
Browse files Browse the repository at this point in the history
  • Loading branch information
LlmDl committed Nov 6, 2024
1 parent 91c31a8 commit 47251b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MapHUD {
private static final String TEAM_TOWN = "townTeam";
private static final String TEAM_OWNER = "ownerTeam";
private static final String TEAM_DISTRICT = "districtTeam";
private static final String TEAM_OUTPOST_NAME = "outpostName";
private static final String TEAM_PLOTNAME = "plotnameTeam";

private static final int mapLineWidth = 19, mapLineHeight = 10;
Expand All @@ -56,7 +57,7 @@ public static void toggleOn(Player player) {
objective.setDisplaySlot(DisplaySlot.SIDEBAR);

// We have a number of lines below the map, this is how many.
int nonMapLines = Math.max(4, MAX_NON_MAP_LINES);
int nonMapLines = Math.max(5, MAX_NON_MAP_LINES);
int score = mapLineHeight + nonMapLines;
ChatColor[] colors = ChatColor.values();
for (int i = 0; i < mapLineHeight; i++) {
Expand All @@ -70,6 +71,7 @@ public static void toggleOn(Player player) {
String ownerEntry = WHITE.toString();
String districtEntry = GOLD.toString();
String plotnameEntry = DARK_GREEN.toString();
String outpostEntry = GREEN.toString();

score = nonMapLines;
board.registerNewTeam(TEAM_TOWN).addEntry(townEntry);
Expand All @@ -81,6 +83,9 @@ public static void toggleOn(Player player) {
board.registerNewTeam(TEAM_DISTRICT).addEntry(districtEntry);
objective.getScore(districtEntry).setScore(score--);

board.registerNewTeam(TEAM_OUTPOST_NAME).addEntry(outpostEntry);
objective.getScore(outpostEntry).setScore(score--);

board.registerNewTeam(TEAM_PLOTNAME).addEntry(plotnameEntry);
objective.getScore(plotnameEntry).setScore(score--);

Expand Down Expand Up @@ -119,6 +124,7 @@ public static void updateMap(Player player, WorldCoord wc) {
board.getTeam(TEAM_TOWN).setSuffix(GREEN + (tb != null && tb.hasTown() ? tb.getTownOrNull().getName() : Translatable.of("status_no_town").forLocale(player)));
board.getTeam(TEAM_OWNER).setSuffix(getOwnerName(tb, player));
board.getTeam(TEAM_DISTRICT).setSuffix(getDistrictName(tb, player));
board.getTeam(TEAM_OUTPOST_NAME).setSuffix(getOutpostName(tb, player));
board.getTeam(TEAM_PLOTNAME).setSuffix(getPlotName(tb, player));
}

Expand All @@ -140,6 +146,15 @@ private static String getDistrictName(TownBlock tb, Player player) {
return HUDManager.check(DARK_GREEN + prefix + GREEN + name);
}

private static String getOutpostName(TownBlock tb, Player player) {
String name = "";
if (tb == null)
return name;
name = !tb.hasOutpostObject() ? "" : tb.getOutpost().getFormattedName();
String prefix = Translatable.of("msg_map_hud_outpost").forLocale(player);
return HUDManager.check(DARK_GREEN + prefix + GREEN + name);
}

private static String getPlotName(TownBlock tb, Player player) {
String name = "";
if (tb == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public class PermHUD {
/* Scoreboards use Teams here is our team names.*/
private static final String HUD_OBJECTIVE = "PERM_HUD_OBJ";
private static final String TEAM_PERMS_TITLE = "permsTitle";
private static final String TEAM_OUTPOST_NAME = "outpostName";
private static final String TEAM_PLOT_COST = "plot_cost";
private static final String TEAM_BUILD = "build";
private static final String TEAM_DESTROY = "destroy";
Expand All @@ -64,7 +63,7 @@ public static String permHudTestKey() {

public static void updatePerms(Player p, WorldCoord worldCoord) {
Translator translator = Translator.locale(p);
String outpostName, build, destroy, switching, item, type, pvp, explosions, firespread, mobspawn, title;
String build, destroy, switching, item, type, pvp, explosions, firespread, mobspawn, title;
Scoreboard board = p.getScoreboard();
// Due to tick delay (probably not confirmed), a HUD can actually be removed from the player.
// Causing board to return null, and since we don't create a new board, a NullPointerException occurs.
Expand Down Expand Up @@ -92,9 +91,6 @@ public static void updatePerms(Player p, WorldCoord worldCoord) {
// Displays the name of the owner, and if the owner is a resident the town name as well.
title = GOLD + owner.getName() + (townBlock.hasResident() ? " (" + townBlock.getTownOrNull().getName() + ")" : "");

// Outpost name
outpostName = townBlock.hasOutpostObject() ? DARK_GREEN + "Outpost: " + townBlock.getOutpost().getFormattedName() : "";

// Plot Type
type = townBlock.getType().equals(TownBlockType.RESIDENTIAL) ? " " : townBlock.getType().getName();

Expand All @@ -117,7 +113,6 @@ public static void updatePerms(Player p, WorldCoord worldCoord) {

// Set the values to our Scoreboard's teams.
board.getObjective(HUD_OBJECTIVE).setDisplayName(HUDManager.check(title));
board.getTeam(TEAM_OUTPOST_NAME).setSuffix(outpostName);
board.getTeam(TEAM_PLOT_TYPE).setSuffix(type);
board.getTeam(TEAM_PLOT_COST).setSuffix(forSale);

Expand Down Expand Up @@ -161,7 +156,6 @@ private static void clearPerms (Player p) {
Scoreboard board = p.getScoreboard();
try {
board.getObjective(HUD_OBJECTIVE).setDisplayName(HUDManager.check(getFormattedWildernessName(p.getWorld())));
board.getTeam(TEAM_OUTPOST_NAME).setSuffix(" ");
board.getTeam(TEAM_PLOT_TYPE).setSuffix(" ");
board.getTeam(TEAM_PLOT_COST).setSuffix(" ");

Expand Down Expand Up @@ -203,7 +197,6 @@ public static void toggleOn (Player p) {

private static void initializeScoreboard(Translator translator, Scoreboard board) {
String PERM_HUD_TITLE = GOLD + "";
String outpostName_entry = GOLD + "";
String keyPlotType_entry = DARK_GREEN + translator.of("msg_perm_hud_plot_type");
String forSale_entry = DARK_GREEN + translator.of("msg_perm_hud_plot_for_sale") + GRAY;

Expand All @@ -230,7 +223,6 @@ private static void initializeScoreboard(Translator translator, Scoreboard board
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
obj.setDisplayName(PERM_HUD_TITLE);
//register teams
Team outpostName = board.registerNewTeam(TEAM_OUTPOST_NAME);
Team keyPlotType = board.registerNewTeam(TEAM_PLOT_TYPE);
Team forSaleTitle = board.registerNewTeam(TEAM_PLOT_COST);

Expand All @@ -251,7 +243,6 @@ private static void initializeScoreboard(Translator translator, Scoreboard board
Team keyAlly = board.registerNewTeam(TEAM_ALLY);

//add each team as an entry (this sets the prefix to each line of the HUD.)
outpostName.addEntry(outpostName_entry);
keyPlotType.addEntry(keyPlotType_entry);
forSaleTitle.addEntry(forSale_entry);

Expand All @@ -273,7 +264,6 @@ private static void initializeScoreboard(Translator translator, Scoreboard board

int score = HUDManager.MAX_SCOREBOARD_HEIGHT;
//set scores for positioning
obj.getScore(outpostName_entry).setScore(score--);
obj.getScore(keyPlotType_entry).setScore(score--);
obj.getScore(forSale_entry).setScore(score--);
obj.getScore(permsTitle_entry).setScore(score--);
Expand Down

0 comments on commit 47251b7

Please sign in to comment.