[4.0.0] Fixed Set-up issue

This commit is contained in:
Rsl1122 2017-10-01 21:07:30 +03:00
parent 37d67cb78d
commit 394cd4474e
24 changed files with 290 additions and 76 deletions

View File

@ -201,9 +201,9 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
ImporterManager.registerImporter(new OfflinePlayerImporter());
if (Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
registerPluginChannelListener();
}
// if (Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
// registerPluginChannelListener();
// }
BStats bStats = new BStats(this);
bStats.registerMetrics();

View File

@ -16,7 +16,6 @@ import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.info.BungeeInformationManager;
import main.java.com.djrapitops.plan.systems.info.InformationManager;
import main.java.com.djrapitops.plan.systems.info.pluginchannel.BungeePluginChannelListener;
import main.java.com.djrapitops.plan.systems.info.server.BungeeServerInfoManager;
import main.java.com.djrapitops.plan.systems.listeners.BungeePlayerListener;
import main.java.com.djrapitops.plan.systems.processing.Processor;
@ -96,8 +95,8 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
}
}).runTaskAsynchronously();
getProxy().registerChannel("Plan");
registerListener(new BungeePluginChannelListener(this));
// getProxy().registerChannel("Plan");
// registerListener(new BungeePluginChannelListener(this));
processingQueue = new ProcessingQueue();

View File

@ -42,22 +42,27 @@ public class ServerSpecificSettings {
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;
try {
String path = setting.getKey();
if ("sender".equals(path)) {
continue;
}
String stringValue = setting.getValue();
Object value = getValue(stringValue);
String currentValue = config.get(path).toString();
if (stringValue.equals(currentValue)) {
continue;
}
config.set(path, value);
Log.debug(" " + path + ": " + value);
} catch (NullPointerException e) {
}
String stringValue = setting.getValue();
Object value = getValue(stringValue);
String currentValue = config.getString(path);
if (currentValue.equals(stringValue)) {
continue;
}
config.set(path, value);
Log.debug(" " + path + ": " + value);
changedSomething = true;
}
if (changedSomething) {
plugin.saveConfig();
Log.info("----------------------------------");

View File

@ -88,7 +88,13 @@ public class AnalyzeCommand extends SubCommand {
try {
List<ServerInfo> bukkitServers = plugin.getDB().getServerTable().getBukkitServers();
Optional<ServerInfo> server = bukkitServers.stream().filter(info -> {
String serverIdentifier = args[0];
StringBuilder idBuilder = new StringBuilder(args[0]);
if (args.length > 1) {
for (int i = 1; i < args.length; i++) {
idBuilder.append(" ").append(args[i]);
}
}
String serverIdentifier = idBuilder.toString();
return Integer.toString(info.getId()).equals(serverIdentifier) || info.getName().equalsIgnoreCase(serverIdentifier);
}).findFirst();
if (server.isPresent()) {

View File

@ -43,5 +43,6 @@ public class ManageCommand extends TreeCommand<Plan> {
commands.add(new ManageRemoveCommand(plugin));
commands.add(new ManageClearCommand(plugin));
commands.add(new ManageDumpCommand(plugin));
commands.add(new ManageSetupCommand(plugin));
}
}

View File

@ -0,0 +1,64 @@
package main.java.com.djrapitops.plan.command.commands.manage;
import com.djrapitops.plugin.command.CommandType;
import com.djrapitops.plugin.command.ISender;
import com.djrapitops.plugin.command.SubCommand;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Permissions;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.webserver.webapi.bungee.RequestSetupWebAPI;
import main.java.com.djrapitops.plan.systems.webserver.webapi.universal.PingWebAPI;
import main.java.com.djrapitops.plan.utilities.Check;
/**
* This manage subcommand is used to swap to a different database and reload the
* plugin if the connection to the new database can be established.
*
* @author Rsl1122
* @since 2.3.0
*/
public class ManageSetupCommand extends SubCommand {
private final Plan plugin;
/**
* Class Constructor.
*
* @param plugin Current instance of Plan
*/
public ManageSetupCommand(Plan plugin) {
super("setup",
CommandType.CONSOLE_WITH_ARGUMENTS,
Permissions.MANAGE.getPermission(),
"Set-Up Bungee WebServer connection",
"<Bungee WebServer address>");
this.plugin = plugin;
}
@Override
public String[] addHelp() {
return Locale.get(Msg.CMD_HELP_MANAGE_HOTSWAP).toArray();
}
@Override
public boolean onCommand(ISender sender, String commandLabel, String[] args) {
if (!Check.isTrue(args.length >= 1, Locale.get(Msg.CMD_FAIL_REQ_ONE_ARG).toString(), sender)) {
return true;
}
String address = args[0].toLowerCase();
try {
plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(address);
plugin.getWebServer().getWebAPI().getAPI(RequestSetupWebAPI.class).sendRequest(address);
sender.sendMessage("§aConnection successful, Plan may restart in a few seconds.");
} catch (WebAPIException e) {
Log.toLog(this.getClass().getName(), e);
sender.sendMessage("§cConnection to Bungee WebServer failed: More info on console");
}
return true;
}
}

View File

@ -64,6 +64,10 @@ public class BukkitInformationManager extends InformationManager {
analysis = new Analysis(plugin);
pluginsTabContents = new HashMap<>();
updateConnection();
}
public void updateConnection() {
Optional<String> bungeeConnectionAddress = plugin.getServerInfoManager().getBungeeConnectionAddress();
if (bungeeConnectionAddress.isPresent() && Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
webServerAddress = bungeeConnectionAddress.get();
@ -71,7 +75,6 @@ public class BukkitInformationManager extends InformationManager {
} else {
usingAnotherWebServer = false;
}
}
@Override
@ -216,6 +219,7 @@ public class BukkitInformationManager extends InformationManager {
if (usingAnotherWebServer) {
try {
getWebAPI().getAPI(AnalysisReadyWebAPI.class).sendRequest(webServerAddress, serverUUID);
updateNetworkPageContent();
return;
} catch (WebAPIException e) {
attemptConnection();
@ -299,8 +303,6 @@ public class BukkitInformationManager extends InformationManager {
try {
getWebAPI().getAPI(PostNetworkPageContentWebAPI.class).sendNetworkContent(webServerAddress, HtmlStructure.createServerContainer(plugin));
} catch (WebAPIException e) {
attemptConnection();
updateNetworkPageContent();
}
}
}

View File

@ -37,6 +37,7 @@ public class BukkitPluginChannelListener implements PluginMessageListener {
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(message))) {
String subChannel = in.readUTF();
Log.debug("Received plugin message, channel: " + subChannel);
String[] data = in.readUTF().split("<!>");
String address = data[0];
accessKey = data[1];

View File

@ -28,13 +28,16 @@ public class BungeePluginChannelListener implements Listener {
@EventHandler
public void onPluginMessage(PluginMessageEvent e) {
if (!e.getTag().equalsIgnoreCase("BungeeCord")) {
String tag = e.getTag();
Log.debug(tag);
if (!tag.equalsIgnoreCase("BungeeCord")) {
return;
}
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()))) {
String channel = in.readUTF(); // channel we delivered
if (channel.equals("bungee_address_get")) {
String channel = in.readUTF();
Log.debug("Received plugin channel message on channel: " + channel);
if ("bungee_address_get".equals(channel)) {
ServerInfo server = plugin.getProxy().getPlayer(e.getReceiver().toString()).getServer().getInfo();
sendToBukkit(server);
}
@ -44,10 +47,14 @@ public class BungeePluginChannelListener implements Listener {
}
private void sendToBukkit(ServerInfo server) {
Log.debug("Sending data to bukkit through plugin channel");
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
String accessKey = plugin.getWebServer().getWebAPI().generateNewAccessKey();
try (DataOutputStream out = new DataOutputStream(stream)) {
out.writeUTF("Forward");
out.writeUTF(server.getName());
out.writeUTF("Plan");
out.writeUTF("bungee_address");
out.writeUTF(plugin.getWebServer().getAccessAddress() + "<!>" + accessKey);
}

View File

@ -110,6 +110,14 @@ public class BukkitServerInfoManager {
} catch (Exception ignored) {
/* Ignored */
}
try {
Optional<ServerInfo> bungeeInfo = plugin.getDB().getServerTable().getBungeeInfo();
if (bungeeInfo.isPresent()) {
return Optional.of(bungeeInfo.get().getWebAddress());
}
} catch (SQLException e) {
Log.toLog(this.getClass().getName(), e);
}
return Optional.empty();
}

View File

@ -80,7 +80,7 @@ public class BungeeServerInfoManager {
return serverInfo.getUuid();
}
public boolean attemptConnection(ServerInfo server) {
public boolean attemptConnection(ServerInfo server, String accessCode) {
if (server == null) {
Log.debug("Attempted a connection to a null ServerInfo");
return false;
@ -88,7 +88,13 @@ public class BungeeServerInfoManager {
try {
String webAddress = server.getWebAddress();
Log.debug("Attempting to connect to Bukkit server.. (" + webAddress + ")");
plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class).sendRequest(webAddress);
PingWebAPI pingApi = plugin.getWebServer().getWebAPI().getAPI(PingWebAPI.class);
if (accessCode != null) {
pingApi.sendRequest(webAddress, accessCode);
plugin.getWebServer().getWebAPI().getAPI(ConfigurationWebAPI.class).sendRequest(webAddress, server.getUuid(), accessCode);
} else {
pingApi.sendRequest(webAddress);
}
connectedToServer(server);
return true;
} catch (WebAPIException e) {
@ -97,6 +103,10 @@ public class BungeeServerInfoManager {
}
}
public boolean attemptConnection(ServerInfo server) {
return attemptConnection(server, null);
}
public void sendConfigSettings(UUID serverUUID) {
try {
ServerInfo server = bukkitServers.get(serverUUID);
@ -119,6 +129,10 @@ public class BungeeServerInfoManager {
public void serverConnected(UUID serverUUID) {
Log.info("Received a connection from a Bukkit server..");
if (onlineServers.contains(serverUUID)) {
sendConfigSettings(serverUUID);
return;
}
try {
Optional<ServerInfo> serverInfo = db.getServerTable().getServerInfo(serverUUID);
serverInfo.ifPresent(server -> {

View File

@ -2,10 +2,8 @@ package main.java.com.djrapitops.plan.systems.listeners;
import com.djrapitops.plugin.utilities.player.Fetch;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
import main.java.com.djrapitops.plan.systems.processing.info.BungeePluginChannelSenderProcessor;
import main.java.com.djrapitops.plan.systems.processing.info.NetworkPageUpdateProcessor;
import main.java.com.djrapitops.plan.systems.processing.player.*;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
@ -95,16 +93,15 @@ public class PlanPlayerListener implements Listener {
int playersOnline = plugin.getTpsCountTimer().getLatestPlayersOnline();
BungeePluginChannelSenderProcessor bungeePluginChannelSenderProcessor = null;
if (!plugin.getInfoManager().isUsingAnotherWebServer() && Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
bungeePluginChannelSenderProcessor = new BungeePluginChannelSenderProcessor(player);
}
// BungeePluginChannelSenderProcessor bungeePluginChannelSenderProcessor = null;
// if (!plugin.getInfoManager().isUsingAnotherWebServer() && Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.isFalse()) {
// bungeePluginChannelSenderProcessor = new BungeePluginChannelSenderProcessor(player);
// }
cache.cacheSession(uuid, Session.start(time, world, gm));
plugin.addToProcessQueue(
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
new IPUpdateProcessor(uuid, ip),
new NameProcessor(uuid, playerName, displayName),
bungeePluginChannelSenderProcessor
new NameProcessor(uuid, playerName, displayName)
),
new NetworkPageUpdateProcessor(plugin.getInfoManager())
);

View File

@ -26,6 +26,7 @@ public class BungeePluginChannelSenderProcessor extends Processor<Player> {
@Override
public void process() {
Log.debug("Sending a Bungee Address get Request through plugin channel");
try (ByteArrayOutputStream b = new ByteArrayOutputStream()) {
try (DataOutputStream out = new DataOutputStream(b)) {
out.writeUTF("bungee_address_get");

View File

@ -7,6 +7,7 @@ package main.java.com.djrapitops.plan.systems.webserver;
import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPIManager;
@ -33,6 +34,8 @@ public class APIRequestHandler implements HttpHandler {
Response response = responseHandler.getAPIResponse(request);
response.setResponseHeaders(responseHeaders);
response.send(exchange);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
} finally {
exchange.close();
}

View File

@ -72,14 +72,36 @@ public class APIResponseHandler {
Map<String, String> variables = WebAPI.readVariables(requestBody);
String sender = variables.get("sender");
Log.debug("Received WebAPI Request" + target + " from " + sender);
if (!checkKey(sender)) {
String error = "Server Key not given or invalid";
Log.debug("Request had invalid Server key");
return PageCache.loadPage(error, () -> {
ForbiddenResponse forbidden = new ForbiddenResponse();
forbidden.setContent(error);
return forbidden;
});
boolean isPing = "pingwebapi".equalsIgnoreCase(method);
boolean isSetupRequest = "requestsetupwebapi".equalsIgnoreCase(method);
boolean isPostOriginalSettings = "postoriginalbukkitsettingswebapi".equalsIgnoreCase(method);
boolean skipAuthCheck = isPing || isSetupRequest || isPostOriginalSettings;
// TODO refactor to more methods
if (!skipAuthCheck) {
String accessKey = variables.get("accessKey");
if (accessKey == null) {
if (!checkKey(sender)) {
String error = "Server Key not given or invalid";
Log.debug("Request had invalid Server key: " + sender);
return PageCache.loadPage(error, () -> {
ForbiddenResponse forbidden = new ForbiddenResponse();
forbidden.setContent(error);
return forbidden;
});
}
} else {
if (!webAPI.isAuthorized(accessKey)) {
String error = "Access Key invalid";
Log.debug("Request had invalid Access key: " + accessKey);
return PageCache.loadPage(error, () -> {
ForbiddenResponse forbidden = new ForbiddenResponse();
forbidden.setContent(error);
return forbidden;
});
}
}
}
WebAPI api = webAPI.getAPI(method);

View File

@ -4,6 +4,7 @@
*/
package main.java.com.djrapitops.plan.systems.webserver;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebUserAuthException;
import main.java.com.djrapitops.plan.data.WebUser;
@ -103,6 +104,7 @@ public class ResponseHandler extends APIResponseHandler {
} catch (WebUserAuthException e) {
return PageCache.loadPage("promptAuthorization", PromptAuthorizationResponse::new);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
return new InternalErrorResponse(e, request.getTarget());
}
}

View File

@ -70,7 +70,8 @@ public class WebServer {
new PostInspectPluginsTabWebAPI(),
new PostNetworkPageContentWebAPI(),
new PostOriginalBukkitSettingsWebAPI(),
new RequestPluginsTabWebAPI()
new RequestPluginsTabWebAPI(),
new RequestSetupWebAPI()
);
}
@ -105,7 +106,7 @@ public class WebServer {
enabled = true;
Log.info(Locale.get(Msg.ENABLE_WEBSERVER_INFO).parse(server.getAddress().getPort()));
Log.info(Locale.get(Msg.ENABLE_WEBSERVER_INFO).parse(server.getAddress().getPort()) + " (" + getAccessAddress() + ")");
} catch (IllegalArgumentException | IllegalStateException | IOException e) {
Log.toLog(this.getClass().getName(), e);
enabled = false;

View File

@ -46,14 +46,8 @@ public abstract class WebAPI {
public Response processRequest(IPlan plugin, Map<String, String> variables) {
String sender = variables.get("sender");
if (sender == null) {
String accessKey = variables.get("accessKey");
WebAPIManager apiManager = MiscUtils.getIPlan().getWebServer().getWebAPI();
if (apiManager.isAuthorized(accessKey)) {
apiManager.authorize(accessKey);
} else {
Log.debug(getClass().getSimpleName() + ": Sender not Found");
return badRequest("Sender not present");
}
Log.debug(getClass().getSimpleName() + ": Sender not Found");
return badRequest("Sender not present");
} else {
try {
UUID.fromString(sender);

View File

@ -39,7 +39,7 @@ public class WebAPIManager {
}
public String generateNewAccessKey() throws Exception {
String key = PassEncryptUtil.createHash(UUID.randomUUID().toString()).split(":")[4];
String key = PassEncryptUtil.createHash(UUID.randomUUID().toString().substring(0, 5)).split(":")[4];
accessKeys.add(key);
return key;
}

View File

@ -6,10 +6,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;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.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;
@ -43,9 +40,17 @@ public class ConfigurationWebAPI extends WebAPI {
throw new IllegalStateException("Wrong method call for this WebAPI, call sendRequest(String, UUID, UUID) instead.");
}
public void sendRequest(String address, UUID serverUUID, String accessKey) throws WebAPIException {
if (accessKey != null) {
addVariable("accessKey", accessKey);
}
addVariable("webAddress", PlanBungee.getInstance().getWebServer().getAccessAddress());
sendRequest(address, serverUUID);
}
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()) {
String key = entry.getKey();
Object value = entry.getValue();
@ -87,8 +92,19 @@ public class ConfigurationWebAPI extends WebAPI {
private void addServerSpecificValues(Map<String, Object> configValues, UUID serverUUID) {
ServerSpecificSettings settings = Settings.serverSpecific();
addConfigValue(configValues, Settings.THEME_BASE, settings.getString(serverUUID, Settings.THEME_BASE));
addConfigValue(configValues, Settings.WEBSERVER_PORT, settings.getInt(serverUUID, Settings.WEBSERVER_PORT));
addConfigValue(configValues, Settings.SERVER_NAME, settings.getString(serverUUID, Settings.SERVER_NAME));
String theme = settings.getString(serverUUID, Settings.THEME_BASE);
Integer port = settings.getInt(serverUUID, Settings.WEBSERVER_PORT);
String name = settings.getString(serverUUID, Settings.SERVER_NAME);
if (!Verify.isEmpty(theme)) {
addConfigValue(configValues, Settings.THEME_BASE, theme);
}
if (port != null && port != 0) {
addConfigValue(configValues, Settings.WEBSERVER_PORT, port);
}
if (!Verify.isEmpty(name)) {
addConfigValue(configValues, Settings.SERVER_NAME, name);
}
}
}

View File

@ -0,0 +1,59 @@
/*
* 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.bungee;
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.PlanBungee;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.systems.info.server.ServerInfo;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
import java.util.Map;
import java.util.UUID;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class RequestSetupWebAPI extends WebAPI {
@Override
public Response onRequest(IPlan plugin, Map<String, String> variables) {
if (!Compatibility.isBungeeAvailable()) {
return badRequest("Called a Bukkit server.");
}
String serverUUIDS = variables.get("sender");
String webAddress = variables.get("webAddress");
String accessCode = variables.get("accessKey");
if (!Verify.notNull(serverUUIDS, webAddress, accessCode)) {
return badRequest("Variable was null");
}
ServerInfo serverInfo = new ServerInfo(-1, UUID.fromString(serverUUIDS), "", webAddress, 0);
PlanBungee.getInstance().getServerInfoManager().attemptConnection(serverInfo, accessCode);
return success();
}
@Override
public void sendRequest(String address) throws WebAPIException {
if (!Compatibility.isBukkitAvailable()) {
throw new IllegalStateException("Not supposed to be called on Bungee");
}
Plan plugin = Plan.getInstance();
try {
addVariable("accessKey", plugin.getWebServer().getWebAPI().generateNewAccessKey());
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
}
addVariable("webAddress", plugin.getWebServer().getAccessAddress());
super.sendRequest(address);
}
}

View File

@ -5,13 +5,16 @@
package main.java.com.djrapitops.plan.systems.webserver.webapi.universal;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.Log;
import main.java.com.djrapitops.plan.Plan;
import main.java.com.djrapitops.plan.PlanBungee;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.WebAPIException;
import main.java.com.djrapitops.plan.systems.info.pluginchannel.BukkitPluginChannelListener;
import main.java.com.djrapitops.plan.systems.info.BukkitInformationManager;
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
import main.java.com.djrapitops.plan.systems.webserver.webapi.WebAPI;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
@ -23,9 +26,17 @@ public class PingWebAPI extends WebAPI {
public Response onRequest(IPlan plugin, Map<String, String> variables) {
if (Compatibility.isBungeeAvailable()) {
((PlanBungee) plugin).getServerInfoManager().serverConnected(UUID.fromString(variables.get("sender")));
}
if (Compatibility.isBukkitAvailable() && !plugin.getInfoManager().isUsingAnotherWebServer()) {
plugin.getInfoManager().attemptConnection();
} else if (!plugin.getInfoManager().isUsingAnotherWebServer()) {
try {
String webAddress = variables.get("webAddress");
if (webAddress != null) {
((Plan) plugin).getServerInfoManager().saveBungeeConnectionAddress(webAddress);
}
((BukkitInformationManager) plugin.getInfoManager()).updateConnection();
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
}
}
return success();
}
@ -33,18 +44,15 @@ public class PingWebAPI extends WebAPI {
@Override
public void sendRequest(String address) throws WebAPIException {
if (Compatibility.isBukkitAvailable()) {
String accessKey = BukkitPluginChannelListener.getAccessKey();
if (accessKey != null) {
addVariable("accessKey", accessKey);
}
super.sendRequest(address);
if (accessKey != null) {
BukkitPluginChannelListener.usedAccessKey();
}
} else {
addVariable("webAddress", PlanBungee.getInstance().getWebServer().getAccessAddress());
super.sendRequest(address);
}
}
public void sendRequest(String address, String accessCode) throws WebAPIException {
addVariable("accessKey", accessCode);
sendRequest(address);
}
}

View File

@ -385,8 +385,12 @@ public class HtmlStructure {
}
int i = 0;
StringBuilder b = new StringBuilder();
Collection<String> values = networkPageContents.values();
List<String> values = new ArrayList<>(networkPageContents.values());
int size = values.size();
int extra = size % 3;
for (int j = 0; j < extra; j++) {
values.add("<div class=\"column\"></div>");
}
for (String server : values) {
if (i % 3 == 0) {
b.append("<div class=\"row\">");

View File

@ -1,7 +1,7 @@
name: Plan
author: Rsl1122
main: main.java.com.djrapitops.plan.Plan
version: 3.9.9
version: 4.0.0
softdepend:
- OnTime
- EssentialsX