-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd721f9
commit 2ce6ee5
Showing
11 changed files
with
102 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,21 @@ | ||
import { EventEmitter } from "node:events"; | ||
import type * as Protocol from "@serenityjs/protocol"; | ||
import type { NetworkEvents } from "@serenityjs/network"; | ||
|
||
class Listener extends EventEmitter { | ||
emit<K extends keyof ListenerEvents>( | ||
eventName: K, | ||
...args: Parameters<ListenerEvents[K]> | ||
): boolean; | ||
emit(eventName: string, ...args: unknown[]): boolean; | ||
emit(eventName: string, ...args: unknown[]): boolean { | ||
return super.emit(eventName, ...args); | ||
} | ||
|
||
on<K extends keyof ListenerEvents>( | ||
eventName: K, | ||
listener: ListenerEvents[K], | ||
): this; | ||
on(eventName: string, listener: (...args: unknown[]) => void): this; | ||
on(eventName: string, listener: (...args: unknown[]) => void): this { | ||
return super.on(eventName, listener); | ||
} | ||
|
||
once<K extends keyof ListenerEvents>( | ||
eventName: K, | ||
listener: ListenerEvents[K], | ||
): this; | ||
once(eventName: string, listener: (...args: unknown[]) => void): this; | ||
once(eventName: string, listener: (...args: unknown[]) => void): this { | ||
return super.once(eventName, listener); | ||
} | ||
} | ||
import Emitter from "@serenityjs/emitter"; | ||
|
||
type PacketNames = { | ||
[K in keyof typeof Protocol]: K extends `${string}Packet` ? K : never; | ||
}[keyof typeof Protocol]; | ||
|
||
type ListenerEvents = { | ||
// @ts-expect-error does not matter | ||
[K in PacketNames]: (packet: InstanceType<(typeof Protocol)[K]>) => void; | ||
[K in PacketNames]: [InstanceType<(typeof Protocol)[K]>]; | ||
} & { | ||
session: () => void; | ||
spawn: () => void; | ||
tick: (tick: number) => void; | ||
PrePlayerAuthInputPacket: ( | ||
packet: Protocol.PlayerAuthInputPacket, | ||
cancel: boolean, | ||
) => void; | ||
session: []; | ||
spawn: []; | ||
tick: [number]; | ||
PrePlayerAuthInputPacket: [Protocol.PlayerAuthInputPacket]; | ||
close: []; | ||
}; | ||
|
||
class Listener extends Emitter<ListenerEvents> {} | ||
|
||
export { Listener, type ListenerEvents }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.