Added ServerConfiguration#toString & fixed the exposure
This commit is contained in:
parent
e30f828a73
commit
91ae04923e
@ -1,6 +1,8 @@
|
|||||||
package de.gnmyt.mcdash.entities;
|
package de.gnmyt.mcdash.entities;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.annotations.Expose;
|
||||||
import de.gnmyt.mcdash.api.Logger;
|
import de.gnmyt.mcdash.api.Logger;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
|
||||||
@ -10,13 +12,25 @@ public class ServerConfiguration {
|
|||||||
|
|
||||||
private final static Logger LOG = new Logger(ServerConfiguration.class);
|
private final static Logger LOG = new Logger(ServerConfiguration.class);
|
||||||
|
|
||||||
|
@Expose(serialize = false, deserialize = false)
|
||||||
private File file;
|
private File file;
|
||||||
|
|
||||||
|
@Expose
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@Expose
|
||||||
private String type;
|
private String type;
|
||||||
|
|
||||||
|
@Expose
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
@Expose
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
|
@Expose
|
||||||
private int memory;
|
private int memory;
|
||||||
|
|
||||||
|
@Expose(serialize = true, deserialize = true)
|
||||||
private boolean autoStart;
|
private boolean autoStart;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,7 +46,9 @@ public class ServerConfiguration {
|
|||||||
if (!file.getName().endsWith(".json")) return null;
|
if (!file.getName().endsWith(".json")) return null;
|
||||||
|
|
||||||
String jsonRaw = FileUtils.readFileToString(file, "UTF-8");
|
String jsonRaw = FileUtils.readFileToString(file, "UTF-8");
|
||||||
ServerConfiguration configuration = new Gson().fromJson(jsonRaw, ServerConfiguration.class);
|
|
||||||
|
ServerConfiguration configuration = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
|
||||||
|
.fromJson(jsonRaw, ServerConfiguration.class);
|
||||||
configuration.file = file;
|
configuration.file = file;
|
||||||
|
|
||||||
return configuration;
|
return configuration;
|
||||||
@ -168,4 +184,16 @@ public class ServerConfiguration {
|
|||||||
this.autoStart = autoStart;
|
this.autoStart = autoStart;
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ServerConfiguration{" +
|
||||||
|
"name='" + name + '\'' +
|
||||||
|
", type='" + type + '\'' +
|
||||||
|
", version='" + version + '\'' +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", memory=" + memory +
|
||||||
|
", autoStart=" + autoStart +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user