feat: complete in-game commands, GUIs, admin panel fixes, and launcher enhancements

This commit is contained in:
scoped committed 2026-09-29 12:14:16 -04:00
1 parent a9ff92e1d1
commit 752f0cc43d
34 files changed
+4170 -181

No files matched your search

@@ -14,24 +14,33 @@ public final class PanelClient {
public PanelClient(Settings settings) { this.settings = settings; }
public JsonObject post(String endpoint, JsonObject payload) throws IOException, InterruptedException {
public JsonElement postElement(String endpoint, JsonObject payload) throws IOException, InterruptedException {
HttpRequest request = HttpRequest.newBuilder(URI.create(settings.panel() + "/api/server/v1/" + endpoint))
.timeout(Duration.ofSeconds(5))
.header("Authorization", "Bearer " + settings.token())
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(payload.toString())).build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() != 200) {
// Never log the token, request body, or an untrusted HTML error page.
throw new IOException("Panel " + endpoint + " returned HTTP " + response.statusCode());
if (response.statusCode() < 200 || response.statusCode() >= 300) {
String msg = "HTTP " + response.statusCode();
try {
JsonObject err = JsonParser.parseString(response.body()).getAsJsonObject();
if (err.has("message")) msg = err.get("message").getAsString();
else if (err.has("error")) msg = err.get("error").getAsString();
} catch (Exception ignored) {}
throw new IOException(msg);
}
try {
return JsonParser.parseString(response.body()).getAsJsonObject();
return JsonParser.parseString(response.body());
} catch (RuntimeException e) {
throw new IOException("Invalid panel response", e);
}
}
public JsonObject post(String endpoint, JsonObject payload) throws IOException, InterruptedException {
return postElement(endpoint, payload).getAsJsonObject();
}
public static String verdict(JsonObject response) throws IOException {
JsonElement allowed = response.get("allowed");
if (allowed == null || !allowed.isJsonPrimitive() || !allowed.getAsJsonPrimitive().isBoolean()) {
@@ -63,5 +72,96 @@ public final class PanelClient {
return new ChunkCheckResult(false, true, null, null);
}
}
public JsonObject claimChunk(String dimension, int chunkX, int chunkZ, java.util.UUID uuid) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("uuid", uuid.toString());
req.addProperty("dimension", dimension);
req.addProperty("chunk_x", chunkX);
req.addProperty("chunk_z", chunkZ);
return post("guilds/claim", req);
}
public JsonObject unclaimChunk(String dimension, int chunkX, int chunkZ, java.util.UUID uuid) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("uuid", uuid.toString());
req.addProperty("dimension", dimension);
req.addProperty("chunk_x", chunkX);
req.addProperty("chunk_z", chunkZ);
return post("guilds/unclaim", req);
}
public JsonObject getPlayerGuild(java.util.UUID uuid) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("uuid", uuid.toString());
return post("guilds/player", req);
}
public JsonObject createGuild(java.util.UUID uuid, String username, String name, String tag) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("uuid", uuid.toString());
req.addProperty("username", username);
req.addProperty("name", name);
req.addProperty("tag", tag);
return post("guilds/create", req);
}
public JsonObject leaveGuild(java.util.UUID uuid) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("uuid", uuid.toString());
return post("guilds/leave", req);
}
public double getBalance(java.util.UUID uuid, String username) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("uuid", uuid.toString());
req.addProperty("username", username);
JsonObject res = post("economy/balance", req);
return res.has("balance") ? res.get("balance").getAsDouble() : 0.0;
}
public double transfer(java.util.UUID fromUuid, String fromName, java.util.UUID toUuid, String toName, double amount, String description) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("from_uuid", fromUuid.toString());
req.addProperty("from_name", fromName);
req.addProperty("to_uuid", toUuid.toString());
req.addProperty("to_name", toName);
req.addProperty("amount", amount);
req.addProperty("description", description);
JsonObject res = post("economy/transfer", req);
return res.has("from_balance") ? res.get("from_balance").getAsDouble() : 0.0;
}
public void syncBalance(java.util.UUID uuid, String username, double newBalance) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("uuid", uuid.toString());
req.addProperty("username", username);
req.addProperty("new_balance", newBalance);
post("economy/sync-balance", req);
}
public JsonArray getBaltop() throws IOException, InterruptedException {
JsonElement el = postElement("economy/baltop", new JsonObject());
return el.isJsonArray() ? el.getAsJsonArray() : new JsonArray();
}
public JsonObject marketList(java.util.UUID sellerUuid, String sellerName, String itemId, String itemName, int amount, double price) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("seller_uuid", sellerUuid.toString());
req.addProperty("seller_name", sellerName);
req.addProperty("item_id", itemId);
req.addProperty("item_name", itemName);
req.addProperty("amount", amount);
req.addProperty("price", price);
return post("economy/market/list", req);
}
public JsonObject marketBuy(long listingId, java.util.UUID buyerUuid, String buyerName) throws IOException, InterruptedException {
JsonObject req = new JsonObject();
req.addProperty("listing_id", listingId);
req.addProperty("buyer_uuid", buyerUuid.toString());
req.addProperty("buyer_name", buyerName);
return post("economy/market/buy", req);
}
}