Configuration WebAPI now functional

This commit is contained in:
Rsl1122 2017-09-25 15:54:35 +03:00
parent 45ab451f5f
commit 59c339c6b0
9 changed files with 69 additions and 34 deletions

View File

@ -7,6 +7,7 @@ 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 org.bukkit.configuration.file.FileConfiguration;
import java.io.IOException;
import java.util.Map;
@ -38,30 +39,47 @@ public class ServerSpecificSettings {
}
}
public void updateSettings(Plan 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;
public static void updateSettings(Plan plugin, Map<String, String> settings) {
Log.debug("Checking new settings..");
FileConfiguration config = plugin.getConfig();
boolean changedSomething = false;
for (Map.Entry<String, String> setting : settings.entrySet()) {
String path = setting.getKey();
if ("sender".equals(path)) {
continue;
}
if (changedSomething) {
plugin.getIConfig().save();
Log.info("----------------------------------");
Log.info("The Received Bungee Settings changed the config values, restarting Plan..");
Log.info("----------------------------------");
plugin.restart();
String stringValue = setting.getValue();
Object value = getValue(stringValue);
String currentValue = config.getString(path);
if (currentValue.equals(stringValue)) {
continue;
}
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
config.set(path, value);
Log.debug(" " + path + ": " + value);
changedSomething = true;
}
if (changedSomething) {
plugin.saveConfig();
Log.info("----------------------------------");
Log.info("The Received Bungee Settings changed the config values, restarting Plan..");
Log.info("----------------------------------");
plugin.restart();
} else {
Log.debug("Settings up to date");
}
}
private static Object getValue(String value) {
try {
return Integer.parseInt(value);
} catch (Exception ignored) {
}
if ("true".equalsIgnoreCase(value)) {
return true;
} else if ("false".equalsIgnoreCase(value)) {
return false;
}
return value;
}
private String getPath(UUID serverUUID, Settings setting) {

View File

@ -16,8 +16,8 @@ import java.util.List;
*/
public enum Settings {
// Boolean
BUNGEE_COPY_CONFIG("Bungee-Override.CopyBungeeConfig"),
BUNGEE_OVERRIDE_STANDALONE_MODE("Bungee-Override.StandaloneMode"),
BUNGEE_COPY_CONFIG("Plugin.Bungee-Override.CopyBungeeConfig"),
BUNGEE_OVERRIDE_STANDALONE_MODE("Plugin.Bungee-Override.StandaloneMode"),
ANALYSIS_EXPORT("Analysis.Export.Enabled"),
SHOW_ALTERNATIVE_IP("Commands.AlternativeIP.Enabled"),
LOG_UNKNOWN_COMMANDS("Data.Commands.LogUnknownCommands"),

View File

@ -61,7 +61,7 @@ public class BukkitInformationManager extends InformationManager {
Optional<String> bungeeConnectionAddress = plugin.getServerInfoManager().getBungeeConnectionAddress();
if (bungeeConnectionAddress.isPresent()) {
webServerAddress = bungeeConnectionAddress.get();
usingAnotherWebServer = attemptConnection();
attemptConnection();
} else {
usingAnotherWebServer = false;
}
@ -226,6 +226,7 @@ public class BukkitInformationManager extends InformationManager {
getWebAPI().getAPI(PostOriginalBukkitSettingsWebAPI.class).sendRequest(webServerAddress);
Log.info("Bungee Connection OK");
plugin.getServerInfoManager().resetConnectionFails();
usingAnotherWebServer = true;
return true;
} catch (WebAPIConnectionFailException e) {
plugin.getServerInfoManager().markConnectionFail();
@ -233,6 +234,7 @@ public class BukkitInformationManager extends InformationManager {
Log.toLog(this.getClass().getName(), e);
}
Log.info("Bungee Connection Failed.");
usingAnotherWebServer = false;
return false;
}

View File

@ -86,12 +86,13 @@ public class APIResponseHandler {
if (api == null) {
String error = "API Method not found";
Log.debug(error);
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
}
Response response = api.processRequest(MiscUtils.getIPlan(), variables);
Log.debug(response.toString());
Log.debug("Response: " + response.getResponse().split("\r\n")[0]);
return response;
}

View File

@ -46,11 +46,13 @@ public abstract class WebAPI {
public Response processRequest(IPlan plugin, Map<String, String> variables) {
String sender = variables.get("sender");
if (sender == null) {
Log.debug(getClass().getSimpleName() + ": Sender not Found");
return badRequest("Sender not present");
}
try {
UUID.fromString(sender);
} catch (Exception e) {
Log.debug(getClass().getSimpleName() + ": Invalid Sender UUID");
return badRequest("Faulty Sender value");
}
return onRequest(plugin, variables);

View File

@ -5,6 +5,7 @@
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
import com.djrapitops.plugin.utilities.Compatibility;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.ServerSpecificSettings;
@ -26,14 +27,14 @@ public class ConfigurationWebAPI extends WebAPI {
@Override
public Response onRequest(IPlan plugin, Map<String, String> variables) {
if (!Compatibility.isBukkitAvailable()) {
Log.debug("Called a wrong server type");
return badRequest("Called a Bungee Server");
}
if (Settings.BUNGEE_COPY_CONFIG.isFalse() || Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isTrue()) {
Log.debug("Bungee Config settings overridden on this server.");
return success();
}
variables.remove("sender");
Settings.serverSpecific().updateSettings((Plan) plugin, variables);
ServerSpecificSettings.updateSettings((Plan) plugin, variables);
return success();
}
@ -44,14 +45,22 @@ public class ConfigurationWebAPI extends WebAPI {
public void sendRequest(String address, UUID serverUUID) throws WebAPIException {
Map<String, Object> configValues = getConfigValues(serverUUID);
Log.debug("Sending config values: " + configValues);
for (Map.Entry<String, Object> entry : configValues.entrySet()) {
addVariable(entry.getKey(), entry.getValue().toString());
String key = entry.getKey();
Object value = entry.getValue();
if (!Verify.notNull(key, value)) {
continue;
}
addVariable(key, value.toString());
}
super.sendRequest(address);
}
private void addConfigValue(Map<String, Object> configValues, Settings setting, Object value) {
configValues.put(setting.getPath(), value);
if (value != null) {
configValues.put(setting.getPath(), value);
}
}
private Map<String, Object> getConfigValues(UUID serverUUID) throws WebAPIException {

View File

@ -22,6 +22,9 @@ public class PingWebAPI extends WebAPI {
if (Compatibility.isBungeeAvailable()) {
((PlanBungee) plugin).getServerInfoManager().serverConnected(UUID.fromString(variables.get("sender")));
}
if (Compatibility.isBukkitAvailable() && !plugin.getInfoManager().isUsingAnotherWebServer()) {
plugin.getInfoManager().attemptConnection();
}
return success();
}
}

View File

@ -199,13 +199,13 @@
var serverSeries = {
name:'Server Playtime',
colorByPoint:true,
colors: ${serverPieColors},
colors: [${serverPieColors}],
data: ${serverPieSeries}
}
var worldSeries = {
name:'World Playtime',
colorByPoint:true,
colors: ${worldPieColors},
colors: [${worldPieColors}],
data: ${worldPieSeries}
};
var gmSeries = ${gmSeries};

View File

@ -409,7 +409,7 @@
var activitySeries = {
name: 'Players',
colorByPoint: true,
colors: ${activityPieColors},
colors: [${activityPieColors}],
data: [{
name: 'Active',
y: ${active}
@ -429,7 +429,7 @@
var worldSeries = {
name: 'World Playtime',
colorByPoint: true,
colors: ${worldPieColors},
colors: [${worldPieColors}],
data: ${worldSeries}
};
var gmSeries = ${gmSeries};
@ -464,7 +464,7 @@
}
x.style.opacity = "1";
openFunc(slideIndex)();
activityPie('activityPie', activitySeries, ${playersTotal}, [${activityColors}]);
activityPie('activityPie', activitySeries, ${playersTotal}, [${activityPieColors}]);
worldPie('worldPie', worldSeries, gmSeries);
playersChart('playerChartDay', playersOnlineSeries, 1);
playersChart('playerChartMonth', playersOnlineSeries, 4);