Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public class TownyLayerManager implements LayerManager {

// Icon Registry Keys
private final String TOWN_ICON = "towny_town_icon";
private final String NATION_ICON = "towny_nation_icon";
private final String CAPITAL_ICON = "towny_capital_icon";
private final String RUINED_ICON = "towny_ruined_icon";
private final String OUTPOST_ICON = "towny_outpost_icon";

private final String TOWN_KEY_PREFIX = "town_";
Expand Down Expand Up @@ -182,10 +184,18 @@ private void loadIcons(MapPlatform platform) {
if (townIcon != null)
platform.registerIcon(TOWN_ICON, townIcon, iconHeight, iconWidth);

BufferedImage nationIcon = plugin.config().loadNationIcon(plugin.getLogger());
if (nationIcon != null)
platform.registerIcon(NATION_ICON, nationIcon, iconHeight, iconWidth);

BufferedImage capitalIcon = plugin.config().loadCapitalIcon(plugin.getLogger());
if (capitalIcon != null)
platform.registerIcon(CAPITAL_ICON, capitalIcon, iconHeight, iconWidth);

BufferedImage ruinedIcon = plugin.config().loadRuinedIcon(plugin.getLogger());
if (ruinedIcon != null)
platform.registerIcon(RUINED_ICON, ruinedIcon, iconHeight, iconWidth);

BufferedImage outpostIcon = plugin.config().loadOutpostIcon(plugin.getLogger());
if (outpostIcon != null) {
platform.registerIcon(OUTPOST_ICON, outpostIcon, iconHeight, iconWidth);
Expand Down Expand Up @@ -318,7 +328,17 @@ public void renderTown(TownRenderEntry tre) {
}
}

final String homeBlockIconKey = tre.isCapital() ? CAPITAL_ICON : TOWN_ICON;
String homeBlockIconKey = TOWN_ICON;
if (tre.hasNation()) {
if (tre.isCapital()) {
homeBlockIconKey = CAPITAL_ICON;
} else {
homeBlockIconKey = NATION_ICON;
}
}
if (tre.isRuined()) {
homeBlockIconKey = RUINED_ICON;
}

// Call event
WorldRenderTownEvent event = new WorldRenderTownEvent(worldName, tre.getTownName(), tre.getTownUUID(),
Expand Down Expand Up @@ -512,9 +532,15 @@ public void close() {
if (mapPlatform.hasIcon(TOWN_ICON))
mapPlatform.unregisterIcon(TOWN_ICON);

if (mapPlatform.hasIcon(NATION_ICON))
mapPlatform.unregisterIcon(NATION_ICON);

if (mapPlatform.hasIcon(CAPITAL_ICON))
mapPlatform.unregisterIcon(CAPITAL_ICON);

if (mapPlatform.hasIcon(RUINED_ICON))
mapPlatform.unregisterIcon(RUINED_ICON);

if (mapPlatform.hasIcon(OUTPOST_ICON))
mapPlatform.unregisterIcon(OUTPOST_ICON);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,21 @@ private class IconInfo {
@Node("town-icon")
private String townIconImage = "https://pics.freeicons.io/uploads/icons/png/20952957581537355851-512.png";

@Comment({"Icon for a town if they are in a nation. Icon must be a valid image URL.",
"Put 'default' to use the town icon image."})
@Node("nation-icon")
private String nationIconImage = "default";

@Comment({"Icon for a town if they are the capital of the nation. Icon must be a valid image URL.",
"Put 'default' to use the town icon image."})
@Node("capital-icon")
private String capitalIconImage = "default";

@Comment({"Icon for a ruined town. Icon must be a valid image URL.",
"Put 'default' to use the town icon image."})
@Node("ruined-icon")
private String ruinedIconImage = "default";

@Comment({"Icon for an outpost claim that will appear at the location of outpost spawns. Icon must be a valid image URL.",
"Put 'default' to use the town icon image.",
"Put 'empty' to not place icons at outposts."})
Expand Down Expand Up @@ -222,6 +232,16 @@ public BufferedImage loadTownIcon(Logger errorLogger) {
return loadIcon("town", iconInfo.townIconImage, errorLogger);
}

@Nullable
public BufferedImage loadNationIcon(Logger errorLogger) {
String url = iconInfo.nationIconImage;

if (url.equalsIgnoreCase("default"))
url = iconInfo.townIconImage;

return loadIcon("nation", url, errorLogger);
}

@Nullable
public BufferedImage loadCapitalIcon(Logger errorLogger) {
String url = iconInfo.capitalIconImage;
Expand All @@ -232,6 +252,16 @@ public BufferedImage loadCapitalIcon(Logger errorLogger) {
return loadIcon("capital", url, errorLogger);
}

@Nullable
public BufferedImage loadRuinedIcon(Logger errorLogger) {
String url = iconInfo.ruinedIconImage;

if (url.equalsIgnoreCase("default"))
url = iconInfo.townIconImage;

return loadIcon("ruined", url, errorLogger);
}

@Nullable
public BufferedImage loadOutpostIcon(Logger errorLogger) {
String url = iconInfo.outpostIconImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class TownRenderEntry {

private final UUID townUUID;
private final String townName;
private final boolean nation;
private final boolean capital;
private final boolean ruined;

private final Color nationColor;
private final Color townColor;
Expand All @@ -66,7 +68,9 @@ public TownRenderEntry(Town town, boolean findOutposts,
String clickText, String hoverText) {
this.townUUID = town.getUUID();
this.townName = town.getName();
this.nation = town.hasNation();
this.capital = town.isCapital();
this.ruined = town.isRuined();

this.clickText = clickText;
this.hoverText = hoverText;
Expand All @@ -92,10 +96,18 @@ public String getTownName() {
return townName;
}

public boolean hasNation() {
return nation;
}

public boolean isCapital() {
return capital;
}

public boolean isRuined() {
return ruined;
}

@NotNull
public Optional<Color> getNationColor() {
return Optional.ofNullable(nationColor);
Expand Down