leejunyoung5819 mc-paper-plugin-test-mcp-26.3
공개마인크래프트 26.3 Paper 서버의 플러그인 테스트를 하려는 AI 에이전트를 위한 MCP 도구
| 1 | package dev.mctester.bridge; |
| 2 | |
| 3 | import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; |
| 4 | |
| 5 | import java.util.Iterator; |
| 6 | import java.util.concurrent.CompletableFuture; |
| 7 | import java.util.concurrent.ConcurrentLinkedQueue; |
| 8 | |
| 9 | /** Client tick counter + "run after N ticks" scheduling (runs on the client thread). */ |
| 10 | public final class Ticks { |
| 11 | private record Task(long due, Runnable run) {} |
| 12 | |
| 13 | private static final ConcurrentLinkedQueue<Task> TASKS = new ConcurrentLinkedQueue<>(); |
| 14 | private static volatile long tick = 0; |
| 15 | |
| 16 | private Ticks() {} |
| 17 | |
| 18 | static void register() { |
| 19 | ClientTickEvents.END_CLIENT_TICK.register(mc -> { |
| 20 | tick++; |
| 21 | for (Iterator<Task> it = TASKS.iterator(); it.hasNext(); ) { |
| 22 | Task t = it.next(); |
| 23 | if (t.due <= tick) { |
| 24 | it.remove(); |
| 25 | try { |
| 26 | t.run.run(); |
| 27 | } catch (Throwable e) { |
| 28 | QaBridgeClient.LOG.error("qa-bridge: scheduled task failed", e); |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | }); |
| 33 | } |
| 34 | |
| 35 | public static long now() { |
| 36 | return tick; |
| 37 | } |
| 38 | |
| 39 | public static void later(int ticks, Runnable r) { |
| 40 | TASKS.add(new Task(tick + Math.max(1, ticks), r)); |
| 41 | } |
| 42 | |
| 43 | public static CompletableFuture<Void> wait(int ticks) { |
| 44 | CompletableFuture<Void> f = new CompletableFuture<>(); |
| 45 | later(ticks, () -> f.complete(null)); |
| 46 | return f; |
| 47 | } |
| 48 | } |