-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-implement serverside config using toml4j
- Loading branch information
Showing
4 changed files
with
47 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.cavoj.servertick; | ||
|
||
import com.moandjiezana.toml.Toml; | ||
import com.moandjiezana.toml.TomlWriter; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class Config { | ||
public final boolean requireOP; | ||
|
||
public Config(Path configPath) { | ||
if (!Files.exists(configPath)) { | ||
createDefault(configPath); | ||
} | ||
Toml toml = new Toml().read(configPath.toFile()); | ||
this.requireOP = toml.getBoolean("requireOP"); | ||
} | ||
|
||
private static void createDefault(Path configPath) { | ||
TomlWriter tw = new TomlWriter(); | ||
Map<String, Object> defaults = new HashMap<>(); | ||
defaults.put("requireOP", true); | ||
try { | ||
tw.write(defaults, configPath.toFile()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters