Skip to content

Commit e0ad7cd

Browse files
committed
feat: add player.closeForm
1 parent c9de01e commit e0ad7cd

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

docs/apis/GuiAPI/Form.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,11 @@ Parameter `callback` The callback function prototype: `function(player,data)`
122122
The reason why the form is closed.
123123
0 = UserClosed, 1 = UserBusy
124124
The reason may be `null`.
125+
126+
### Close the form that the player is currently opening
127+
128+
`pl.closeForm()`
129+
130+
- Return value: Whether the request is successful
131+
- Return value type: `Boolean`
132+

docs/apis/GuiAPI/Form.zh.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,11 @@
115115
- reason : `Integer`(在0.9.0中加入)
116116
表单被取消的原因
117117
0 = UserClosed, 1 = UserBusy
118-
reason可能会是`null`.
118+
reason可能会是`null`.
119+
120+
### 关闭玩家正在打开的表单
121+
122+
`pl.closeForm()`
123+
124+
- 返回值:请求是否成功
125+
- 返回值类型:`Boolean`

src/legacy/api/PlayerAPI.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
#include "mc/network/NetEventCallback.h"
4949
#include "mc/network/ServerNetworkHandler.h"
5050
#include "mc/network/packet/BossEventPacket.h"
51+
#include "mc/network/packet/ClientboundCloseFormPacket.h"
5152
#include "mc/network/packet/LevelChunkPacket.h"
52-
#include "mc/network/packet/ModalFormRequestPacket.h"
5353
#include "mc/network/packet/RemoveObjectivePacket.h"
5454
#include "mc/network/packet/ScorePacketInfo.h"
5555
#include "mc/network/packet/SetDisplayObjectivePacket.h"
@@ -260,6 +260,7 @@ ClassDefine<PlayerClass> PlayerClassBuilder =
260260
.instanceFunction("sendModalForm", &PlayerClass::sendModalForm)
261261
.instanceFunction("sendCustomForm", &PlayerClass::sendCustomForm)
262262
.instanceFunction("sendForm", &PlayerClass::sendForm)
263+
.instanceFunction("closeForm", &PlayerClass::closeForm)
263264
.instanceFunction("sendPacket", &PlayerClass::sendPacket)
264265

265266
.instanceFunction("setExtraData", &PlayerClass::setExtraData)
@@ -2609,6 +2610,17 @@ Local<Value> PlayerClass::sendForm(const Arguments& args) {
26092610
CATCH("Fail in sendForm!");
26102611
}
26112612

2613+
Local<Value> PlayerClass::closeForm(const Arguments&) {
2614+
try {
2615+
Player* player = get();
2616+
if (!player) return Local<Value>();
2617+
2618+
ClientboundCloseFormPacket().sendTo(*player);
2619+
return Boolean::newBoolean(true);
2620+
}
2621+
CATCH("Fail in sendForm!");
2622+
}
2623+
26122624
Local<Value> PlayerClass::sendPacket(const Arguments& args) {
26132625
CHECK_ARGS_COUNT(args, 1);
26142626
CHECK_ARG_TYPE(args[0], ValueKind::kObject);

src/legacy/api/PlayerAPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ class PlayerClass : public ScriptClass {
159159
Local<Value> sendModalForm(const Arguments& args);
160160
Local<Value> sendCustomForm(const Arguments& args);
161161
Local<Value> sendForm(const Arguments& args);
162+
Local<Value> closeForm(const Arguments& args);
162163
Local<Value> sendPacket(const Arguments& args);
163164

164165
Local<Value> setExtraData(const Arguments& args);

0 commit comments

Comments
 (0)