Skip to content

Commit

Permalink
fix config.properties being accessible in .jar
Browse files Browse the repository at this point in the history
  • Loading branch information
Leg0shii committed Apr 29, 2023
1 parent 8b23e80 commit 456c466
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 50 deletions.
20 changes: 20 additions & 0 deletions config.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Configuration settings
#Sat Apr 29 23:54:25 CEST 2023
realVelocity=true
pathCollision=true
parkourVersion=V_1_12
maxMouseMultiplier=2.5
mouseSpeed=0.02
forward=W
sprint=CONTROL
right=D
down=SHIFT
previewBlock=true
placeBlock=PRIMARY
cameraSpeed=0.02
left=A
coordinatePrecision=8
backward=S
maxSpeedMultiplier=2.5
up=SPACE
destroyBlock=SECONDARY
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,35 @@ public ConfigProperties() {

private void loadConfig() {
System.out.println();
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)) {
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
String workingDirectory = System.getProperty("user.dir");
Path configFilePath = Paths.get(workingDirectory, "config.properties");

if (Files.exists(configFilePath)) {
try (InputStream inputStream = Files.newInputStream(configFilePath)) {
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
} else {
try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)) {
properties.load(inputStream);
saveConfig(); // Save the configuration file to the working directory
} catch (IOException e) {
e.printStackTrace();
}
}
}

public void saveConfig() {
try {
URL configFileUrl = getClass().getClassLoader().getResource(CONFIG_FILE);
if (configFileUrl != null) {
Path configFilePath = Paths.get(configFileUrl.toURI());
try (OutputStream outputStream = Files.newOutputStream(configFilePath)) {
properties.store(outputStream, "Configuration settings");
}
} else {
System.err.println("Unable to locate " + CONFIG_FILE);
String workingDirectory = System.getProperty("user.dir");
Path configFilePath = Paths.get(workingDirectory, "config.properties");
try (OutputStream outputStream = Files.newOutputStream(configFilePath)) {
properties.store(outputStream, "Configuration settings");
}
} catch (IOException | URISyntaxException e) {
} catch (IOException e) {
e.printStackTrace();
}

}

public void resetToDefault() {
Expand Down
36 changes: 0 additions & 36 deletions src/main/resources/config.properties

This file was deleted.

0 comments on commit 456c466

Please sign in to comment.