So I am finally getting around to learning Sponge, and I’ve hit my first bump. Sponge uses a Path object to reference where the config file is and a ConfigurationLoader to do all the actual load operations and whatnot. Ok great, I have that set up like this:
@Inject
@ConfigDir(sharedRoot = true)
private Path configDir;
@Inject
@DefaultConfig(sharedRoot = true)
private ConfigurationLoader<CommentedConfigurationNode> configLoader;
Ok, so I have my config file’s “default template” in the jar (using Maven, the path is set up according to the Sponge Docs, I checked that thread already), and I have my plugin set to check if a config exists on the file system already, and if not to extract the default. Looks like this:
if (!this.configDir.toFile().exists()) {
log.info("File doesn't exist, extracting");
URL configFile = this.getClass().getResource("Default.conf");
configLoader = HoconConfigurationLoader.builder().setURL(configFile).build();
} else {
log.info("File exists, referencing");
configLoader = HoconConfigurationLoader.builder().setPath(configDir).build();
}
Ok, great, now what the heck is wrong with this?
[Server thread/INFO] [groupbroadcaster]: File exists, referencing`
That’s fine, right? Except the file doesn’t exist on my file system yet. So apparently, the call to
!this.configDir.toFile().exists()
is telling my plugin that yes, the file does in fact exist on the file system and please do read from it, even though it does not exist and you most certainly should not try to read from it. I guess from all of this, my main question is, did I mess something up, or is there an inherent problem with converting a Path to a File, and checking if it exists?