Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ public static ArrayResult error(String error) {
* @return ObjectResult containing the parsed data or error
*/
public static ObjectResult parseObject(String responseBody, String context) {
// Handle null or empty response
if (responseBody == null || responseBody.trim().isEmpty()) {
LOGGER.warning(context + " - Response body is empty or null");
return ObjectResult.error("Empty response from server");
}

// Check for HTML responses (common error pages)
String trimmed = responseBody.trim();
if (trimmed.startsWith("<") || trimmed.startsWith("<!")) {
LOGGER.warning(context + " - Received HTML instead of JSON (possible error page)");
return ObjectResult.error("Server returned HTML instead of JSON");
}

try {
JSONObject response = new JSONObject(responseBody);

Expand Down Expand Up @@ -150,6 +163,11 @@ public static ObjectResult parseObject(String responseBody, String context) {
} catch (JSONException e) {
String error = "Failed to parse response: " + e.getMessage();
LOGGER.warning(context + " - " + error);
// Log the actual response for debugging (truncated for safety)
String preview = responseBody.length() > 200
? responseBody.substring(0, 200) + "..."
: responseBody;
LOGGER.warning(context + " - Response body: " + preview);
return ObjectResult.error(error);
}
}
Expand All @@ -163,6 +181,19 @@ public static ObjectResult parseObject(String responseBody, String context) {
* @return ArrayResult containing the parsed array or error
*/
public static ArrayResult parseArray(String responseBody, String context) {
// Handle null or empty response
if (responseBody == null || responseBody.trim().isEmpty()) {
LOGGER.warning(context + " - Response body is empty or null");
return ArrayResult.error("Empty response from server");
}

// Check for HTML responses (common error pages)
String trimmed = responseBody.trim();
if (trimmed.startsWith("<") || trimmed.startsWith("<!")) {
LOGGER.warning(context + " - Received HTML instead of JSON (possible error page)");
return ArrayResult.error("Server returned HTML instead of JSON");
}

try {
JSONObject response = new JSONObject(responseBody);

Expand All @@ -188,6 +219,11 @@ public static ArrayResult parseArray(String responseBody, String context) {
} catch (JSONException e) {
String error = "Failed to parse response: " + e.getMessage();
LOGGER.warning(context + " - " + error);
// Log the actual response for debugging (truncated for safety)
String preview = responseBody.length() > 200
? responseBody.substring(0, 200) + "..."
: responseBody;
LOGGER.warning(context + " - Response body: " + preview);
return ArrayResult.error(error);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public static String createMatch(Player player1, Player player2) {
WorldCreator creator = new WorldCreator(worldName);
creator.type(WorldType.FLAT);
creator.generateStructures(false); // No structures like villages
// Specify flat world generator settings to avoid "No key layers" warning
// Format: minecraft:bedrock,2*minecraft:dirt,minecraft:grass_block;minecraft:plains
creator.generatorSettings("{\"layers\":[{\"block\":\"minecraft:bedrock\",\"height\":1},{\"block\":\"minecraft:stone\",\"height\":2},{\"block\":\"minecraft:grass_block\",\"height\":1}],\"biome\":\"minecraft:plains\"}");

World world = creator.createWorld();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,9 @@ private void clearPlayerToken(Plugin plugin, String playerId, String matchId) {
JSONObject data = result.optJSONObject("data");
if (data != null && data.optBoolean("success", false)) {
LOGGER.info("Cleared token for player " + playerId + " in match " + matchId);
} else {
// Token not cleared (likely match not in "Waiting" status) - this is expected
String error = data != null ? data.optString("error", "") : "";
LOGGER.info("Token not cleared for player " + playerId + ": " + error);
}
// If token wasn't cleared, it's expected (match not in "Waiting" status)
// No need to log - this is normal for finished/playing matches
}
} else {
LOGGER.warning("Failed to clear token: HTTP " + responseCode);
Expand Down