11package com .github .justadeni .multiProxyPlayerCount .config ;
22
3- import com .github .justadeni .multiProxyPlayerCount .MultiProxyPlayerCount ;
4- import io .github .wasabithumb .jtoml .JToml ;
5- import io .github .wasabithumb .jtoml .document .TomlDocument ;
6- import io .github .wasabithumb .jtoml .except .TomlException ;
3+ import com .moandjiezana .toml .Toml ;
74import org .slf4j .Logger ;
85
96import java .io .IOException ;
1512
1613public class ConfigImpl implements Config {
1714
18- private static final JToml jtoml = JToml .jToml ();
19-
2015 private final Logger logger ;
2116 private final Path path ;
22- private TomlDocument doc ;
17+ private Toml toml ;
2318
2419 public ConfigImpl (Path path , Logger logger ) {
2520 this .path = path .resolve ("config.toml" );
2621 this .logger = logger ;
2722 if (Files .notExists (this .path )) {
28- try (InputStream in = ConfigImpl .class .getResourceAsStream ("/config.toml" )) {
23+ try (InputStream is = ConfigImpl .class .getResourceAsStream ("/config.toml" )) {
2924 Files .createDirectories (this .path .getParent ());
30- Files .copy (in , this .path , StandardCopyOption .REPLACE_EXISTING );
25+ Files .copy (is , this .path , StandardCopyOption .REPLACE_EXISTING );
3126 } catch (IOException e ) {
3227 logger .error ("Error while copying config to data directory. Printing stack trace." );
3328 Arrays .stream (e .getStackTrace ()).forEach (s -> logger .warn (s .toString ()));
@@ -39,54 +34,54 @@ public ConfigImpl(Path path, Logger logger) {
3934
4035 @ Override
4136 public String getBaseCommand () {
42- return doc . get ("command" ).asTable (). get ( "base" ). asPrimitive (). asString ( );
37+ return toml . getTable ("command" ).getString ( "base" );
4338 }
4439
4540 @ Override
4641 public String getDetailedCommand () {
47- return doc . get ("command" ).asTable (). get ( "detailed" ). asPrimitive (). asString ( );
42+ return toml . getTable ("command" ).getString ( "detailed" );
4843 }
4944
5045 @ Override
5146 public String getProxyIdentifier () {
52- return doc . get ("format" ).asTable (). get ( "name" ). asPrimitive (). asString ( );
47+ return toml . getTable ("format" ).getString ( "name" );
5348 }
5449
5550 @ Override
5651 public String getHost () {
57- return doc . get ("connection" ).asTable (). get ( "host" ). asPrimitive (). asString ( );
52+ return toml . getTable ("connection" ).getString ( "host" );
5853 }
5954
6055 @ Override
6156 public int getPort () {
62- return doc . get ( "connection" ).asTable (). get ( "port" ). asPrimitive (). asInteger ( );
57+ return Math . toIntExact ( toml . getTable ( "connection" ).getLong ( "port" ));
6358 }
6459
6560 @ Override
6661 public String getUser () {
67- return doc . get ("connection" ).asTable (). get ( "user" ). asPrimitive (). asString ( );
62+ return toml . getTable ("connection" ).getString ( "user" );
6863 }
6964
7065 @ Override
7166 public String getPassword () {
72- return doc . get ("connection" ).asTable (). get ( "password" ). asPrimitive (). asString ( );
67+ return toml . getTable ("connection" ).getString ( "password" );
7368 }
7469
7570 @ Override
7671 public String getSimpleFormat () {
77- return doc . get ("format" ).asTable (). get ( "simple" ). asPrimitive (). asString ( );
72+ return toml . getTable ("format" ).getString ( "simple" );
7873 }
7974
8075 @ Override
8176 public String getDetailedFormat () {
82- return doc . get ("format" ).asTable (). get ( "detailed" ). asPrimitive (). asString ( );
77+ return toml . getTable ("format" ).getString ( "detailed" );
8378 }
8479
8580 @ Override
8681 public void reload () {
87- try {
88- doc = jtoml .read (this . path );
89- } catch (TomlException e ) {
82+ try ( InputStream is = Files . newInputStream ( path )) {
83+ toml = toml .read (is );
84+ } catch (IOException e ) {
9085 logger .error ("Error while reading config. Printing stack trace." );
9186 Arrays .stream (e .getStackTrace ()).forEach (s -> logger .warn (s .toString ()));
9287 }
0 commit comments