feat: complete in-game commands, GUIs, admin panel fixes, and launcher enhancements
This commit is contained in:
1 parent
a9ff92e1d1
commit
752f0cc43d
34 files changed
+4170
-181
No files matched your search
@@ -119,6 +119,10 @@ public final class Integration implements AutoCloseable {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public PanelClient client() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public ChunkCheckResult checkChunk(String dimension, int chunkX, int chunkZ, UUID uuid) {
|
||||
return client.checkChunk(dimension, chunkX, chunkZ, uuid);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ public record Settings(
|
||||
boolean guildsEnabled,
|
||||
boolean landClaimingEnabled,
|
||||
boolean socialEnabled,
|
||||
boolean chatPrefixesEnabled
|
||||
boolean chatPrefixesEnabled,
|
||||
boolean essentialsEnabled,
|
||||
boolean economyEnabled
|
||||
) {
|
||||
public Settings {
|
||||
if (panel == null || panel.getHost() == null || panel.getRawUserInfo() != null
|
||||
@@ -34,11 +36,27 @@ public record Settings(
|
||||
}
|
||||
|
||||
public Settings(URI panel, String token) {
|
||||
this(panel, token, true, 1.0, 1.5, true, true, true, true, true, true);
|
||||
this(panel, token, true, 1.0, 1.5, true, true, true, true, true, true, true, true);
|
||||
}
|
||||
|
||||
public Settings(
|
||||
URI panel,
|
||||
String token,
|
||||
boolean levelingEnabled,
|
||||
double globalXpMultiplier,
|
||||
double serverXpMultiplier,
|
||||
boolean questsEnabled,
|
||||
boolean achievementsEnabled,
|
||||
boolean guildsEnabled,
|
||||
boolean landClaimingEnabled,
|
||||
boolean socialEnabled,
|
||||
boolean chatPrefixesEnabled
|
||||
) {
|
||||
this(panel, token, levelingEnabled, globalXpMultiplier, serverXpMultiplier, questsEnabled, achievementsEnabled, guildsEnabled, landClaimingEnabled, socialEnabled, chatPrefixesEnabled, true, true);
|
||||
}
|
||||
|
||||
public static Settings of(String panel, String token) {
|
||||
return of(panel, token, true, 1.0, 1.5, true, true, true, true, true, true);
|
||||
return of(panel, token, true, 1.0, 1.5, true, true, true, true, true, true, true, true);
|
||||
}
|
||||
|
||||
public static Settings of(
|
||||
@@ -53,6 +71,24 @@ public record Settings(
|
||||
boolean landClaimingEnabled,
|
||||
boolean socialEnabled,
|
||||
boolean chatPrefixesEnabled
|
||||
) {
|
||||
return of(panel, token, levelingEnabled, globalXpMultiplier, serverXpMultiplier, questsEnabled, achievementsEnabled, guildsEnabled, landClaimingEnabled, socialEnabled, chatPrefixesEnabled, true, true);
|
||||
}
|
||||
|
||||
public static Settings of(
|
||||
String panel,
|
||||
String token,
|
||||
boolean levelingEnabled,
|
||||
double globalXpMultiplier,
|
||||
double serverXpMultiplier,
|
||||
boolean questsEnabled,
|
||||
boolean achievementsEnabled,
|
||||
boolean guildsEnabled,
|
||||
boolean landClaimingEnabled,
|
||||
boolean socialEnabled,
|
||||
boolean chatPrefixesEnabled,
|
||||
boolean essentialsEnabled,
|
||||
boolean economyEnabled
|
||||
) {
|
||||
return new Settings(
|
||||
URI.create(panel.trim().replaceAll("/+$", "")),
|
||||
@@ -65,7 +101,9 @@ public record Settings(
|
||||
guildsEnabled,
|
||||
landClaimingEnabled,
|
||||
socialEnabled,
|
||||
chatPrefixesEnabled
|
||||
chatPrefixesEnabled,
|
||||
essentialsEnabled,
|
||||
economyEnabled
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,6 +125,8 @@ public record Settings(
|
||||
guilds.land_claiming=true
|
||||
social.enabled=true
|
||||
social.chat_prefixes=true
|
||||
essentials.enabled=true
|
||||
economy.enabled=true
|
||||
""";
|
||||
Files.writeString(path, defaultProps, StandardCharsets.UTF_8);
|
||||
}
|
||||
@@ -105,7 +145,9 @@ public record Settings(
|
||||
Boolean.parseBoolean(properties.getProperty("guilds.enabled", "true")),
|
||||
Boolean.parseBoolean(properties.getProperty("guilds.land_claiming", "true")),
|
||||
Boolean.parseBoolean(properties.getProperty("social.enabled", "true")),
|
||||
Boolean.parseBoolean(properties.getProperty("social.chat_prefixes", "true"))
|
||||
Boolean.parseBoolean(properties.getProperty("social.chat_prefixes", "true")),
|
||||
Boolean.parseBoolean(properties.getProperty("essentials.enabled", "true")),
|
||||
Boolean.parseBoolean(properties.getProperty("economy.enabled", "true"))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user