mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Changed WebAPI to use IPlan instead of Plan
This commit is contained in:
parent
3ffc5dd95d
commit
d9b9fd53f7
@ -4,7 +4,7 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.webapi;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||
|
||||
import java.util.Map;
|
||||
@ -14,5 +14,5 @@ import java.util.Map;
|
||||
*/
|
||||
public interface WebAPI {
|
||||
|
||||
Response onResponse(Plan plan, Map<String, String> variables);
|
||||
Response onResponse(IPlan plugin, Map<String, String> variables);
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.webapi.bukkit;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
@ -19,8 +19,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class AnalyticsWebAPI implements WebAPI {
|
||||
@Override
|
||||
public Response onResponse(Plan plan, Map<String, String> variables) {
|
||||
InformationManager infoManager = plan.getInfoManager();
|
||||
public Response onResponse(IPlan plugin, Map<String, String> variables) {
|
||||
InformationManager infoManager = plugin.getInfoManager();
|
||||
|
||||
if (!infoManager.isAnalysisCached()) {
|
||||
return PageCache.loadPage("No Analysis Data", () -> new BadRequestResponse("No analysis data available"));
|
||||
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.webapi.bukkit;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||
@ -17,8 +17,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class AnalyzeWebAPI implements WebAPI {
|
||||
@Override
|
||||
public Response onResponse(Plan plan, Map<String, String> variables) {
|
||||
plan.getInfoManager().refreshAnalysis();
|
||||
public Response onResponse(IPlan plugin, Map<String, String> variables) {
|
||||
plugin.getInfoManager().refreshAnalysis();
|
||||
return PageCache.loadPage("success", SuccessResponse::new);
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,16 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.webapi.bukkit;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plugin.config.fileconfig.IFileConfig;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.SuccessResponse;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -19,7 +21,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class ConfigureWebAPI implements WebAPI {
|
||||
@Override
|
||||
public Response onResponse(Plan plan, Map<String, String> variables) {
|
||||
public Response onResponse(IPlan plugin, Map<String, String> variables) {
|
||||
String key = variables.get("configKey");
|
||||
|
||||
if (key == null) {
|
||||
@ -38,9 +40,14 @@ public class ConfigureWebAPI implements WebAPI {
|
||||
value = null;
|
||||
}
|
||||
|
||||
FileConfiguration config = plan.getConfig();
|
||||
config.set(key, value);
|
||||
plan.saveConfig();
|
||||
IFileConfig config = null;
|
||||
try {
|
||||
config = plugin.getIConfig().getConfig();
|
||||
config.set(key, value);
|
||||
plugin.getIConfig().save();
|
||||
} catch (IOException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
|
||||
return PageCache.loadPage("success", SuccessResponse::new);
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.webapi.bukkit;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||
@ -20,7 +20,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class InspectWebAPI implements WebAPI {
|
||||
@Override
|
||||
public Response onResponse(Plan plan, Map<String, String> variables) {
|
||||
public Response onResponse(IPlan plugin, Map<String, String> variables) {
|
||||
String playerString = variables.get("player");
|
||||
|
||||
if (playerString == null) {
|
||||
@ -35,7 +35,7 @@ public class InspectWebAPI implements WebAPI {
|
||||
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
|
||||
}
|
||||
|
||||
plan.getInfoManager().cachePlayer(uuid);
|
||||
plugin.getInfoManager().cachePlayer(uuid);
|
||||
|
||||
return PageCache.loadPage("success", SuccessResponse::new);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
package main.java.com.djrapitops.plan.systems.webapi.bukkit;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse;
|
||||
@ -17,8 +18,8 @@ import java.util.Map;
|
||||
*/
|
||||
public class OnlinePlayersWebAPI implements WebAPI {
|
||||
@Override
|
||||
public Response onResponse(Plan plan, Map<String, String> variables) {
|
||||
Server server = plan.getServer();
|
||||
public Response onResponse(IPlan plugin, Map<String, String> variables) {
|
||||
Server server = ((Plan) plugin).getServer();
|
||||
|
||||
return new JsonResponse(server.getOnlinePlayers() + "/" + server.getMaxPlayers());
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.webapi.universal;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||
@ -17,7 +17,7 @@ import java.util.Map;
|
||||
*/
|
||||
public class PingWebAPI implements WebAPI {
|
||||
@Override
|
||||
public Response onResponse(Plan plan, Map<String, String> variables) {
|
||||
public Response onResponse(IPlan plugin, Map<String, String> variables) {
|
||||
return PageCache.loadPage("success", SuccessResponse::new);
|
||||
}
|
||||
}
|
@ -44,18 +44,18 @@ public class APIResponseHandler {
|
||||
}
|
||||
|
||||
String method = args[2];
|
||||
String response = null;
|
||||
String requestBody;
|
||||
try (InputStream inputStream = request.getRequestBody()) {
|
||||
response = readPOSTRequest(inputStream);
|
||||
requestBody = readPOSTRequest(inputStream);
|
||||
}
|
||||
|
||||
if (response == null) {
|
||||
if (requestBody == null) {
|
||||
String error = "Error at reading the POST request." +
|
||||
"Note that the Encoding must be ISO-8859-1.";
|
||||
return PageCache.loadPage(error, () -> new BadRequestResponse(error));
|
||||
}
|
||||
|
||||
Map<String, String> variables = readVariables(response);
|
||||
Map<String, String> variables = readVariables(requestBody);
|
||||
String key = variables.get("key");
|
||||
|
||||
if (!checkKey(key)) {
|
||||
@ -111,12 +111,12 @@ public class APIResponseHandler {
|
||||
return uuid.equals(keyUUID);
|
||||
}
|
||||
|
||||
private Map<String, String> readVariables(String response) {
|
||||
String[] variables = response.split("&");
|
||||
private Map<String, String> readVariables(String requestBody) {
|
||||
String[] variables = requestBody.split("&");
|
||||
|
||||
return Arrays.stream(variables)
|
||||
.map(variable -> variable.split("=", 2))
|
||||
.filter(splittedVariables -> splittedVariables.length == 2)
|
||||
.collect(Collectors.toMap(splittedVariables -> splittedVariables[0], splittedVariables -> splittedVariables[1], (a, b) -> b));
|
||||
.filter(splitVariables -> splitVariables.length == 2)
|
||||
.collect(Collectors.toMap(splitVariables -> splitVariables[0], splitVariables -> splitVariables[1], (a, b) -> b));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user