mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-27 22:16:06 +01:00
ServerSpecificSetting getting and setting (Bungee)
This commit is contained in:
parent
4918fea0b0
commit
7d5ccd2d0f
Plan/src/main
java/com/djrapitops/plan
resources
@ -4,7 +4,9 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plugin.config.IConfig;
|
||||
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -48,7 +50,81 @@ public class ServerSpecificSettings {
|
||||
}
|
||||
}
|
||||
|
||||
private String getPath(UUID serverUUID, Settings setting) {
|
||||
String path = "Servers." + serverUUID;
|
||||
switch (setting) {
|
||||
case WEBSERVER_PORT:
|
||||
path += ".WebServerPort";
|
||||
break;
|
||||
case SERVER_NAME:
|
||||
path += ".ServerName";
|
||||
break;
|
||||
case THEME_BASE:
|
||||
path += ".ThemeBase";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public Object get(UUID serverUUID, Settings setting) {
|
||||
try {
|
||||
IFileConfig config = PlanBungee.getInstance().getIConfig().getConfig();
|
||||
String path = getPath(serverUUID, setting);
|
||||
String value = config.getString(path);
|
||||
try {
|
||||
return Boolean.parseBoolean(value);
|
||||
} catch (Exception e) {
|
||||
if (Verify.isEmpty(value)) {
|
||||
return config.getInt(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean getBoolean(UUID serverUUID, Settings setting) {
|
||||
try {
|
||||
IFileConfig config = PlanBungee.getInstance().getIConfig().getConfig();
|
||||
String path = getPath(serverUUID, setting);
|
||||
return config.getBoolean(path);
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getString(UUID serverUUID, Settings setting) {
|
||||
try {
|
||||
IFileConfig config = PlanBungee.getInstance().getIConfig().getConfig();
|
||||
String path = getPath(serverUUID, setting);
|
||||
return config.getString(path);
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Integer getInt(UUID serverUUID, Settings setting) {
|
||||
try {
|
||||
IFileConfig config = PlanBungee.getInstance().getIConfig().getConfig();
|
||||
String path = getPath(serverUUID, setting);
|
||||
return config.getInt(path);
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void set(UUID serverUUID, Settings setting, Object value) throws IOException {
|
||||
IConfig iConfig = PlanBungee.getInstance().getIConfig();
|
||||
IFileConfig config = iConfig.getConfig();
|
||||
String path = getPath(serverUUID, setting);
|
||||
config.set(path, value);
|
||||
iConfig.save();
|
||||
}
|
||||
}
|
@ -69,14 +69,13 @@ public class ConfigurationWebAPI extends WebAPI {
|
||||
addConfigValue(setting, setting.toString());
|
||||
}
|
||||
addConfigValue(Settings.DB_PORT, Settings.DB_PORT.getNumber());
|
||||
addConfigValue(Settings.WEBSERVER_PORT, newPort);
|
||||
addServerSpecificValues(serverUUID);
|
||||
}
|
||||
|
||||
private void addServerSpecificValues(UUID serverUUID) {
|
||||
ServerSpecificSettings settings = Settings.serverSpecific();
|
||||
addConfigValue(Settings.THEME_BASE, settings.get(serverUUID, Settings.THEME_BASE));
|
||||
addConfigValue(Settings.WEBSERVER_PORT, settings.get(serverUUID, Settings.WEBSERVER_PORT));
|
||||
addConfigValue(Settings.SERVER_NAME, settings.get(serverUUID, Settings.SERVER_NAME));
|
||||
addConfigValue(Settings.THEME_BASE, settings.getString(serverUUID, Settings.THEME_BASE));
|
||||
addConfigValue(Settings.WEBSERVER_PORT, settings.getInt(serverUUID, Settings.WEBSERVER_PORT));
|
||||
addConfigValue(Settings.SERVER_NAME, settings.getString(serverUUID, Settings.SERVER_NAME));
|
||||
}
|
||||
}
|
||||
|
@ -86,12 +86,16 @@ Theme:
|
||||
PunchCard: Base
|
||||
PlayersOnline: Base
|
||||
TPS:
|
||||
High-Threshold: 18
|
||||
Medium-Threshold: 10
|
||||
High: Base
|
||||
Medium: Base
|
||||
Low: Base
|
||||
CPU: Base
|
||||
RAM: Base
|
||||
Chunks: Base
|
||||
Entities: Base
|
||||
Entities: Base
|
||||
|
||||
Servers:
|
||||
Example:
|
||||
WebServerPort: 8034
|
||||
ServerName: Example
|
||||
ThemeBase: Default
|
Loading…
Reference in New Issue
Block a user