mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-13 17:38:03 +08:00
Bungee->Bukkit Configuration WebAPI
This commit is contained in:
parent
7c154bbb5e
commit
4918fea0b0
@ -4,7 +4,14 @@
|
|||||||
*/
|
*/
|
||||||
package main.java.com.djrapitops.plan;
|
package main.java.com.djrapitops.plan;
|
||||||
|
|
||||||
import java.util.UUID; /**
|
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
|
||||||
|
import main.java.com.djrapitops.plan.api.IPlan;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
* Bungee Config manager for Server Settings such as:
|
* Bungee Config manager for Server Settings such as:
|
||||||
* - WebServer Port
|
* - WebServer Port
|
||||||
* - ServerName
|
* - ServerName
|
||||||
@ -13,6 +20,34 @@ import java.util.UUID; /**
|
|||||||
* @author Rsl1122
|
* @author Rsl1122
|
||||||
*/
|
*/
|
||||||
public class ServerSpecificSettings {
|
public class ServerSpecificSettings {
|
||||||
|
|
||||||
|
public void updateSettings(IPlan plugin, Map<String, String> settings) {
|
||||||
|
try {
|
||||||
|
IFileConfig config = plugin.getIConfig().getConfig();
|
||||||
|
boolean changedSomething = false;
|
||||||
|
for (Map.Entry<String, String> setting : settings.entrySet()) {
|
||||||
|
String path = setting.getKey();
|
||||||
|
String value = setting.getValue();
|
||||||
|
String currentValue = config.getString(path);
|
||||||
|
if (currentValue.equals(value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
config.set(path, value);
|
||||||
|
changedSomething = true;
|
||||||
|
}
|
||||||
|
if (changedSomething) {
|
||||||
|
plugin.getIConfig().save();
|
||||||
|
Log.info("----------------------------------");
|
||||||
|
Log.info("The Received Bungee Settings changed the config values, restarting Plan..");
|
||||||
|
Log.info("----------------------------------");
|
||||||
|
plugin.onDisable();
|
||||||
|
plugin.onEnable();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.toLog(this.getClass().getName(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Object get(UUID serverUUID, Settings setting) {
|
public Object get(UUID serverUUID, Settings setting) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
|
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
|
||||||
|
|
||||||
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
|
|
||||||
import com.djrapitops.plugin.utilities.Compatibility;
|
import com.djrapitops.plugin.utilities.Compatibility;
|
||||||
import main.java.com.djrapitops.plan.Log;
|
|
||||||
import main.java.com.djrapitops.plan.ServerSpecificSettings;
|
import main.java.com.djrapitops.plan.ServerSpecificSettings;
|
||||||
import main.java.com.djrapitops.plan.Settings;
|
import main.java.com.djrapitops.plan.Settings;
|
||||||
import main.java.com.djrapitops.plan.api.IPlan;
|
import main.java.com.djrapitops.plan.api.IPlan;
|
||||||
@ -14,7 +12,6 @@ import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
|
|||||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||||
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
|
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -28,41 +25,35 @@ public class ConfigurationWebAPI extends WebAPI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Response onRequest(IPlan plugin, Map<String, String> variables) {
|
public Response onRequest(IPlan plugin, Map<String, String> variables) {
|
||||||
|
if (!Compatibility.isBukkitAvailable()) {
|
||||||
|
return badRequest("Called a Bungee Server");
|
||||||
|
}
|
||||||
if (Settings.BUNGEE_COPY_CONFIG.isFalse() || Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isTrue()) {
|
if (Settings.BUNGEE_COPY_CONFIG.isFalse() || Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isTrue()) {
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
String key = variables.get("configKey");
|
variables.remove("sender");
|
||||||
|
Settings.serverSpecific().updateSettings(plugin, variables);
|
||||||
if (key == null) {
|
|
||||||
return badRequest("Config Key null");
|
|
||||||
}
|
|
||||||
|
|
||||||
String value = variables.get("configValue");
|
|
||||||
|
|
||||||
if (value == null) {
|
|
||||||
return badRequest("Config Value null");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value.equals("null")) {
|
|
||||||
value = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
IFileConfig config = plugin.getIConfig().getConfig();
|
|
||||||
config.set(key, value);
|
|
||||||
plugin.getIConfig().save();
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.toLog(this.getClass().getName(), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addConfigValue(Settings setting, Object value) {
|
@Override
|
||||||
|
public void sendRequest(String address) throws WebAPIException {
|
||||||
|
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRequest(String address, UUID serverUUID, int newPort) throws WebAPIException {
|
||||||
|
setConfigValues(serverUUID, newPort);
|
||||||
|
for (Map.Entry<String, Object> entry : configValues.entrySet()) {
|
||||||
|
addVariable(entry.getKey(), entry.getValue().toString());
|
||||||
|
}
|
||||||
|
super.sendRequest(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addConfigValue(Settings setting, Object value) {
|
||||||
configValues.put(setting.getPath(), value);
|
configValues.put(setting.getPath(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConfigValues(UUID serverUUID, int port) throws WebAPIException {
|
public void setConfigValues(UUID serverUUID, int newPort) throws WebAPIException {
|
||||||
if (!Compatibility.isBungeeAvailable()) {
|
if (!Compatibility.isBungeeAvailable()) {
|
||||||
throw new WebAPIException("Attempted to send config values from Bukkit to Bungee.");
|
throw new WebAPIException("Attempted to send config values from Bukkit to Bungee.");
|
||||||
}
|
}
|
||||||
@ -78,7 +69,7 @@ public class ConfigurationWebAPI extends WebAPI {
|
|||||||
addConfigValue(setting, setting.toString());
|
addConfigValue(setting, setting.toString());
|
||||||
}
|
}
|
||||||
addConfigValue(Settings.DB_PORT, Settings.DB_PORT.getNumber());
|
addConfigValue(Settings.DB_PORT, Settings.DB_PORT.getNumber());
|
||||||
addConfigValue(Settings.WEBSERVER_PORT, port);
|
addConfigValue(Settings.WEBSERVER_PORT, newPort);
|
||||||
addServerSpecificValues(serverUUID);
|
addServerSpecificValues(serverUUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user