use of org.bukkit.event.player.PlayerItemHeldEvent in project Glowstone by GlowstoneMC.
the class HeldItemHandler method handle.
@Override
public void handle(GlowSession session, HeldItemMessage message) {
int slot = message.getSlot();
if (slot < 0 || slot > 8) {
// sanity check
return;
}
GlowPlayer player = session.getPlayer();
int oldSlot = player.getInventory().getHeldItemSlot();
if (slot == oldSlot) {
// ignore
return;
}
PlayerItemHeldEvent event = new PlayerItemHeldEvent(player, oldSlot, slot);
EventFactory.callEvent(event);
if (!event.isCancelled()) {
player.getInventory().setRawHeldItemSlot(slot);
} else {
// sends a packet to switch back to the previous held slot
player.getInventory().setHeldItemSlot(oldSlot);
}
}
Aggregations