diff --git a/connector/pom.xml b/connector/pom.xml
index 2dc797060..149c74a7d 100644
--- a/connector/pom.xml
+++ b/connector/pom.xml
@@ -152,9 +152,9 @@
compile
- com.github.GeyserMC
- MCProtocolLib
- 7248769
+ com.github.steveice10
+ mcprotocollib
+ 1.17.1-pre1-SNAPSHOT
compile
diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java
index 664781763..9190d1fdf 100644
--- a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java
+++ b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java
@@ -40,6 +40,14 @@ public class Inventory {
@Getter
protected final int id;
+ /**
+ * If this is out of sync with the server, the server will resync items.
+ * Since Java Edition 1.17.1.
+ */
+ @Getter
+ @Setter
+ private int stateId;
+
@Getter
protected final int size;
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockBookEditTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockBookEditTranslator.java
index 8e2d77df7..67dcb40c8 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockBookEditTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockBookEditTranslator.java
@@ -37,15 +37,24 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@Translator(packet = BookEditPacket.class)
public class BedrockBookEditTranslator extends PacketTranslator {
+ private static final int MAXIMUM_PAGE_LENGTH = 8192 * 4;
+ private static final int MAXIMUM_TITLE_LENGTH = 128 * 4;
@Override
public void translate(BookEditPacket packet, GeyserSession session) {
+ if (packet.getText() != null && !packet.getText().isEmpty() && packet.getText().getBytes(StandardCharsets.UTF_8).length > MAXIMUM_PAGE_LENGTH) {
+ session.getConnector().getLogger().warning("Page length greater than server allowed!");
+ return;
+ }
+
GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand();
if (itemStack != null) {
CompoundTag tag = itemStack.getNbt() != null ? itemStack.getNbt() : new CompoundTag("");
@@ -106,10 +115,29 @@ public class BedrockBookEditTranslator extends PacketTranslator
}
}
tag.put(new ListTag("pages", pages));
+ // Update local copy
session.getPlayerInventory().setItem(36 + session.getPlayerInventory().getHeldItemSlot(), GeyserItemStack.from(bookItem), session);
session.getInventoryTranslator().updateInventory(session, session.getPlayerInventory());
- session.getBookEditCache().setPacket(new ClientEditBookPacket(bookItem, packet.getAction() == BookEditPacket.Action.SIGN_BOOK, session.getPlayerInventory().getHeldItemSlot()));
+ List networkPages = new ArrayList<>();
+ for (Tag pageTag : pages) {
+ networkPages.add(((StringTag) pageTag).getValue());
+ }
+
+ String title;
+ if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
+ // Add title to packet so the server knows we're signing
+ if (packet.getTitle().getBytes(StandardCharsets.UTF_8).length > MAXIMUM_TITLE_LENGTH) {
+ session.getConnector().getLogger().warning("Book title larger than server allows!");
+ return;
+ }
+
+ title = packet.getTitle();
+ } else {
+ title = null;
+ }
+
+ session.getBookEditCache().setPacket(new ClientEditBookPacket(session.getPlayerInventory().getHeldItemSlot(), networkPages, title));
// There won't be any more book updates after this, so we can try sending the edit packet immediately
if (packet.getAction() == BookEditPacket.Action.SIGN_BOOK) {
session.getBookEditCache().checkForSend();
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/click/ClickPlan.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/click/ClickPlan.java
index 5204bf675..997193091 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/click/ClickPlan.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/click/ClickPlan.java
@@ -124,6 +124,7 @@ public class ClickPlan {
ClientWindowActionPacket clickPacket = new ClientWindowActionPacket(
inventory.getId(),
+ inventory.getStateId(),
action.slot,
action.click.windowAction,
action.click.actionParam,
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java
index a0e9901f3..b0ce8994e 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaSetSlotTranslator.java
@@ -72,6 +72,8 @@ public class JavaSetSlotTranslator extends PacketTranslator
if (inventory == null)
return;
+ inventory.setStateId(packet.getStateId());
+
InventoryTranslator translator = session.getInventoryTranslator();
if (translator != null) {
if (session.getCraftingGridFuture() != null) {
diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java
index 7d29f54b3..4b121229f 100644
--- a/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java
+++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/window/JavaWindowItemsTranslator.java
@@ -44,6 +44,8 @@ public class JavaWindowItemsTranslator extends PacketTranslator