feat: code
This commit is contained in:
@@ -181,7 +181,7 @@ public class BindRequest {
|
|||||||
public class PlayerBindStatusResponse implements Serializable {
|
public class PlayerBindStatusResponse implements Serializable {
|
||||||
@SerializedName("status") private PlayerBindStatusEnum status;
|
@SerializedName("status") private PlayerBindStatusEnum status;
|
||||||
|
|
||||||
@SerializedName("msg") private String message;
|
@SerializedName("message") private String message;
|
||||||
|
|
||||||
@SerializedName("cached") private boolean cached;
|
@SerializedName("cached") private boolean cached;
|
||||||
|
|
||||||
@@ -276,14 +276,18 @@ public class BindRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<PlayerBindStatusResponse> checkPlayerBindStatus(
|
public CompletableFuture<PlayerBindStatusResponse> checkPlayerBindStatus(
|
||||||
UUID player_uuid, String user_email
|
UUID playerUuid, String userEmail
|
||||||
) {
|
) {
|
||||||
String path = "/server/user-bind-status";
|
String path = "/server/user-bind-status";
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
|
|
||||||
params.put("web_email", user_email);
|
params.put("web_email", userEmail);
|
||||||
params.put("mc_uuid", player_uuid.toString());
|
|
||||||
|
if (playerUuid != null) {
|
||||||
|
String simpleUuid = playerUuid.toString().replace("-", "");
|
||||||
|
params.put("mc_uuid", simpleUuid);
|
||||||
|
}
|
||||||
|
|
||||||
return networkService.getData(path, params)
|
return networkService.getData(path, params)
|
||||||
.thenApply(response -> {
|
.thenApply(response -> {
|
||||||
@@ -352,14 +356,16 @@ public class BindRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<PlayerBindResponse> PlayerBindRequest(
|
public CompletableFuture<PlayerBindResponse> PlayerBindRequest(
|
||||||
String webEmail, String playerUuid, String playerUsername
|
String webEmail, UUID playerUuid, String playerUsername
|
||||||
) {
|
) {
|
||||||
String path = "/server/user-bind";
|
String path = "/server/user-bind";
|
||||||
|
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
|
|
||||||
|
String simpleUuid = playerUuid.toString().replace("-", "");
|
||||||
|
|
||||||
json.addProperty("web_email", webEmail);
|
json.addProperty("web_email", webEmail);
|
||||||
json.addProperty("mc_uuid", playerUuid);
|
json.addProperty("mc_uuid", simpleUuid);
|
||||||
json.addProperty("mc_username", playerUsername);
|
json.addProperty("mc_username", playerUsername);
|
||||||
|
|
||||||
return networkService.postData(path, json)
|
return networkService.postData(path, json)
|
||||||
|
|||||||
@@ -53,12 +53,11 @@ public class PlayerBindListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var response = this.plugin.getBindRequest()
|
var response = this.plugin.getBindRequest().checkPlayerBindStatus(uuid, null).join();
|
||||||
.checkPlayerBindStatus(uuid, event.getConnection().getProfile().getName())
|
|
||||||
.join();
|
|
||||||
|
|
||||||
PlayerBindStatusEnum status = response.getStatus();
|
PlayerBindStatusEnum status = response.getStatus();
|
||||||
|
|
||||||
|
plugin.getSLF4JLogger().info(status.toString());
|
||||||
if (status == PlayerBindStatusEnum.BOUND) {
|
if (status == PlayerBindStatusEnum.BOUND) {
|
||||||
return;
|
return;
|
||||||
} else if (status == PlayerBindStatusEnum.NOT_BOUND) {
|
} else if (status == PlayerBindStatusEnum.NOT_BOUND) {
|
||||||
@@ -85,13 +84,31 @@ public class PlayerBindListener implements Listener {
|
|||||||
audience.showDialog(dialog);
|
audience.showDialog(dialog);
|
||||||
|
|
||||||
PlayerBindResponse bindResponse = dialogResponse.join();
|
PlayerBindResponse bindResponse = dialogResponse.join();
|
||||||
if (bindResponse.getStatus() != PlayerBindEnum.BOUND) {
|
if (bindResponse == null) {
|
||||||
|
audience.closeDialog();
|
||||||
|
connection.disconnect(
|
||||||
|
Component.text("Operation timed out, please try again.", NamedTextColor.RED)
|
||||||
|
);
|
||||||
|
awaitingResponse.remove(uniqueId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bindResponse.getStatus() == PlayerBindEnum.BOUND) {
|
||||||
|
return;
|
||||||
|
} else if (bindResponse.getStatus() == PlayerBindEnum.PENDING) {
|
||||||
|
audience.closeDialog();
|
||||||
|
String msg = "Binding request submitted!\nPlease go to Mineroo.Online to confirm the "
|
||||||
|
+ "binding. After confirmation, please re-enter the server.";
|
||||||
|
connection.disconnect(Component.text(msg, NamedTextColor.GREEN));
|
||||||
|
} else {
|
||||||
audience.closeDialog();
|
audience.closeDialog();
|
||||||
|
|
||||||
String statusStr = (status != null) ? status.toString() : "UNKNOWN_STATUS";
|
String statusStr = (bindResponse.getStatus() != null)
|
||||||
|
? bindResponse.getStatus().toString()
|
||||||
|
: "UNKNOWN_STATUS";
|
||||||
String msg = bindResponse.getMessage();
|
String msg = bindResponse.getMessage();
|
||||||
if (msg == null)
|
if (msg == null)
|
||||||
msg = "Unkown";
|
msg = "Bind failed.";
|
||||||
|
|
||||||
String kickMessage = statusStr + " : " + msg;
|
String kickMessage = statusStr + " : " + msg;
|
||||||
|
|
||||||
@@ -145,7 +162,7 @@ public class PlayerBindListener implements Listener {
|
|||||||
BindRequest bindRequest = plugin.getBindRequest();
|
BindRequest bindRequest = plugin.getBindRequest();
|
||||||
String playerName = conn.getProfile().getName();
|
String playerName = conn.getProfile().getName();
|
||||||
|
|
||||||
bindRequest.PlayerBindRequest(userEmail, uniqueId.toString(), conn.getProfile().getName())
|
bindRequest.PlayerBindRequest(userEmail, uniqueId, conn.getProfile().getName())
|
||||||
.thenAccept(response -> { setConnectionJoinResult(uniqueId, response); })
|
.thenAccept(response -> { setConnectionJoinResult(uniqueId, response); })
|
||||||
.exceptionally(ex -> {
|
.exceptionally(ex -> {
|
||||||
logger.error("Error occurred during bind request for " + playerName, ex);
|
logger.error("Error occurred during bind request for " + playerName, ex);
|
||||||
|
|||||||
Reference in New Issue
Block a user