Bridge editor requests to AstraPlus integrated server

This commit is contained in:
2026-09-11 21:34:50 +03:00
parent fd082ea638
commit 5541d291e4
4 changed files with 46 additions and 2 deletions
@@ -23,7 +23,7 @@ public final class EditorConnection {
public void register(RegisterPayloadHandlersEvent event) {
event.registrar("1").optional()
.playToServer(EditorRequest.TYPE, EditorRequest.CODEC, (request, context) -> {})
.playToServer(EditorRequest.TYPE, EditorRequest.CODEC, LocalEditorServer::handle)
.playToClient(EditorResponse.TYPE, EditorResponse.CODEC, (response, context) -> receive(response));
}
@@ -0,0 +1,23 @@
package online.astradev.plus.editor.network;
import java.util.function.Consumer;
import net.neoforged.neoforge.network.handling.IPayloadContext;
/** Optional bridge to the integrated server. All permissions and validation remain in AstraPlus. */
final class LocalEditorServer {
static void handle(EditorRequest request, IPayloadContext context) {
try {
var method = Class.forName("online.astradev.plus.editor.server.PlusEditorNetwork")
.getMethod("handleLocal", String.class, IPayloadContext.class, Consumer.class);
Consumer<String> reply = json -> context.reply(new EditorResponse(json));
method.invoke(null, request.json(), context, reply);
} catch (ReflectiveOperationException failure) {
var response = new com.google.gson.JsonObject();
try { response.add("requestId", com.google.gson.JsonParser.parseString(request.json()).getAsJsonObject().get("requestId")); }
catch (RuntimeException ignored) { response.addProperty("requestId", -1); }
response.addProperty("ok", false);
response.addProperty("message", "Для редактора в одиночной игре нужен AstraPlus 0.5.45 или новее.");
context.reply(new EditorResponse(response.toString()));
}
}
}