@@ -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