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; return windowId;
} }
public int showForm(Form form) { public void showForm(Form form) {
int windowId = addForm(form); int windowId = addForm(form);
if (session.getUpstream().isInitialized()) {
sendForm(windowId, form);
}
}
private void sendForm(int windowId, Form form) {
ModalFormRequestPacket formRequestPacket = new ModalFormRequestPacket(); ModalFormRequestPacket formRequestPacket = new ModalFormRequestPacket();
formRequestPacket.setFormId(windowId); formRequestPacket.setFormId(windowId);
formRequestPacket.setFormData(form.getJsonData()); formRequestPacket.setFormData(form.getJsonData());
@ -68,8 +74,12 @@ public class FormCache {
session.scheduleInEventLoop(() -> session.sendUpstreamPacket(latencyPacket), session.scheduleInEventLoop(() -> session.sendUpstreamPacket(latencyPacket),
500, TimeUnit.MILLISECONDS); 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) { public void handleResponse(ModalFormResponsePacket response) {

View file

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