SchematicsManager: Handling and caching list of known schematics, providing cli suggestions
I implemented a SchematicsManager that handles the listing / caching of known schematic files.
The SchematicsManager has multiple possible backends.
The preferred backend is:
FileWatcherSchematicsBackend:
This backend uses Java's WatchService to listen for changes in the schematics directory. This rids us of any file listing IO.
PollingSchematicsBackend:
This is the fallback backend for the previous mentioned that is only used when the previous failed to initialize (for whatever reason that might be). It caches the result and returns the previous result as long as it's not older than 10 seconds. This is basically an Eventually Consistent Cache.
I then went on to implement a SchematicConverter to parse Schematics from arguments and provide suggestions.
This fixes #2095
This change in action:
(The suggestions for //schematics load ... and //schematics delete ...)
https://user-images.githubusercontent.com/820845/200692406-920a1447-10e2-4685-9d22-23ccc53685d6.mp4
I noticed that the implementation doesn't handle symlinks correctly.
With the setting files.allow-symbolic-links the symlinks will be followed.
Another issue with symlinks: Using recursive symlinks doesn't work fine:
- Create a folder in schematics (e.g.
mkdir dummy) - Create a symlink that points to one directory upwards (e.g.
cd dummy && ln -fs ../ test) With this setup WorldEdit will follow the schematic path:
[12:45:30 INFO]: New Schematic found: /home/user/dev/server/paper/plugins/WorldEdit/schematics/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test/dummy/test
Has this unfortunately been abandoned now? It seemed like a really good idea.
Closing in favour of https://github.com/EngineHub/WorldEdit/pull/2542