Player player = session.getPlayer();
QuickbarInventory quickbar = PlayerUtil.getQuickbar(session.getPlayer());
if (quickbar == null) {
return;
}
PlayerHeldItemChangeEvent event = new PlayerHeldItemChangeEvent(player, quickbar.getSelectedSlot().getIndex(), newSlot);
if (player.getEngine().getEventManager().callEvent(event).isCancelled()) {
// Reset
player.getNetwork().callProtocolEvent(new PlayerSelectedSlotChangeEvent(session.getPlayer(), event.getPreviousSlot()), player);
} else {
quickbar.setSelectedSlot(event.getNewSlot());
quickbar.updateHeldItem(player);
// Changed slot by event handler
if (newSlot != event.getNewSlot()) {
player.getNetwork().callProtocolEvent(new PlayerSelectedSlotChangeEvent(session.getPlayer(), event.getNewSlot()), player);
}
}
}