mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix closing the inventory from the server
This commit is contained in:
parent
0727008881
commit
e1db626529
2 changed files with 10 additions and 5 deletions
|
@ -36,6 +36,6 @@ public class JavaCloseWindowTranslator extends PacketTranslator<ServerCloseWindo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void translate(ServerCloseWindowPacket packet, GeyserSession session) {
|
public void translate(ServerCloseWindowPacket packet, GeyserSession session) {
|
||||||
session.addInventoryTask(() -> InventoryUtils.closeInventory(session, packet.getWindowId(), true));
|
session.addInventoryTask(() -> InventoryUtils.closeInventory(session, packet.getWindowId(), (session.getOpenInventory() != null && session.getOpenInventory().getId() == packet.getWindowId())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,10 @@ import com.nukkitx.protocol.bedrock.packet.InventorySlotPacket;
|
||||||
import com.nukkitx.protocol.bedrock.packet.PlayerHotbarPacket;
|
import com.nukkitx.protocol.bedrock.packet.PlayerHotbarPacket;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
import org.geysermc.connector.common.ChatColor;
|
import org.geysermc.connector.common.ChatColor;
|
||||||
import org.geysermc.connector.inventory.*;
|
import org.geysermc.connector.inventory.Container;
|
||||||
|
import org.geysermc.connector.inventory.GeyserItemStack;
|
||||||
|
import org.geysermc.connector.inventory.Inventory;
|
||||||
|
import org.geysermc.connector.inventory.PlayerInventory;
|
||||||
import org.geysermc.connector.network.session.GeyserSession;
|
import org.geysermc.connector.network.session.GeyserSession;
|
||||||
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
||||||
import org.geysermc.connector.network.translators.inventory.translators.LecternInventoryTranslator;
|
import org.geysermc.connector.network.translators.inventory.translators.LecternInventoryTranslator;
|
||||||
|
@ -70,19 +73,21 @@ public class InventoryUtils {
|
||||||
if (translator != null) {
|
if (translator != null) {
|
||||||
translator.prepareInventory(session, inventory);
|
translator.prepareInventory(session, inventory);
|
||||||
if (translator instanceof DoubleChestInventoryTranslator && !((Container) inventory).isUsingRealBlock()) {
|
if (translator instanceof DoubleChestInventoryTranslator && !((Container) inventory).isUsingRealBlock()) {
|
||||||
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> {
|
GeyserConnector.getInstance().getGeneralThreadPool().schedule(() ->
|
||||||
session.addInventoryTask(() -> {
|
session.addInventoryTask(() -> {
|
||||||
Inventory openInv = session.getOpenInventory();
|
Inventory openInv = session.getOpenInventory();
|
||||||
if (openInv != null && openInv.getId() == inventory.getId()) {
|
if (openInv != null && openInv.getId() == inventory.getId()) {
|
||||||
translator.openInventory(session, inventory);
|
translator.openInventory(session, inventory);
|
||||||
translator.updateInventory(session, inventory);
|
translator.updateInventory(session, inventory);
|
||||||
}
|
}
|
||||||
});
|
}), 200, TimeUnit.MILLISECONDS);
|
||||||
}, 200, TimeUnit.MILLISECONDS);
|
|
||||||
} else {
|
} else {
|
||||||
translator.openInventory(session, inventory);
|
translator.openInventory(session, inventory);
|
||||||
translator.updateInventory(session, inventory);
|
translator.updateInventory(session, inventory);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Precaution - as of 1.16 every inventory should be translated so this shouldn't happen
|
||||||
|
session.setOpenInventory(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue