feat: use clang-format
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package online.mineroo.common;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
@@ -43,14 +48,14 @@ public class BindRequest {
|
||||
* @return A future that completes with true if status is 'bound', false
|
||||
* otherwise
|
||||
*/
|
||||
public CompletableFuture<Boolean> checkBindStatus(String hostname, int port) {
|
||||
public CompletableFuture<Boolean> checkBindStatus(String hostname, String port) {
|
||||
// NetworkService is already configured with BaseURL, only need the path here
|
||||
String path = "/server/server-bind-status";
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
params.put("address", hostname);
|
||||
params.put("port", String.valueOf(port));
|
||||
params.put("port", port);
|
||||
|
||||
return networkService.getData(path, params)
|
||||
.thenApply(response -> {
|
||||
@@ -86,12 +91,26 @@ public class BindRequest {
|
||||
* @param port The server port
|
||||
* @return A future that completes with true if tokens are received
|
||||
*/
|
||||
public CompletableFuture<Boolean> initialMotdVerifyRequest(String hostname, int port) {
|
||||
public CompletableFuture<Boolean> initialMotdVerifyRequest(String hostname, String port) {
|
||||
String path = "/server/motd-verify";
|
||||
|
||||
Integer num_port = -1;
|
||||
if (!"$port".equals(port)) {
|
||||
try {
|
||||
num_port = Integer.valueOf(port);
|
||||
} catch (NumberFormatException ignored) {
|
||||
num_port = 25565;
|
||||
}
|
||||
}
|
||||
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("server_address", hostname);
|
||||
json.addProperty("server_port", port);
|
||||
|
||||
if (num_port == -1) {
|
||||
json.addProperty("server_port", port);
|
||||
} else {
|
||||
json.addProperty("server_port", num_port);
|
||||
}
|
||||
|
||||
return networkService.postData(path, json)
|
||||
.thenApply(response -> {
|
||||
@@ -149,7 +168,6 @@ public class BindRequest {
|
||||
|
||||
return networkService.postData(path, json)
|
||||
.thenApply(response -> {
|
||||
String responseBody = response.getBody();
|
||||
// Assume as long as the request returns successfully and no exception is
|
||||
// thrown, it is considered successful (HTTP 200)
|
||||
// If the API returns a specific {"success": false}, you need to parse the JSON
|
||||
@@ -162,6 +180,152 @@ public class BindRequest {
|
||||
});
|
||||
}
|
||||
|
||||
public class PlayerBindResponse implements Serializable {
|
||||
|
||||
@SerializedName("status")
|
||||
private PlayerBindStatus status;
|
||||
|
||||
@SerializedName("message")
|
||||
private String message;
|
||||
|
||||
@SerializedName("cached")
|
||||
private boolean cached;
|
||||
|
||||
@SerializedName("timestamp")
|
||||
private long timestamp;
|
||||
|
||||
@SerializedName("info")
|
||||
private PlayerBindInfo info;
|
||||
|
||||
// --- Getters ---
|
||||
|
||||
public PlayerBindStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public boolean isCached() {
|
||||
return cached;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public PlayerBindInfo getInfo() {
|
||||
return info;
|
||||
}
|
||||
|
||||
public void setStatus(PlayerBindStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
public static enum PlayerBindStatus {
|
||||
@SerializedName("notBound")
|
||||
NOT_BOUND,
|
||||
|
||||
@SerializedName("bound")
|
||||
BOUND,
|
||||
|
||||
@SerializedName("conflictUser")
|
||||
CONFLICT_USER,
|
||||
|
||||
@SerializedName("conflictPlayer")
|
||||
CONFLICT_PLAYER,
|
||||
|
||||
@SerializedName("error")
|
||||
ERROR
|
||||
}
|
||||
|
||||
public static class PlayerBindInfo implements Serializable {
|
||||
@SerializedName("bound_uuid")
|
||||
private String boundUuid;
|
||||
|
||||
@SerializedName("minecraft_uuid")
|
||||
private String minecraftUuid;
|
||||
|
||||
@SerializedName("bound_user_id")
|
||||
private Integer boundUserId;
|
||||
|
||||
@SerializedName("user_id")
|
||||
private Integer userId;
|
||||
|
||||
// --- Getters ---
|
||||
|
||||
public String getBoundUuid() {
|
||||
return boundUuid;
|
||||
}
|
||||
|
||||
public String getMinecraftUuid() {
|
||||
return minecraftUuid;
|
||||
}
|
||||
|
||||
public Integer getBoundUserId() {
|
||||
return boundUserId;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public String getEffectiveUuid() {
|
||||
return minecraftUuid != null ? minecraftUuid : boundUuid;
|
||||
}
|
||||
|
||||
public Integer getEffectiveUserId() {
|
||||
return userId != null ? userId : boundUserId;
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerBindResponse createErrorResponse(String errorMessage) {
|
||||
PlayerBindResponse errorRes = new PlayerBindResponse();
|
||||
errorRes.setStatus(PlayerBindStatus.ERROR);
|
||||
errorRes.setMessage(errorMessage);
|
||||
return errorRes;
|
||||
}
|
||||
|
||||
public CompletableFuture<PlayerBindResponse> checkPlayerBindStatus(UUID player_uuid, String user_email) {
|
||||
String path = "/server/user-bind-status";
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
params.put("user_email", user_email);
|
||||
params.put("player_uuid", player_uuid.toString());
|
||||
|
||||
return networkService.getData(path, params)
|
||||
.thenApply(response -> {
|
||||
Gson gson = new Gson();
|
||||
String responseBody = response.getBody();
|
||||
|
||||
if (response.getStatusCode() != 200) {
|
||||
try {
|
||||
return gson.fromJson(responseBody, PlayerBindResponse.class);
|
||||
} catch (Exception ignored) {
|
||||
return createErrorResponse("HTTP Error: " + response.getStatusCode());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return gson.fromJson(responseBody, PlayerBindResponse.class);
|
||||
} catch (Exception e) {
|
||||
logger.error("Mineroo Bind: Failed to parse JSON", e);
|
||||
return createErrorResponse("JSON Parse Error");
|
||||
}
|
||||
})
|
||||
.exceptionally(e -> {
|
||||
logger.error("Mineroo Bind: Network exception", e);
|
||||
return createErrorResponse("Network Error: " + e.getMessage());
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the MOTD token received from the API.
|
||||
*
|
||||
|
||||
@@ -2,9 +2,10 @@ package online.mineroo.common;
|
||||
|
||||
public class ProtocolConstants {
|
||||
// Protocol channel name
|
||||
public static String PROTOCOL_CHANNEL = "mineroo:plugin:api";
|
||||
public static String PROTOCOL_CHANNEL = "mineroo:net";
|
||||
|
||||
// Sub-channel/event names
|
||||
public static String API_REQUEST = "API_REQUEST";
|
||||
public static String API_REQUEST = "OAPI_REQUEST";
|
||||
public static String API_RESPONSE = "OAPI_RESPONSE";
|
||||
public static String BIND_MOTD_TOKEN = "SET_MOTD_TOKEN";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user