Skip to content

Commit

Permalink
Cache forms until the player has fully initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Dec 29, 2021
1 parent 7beedb4 commit d7eef7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ public int addForm(Form form) {
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());
Expand All @@ -68,8 +74,12 @@ public int showForm(Form form) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public void translate(GeyserSession session, SetLocalPlayerAsInitializedPacket p
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();
}
}
}
Expand Down

0 comments on commit d7eef7a

Please sign in to comment.