1
0
Fork 0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-04-17 19:12:14 +02:00

Fix debug logging with arguments, don't attempt to re-use inventory that's currently closing

This commit is contained in:
onebeastchris 2025-03-31 15:13:47 +02:00
parent 3c9c62f1f5
commit 0f31134e2f
9 changed files with 32 additions and 21 deletions
bootstrap
mod/src/main/java/org/geysermc/geyser/platform/mod
standalone/src/main/java/org/geysermc/geyser/platform/standalone
velocity/src/main/java/org/geysermc/geyser/platform/velocity
core/src/main/java/org/geysermc/geyser

View file

@ -87,7 +87,7 @@ public class GeyserModLogger implements GeyserLogger {
@Override
public void debug(String message, Object... arguments) {
if (debug) {
logger.info(message, arguments);
logger.info(String.format(message, arguments));
}
}

View file

@ -117,7 +117,8 @@ public class GeyserStandaloneLogger extends SimpleTerminalConsole implements Gey
@Override
public void debug(String message, Object... arguments) {
log.debug(ChatColor.GRAY + message, arguments);
// We can't use the debug call that would format for us as we're using Java's string formatting
log.debug(ChatColor.GRAY + String.format(message, arguments));
}
@Override

View file

@ -77,7 +77,7 @@ public class GeyserVelocityLogger implements GeyserLogger {
@Override
public void debug(String message, Object... arguments) {
if (debug) {
logger.info(message, arguments);
logger.info(String.format(message, arguments));
}
}
}

View file

@ -104,7 +104,7 @@ public abstract class Inventory {
@Getter
@Setter
private boolean isCurrentlyDelayed = false;
private boolean delayed = false;
@Getter
private final InventoryTranslator translator;

View file

@ -298,7 +298,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
private boolean closingInventory;
/**
* Stores the java inventory id of the pending inventory, or -1 if no inventory is pending.
* Stores the bedrock inventory id of the pending inventory, or -1 if no inventory is pending.
*/
@Setter
private int pendingInventoryId = -1;

View file

@ -145,10 +145,10 @@ public abstract class InventoryTranslator {
* Whether a new inventory should be prepared - or if we can re-use the previous one.
*/
public boolean canReuseInventory(GeyserSession session, @NonNull Inventory inventory, @NonNull Inventory previous) {
// Filter for mismatches that require a new inventory
// Filter for mismatches that require a new inventory. Further, if we're closing a current inventory, we cannot reuse it.
if (inventory.getContainerType() == null || previous.getContainerType() == null
|| !Objects.equals(inventory.getContainerType(), previous.getContainerType())
|| inventory.getJavaId() != previous.getJavaId()
|| inventory.getJavaId() != previous.getJavaId() || session.isClosingInventory()
) {
return false;
}

View file

@ -64,8 +64,8 @@ public class BedrockContainerCloseTranslator extends PacketTranslator<ContainerC
if (openInventory instanceof Container container && !(container instanceof MerchantContainer) && !container.isUsingRealBlock()) {
if (session.getContainerOpenAttempts() < 3) {
container.setPending(true);
container.setCurrentlyDelayed(true);
session.setPendingInventoryId(container.getJavaId());
container.setDelayed(true);
session.setPendingInventoryId(container.getBedrockId());
session.scheduleInEventLoop(() -> {
NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket();

View file

@ -87,11 +87,10 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
boolean pending = openInventory.isPending();
newInventory.setDisplayed(openInventory.isDisplayed());
newInventory.setPending(pending);
newInventory.setCurrentlyDelayed(openInventory.isCurrentlyDelayed());
newInventory.setDelayed(openInventory.isDelayed());
session.setOpenInventory(newInventory);
GeyserImpl.getInstance().getLogger().debug(session, "Able to reuse current inventory, matching Bedrock id (%s). Is current pending? %s",
openInventory.getBedrockId(), pending);
GeyserImpl.getInstance().getLogger().debug(session, "Able to reuse current inventory. Is current pending? %s", pending);
// If the current inventory is still pending, it'll be updated once open
if (newInventory.isDisplayed()) {

View file

@ -104,7 +104,7 @@ public class InventoryUtils {
// Wait for close confirmation from client before opening the new inventory.
// Handled in BedrockContainerCloseTranslator
// or - client hasn't yet loaded in; wait until inventory is shown
GeyserImpl.getInstance().getLogger().debug(session, "Inventory (%s) set pending: closing inv? %s, pending inv id? %s", inventory.getJavaId(), session.isClosingInventory(), session.getPendingInventoryId());
GeyserImpl.getInstance().getLogger().debug(session, "Inventory (%s) set pending: closing inv? %s, pending inv id? %s", debugInventory(inventory), session.isClosingInventory(), session.getPendingInventoryId());
inventory.setPending(true);
return;
}
@ -119,19 +119,19 @@ public class InventoryUtils {
public static void openPendingInventory(GeyserSession session) {
Inventory currentInventory = session.getOpenInventory();
if (currentInventory == null || !currentInventory.isPending()) {
GeyserImpl.getInstance().getLogger().debug(session, "No pending inventory, not opening an inventory! Current inventory: %s", currentInventory);
GeyserImpl.getInstance().getLogger().debug(session, "No pending inventory, not opening an inventory! Current inventory: %s", debugInventory(currentInventory));
session.setPendingInventoryId(-1);
return;
}
// Current inventory isn't null! Let's see if we need to open it.
if (currentInventory.isCurrentlyDelayed() && currentInventory.getJavaId() == session.getPendingInventoryId()) {
GeyserImpl.getInstance().getLogger().debug(session, "Attempting to open currently delayed inventory with matching java id! " + currentInventory.getJavaId());
if (currentInventory.isDelayed() && currentInventory.getBedrockId() == session.getPendingInventoryId()) {
GeyserImpl.getInstance().getLogger().debug(session, "Attempting to open currently delayed inventory with matching bedrock id! " + currentInventory.getBedrockId());
openAndUpdateInventory(session, currentInventory);
return;
}
GeyserImpl.getInstance().getLogger().debug(session, "Opening any pending inventory! " + currentInventory.getJavaId());
GeyserImpl.getInstance().getLogger().debug(session, "Opening any pending inventory! " + debugInventory(currentInventory));
session.setPendingInventoryId(-1);
openInventory(session, currentInventory);
@ -146,15 +146,15 @@ public class InventoryUtils {
if (translator.prepareInventory(session, inventory)) {
if (translator.shouldDelayInventoryOpen(session, inventory)) {
inventory.setPending(true);
inventory.setCurrentlyDelayed(true);
session.setPendingInventoryId(inventory.getJavaId());
inventory.setDelayed(true);
session.setPendingInventoryId(inventory.getBedrockId());
NetworkStackLatencyPacket latencyPacket = new NetworkStackLatencyPacket();
latencyPacket.setFromServer(true);
latencyPacket.setTimestamp(MAGIC_VIRTUAL_INVENTORY_HACK);
session.sendUpstreamPacket(latencyPacket);
GeyserImpl.getInstance().getLogger().debug(session, "Queuing virtual inventory with id %s", inventory.getJavaId());
GeyserImpl.getInstance().getLogger().debug(session, "Queuing virtual inventory (%s)", debugInventory(inventory));
} else {
openAndUpdateInventory(session, inventory);
}
@ -173,7 +173,7 @@ public class InventoryUtils {
inventory.getTranslator().updateInventory(session, inventory);
inventory.setDisplayed(true);
inventory.setPending(false);
inventory.setCurrentlyDelayed(false);
inventory.setDelayed(false);
session.setPendingInventoryId(-1);
}
@ -491,4 +491,15 @@ public class InventoryUtils {
}
return true;
}
private static String debugInventory(@Nullable Inventory inventory) {
if (inventory == null) {
return "null";
}
return inventory.getClass().getSimpleName() + ": javaId=" + inventory.getJavaId() +
", bedrockId=" + inventory.getBedrockId() + ", size=" + inventory.getSize() +
", type=" + inventory.getContainerType().name() + ", pending=" + inventory.isPending() +
", displayed=" + inventory.isPending() + ", delayed=" + inventory.isPending();
}
}