Skip to content

Commit

Permalink
Fix sending forms with floodgate for 1.19.20 (#3217)
Browse files Browse the repository at this point in the history
* Fix sending forms with floodgate

* Comment about 1.19.20

* Swapped if-else

Co-authored-by: Tim203 <mctim203@gmail.com>
  • Loading branch information
Konicai and Tim203 committed Aug 10, 2022
1 parent 25a18a2 commit ab2b794
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@ public void translate(GeyserSession session, ClientboundCustomPayloadPacket pack
String dataString = new String(data, 3, data.length - 3, Charsets.UTF_8);

Form form = Forms.fromJson(dataString, type, (ignored, response) -> {
byte[] raw = response.getBytes(StandardCharsets.UTF_8);
byte[] finalData = new byte[raw.length + 2];

finalData[0] = data[1];
finalData[1] = data[2];
System.arraycopy(raw, 0, finalData, 2, raw.length);
byte[] finalData;
if (response == null) {
// Response data can be null as of 1.19.20 (same behaviour as empty response data)
// Only need to send the form id
finalData = new byte[]{data[1], data[2]};
} else {
byte[] raw = response.getBytes(StandardCharsets.UTF_8);
finalData = new byte[raw.length + 2];

finalData[0] = data[1];
finalData[1] = data[2];
System.arraycopy(raw, 0, finalData, 2, raw.length);
}

session.sendDownstreamPacket(new ServerboundCustomPayloadPacket(channel, finalData));
});
Expand Down

0 comments on commit ab2b794

Please sign in to comment.