-
-
Notifications
You must be signed in to change notification settings - Fork 884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SchematicsManager: Handling and caching list of known schematics, providing cli suggestions #2212
Conversation
worldedit-core/src/main/java/com/sk89q/worldedit/util/schematic/Schematic.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/schematic/Schematic.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/schematic/Schematic.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/schematic/Schematic.java
Outdated
Show resolved
Hide resolved
This change in action: SchematicCompletion.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this PR outside of the noted log points, but I'd also like someone else to have a go over it too :)
.../src/main/java/com/sk89q/worldedit/util/schematic/backends/FileWatcherSchematicsBackend.java
Outdated
Show resolved
Hide resolved
...core/src/main/java/com/sk89q/worldedit/util/schematic/backends/PollingSchematicsBackend.java
Outdated
Show resolved
Hide resolved
I noticed that the implementation doesn't handle symlinks correctly. Another issue with symlinks: Using recursive symlinks doesn't work fine:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this a lot, but there are some edgecases to handle and cleanup to do.
Can we also move the com.sk89q.worldedit.util.schematic
stuff to com.sk89q.worldedit.internal.schematic
? I don't think this should be exposed as API. The RecursiveDirectoryWatcher
should probably also be moved to com.sk89q.worldedit.internal.util
.
worldedit-core/src/main/java/com/sk89q/worldedit/util/schematic/SchematicPath.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/RecursiveDirectoryWatcher.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/RecursiveDirectoryWatcher.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/RecursiveDirectoryWatcher.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/io/file/RecursiveDirectoryWatcher.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/schematic/backends/SchematicsBackend.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/schematic/backends/SchematicsBackend.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/main/java/com/sk89q/worldedit/util/schematic/backends/SchematicsBackend.java
Outdated
Show resolved
Hide resolved
worldedit-core/src/test/java/com/sk89q/worldedit/util/schematic/SchematicPathTest.java
Outdated
Show resolved
Hide resolved
...core/src/main/java/com/sk89q/worldedit/util/schematic/backends/PollingSchematicsBackend.java
Outdated
Show resolved
Hide resolved
@@ -21,6 +21,7 @@ | |||
|
|||
import com.sk89q.worldedit.WorldEdit; | |||
import com.sk89q.worldedit.internal.block.BlockStateIdAccess; | |||
import com.sk89q.worldedit.internal.util.LogManagerCompat; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra import?
var fileWatcherBackend = FileWatcherSchematicsBackend.create(schematicsDir); | ||
if (fileWatcherBackend.isPresent()) { | ||
backend = fileWatcherBackend.get(); | ||
} else { | ||
createFallbackBackend(); | ||
} | ||
} catch (IOException e) { | ||
createFallbackBackend(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're generally not in the habit of using optionals in WE; it's being passed up from the recursivedirectory watcher, but isn't at all consistent with the fallback. additionally, it uses an empty optional to signify unsupportedexception, but on IOexception it just creates the fallback anyway. there is no difference in results.
if (event instanceof RecursiveDirectoryWatcher.FileCreatedEvent) { | ||
LOGGER.debug("New Schematic found: " + event.path()); | ||
} else if (event instanceof RecursiveDirectoryWatcher.FileDeletedEvent) { | ||
LOGGER.debug("Schematic deleted: " + event.path()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why can't this just be inside the try statement, the instanceof is already being checked once.
- Resolve first batch of review comments - Renamed Schematic to SchematicPath - Removed custom hashCode() and equals() implementations - Added unit-test to make sure it behaves as expected
Co-authored-by: Octavia Togami <octavia.togami@gmail.com>
Has this unfortunately been abandoned now? It seemed like a really good idea. |
Closing in favour of #2542 |
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 theschematics
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