Skip to content

Commit 3a6c4d1

Browse files
committed
feat: removed external TOML dependency to instead rely on the Velocity-included library, reducing size
1 parent 56d70f6 commit 3a6c4d1

2 files changed

Lines changed: 17 additions & 28 deletions

File tree

pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.justadeni</groupId>
88
<artifactId>multiproxyplayercount</artifactId>
9-
<version>0.1.7</version>
9+
<version>0.1.8</version>
1010
<packaging>jar</packaging>
1111

1212
<name>MultiProxyPlayerCount</name>
@@ -122,12 +122,6 @@
122122
<version>6.0.0</version>
123123
<scope>compile</scope>
124124
</dependency>
125-
<dependency>
126-
<groupId>io.github.wasabithumb</groupId>
127-
<artifactId>jtoml</artifactId>
128-
<version>1.0.0</version>
129-
<scope>compile</scope>
130-
</dependency>
131125
</dependencies>
132126

133127
</project>

src/main/java/com/github/justadeni/multiProxyPlayerCount/config/ConfigImpl.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package 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;
74
import org.slf4j.Logger;
85

96
import java.io.IOException;
@@ -15,19 +12,17 @@
1512

1613
public 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

Comments
 (0)