Paper from TypeScript
Your game sees the server’s public JVM through GraalJS, typed by @minekube/paper. No package ships these types: the runtime generates them from your server’s own Paper, Adventure, Brigadier and JOML jars when the server starts, and mk dev . copies them into your project’s types/paper and reinstalls. Until the first mk dev ., bun run check cannot find them; never edit them. Read the types instead of guessing: types/paper/paper.d.ts has every class with Paper’s own names, overloads, nullability and @deprecated marks.
There is no wrapper in between. If something cannot be done through the server’s API from TypeScript, it is a missing capability of the runtime: report it to Minekube instead of working around it.
Classes
Section titled “Classes”Java.type("org.bukkit.Material")returns the class: static fields and methods, enum constants, andnewfor constructors. Nested classes use$:Java.type("org.bukkit.Particle$DustOptions"). The name is checked againstJavaClasses.- Instances are typed by namespace:
org.bukkit.entity.Player,org.bukkit.World. Use these in your signatures. value instanceof Signnarrows, withconst Sign = Java.type("org.bukkit.block.Sign").- Getters are methods:
player.getName(), neverplayer.name. - Compare enum constants with
===:event.getAction() === Action.RIGHT_CLICK_BLOCK. - Parameter names come out as
arg0,arg1when the API jar has none. The JDK classes have real names.
Values crossing the boundary
Section titled “Values crossing the boundary”- Null: methods annotated
@NullablereturnT | null. Check fornull, notundefined. - Numbers: a JS number goes into
int,longanddoubleparameters when the value fits;1.5into anintthrows. The runtime also converts numbers tofloat, sonew DustOptions(color, 1.4)works. - Strings: JS strings pass as
StringandCharSequence. - Functions: a JS function passes where Java expects a functional interface, such as
Consumer,RunnableorPredicate. - Collections: a
java.util.Listindexes like an array (list[0],list.length) and iterates withfor…of.Java.from(collection)copies into a JS array;Java.to(array, "java.lang.String[]")copies out. - Varargs: pass the values one by one.
Exceptions and resources: Jvm
Section titled “Exceptions and resources: Jvm”The types mark what a Java call obliges you to handle, and only Jvm from @minekube/games lets you make such a call:
- A method that declares checked exceptions (most of
java.nio.file.Files,BufferedReader.readLine) takesthis: Guarded. Calling it directly does not compile, even as a statement.Jvm.attempt(receiver, (guarded) => guarded.method(...))returns anEffectwhose failure is the Java exception itself, typed from the declaration. - A call that hands you something to close (
Files.newBufferedReader,Files.lines,new FileInputStream(...)) returnsResource<A>.Jvm.acquire(receiver, (guarded) => ...)opens it and closes it when the Effect’s Scope closes. In a game, that is at the latest when the revision stops. - The receiver is the object, or the class from
Java.typefor static methods and constructors.
import { Jvm, Paper } from "@minekube/games";import { Effect } from "effect";
const Files = Java.type("java.nio.file.Files");const FileAlreadyExists = Java.type("java.nio.file.FileAlreadyExistsException");
// The first line of saves/scores.txt in the game's data folder.const firstScore = Effect.gen(function* () { const { plugin } = yield* Paper; const saves = plugin.getDataFolder().toPath().resolve("saves"); yield* Jvm.attempt(Files, (files) => files.createDirectory(saves)).pipe( Effect.catchIf((error) => error instanceof FileAlreadyExists, () => Effect.void), ); const reader = yield* Jvm.acquire(Files, (files) => files.newBufferedReader(saves.resolve("scores.txt"))); return yield* Jvm.attempt(reader, (open) => open.readLine());}).pipe(Effect.scoped);Every other Java call stays a plain call. What it throws (IllegalArgumentException, NullPointerException) is a bug; inside an Effect it becomes a defect, which the runtime reports.
Data for messages: generated Schemas
Section titled “Data for messages: generated Schemas”Messages, Models and Command args are data. For Java values, use the generated Schemas from @minekube/paper/schemas; never write your own Schema for a Paper type.
| Java type | Schemas[...] |
Data form |
|---|---|---|
java.util.UUID |
Schemas["java.util.UUID"] |
A checked UUID string, branded java.util.UUID |
Every enum of the scanned jars (org.bukkit.Material, org.bukkit.Particle, org.bukkit.GameMode, …) |
Schemas["org.bukkit.Material"] |
A union of the constant names |
Every registry type that is not an enum (org.bukkit.Sound, org.bukkit.block.Biome, org.bukkit.enchantments.Enchantment, …) |
Schemas["org.bukkit.Sound"] |
Its key, such as minecraft:entity.player.levelup, branded by class |
fromJava(className, value) from @minekube/games turns a Java value into its data form for a message; toJava(className, data) turns it back inside a Command. Registry types look their keys up in the server’s registry, so convert them in game.ts, not in the rules. Schemas[...].make(...) builds checked values in tests.
If a Java type you want in a message has no Schema, report it to Minekube.
Threads and time
Section titled “Threads and time”- Game code runs only on the server thread. Events Paper fires on another thread (the status ping, async chat, pre-login) wait for the server thread and run there, so your handler can still cancel them. They are skipped, with a warning, if the server thread does not answer within a second.
- The same holds for any JS function you hand to Java: a
runTaskAsynchronouslytask, aCompletableFuturecallback, a Brigadier command. The runtime runs it on the server thread. Without a result it is queued; with one, the calling thread waits up to a second, then the call fails. So an async task is no way to move work off the tick: JS never runs in parallel. - Name the overload where a method has overloads for several interfaces, such as
runTaskAsynchronously(plugin, Runnable)and(plugin, Consumer). GraalJS cannot tell which one a JS function means:scheduler["runTaskAsynchronously(org.bukkit.plugin.Plugin,java.lang.Runnable)"](plugin, () => ...). - Timers run on server ticks.
setTimeoutandsetIntervalhave 50 ms resolution;setImmediateandqueueMicrotaskrun before control returns to Paper. Effect’sScheduleandEffect.sleepuse these. - Every handler, Command start and task is timed. Above 10 ms the server logs
[<id>] <label> took N ms on the main thread, with the label’s usual time and whether it was a cold first call. Keep work per tick small.
Other globals
Section titled “Other globals”Available: the timers above, performance.now(), console (goes to the server log), TextEncoder and TextDecoder (UTF-8), and the JDK, for example java.nio.file.Files with plugin.getDataFolder().toPath().
Not available: fetch, WebSocket, crypto. If your game needs one, report it to Minekube as a missing capability.
What the runtime adds
Section titled “What the runtime adds”The Paper service gives server, plugin and host. host is the runtime’s small API: getId(), getRevision(), getPreviousState(), listen(...), schedule(...), log(...) and report(...), which shows red in the chat of operators. Game.event, Game.on, the timers and the recording are built on it; a game rarely needs it directly.
When the types are wrong
Section titled “When the types are wrong”A missing event or class, or wrong nullability, is a bug in the generated types. Report it with the class name and the server’s Paper version instead of casting around it.
The runtime itself supports Paper 1.21 and newer with one jar. Only the types depend on the Paper version, and they are always those of the server that wrote them. The dev server runs Paper 26.3.
Was this helpful?
Thanks for the feedback.