use of net.glowstone.net.message.play.inv.CloseWindowMessage in project Dragonet-Legacy by DragonetMC.
the class OpenWindowMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(OpenWindowMessage packet) {
byte typePE = InventoryType.PEInventory.toPEInventory(InventoryType.PCInventory.fromString(packet.type), packet.slots);
if (typePE == (byte) 0xFF) {
// Not supported, close it
CloseWindowMessage msgCloseWindow = new CloseWindowMessage(packet.id);
this.getSession().messageReceived(msgCloseWindow);
return null;
}
WindowOpenPacket pkOpenWindow = new WindowOpenPacket();
pkOpenWindow.windowID = (byte) (packet.id & 0xFF);
pkOpenWindow.type = typePE;
pkOpenWindow.slots = (byte) (packet.slots & 0xFFFF);
pkOpenWindow.x = this.getSession().getPlayer().getLocation().getBlockX();
pkOpenWindow.y = this.getSession().getPlayer().getLocation().getBlockY();
pkOpenWindow.z = this.getSession().getPlayer().getLocation().getBlockZ();
getSession().getOpenedWindows().add(packet.id);
this.getTranslator().cachedWindowType[packet.id & 0xFF] = typePE;
return new PEPacket[] { pkOpenWindow };
}
use of net.glowstone.net.message.play.inv.CloseWindowMessage in project Glowstone by GlowstoneMC.
the class GlowPlayer method openInventory.
@Override
public void openInventory(InventoryView view) {
session.send(new CloseWindowMessage(invMonitor.getId()));
super.openInventory(view);
invMonitor = new InventoryMonitor(getOpenInventory());
int viewId = invMonitor.getId();
if (viewId != 0) {
InventoryOpenEvent event = EventFactory.getInstance().callEvent(new InventoryOpenEvent(view));
if (event.isCancelled()) {
// close the inventory but don't fire the InventoryCloseEvent
resetInventoryView();
return;
}
String title = view.getTitle();
boolean defaultTitle = Objects.equals(view.getType().getDefaultTitle(), title);
if (view.getTopInventory() instanceof PlayerInventory && defaultTitle) {
title = ((PlayerInventory) view.getTopInventory()).getHolder().getName();
}
Message open = new OpenWindowMessage(viewId, invMonitor.getType(), title, ((GlowInventory) view.getTopInventory()).getRawSlots());
session.send(open);
}
updateInventory();
}
Aggregations