Skip to content

Commit df7a4a7

Browse files
committed
update docs for v41
1 parent 42bcdd8 commit df7a4a7

6 files changed

Lines changed: 143 additions & 8 deletions

File tree

‎CLAUDE.md‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ All return an `int` task id. Bukkit-style aliases exist (`runTask`, `runTaskTime
6969
| `newLocation(world, x, y, z, pitch?, yaw?)` | Note: pitch before yaw |
7070
| `asInt/asLong/asFloat/asDouble/asShort/asByte` | Disambiguate Java numeric overloads |
7171
| `ArrayList`, `HashMap`, `HashSet`, `UUID`, `Gson`, `Arrays`, `List` | Preloaded Java classes |
72-
| `Java.extend(AbstractClass, overrides)` | Subclass a Java abstract class |
72+
| `Java.extend(AbstractClass, overrides)` | Subclass a Java abstract class (legacy, prefer native `class extends`) |
7373
| `Java.synchronized(fn, lockObject)` | Java `synchronized` semantics |
7474
| `JSON`, `Map`, `Set`, `Math`, `Date` | Standard JS |
7575

@@ -339,7 +339,35 @@ constructor:
339339
const impl = new SomeInterface({ methodA() {}, methodB(x) { return x; } });
340340
```
341341

342-
**Abstract classes need `Java.extend`:**
342+
**Java classes can be subclassed with plain `class ... extends`**, including abstract ones like Bukkit's
343+
`Event`. This is the preferred way to subclass now. `super(...)` takes the Java constructor's arguments,
344+
and `TheClass.class` gets you the raw `Class` object a listener registration or reflective API wants:
345+
346+
```javascript
347+
const PlayerEvent = Script.loadClass('org.bukkit.event.player.PlayerEvent');
348+
const HandlerList = Script.loadClass('org.bukkit.event.HandlerList');
349+
350+
class CustomPlayerEvent extends PlayerEvent {
351+
static handlerList = new HandlerList();
352+
353+
constructor(player) {
354+
super(player);
355+
}
356+
357+
getHandlers() {
358+
return CustomPlayerEvent.handlerList;
359+
}
360+
361+
static getHandlerList() {
362+
return CustomPlayerEvent.handlerList;
363+
}
364+
}
365+
366+
registerListener(CustomPlayerEvent.class, (event) => { /* ... */ });
367+
Bukkit.getPluginManager().callEvent(new CustomPlayerEvent(player));
368+
```
369+
370+
**`Java.extend` still works but is legacy**, prefer native `class extends` for new code:
343371

344372
```javascript
345373
const MyAdapter = Java.extend(PacketAdapter, {
@@ -565,6 +593,7 @@ autocomplete after the next reload.
565593
| `/script info <path>` | Parents, extensions, load time, profiler data (avg/min/max) |
566594
| `/script list` | Every loaded script path |
567595
| `/script timings <enable\|disable>` | Profiler collection, on by default |
596+
| `/script evalin <path> <code>` | Eval code in a loaded script's own scope — call a function or inspect state without editing the file. Bare variable name returns its value; anything else returns the statement's return value |
568597

569598
`Script.measure('name', fn)` adds your own entry to `/script info`.
570599

‎changelog.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ updated: 2026-07-28
99
nav_order: 8
1010
permalink: /changelog/
1111
---
12+
### 5 August 2026 - Version 41
13+
- Added support for `class ... extends` directly against a Java class, including abstract classes like Bukkit's `Event`. `super(...)` takes the Java constructor's arguments, and `TheClass.class` gets the raw generated `Class` for registration APIs. `Java.extend` still works but is now considered legacy in favor of this.
14+
- Improved `.d.ts` generation, fixing a lot of common gripes. Complicated lines like `world.getEntitiesByClass(ItemEntity.class).forEach((entity: org.bukkit.entity.Item) => {` now correctly resolve all types, even when it involves generics, and the generated types are now more readable.
15+
- Errors from `.ts` files now show the correct line numbers and context source through sourcemaps that are drilled down to deltas during compilation time (little to no runtime overhead).
16+
- Added the `evalin` command, which lets you eval code in the context of a script. Useful for manual/agentic debugging, because it lets you call indidividual functions and inspect variables in a script without having to modify the script itself. Example: `/script evalin global/features/machines/api/chainable.ts log("hello from chainable!");`
17+
- Fixed a small bug where the `.d.ts` generator would sometimes be executed more than it should.
18+
1219
### 4 August 2026 - Version 40
1320
- Merged new template repository that gets used for default projects. The new example project is based on real organization and structure from ImagineFun and DroomCraft
1421
- Cleaned up logging

‎spec-006-events.md‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Event listeners
55
description: Respond to Bukkit events with registerListener, including priorities and automatic cleanup.
66
status: stable
77
tags: [api, events, listener]
8-
updated: 2026-07-28
8+
updated: 2026-08-08
99
parent: API reference
1010
nav_order: 6
1111
permalink: /api-event-listener/
@@ -93,6 +93,29 @@ registerListener($.BlockBreakEvent, (event) => {
9393

9494
Only cancellable events have `setCancelled`. Calling it on one that is not will throw.
9595

96+
## Your own custom events
97+
98+
Custom events, ones your own scripts define rather than ones Bukkit or another plugin fires, are written
99+
with native `class ... extends`, subclassing a Java event class directly. See
100+
[Interfaces and abstract classes](./tips-002-interfaces-and-abstract-classes.md) for the full pattern
101+
(`HandlerList`, `super(...)`, private fields).
102+
103+
Once defined, wiring one up is the same two calls as any other event: `registerListener` to listen,
104+
`Bukkit.getPluginManager().callEvent(event)` to fire. `registerListener` takes the class's raw `Class`
105+
object (`CustomPlayerEvent.class`), not the JS class itself:
106+
107+
```javascript
108+
registerListener(CustomPlayerEvent.class, (event) => {
109+
log(`${event.getPlayer().getName()} triggered CustomPlayerEvent`);
110+
});
111+
112+
const event = new CustomPlayerEvent(player, 10);
113+
Bukkit.getPluginManager().callEvent(event);
114+
```
115+
116+
Firing is plain Bukkit. `callEvent` is not a PixelScript wrapper, so it runs listeners synchronously on
117+
whatever thread calls it, same as firing any other event.
118+
96119
## Threading
97120

98121
Listeners run on whatever thread fires the event. Most Bukkit events are on the main thread, so you can

‎tips-002-interfaces-and-abstract-classes.md‎

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Interfaces and abstract classes
55
description: Implementing Java interfaces and extending abstract classes from JavaScript.
66
status: stable
77
tags: [jvm, interop, java]
8-
updated: 2026-07-28
8+
updated: 2026-08-08
99
parent: Tips & tricks
1010
nav_order: 2
1111
permalink: /interfaces-and-abs-classes/
@@ -88,10 +88,64 @@ const myRenderer = new ChatRenderer({
8888
registerListener(AsyncChatEvent, (event) => event.renderer(myRenderer));
8989
```
9090

91-
## Abstract classes: `Java.extend`
91+
## Subclassing: native `class extends`
9292

93-
Abstract classes need `Java.extend(BaseClass, overrides)`, which produces a new class you then instantiate
94-
with the parent's constructor arguments.
93+
Any JS class can `extends` a Java class directly, abstract or concrete, including ones whose constructor
94+
takes arguments. This is the current, preferred way to subclass; the runtime generates a real Java adapter
95+
class behind the scenes. Call `super(...)` with whatever the Java constructor expects, same as extending a
96+
JS class.
97+
98+
A worked example: a custom Bukkit event, subclassing `PlayerEvent`.
99+
100+
```javascript
101+
const PlayerEvent = Script.loadClass('org.bukkit.event.player.PlayerEvent');
102+
const HandlerList = Script.loadClass('org.bukkit.event.HandlerList');
103+
104+
class CustomPlayerEvent extends PlayerEvent {
105+
static handlerList = new HandlerList();
106+
#height;
107+
108+
constructor(player, height) {
109+
super(player);
110+
this.#height = height;
111+
}
112+
113+
getHeight() {
114+
return this.#height;
115+
}
116+
117+
getHandlers() {
118+
return CustomPlayerEvent.handlerList;
119+
}
120+
121+
static getHandlerList() {
122+
return CustomPlayerEvent.handlerList;
123+
}
124+
}
125+
```
126+
127+
`CustomPlayerEvent.class` gets you the raw generated Java `Class`, the same trick used
128+
[everywhere else Java wants a `Class` object](./tips-001-java-interop.md). That is what a listener
129+
registration expects, not the JS class itself. Firing the event is plain Bukkit, not a PixelScript API:
130+
131+
```javascript
132+
registerListener(CustomPlayerEvent.class, (event) => {
133+
log(`CustomPlayerEvent fired for ${event.getPlayer().getName()} with height ${event.getHeight()}`);
134+
});
135+
136+
const event = new CustomPlayerEvent(Bukkit.getPlayer('chemhypeboy'), 10);
137+
Bukkit.getPluginManager().callEvent(event);
138+
```
139+
140+
This is not limited to events. Anything covered by `Java.extend` below (packet adapters, custom GUI
141+
holders, any abstract class a third-party API wants a subclass of) can be written this way instead, and it
142+
is the preferred style for new code.
143+
144+
## Legacy: `Java.extend`
145+
146+
`Java.extend(BaseClass, overrides)` predates native `class extends` support and does the same job: it
147+
produces a new class you then instantiate with the parent's constructor arguments. It still works and
148+
nothing needs to migrate, but reach for native `class extends` above in new code instead.
95149

96150
Here is the canonical case, a ProtocolLib packet adapter:
97151

‎tips-005-built-in-commands.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ answer "what is actually loaded right now" without guessing.
2323
| `/script list` | `pixelscript.list` |
2424
| `/script timings <enable\|disable>` | `pixelscript.profiler.enable` / `pixelscript.profiler.disable` |
2525
| `/script registrydebug` | `pixelscript.debug` |
26+
| `/script evalin <file> <code>` | `pixelscript.debug` |
2627

2728
## `/script`
2829

@@ -75,3 +76,24 @@ Counts scripts, root scripts, modules, isolate modules and failed scripts. Semi-
7576
when we are helping you diagnose a resolver issue.
7677

7778
![registrydebug screenshot](./assets/img/command-registrydebug.png)
79+
80+
## `/script evalin <file> <code>`
81+
82+
Evaluates JS in the scope of an already-loaded script, without editing the script itself. Useful for
83+
manual or agentic debugging: call an individual function or inspect a variable from a script without
84+
touching the file (and without triggering a reload).
85+
86+
```
87+
/script evalin global/features/machines/api/chainable.ts log("hello from chainable!");
88+
```
89+
90+
The `<file>` path is relative to the `scripts` directory, same as `/script info`, and tab completion
91+
suggests loaded script paths.
92+
93+
If `<code>` is a bare variable name, its current value is returned in chat instead of `undefined`.
94+
Anything else is evaluated as a statement/expression and, if it returns a value, that return value is
95+
shown instead.
96+
97+
```
98+
/script evalin global/features/machines/api/chainable.ts machineRegistry
99+
```

‎tips.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The things that are not part of the API surface but will bite you or save you an
1111
| Article | Covers |
1212
|---------|--------|
1313
| [Java interop](./tips-001-java-interop.md) | Numeric casts, ambiguous overloads, Java collections versus JS collections |
14-
| [Interfaces and abstract classes](./tips-002-interfaces-and-abstract-classes.md) | `Java.extend`, interface literals, and cleaning up after third-party APIs |
14+
| [Interfaces and abstract classes](./tips-002-interfaces-and-abstract-classes.md) | Native `class extends` for Java classes, `Java.extend` (legacy), interface literals, and cleaning up after third-party APIs |
1515
| [TypeScript and type generation](./tips-003-typescript-and-types.md) | `definitions.d.ts`, writing `.ts` scripts, `tsconfig.json` |
1616
| [Performance profiling](./tips-004-performance-profiling.md) | Built-in timings and where the time usually goes |
1717
| [Built-in commands](./tips-005-built-in-commands.md) | The `/script` admin and debugging commands |

0 commit comments

Comments
 (0)