Does anybody understand why Paths.get is converting NWSConfiguration and “/GASGeneral” to null/GASGeneral???
NWSConfiguration is working just fine, the syntax seems correct, no error codes in Eclipse
This is the error code in the console:
[00:09:23] [Server thread/INFO] [nwsglobaladministrativesystem]: NWS-GAS: C:\Users\User\Desktop\Workbench\Server Hosting\MinecraftForge.\config\nwsglobaladministrativesystem
[00:09:23] [Server thread/INFO] [nwsglobaladministrativesystem]: NWS-GAS: null\GASGeneral.conf
[00:09:23] [Server thread/INFO] [nwsglobaladministrativesystem]: NWS-GAS: Checking the existence of the General configuration file.
[00:09:23] [Server thread/WARN] [nwsglobaladministrativesystem]: NWS-GAS: The Configuration file was not found! Attempting to create it…
[00:09:23] [Server thread/ERROR] [nwsglobaladministrativesystem]: NWS-GAS: Configuration file was unsuccessful!
[00:09:23] [Server thread/INFO] [STDERR]: [net.newworldservers.globaladministrativesystem.globaladministrativesystem:createCheckConfigFile:86]: java.nio.file.NoSuchFileException: null\GASGeneral.conf
I had both variables log their values to show it’s Paths.get failing to actually convert NWSConfiguration to an actual path.
Here is the code:
@Inject
@ConfigDir(sharedRoot = false)
private Path NWSConfiguration;
//Configuration Creation Setup
private Path generalConfigFile = Paths.get(NWSConfiguration + "/GASGeneral.conf");
private ConfigurationLoader<CommentedConfigurationNode> configLoader = HoconConfigurationLoader.builder().setPath(generalConfigFile).build();
private CommentedConfigurationNode configNode;
//Variables
private String pluginTag = "NWS-GAS: ";
//Methods
public Logger getLogger() {
return logger;
}
private boolean createCheckConfigFile(String configFileName, Path directory, Path configFile) {
getLogger().info(pluginTag + NWSConfiguration);
getLogger().info(pluginTag + generalConfigFile);
getLogger().info(pluginTag + "Checking the existence of the " + configFileName + " configuration file.");
if(!Files.exists(directory)) {
try {
getLogger().warn(pluginTag + directory + " not found! Attempting to create the directory...");
Files.createDirectories(directory);
getLogger().info(pluginTag + "Directory creation was successful!");
}catch(IOException io){
getLogger().error(pluginTag + "Directory creation was unsuccessful!");
io.printStackTrace();
return false;
}
}
if(!Files.exists(configFile)) {
try {
getLogger().warn(pluginTag + "The Configuration file was not found! Attempting to create it...");
Files.createFile(configFile);
getLogger().info(pluginTag + "Configuration file creation was successful!");
}catch(IOException io) {
getLogger().error(pluginTag + "Configuration file was unsuccessful!");
io.printStackTrace();
return false;
}
}
getLogger().info(pluginTag + "Configuration file found.");
return true;
}
@Listener
public void onPreInit(GamePreInitializationEvent event){
if(!createCheckConfigFile("General", NWSConfiguration, generalConfigFile)) {
getLogger().error(pluginTag + "Unable to create or find a usable configuration file! System shutting down to prevent crashing...");
}
}
This has been giving me a headache for about 3 hours, I would appreciate any help. Thank you.