Skip to content

Commit

Permalink
Add Districts to TownBlocks and Towns. (#7480)
Browse files Browse the repository at this point in the history
* Backend object, database stuff.

TODO: front end command stuff.

* Switch to saving/loading the town from/to a UUID, because that would be
more sane.

* Reduce diff and delete unloadable district when it should.

* Add /plot district command.

TODO: Make adjacent townblocks rules apply for adding and removing to/from the district

* Fix yaml linter.

* Fix up commands a bit, add proximity tests to add/remove.

* Add PlayerExitsFromDistrictEvent and PlayerEntersIntoDistrictEvent

* Lang file

* Add District to ChunkNotification

* Handle permissions in plugin.yml, make the command limited to players
who are also mayors or equivalent.

* Make new Proximity methods that will actually work... Block unclaiming
which would mangle Districts.

* Add equals method, do a bit of cleanup, add a missed proximity test.

* Update colours used in lang strings.

* Fixes found during testing.

* Display districs on the townblock status screen as well as in the ascii
map hovers.

* Fix YAML linter complaint.

* Make the perm hud aware of Districts.
  • Loading branch information
LlmDl authored Jul 12, 2024
1 parent d8ce7b3 commit 0fbfb8f
Show file tree
Hide file tree
Showing 29 changed files with 1,313 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,7 @@ public enum ConfigNodes {
NOTIFICATION_PLOT_NOTFORSALE("notification.plot.notforsale", "&e[Not For Sale]"),
NOTIFICATION_PLOT_TYPE("notification.plot.type", "&6[%s]"),
NOTIFICATION_GROUP("notification.group", "&f[%s]"),
NOTIFICATION_DISTRICT("notification.district", "&2[%s]"),
NOTIFICATION_TOWN_NAMES_ARE_VERBOSE(
"notification.town_names_are_verbose",
"true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.palmergames.bukkit.towny.object.TownBlockType;
import com.palmergames.bukkit.towny.object.TownyWorld;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.object.District;
import com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus;
import com.palmergames.bukkit.towny.utils.CombatUtil;
import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
Expand Down Expand Up @@ -41,6 +42,7 @@ public class ChunkNotification {
public static String notForSaleNotificationFormat = Colors.Yellow + "[Not For Sale]";
public static String plotTypeNotificationFormat = Colors.Gold + "[%s]";
public static String groupNotificationFormat = Colors.White + "[%s]";
public static String districtNotificationFormat = Colors.DARK_GREEN + "[%s]";

/**
* Called on Config load.
Expand All @@ -64,16 +66,18 @@ public static void loadFormatStrings() {
notForSaleNotificationFormat = Colors.translateColorCodes(TownySettings.getString(ConfigNodes.NOTIFICATION_PLOT_NOTFORSALE));
plotTypeNotificationFormat = Colors.translateColorCodes(TownySettings.getString(ConfigNodes.NOTIFICATION_PLOT_TYPE));
groupNotificationFormat = Colors.translateColorCodes(TownySettings.getString(ConfigNodes.NOTIFICATION_GROUP));
districtNotificationFormat = Colors.translateColorCodes(TownySettings.getString(ConfigNodes.NOTIFICATION_DISTRICT));
}

WorldCoord from, to;
boolean fromWild = false, toWild = false, toForSale = false, fromForSale = false,
toHomeBlock = false, toOutpostBlock = false, toPlotGroupBlock = false;
toHomeBlock = false, toOutpostBlock = false, toPlotGroupBlock = false, toDistrictBlock = false;
TownBlock fromTownBlock, toTownBlock = null;
Town fromTown = null, toTown = null;
Resident fromResident = null, toResident = null;
TownBlockType fromPlotType = null, toPlotType = null;
PlotGroup fromPlotGroup = null, toPlotGroup = null;
District fromDistrict = null, toDistrict = null;

public ChunkNotification(WorldCoord from, WorldCoord to) {

Expand All @@ -88,6 +92,9 @@ public ChunkNotification(WorldCoord from, WorldCoord to) {
fromPlotGroup = fromTownBlock.getPlotObjectGroup();
fromForSale = fromPlotGroup.getPrice() != -1;
}
if (fromTownBlock.hasDistrict()) {
fromDistrict = fromTownBlock.getDistrict();
}
fromTown = fromTownBlock.getTownOrNull();
fromResident = fromTownBlock.getResidentOrNull();

Expand All @@ -109,7 +116,10 @@ public ChunkNotification(WorldCoord from, WorldCoord to) {
toPlotGroup = toTownBlock.getPlotObjectGroup();
toForSale = toPlotGroup.getPrice() != -1;
}

toDistrictBlock = toTownBlock.hasDistrict();
if (toDistrictBlock) {
toDistrict = toTownBlock.getDistrict();
}
} else {
toWild = true;
}
Expand Down Expand Up @@ -277,6 +287,10 @@ public List<String> getPlotNotificationContent() {
if (output != null && output.length() > 0)
out.add(output);

output = getDistrictNotification();
if (output != null && output.length() > 0)
out.add(output);

return out;
}

Expand Down Expand Up @@ -323,6 +337,12 @@ public String getGroupNotification() {
return null;
}

public String getDistrictNotification() {
if (toDistrictBlock && (fromDistrict != toDistrict))
return String.format(districtNotificationFormat, StringMgmt.remUnderscore(toDistrict.getName()));
return null;
}

public String getPlotTypeNotification() {

if (toPlotType != null && !toPlotType.equals(fromPlotType) && !TownBlockType.RESIDENTIAL.equals(toPlotType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ else if (townblock.isOutpost())
Component forSaleComponent = Component.empty();
Component claimedAtComponent = Component.empty();
Component groupComponent = Component.empty();
Component districtComponent = Component.empty();

if (TownyEconomyHandler.isActive()) {
double cost = townblock.hasPlotObjectGroup()
Expand All @@ -192,6 +193,13 @@ else if (townblock.isOutpost())
.append(translator.component("map_hover_plots", townblock.getPlotObjectGroup().getTownBlocks().size()).color(NamedTextColor.GREEN)
.append(Component.newline()))));

if (townblock.hasDistrict())
districtComponent = translator.component("map_hover_district").color(NamedTextColor.DARK_GREEN)
.append(Component.text(townblock.getDistrict().getFormattedName(), NamedTextColor.GREEN)
.append(translator.component("map_hover_plot_group_size").color(NamedTextColor.DARK_GREEN)
.append(translator.component("map_hover_plots", townblock.getDistrict().getTownBlocks().size()).color(NamedTextColor.GREEN)
.append(Component.newline()))));

if (townblock.hasResident())
residentComponent = Component.text(" (" + townblock.getResidentOrNull().getName() + ")", NamedTextColor.GREEN);

Expand All @@ -209,6 +217,7 @@ else if (townblock.isOutpost())

Component hoverComponent = townComponent
.append(plotTypeComponent)
.append(districtComponent)
.append(groupComponent)
.append(forSaleComponent)
.append(claimedAtComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public static StatusScreen getStatus(TownBlock townBlock, Player player) {
screen.addComponentOf("firespread", colourKeyValue(translator.of("firespread"), ((world.isForceFire() || townBlock.getPermissions().fire) ? translator.of("status_on"):translator.of("status_off"))));
screen.addComponentOf("mobspawns", colourKeyValue(translator.of("mobspawns"), ((world.isForceTownMobs() || townBlock.getPermissions().mobs || town.isAdminEnabledMobs()) ? translator.of("status_on"): translator.of("status_off"))));

if (townBlock.hasDistrict())
screen.addComponentOf("district", colourKey(translator.of("status_district_name_and_size", townBlock.getDistrict().getName(), townBlock.getDistrict().getTownBlocks().size())));

if (townBlock.hasPlotObjectGroup())
screen.addComponentOf("plotgroup", colourKey(translator.of("status_plot_group_name_and_size", townBlock.getPlotObjectGroup().getName(), townBlock.getPlotObjectGroup().getTownBlocks().size())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.palmergames.bukkit.towny.exceptions.KeyAlreadyRegisteredException;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.exceptions.initialization.TownyInitException;
import com.palmergames.bukkit.towny.object.District;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.PlotGroup;
import com.palmergames.bukkit.towny.object.Position;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class TownyUniverse {
private final Map<UUID, Jail> jailUUIDMap = new ConcurrentHashMap<>();
private final Map<String, String> replacementNamesMap = new ConcurrentHashMap<>();
private final Map<UUID, PlotGroup> plotGroupUUIDMap = new ConcurrentHashMap<>();
private final Map<UUID, District> districtUUIDMap = new ConcurrentHashMap<>();

private final Map<WorldCoord, TownyMapData> wildernessMapDataMap = new ConcurrentHashMap<WorldCoord, TownyMapData>();
private final String rootFolder;
Expand Down Expand Up @@ -905,6 +907,57 @@ public PlotGroup getGroup(UUID groupID) {
return plotGroupUUIDMap.get(groupID);
}

/*
* District Stuff.
*/

/**
* Used in loading only.
* @param uuid UUID to assign to the District.
*/
public void newDistrictInternal(UUID uuid) {
District district = new District(uuid, null, null);
registerDistrict(district);
}


public void registerDistrict(District district) {
districtUUIDMap.put(district.getUUID(), district);
}

public void unregisterDistrict(UUID uuid) {
District district = districtUUIDMap.get(uuid);
if (district == null)
return;
district.getTown().removeDistrict(district);
districtUUIDMap.remove(uuid);
}

/**
* Get all the districts from all towns
* Returns a collection that does not reflect any district additions/removals
*
* @return collection of District
*/
public Collection<District> getDistricts() {
return new ArrayList<>(districtUUIDMap.values());
}

public Set<UUID> getDistrictUUIDs() {
return districtUUIDMap.keySet();
}

/**
* Gets the district from the town name and the district UUID
*
* @param districtID UUID of the district
* @return District if found, null if none found.
*/
@Nullable
public District getDistrict(UUID districtID) {
return districtUUIDMap.get(districtID);
}

/*
* Metadata Stuff
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ protected MenuBuilder load() {
.add(Translatable.of("msg_nfs_abr"));
}
},

PLOT_DISTRICT_HELP {
@Override
protected MenuBuilder load() {
return new MenuBuilder("plot district")
.add("add|new|create [name]", Translatable.of("plot_district_help_0"))
.add("remove", Translatable.of("plot_district_help_1"))
.add("delete", Translatable.of("plot_district_help_2"))
.add("rename [newName]", Translatable.of("plot_district_help_3"));
}
},

PLOT_GROUP_HELP {
@Override
Expand Down
Loading

0 comments on commit 0fbfb8f

Please sign in to comment.