|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.translators.bedrock; |
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.client.window.ClientCloseWindowPacket; |
|
import com.nukkitx.protocol.bedrock.packet.ContainerClosePacket; |
|
import org.geysermc.connector.inventory.Inventory; |
|
import org.geysermc.connector.inventory.MerchantContainer; |
|
import org.geysermc.connector.network.session.GeyserSession; |
|
import org.geysermc.connector.network.translators.PacketTranslator; |
|
import org.geysermc.connector.network.translators.Translator; |
|
import org.geysermc.connector.utils.InventoryUtils; |
|
|
|
@Translator(packet = ContainerClosePacket.class) |
|
public class BedrockContainerCloseTranslator extends PacketTranslator<ContainerClosePacket> { |
|
|
|
@Override |
|
|
|
|
|
|
|
public void translate(GeyserSession session, ContainerClosePacket packet) { |
|
byte windowId = packet.getId(); |
|
|
|
|
|
session.sendUpstreamPacket(packet); |
|
session.setClosingInventory(false); |
|
|
|
if (windowId == -1 && session.getOpenInventory() instanceof MerchantContainer) { |
|
|
|
windowId = (byte) session.getOpenInventory().getId(); |
|
} |
|
|
|
Inventory openInventory = session.getOpenInventory(); |
|
if (openInventory != null) { |
|
if (windowId == openInventory.getId()) { |
|
ClientCloseWindowPacket closeWindowPacket = new ClientCloseWindowPacket(windowId); |
|
session.sendDownstreamPacket(closeWindowPacket); |
|
InventoryUtils.closeInventory(session, windowId, false); |
|
} else if (openInventory.isPending()) { |
|
InventoryUtils.displayInventory(session, openInventory); |
|
openInventory.setPending(false); |
|
} |
|
} |
|
} |
|
} |
|
|