Skip to content

Commit 2be7bf7

Browse files
committed
Improved Waypoints
1 parent 3b0feb9 commit 2be7bf7

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can adjust your own maximum zoom (I recommend 6000) using the command ```/sm
2222
### World Border Limit
2323
Limit the SeedMap and Minimap to a server's world border size so the map only shows that area (centered at 0,0).
2424

25-
Set it with ```/sm:config WorldBorder 8000``` to show a border from -8000 to +8000 on both axes. Use 0 to disable.
25+
Set it with ```/sm:config WorldBorder set 8000``` to show a border from -8000 to +8000 on both axes. Use 0 to disable.
2626

2727
### Double Click Recenter
2828
Double clicking anywhere on the map will recenter the map to the players location.

src/main/java/dev/xpple/seedmapper/seedmap/SeedMapScreen.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,12 @@ private void importWurstWaypoints() {
951951
Map<String, Waypoint> existing = waypointsApi.getWorldWaypoints(identifier);
952952
Set<String> reservedNames = new HashSet<>(existing.keySet());
953953
Set<String> occupiedCoords = new HashSet<>();
954+
Map<String, String> coordToName = new Object2ObjectOpenHashMap<>();
954955
existing.forEach((existingName, existingWaypoint) -> {
955956
BlockPos pos = existingWaypoint.location();
956-
occupiedCoords.add("%d,%d,%d".formatted(pos.getX(), pos.getY(), pos.getZ()));
957+
String coordKey = "%d,%d,%d".formatted(pos.getX(), pos.getY(), pos.getZ());
958+
occupiedCoords.add(coordKey);
959+
coordToName.putIfAbsent(coordKey, existingName);
957960
});
958961
JsonArray waypoints = root.getAsJsonArray("waypoints");
959962
int added = 0;
@@ -1008,6 +1011,30 @@ private void importWurstWaypoints() {
10081011

10091012
String coordKey = "%d,%d,%d".formatted(x, y, z);
10101013
if (occupiedCoords.contains(coordKey)) {
1014+
String existingNameAtCoord = coordToName.get(coordKey);
1015+
if (existingNameAtCoord == null) {
1016+
skipped++;
1017+
continue;
1018+
}
1019+
String targetName = existingNameAtCoord.equals(name) ? existingNameAtCoord : name;
1020+
if (!existingNameAtCoord.equals(targetName)) {
1021+
if (reservedNames.contains(targetName)) {
1022+
targetName = this.createUniqueWurstName(reservedNames, name);
1023+
}
1024+
boolean renamed = this.tryRenameSimpleWaypoint(identifier, existingNameAtCoord, targetName);
1025+
if (!renamed) {
1026+
skipped++;
1027+
continue;
1028+
}
1029+
reservedNames.remove(existingNameAtCoord);
1030+
reservedNames.add(targetName);
1031+
coordToName.put(coordKey, targetName);
1032+
}
1033+
this.wurstWaypointNames.add(targetName);
1034+
this.wurstWaypointDisplayNames.put(targetName, rawName);
1035+
if (color != null) {
1036+
this.wurstWaypointColors.put(targetName, color);
1037+
}
10111038
skipped++;
10121039
continue;
10131040
}
@@ -1074,6 +1101,20 @@ private boolean addSimpleWaypoint(String identifier, ResourceKey<Level> dimensio
10741101
}
10751102
}
10761103

1104+
private boolean tryRenameSimpleWaypoint(String identifier, String oldName, String newName) {
1105+
if (identifier == null || identifier.isBlank() || oldName == null || newName == null) {
1106+
return false;
1107+
}
1108+
SimpleWaypointsAPI api = SimpleWaypointsAPI.getInstance();
1109+
try {
1110+
api.renameWaypoint(identifier, oldName, newName);
1111+
return true;
1112+
} catch (CommandSyntaxException e) {
1113+
LOGGER.warn("Failed to rename waypoint", e);
1114+
return false;
1115+
}
1116+
}
1117+
10771118
private String createUniqueWurstName(Set<String> reservedNames, String base) {
10781119
String candidate = buildWurstNameWithSuffix(base, "_W");
10791120
if (!reservedNames.contains(candidate)) {

0 commit comments

Comments
 (0)