leejunyoung5819 mc-paper-plugin-test-mcp-26.3
공개마인크래프트 26.3 Paper 서버의 플러그인 테스트를 하려는 AI 에이전트를 위한 MCP 도구
| 1 | package dev.mctester.bridge; |
| 2 | |
| 3 | import com.google.gson.JsonArray; |
| 4 | import com.google.gson.JsonObject; |
| 5 | import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; |
| 6 | import net.minecraft.network.chat.Component; |
| 7 | |
| 8 | import java.util.ArrayDeque; |
| 9 | |
| 10 | /** Ring buffer of everything the client received in chat / action bar, with sequence numbers. */ |
| 11 | public final class ChatLog { |
| 12 | private static final int MAX = 1000; |
| 13 | private static final ArrayDeque<JsonObject> BUF = new ArrayDeque<>(); |
| 14 | private static long seq = 0; |
| 15 | |
| 16 | private ChatLog() {} |
| 17 | |
| 18 | static void register() { |
| 19 | ClientReceiveMessageEvents.GAME.register((message, overlay) -> add(overlay ? "actionbar" : "game", message, null)); |
| 20 | ClientReceiveMessageEvents.CHAT.register((message, signed, sender, params, ts) -> |
| 21 | add("chat", message, sender == null ? null : sender.name())); |
| 22 | } |
| 23 | |
| 24 | public static synchronized void add(String type, Component message, String sender) { |
| 25 | JsonObject o = new JsonObject(); |
| 26 | o.addProperty("seq", ++seq); |
| 27 | o.addProperty("time", System.currentTimeMillis()); |
| 28 | o.addProperty("type", type); |
| 29 | if (sender != null) o.addProperty("sender", sender); |
| 30 | o.addProperty("text", message.getString()); |
| 31 | BUF.addLast(o); |
| 32 | while (BUF.size() > MAX) BUF.removeFirst(); |
| 33 | } |
| 34 | |
| 35 | public static synchronized JsonObject since(long after) { |
| 36 | JsonArray arr = new JsonArray(); |
| 37 | for (JsonObject o : BUF) if (o.get("seq").getAsLong() > after) arr.add(o); |
| 38 | JsonObject r = new JsonObject(); |
| 39 | r.addProperty("next", seq); |
| 40 | r.add("messages", arr); |
| 41 | return r; |
| 42 | } |
| 43 | } |