Cache forms until the player has fully initialized

This commit is contained in:
Camotoy 2021-12-29 14:20:34 -05:00
parent 7beedb46f8
commit d7eef7aaeb
No known key found for this signature in database
GPG Key ID: 7EEFB66FE798081F
2 changed files with 15 additions and 2 deletions

View File

@ -52,9 +52,15 @@ public class FormCache {
return windowId;
}
public int showForm(Form form) {
public void showForm(Form form) {
int windowId = addForm(form);
if (session.getUpstream().isInitialized()) {
sendForm(windowId, form);
}
}
private void sendForm(int windowId, Form form) {
ModalFormRequestPacket formRequestPacket = new ModalFormRequestPacket();
formRequestPacket.setFormId(windowId);
formRequestPacket.setFormData(form.getJsonData());
@ -68,8 +74,12 @@ public class FormCache {
session.scheduleInEventLoop(() -> session.sendUpstreamPacket(latencyPacket),
500, TimeUnit.MILLISECONDS);
}
}
return windowId;
public void resendAllForms() {
for (Int2ObjectMap.Entry<Form> entry : forms.int2ObjectEntrySet()) {
sendForm(entry.getIntKey(), entry.getValue());
}
}
public void handleResponse(ModalFormResponsePacket response) {

View File

@ -55,6 +55,9 @@ public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslat
if (session.getOpenInventory() != null && session.getOpenInventory().isPending()) {
InventoryUtils.openInventory(session, session.getOpenInventory());
}
// What am I to expect - as of Bedrock 1.18
session.getFormCache().resendAllForms();
}
}
}