IsOnlineWebAPI and Removed all JsonResponse APIs (response body not used)

This commit is contained in:
Rsl1122 2017-09-18 13:13:14 +03:00
parent 7d5ccd2d0f
commit 06eb66047b
5 changed files with 66 additions and 50 deletions

View File

@ -8,18 +8,18 @@ import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIConnectionFailException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.api.exceptions.WebAPINotFoundException;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.AnalyzeWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit.IsOnlineWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bungee.RequestPluginsTabWebAPI;
import main.java.com.djrapitops.plan.utilities.html.HtmlStructure;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -82,6 +82,21 @@ public class BungeeInformationManager extends InformationManager {
getWebAPI().getAPI(RequestPluginsTabWebAPI.class).sendRequestsToBukkitServers(plugin, uuid);
}
public ServerInfo getInspectRequestProcessorServer(UUID uuid) throws SQLException {
List<ServerInfo> bukkitServers = plugin.getDB().getServerTable().getBukkitServers();
for (ServerInfo server : bukkitServers) {
try {
getWebAPI().getAPI(IsOnlineWebAPI.class).sendRequest(server.getWebAddress());
return server;
} catch (WebAPINotFoundException e) {
/*continue*/
} catch (WebAPIException e) {
Log.toLog(this.getClass().getName(), e);
}
}
return bukkitServers.get(new Random().nextInt(bukkitServers.size()));
}
@Override
public DataCache getDataCache() {
return null;

View File

@ -60,8 +60,7 @@ public class WebServer {
webAPI.registerNewAPI(new AnalyzeWebAPI());
webAPI.registerNewAPI(new ConfigurationWebAPI());
webAPI.registerNewAPI(new InspectWebAPI());
webAPI.registerNewAPI(new GetOnlinePlayersWebAPI());
webAPI.registerNewAPI(new GetMaxPlayersWebAPI());
webAPI.registerNewAPI(new IsOnlineWebAPI());
webAPI.registerNewAPI(new PingWebAPI());
webAPI.registerNewAPI(new RequestInspectPluginsTabBukkitWebAPI());

View File

@ -1,22 +0,0 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
import java.util.Map;
/**
* @author Rsl1122
*/
public class GetMaxPlayersWebAPI extends WebAPI {
@Override
public Response onRequest(IPlan plugin, Map<String, String> variables) {
return new JsonResponse(plugin.getVariable().getMaxPlayers());
}
}

View File

@ -1,23 +0,0 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
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 main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
import java.util.Map;
/**
* @author Fuzzlemann
*/
public class GetOnlinePlayersWebAPI extends WebAPI {
@Override
public Response onRequest(IPlan plugin, Map<String, String> variables) {
return new JsonResponse(((Plan) plugin).getServer().getOnlinePlayers());
}
}

View File

@ -0,0 +1,47 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package main.java.com.djrapitops.plan.systems.webserver.webapi.bukkit;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.IPlan;
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.webapi.WebAPI;
import org.bukkit.entity.Player;
import java.util.Map;
import java.util.UUID;
/**
* @author Fuzzlemann
*/
public class IsOnlineWebAPI extends WebAPI {
@Override
public Response onRequest(IPlan plugin, Map<String, String> variables) {
String uuidS = variables.get("uuid");
if (uuidS == null) {
return badRequest("UUID not included");
}
UUID uuid = UUID.fromString(uuidS);
Player player = Plan.getInstance().getServer().getPlayer(uuid);
if (player != null && player.isOnline()) {
return success();
} else {
return fail("Not Online");
}
}
@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 uuid) throws WebAPIException {
addVariable("uuid", uuid.toString());
super.sendRequest(address);
}
}