-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feat/litematic support #233
Conversation
VoxelSniperCore/src/main/java/com/github/kevindagame/command/VoxelCommand.java
Show resolved
Hide resolved
VoxelSniperCore/src/main/java/com/github/kevindagame/brush/SchematicBrush.kt
Show resolved
Hide resolved
class DataFolderSchematicReader : ISchematicReader { | ||
override fun getSchematicFile(name: String): File? { | ||
//check for exact name | ||
val exactSchematic = VoxelSniper.voxelsniper.fileHandler.getDataFile(SCHEMATIC_FILE_ROOT_PATH + name) |
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 think it is better to use new File(baseDirectory, file);
or simular.
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 disagree. Until now we have used the file handler everywhere. Making a file directly would require getting the full path to the plugin root, which is extra work
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.
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.
Also I am not sure if using '/' is platform dependent or not..
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.
That's more an issue on that part. I prefer to leave this file logic to the main file handler. It might be a good idea to refactor this in other places
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.
Maybe this would be a nice option, we could add/change a method in filehandler File getDataFile(String... path)
, which could take all path 'parts', without having to concatenate the strings, which I think is not the way it is meant to be done in Java (could be wrong here, but most examples either use File or Paths).
default File getDataFile(String... path) {
File f = getDataFolder();
for (String p : path) {
f = new File(f, p);
}
return f;
}
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.
INFO: Why don't you like the way I'm using it? I'd like to stay away from the File constructor wherever possible, to prevent divergence later on.
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 do think though that the way we access the filehandler isn't nice. Perhabs this could be solved using dependency injection
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 will approve the PR, since the same issue was already present before I think, but we should indeed look into improving this.
I feel like we should, if we want to be able to change the implementation, supply every part of the path to the filehandler separately, so that it can traverse the filesystem in whatever way it needs to.
...lSniperCore/src/main/java/com/github/kevindagame/util/schematic/DataFolderSchematicReader.kt
Show resolved
Hide resolved
VoxelSniperCore/src/main/java/com/github/kevindagame/util/schematic/VoxelSchematicLoader.kt
Show resolved
Hide resolved
VoxelSniperFabric/src/main/java/com/github/kevdadev/voxelsniperfabric/VoxelSniperFabric.kt
Show resolved
Hide resolved
…ception. (This is a failsafe. Ideally this shouldn't happen at all)
That can already be done like this: Set<String> supportedExtensions = new HashSet<>();
for (SchematicFormat format : SchematicFormat.values()) {
supportedExtensions.add(format.fileExtension);
}
// Or as a one-liner:
Set<String> supportedExtensions = Arrays.stream(SchematicFormat.values())
.map(f -> f.fileExtension)
.collect(Collectors.toSet()); |
What type of PR is this? (check all applicable)
Description
close #232
QA Instructions, Screenshots, Recordings
The following schematics can be used for testing:
schematics.zip
Added/updated tests?
have not been included
[optional] What gif best describes this PR or how it makes you feel?