Player object
Player object represents player, connected to MCmdLogger.
Reference
Fields
Name | Type | Description |
---|---|---|
name | string | Player name |
uuid | string | Player's UUID |
version | string | Minecraft version |
protocol | number | Minecraft protocol number |
ip | string | Player IP address |
statuses | string[] | Statuses list (for example, "mute" , "deaf" ) |
Methods
Definition | Description |
---|---|
on(event: string, callback) | Add event listener |
off(event: string, callback) | Remove event listener |
send(message: string) | Send chat message to player |
sendJSON(json: TextComponent) | Send JSON (text component) chat message to player. |
kick() | Kick without message |
kick(message: string) | Kick with custom disconnected screen message |
sudo(message: string) | Send message (or command) as player |
deaf(deaf: boolean) | Deaf/undeaf player |
mute(mute: boolean) | Mute/unmute player |
fakegm(gamemode: number) | Set fake gamemode |
getCoords() | Get last known player coordinates |
Events
Name | Callback | Description |
---|---|---|
player_message | (event: EventPlayerMessage) => any | Player sent chat message or command to server |
server_message | (event: EventServerMessage) => any | Server sent chat message to player |
player_packet | (event: EventPacket) => any | Player sent packet to server |
server_packet | (event: EventPacket) => any | Server sent packet to player |
message | (message: string) => any | |
leave | () => any | Player disconnected |
EventPlayerMessage
Allows to intercept and handle player's chat messages and commands.
You cannot modify message text, but you can cancel it (and send new one with sudo(...)
if required).
interface EventPlayerMessage {
text: string
canceled: boolean
cancel(): void
}
EventServerMessage
Allows to intercept and handle server's chat messages.
You cannot modify message text, but you can cancel it (and send new one with send(...)
or sendJSON(...)
if required).
interface EventServerMessage {
json: TextComponent
legacy: string
text: string
click_actions: {
open_url?: string[]
open_file?: string[]
run_command?: string[]
suggest_command?: string[]
change_page?: string[]
copy_to_clipboard?: string[]
}
canceled: boolean
cancel(): void
}
This event provides additional fields. For example, json
contains full text component, legacy
contains it's legacy representation (string with style codes), text
contains plain text, stripped from formatting and click_actions
contains list of click actions, used in this message (this can be used to, for example, quickly extract all links from message).
EventPacket
Allows to intercept and handle packets, sent to/from player.
You cannot access packet data, but you can cancel it. This can be used to prevent player from sending or receiving certain packets.
interface EventPacket {
id: number
name: string
canceled: boolean
cancel(): void
}