mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 19:47:49 +01:00
Fixed /plan m setup command not working & added more error cases to it
This commit is contained in:
parent
b2f0e8c8c8
commit
c218627ede
@ -1,9 +1,6 @@
|
|||||||
package com.djrapitops.plan.command.commands.manage;
|
package com.djrapitops.plan.command.commands.manage;
|
||||||
|
|
||||||
import com.djrapitops.plan.api.exceptions.connection.BadRequestException;
|
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||||
import com.djrapitops.plan.api.exceptions.connection.ForbiddenException;
|
|
||||||
import com.djrapitops.plan.api.exceptions.connection.UnauthorizedServerException;
|
|
||||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
|
||||||
import com.djrapitops.plan.system.info.InfoSystem;
|
import com.djrapitops.plan.system.info.InfoSystem;
|
||||||
import com.djrapitops.plan.system.settings.Permissions;
|
import com.djrapitops.plan.system.settings.Permissions;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
import com.djrapitops.plan.system.settings.Settings;
|
||||||
@ -47,7 +44,7 @@ public class ManageSetupCommand extends SubCommand {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String address = args[0].toLowerCase();
|
String address = args[0].toLowerCase();
|
||||||
if (!address.startsWith("http")) {
|
if (!address.startsWith("http") || address.endsWith("://")) {
|
||||||
sender.sendMessage("§cMake sure you're using the full address (Starts with http:// or https://) - Check Bungee enable log for the full address.");
|
sender.sendMessage("§cMake sure you're using the full address (Starts with http:// or https://) - Check Bungee enable log for the full address.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -67,9 +64,13 @@ public class ManageSetupCommand extends SubCommand {
|
|||||||
sender.sendMessage("§eConnection succeeded, but Receiving server was a Bukkit server. Use Bungee address instead.");
|
sender.sendMessage("§eConnection succeeded, but Receiving server was a Bukkit server. Use Bungee address instead.");
|
||||||
} catch (UnauthorizedServerException e) {
|
} catch (UnauthorizedServerException e) {
|
||||||
sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support");
|
sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support");
|
||||||
|
} catch (ConnectionFailException e) {
|
||||||
|
sender.sendMessage("§eConnection failed: " + e.getMessage());
|
||||||
|
} catch (InternalErrorException e) {
|
||||||
|
sender.sendMessage("§eConnection succeeded. " + e.getMessage() + ", check possible ErrorLog on receiving server's debug page.");
|
||||||
} catch (WebException e) {
|
} catch (WebException e) {
|
||||||
Log.toLog(this.getClass(), e);
|
Log.toLog(this.getClass(), e);
|
||||||
sender.sendMessage("§cConnection to Bungee WebServer failed: More info on console");
|
sender.sendMessage("§cConnection to Bungee WebServer failed: More info in the error log.");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import com.djrapitops.plan.system.info.request.InfoRequest;
|
|||||||
import com.djrapitops.plan.system.info.request.SetupRequest;
|
import com.djrapitops.plan.system.info.request.SetupRequest;
|
||||||
import com.djrapitops.plan.system.webserver.Request;
|
import com.djrapitops.plan.system.webserver.Request;
|
||||||
import com.djrapitops.plan.system.webserver.response.Response;
|
import com.djrapitops.plan.system.webserver.response.Response;
|
||||||
|
import com.djrapitops.plugin.api.utility.log.Log;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -26,32 +27,43 @@ public class ConnectionIn {
|
|||||||
public ConnectionIn(Request httpRequest, InfoRequest infoRequest) throws WebException {
|
public ConnectionIn(Request httpRequest, InfoRequest infoRequest) throws WebException {
|
||||||
Verify.nullCheck(httpRequest, infoRequest);
|
Verify.nullCheck(httpRequest, infoRequest);
|
||||||
|
|
||||||
Map<String, String> variables = readVariables(httpRequest);
|
this.variables = readVariables(httpRequest);
|
||||||
checkAuthentication(variables);
|
|
||||||
|
|
||||||
this.variables = variables;
|
|
||||||
this.infoRequest = infoRequest;
|
this.infoRequest = infoRequest;
|
||||||
|
|
||||||
|
checkAuthentication();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAuthentication(Map<String, String> variables) throws WebException {
|
private void checkAuthentication() throws WebException {
|
||||||
String sender = variables.get("sender");
|
UUID serverUUID = getServerUUID();
|
||||||
Verify.nullCheck(sender, () -> new BadRequestException("Sender ('sender') variable not supplied in the request."));
|
|
||||||
UUID serverUUID = UUID.fromString(sender);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!Database.getActive().check().isServerInDatabase(serverUUID)) {
|
if (Database.getActive().check().isServerInDatabase(serverUUID)) {
|
||||||
if (infoRequest instanceof SetupRequest) {
|
return;
|
||||||
if (ConnectionSystem.isSetupAllowed()) {
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
throw new ForbiddenException("Setup not enabled on this server, use commands to enable.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new UnauthorizedServerException(sender + " (Sender) was not found from database");
|
|
||||||
}
|
}
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
throw new TransferDatabaseException(e);
|
throw new TransferDatabaseException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.debug("ConnectionIn: " + infoRequest.getClass().getSimpleName());
|
||||||
|
|
||||||
|
if (infoRequest instanceof SetupRequest) {
|
||||||
|
if (!ConnectionSystem.isSetupAllowed()) {
|
||||||
|
throw new ForbiddenException("Setup not enabled on this server, use commands to enable.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new UnauthorizedServerException(serverUUID + " (Sender) was not found from database");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private UUID getServerUUID() throws BadRequestException {
|
||||||
|
String sender = variables.get("sender");
|
||||||
|
Verify.nullCheck(sender, () -> new BadRequestException("Sender ('sender') variable not supplied in the request."));
|
||||||
|
|
||||||
|
try {
|
||||||
|
return UUID.fromString(sender);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new BadRequestException("Sender ('sender') was not a valid UUID: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> readVariables(Request request) throws WebException {
|
private Map<String, String> readVariables(Request request) throws WebException {
|
||||||
|
Loading…
Reference in New Issue
Block a user