Skip to content

Commit 3829a25

Browse files
authored
Proper title event (PrismarineJS#3498)
* titles event * only 1 event * remove chatmsg * add docs and example * LINT
1 parent fdba037 commit 3829a25

File tree

8 files changed

+58
-26
lines changed

8 files changed

+58
-26
lines changed

docs/api.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
- ["respawn"](#respawn)
170170
- ["game"](#game)
171171
- ["resourcePack" (url, hash)](#resourcepack-url-hash)
172-
- ["title"](#title)
172+
- ["title" (title, type)](#title-title-type)
173173
- ["rain"](#rain)
174174
- ["weatherUpdate"](#weatherupdate)
175175
- ["time"](#time)
@@ -1237,11 +1237,12 @@ Emitted when the server changes any of the game properties.
12371237

12381238
Emitted when the server sends a resource pack.
12391239

1240-
#### "title"
1240+
#### "title" (title, type)
12411241

12421242
Emitted when the server sends a title
12431243

1244-
* `text` - title's text
1244+
* `title` - title's text
1245+
* `type` - title's type "subtitle" or "title"
12451246

12461247
#### "rain"
12471248

@@ -1771,7 +1772,7 @@ Checks if the given plugin is loaded (or scheduled to be loaded) on this bot.
17711772

17721773
This function returns a `Promise`, with `void` as its argument upon completion.
17731774

1774-
Sleep in a bed. `bedBlock` should be a `Block` instance which is a bed.
1775+
Sleep in a bed. `bedBlock` should be a `Block` instance which is a bed.
17751776

17761777
#### bot.isABed(bedBlock)
17771778

@@ -1781,7 +1782,7 @@ Return true if `bedBlock` is a bed
17811782

17821783
This function returns a `Promise`, with `void` as its argument upon completion.
17831784

1784-
Get out of bed.
1785+
Get out of bed.
17851786

17861787
#### bot.setControlState(control, state)
17871788

@@ -2120,7 +2121,7 @@ These are lower level methods for the inventory, they can be useful sometimes bu
21202121
#### bot.clickWindow(slot, mouseButton, mode)
21212122

21222123
This function returns a `Promise`, with `void` as its argument upon completion.
2123-
2124+
21242125
The only valid mode option at the moment is 0. Shift clicking or mouse dragging is not implemented.
21252126

21262127
Click on the current window. See details at https://wiki.vg/Protocol#Click_Container

docs/br/api_br.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
- ["respawn"](#respawn)
142142
- ["game"](#game)
143143
- ["resourcePack" (url, hash)](#resourcepack-url-hash)
144-
- ["title"](#title)
144+
- ["title" (title, type)](#title-title-type)
145145
- ["rain"](#rain)
146146
- ["weatherUpdate"](#weatherupdate)
147147
- ["time"](#time)
@@ -1060,11 +1060,12 @@ Este evento é emitido quando o arquivo index é carregado. Você pode carregar
10601060

10611061
É emitido quando o servidor envia um pacote de recursos.
10621062

1063-
#### "title"
1063+
#### "title" (title, type)
10641064

10651065
É emitido quando o servidor exibe um título.
10661066

1067-
* `text` - texto do título
1067+
* `title` - texto do título
1068+
* `type` - tipo do título "subtitle" ou "title"
10681069

10691070
#### "rain"
10701071

@@ -2035,4 +2036,4 @@ Observação: enquanto você voa, `bot.entity.velocity` não é preciso.
20352036

20362037
#### bot.creative.stopFlying()
20372038

2038-
Restaura `bot.physics.gravity` ao seu valor original.
2039+
Restaura `bot.physics.gravity` ao seu valor original.

docs/es/api_es.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
- ["respawn"](#respawn)
142142
- ["game"](#game)
143143
- ["resourcePack" (url, hash)](#resourcepack-url-hash)
144-
- ["title"](#title)
144+
- ["title" (title, type)](#title-title-type)
145145
- ["rain"](#rain)
146146
- ["weatherUpdate"](#weatherupdate)
147147
- ["time"](#time)
@@ -1071,11 +1071,12 @@ Se emite cuando el servidor cambia cualquiera de sus propiedades
10711071

10721072
Se emite cuando el servidor manda un paquete de recursos
10731073

1074-
#### "title"
1074+
#### "title" (title, type)
10751075

10761076
Se emite cuando el servidor manda/muestra un título
10771077

1078-
* `text` - texto del título
1078+
* `title` - texto del título
1079+
* `type` - tipo del título "subtitle" o "title"
10791080

10801081
#### "rain"
10811082

docs/ru/api_ru.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
- ["respawn"](#respawn)
170170
- ["game"](#game)
171171
- ["resourcePack" (url, hash)](#resourcepack-url-hash)
172-
- ["title"](#title)
172+
- ["title" (title, type)](#title-title-type)
173173
- ["rain"](#rain)
174174
- ["weatherUpdate"](#weatherupdate)
175175
- ["time"](#time)
@@ -1264,11 +1264,12 @@ UUID существа, который определяется боссом.
12641264

12651265
Срабатывает, когда сервер отправляет ресурспак.
12661266

1267-
#### "title"
1267+
#### "title" (title, type)
12681268

12691269
Срабатывает, когда сервер отправляет текст по центру экрана.
12701270

1271-
* `text` - Текст на экране.
1271+
* `title` - Текст на экране.
1272+
* `type` - Тип текста "subtitle" или "title"
12721273

12731274
#### "rain"
12741275

@@ -1634,7 +1635,7 @@ UUID существа, который определяется боссом.
16341635

16351636
#### bot.recipesFor(itemType, metadata, minResultCount, craftingTable)
16361637

1637-
Возвращает список рецептов(`Recipe`), которые вы можете использовать для крафта
1638+
Возвращает список рецептов(`Recipe`), которые вы можете использовать для крафта
16381639
предмета(`itemType`) с мета-данными(`metadata`).
16391640

16401641
* `itemType` - Числовой ID предмета, который вы хотите создать.
@@ -2116,7 +2117,7 @@ bot.once('login', () => {
21162117
#### bot.clickWindow(slot, mouseButton, mode)
21172118

21182119
Эта функция возвращает `Promise` с `void` в качестве аргумента при завершении.
2119-
2120+
21202121
Единственное действительное значение для `mode` - 0. Нажатие с шифтом или перемещение через мышь не реализовано.
21212122

21222123
Нажимает на текущее окно. Подробнее - https://wiki.vg/Protocol#Click_Container

docs/zh/api.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
- ["respawn"](#respawn)
154154
- ["game"](#game)
155155
- ["resourcePack" (url, hash)](#resourcepack-url-hash)
156-
- ["title"](#title)
156+
- ["title" (title, type)](#title-title-type)
157157
- ["rain"](#rain)
158158
- ["weatherUpdate"](#weatherupdate)
159159
- ["time"](#time)
@@ -1127,11 +1127,12 @@ Emitted for every server message, including chats.
11271127

11281128
当服务器发送资源包时触发
11291129

1130-
#### "title"
1130+
#### "title" (title, type)
11311131

11321132
当服务器发送标题时触发
11331133

1134-
* `text` - 标题文本
1134+
* `title` - 标题文本
1135+
* `type` - 标题类型 "subtitle" 或 "title"
11351136

11361137
#### "rain"
11371138

@@ -1150,11 +1151,11 @@ If you join a server where it is already raining, this event will fire.
11501151

11511152
当bot从服务器被踢出时触发
11521153

1153-
`reason`是一条解释你被踢的原因的聊天信息.
1154+
`reason`是一条解释你被踢的原因的聊天信息.
11541155

11551156
`loggedIn`
11561157
如果客户端在成功登录后被踢出则为`true`
1157-
如果kick发生在登录阶段则为 `false`
1158+
如果kick发生在登录阶段则为 `false`
11581159

11591160
#### "end" (reason)
11601161

examples/titles.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* An example of how to handle title events from the server.
3+
*/
4+
const mineflayer = require('mineflayer')
5+
6+
if (process.argv.length < 4 || process.argv.length > 6) {
7+
console.log('Usage : node titles.js <host> <port> [<name>] [<password>]')
8+
process.exit(1)
9+
}
10+
11+
const bot = mineflayer.createBot({
12+
host: process.argv[2],
13+
port: parseInt(process.argv[3]),
14+
username: process.argv[4] ? process.argv[4] : 'titles',
15+
password: process.argv[5]
16+
})
17+
18+
// This event is triggered when the server sends a title to the client.
19+
bot.on('title', (text, type) => {
20+
// type is either "title" or "subtitle"
21+
console.log(`Received ${type}: ${text}`)
22+
})

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export interface BotEvents {
7171
spawn: () => Promise<void> | void
7272
respawn: () => Promise<void> | void
7373
game: () => Promise<void> | void
74-
title: (text: string) => Promise<void> | void
74+
title: (text: string, type: "subtitle" | "title") => Promise<void> | void
7575
rain: () => Promise<void> | void
7676
time: () => Promise<void> | void
7777
kicked: (reason: string, loggedIn: boolean) => Promise<void> | void

lib/plugins/title.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
module.exports = inject
2-
32
function inject (bot) {
43
bot._client.on('title', (packet) => {
54
if (packet.action === 0 || packet.action === 1) {
6-
bot.emit('title', packet.text)
5+
bot.emit('title', packet.text, 'title')
76
}
87
})
8+
bot._client.on('set_title_text', packet => {
9+
bot.emit('title', packet.text, 'title')
10+
})
11+
bot._client.on('set_title_subtitle', packet => {
12+
bot.emit('title', packet.text, 'subtitle')
13+
})
914
}

0 commit comments

Comments
 (0)