SwitchActiveSlotEvent
Package:
com.hypixel.hytale.server.core.event.events.ecsExtends:CancellableEcsEventImplements:ICancellableEcsEventCancellable: Yes
ECS event dispatched when the active hotbar slot changes. Fires for both client-initiated slot switches (player pressing hotbar keys) and server-initiated slot switches (programmatic changes). The serverRequest field distinguishes the two origins. An additional isClientRequest() convenience method returns the inverse.
Cancelling this event prevents the active slot from changing. The newSlot field is mutable, allowing listeners to redirect the selection to a different slot.
Fields / Accessors
Section titled “Fields / Accessors”| Field | Type | Accessor | Mutable | Nullable |
|---|---|---|---|---|
inventorySectionId | int | getInventorySectionId() | No | No |
previousSlot | int | getPreviousSlot() | No | No |
newSlot | byte | getNewSlot() | Yes | No |
serverRequest | boolean | isServerRequest() | No | No |
- inventorySectionId — The inventory section being switched within (identifies the hotbar section).
- previousSlot — The slot index that was active before this switch.
- newSlot — The slot index being switched to. Mutable via
setNewSlot(byte)— changing this redirects which slot becomes active. - serverRequest —
trueif initiated by the server,falseif initiated by the client (player input). Also accessible asisClientRequest().
Fired By
Section titled “Fired By”InventoryPacketHandler(lines 357, 415) viastore.invoke(ref, event)— ECS dispatch when active hotbar slot changes (two call sites — server-request and client-request).
Listening
Section titled “Listening”ECS events are handled by EntityEventSystem subclasses, not by getEventRegistry().register().
public class MySlotSwitchHandler extends EntityEventSystem<EntityStore, SwitchActiveSlotEvent> { @Override public Query<EntityStore> getQuery() { return MY_COMPONENT_TYPE; }
@Override public void handle(int index, ArchetypeChunk<EntityStore> chunk, Store<EntityStore> store, CommandBuffer<EntityStore> commandBuffer, SwitchActiveSlotEvent event) { int previous = event.getPreviousSlot(); byte newSlot = event.getNewSlot(); boolean fromServer = event.isServerRequest();
// Example: lock the active slot during a minigame if (isMinigameActive()) { event.setCancelled(true); } }}
// Register in plugin setup():getEntityStoreRegistry().registerSystem(new MySlotSwitchHandler());Related Events
Section titled “Related Events”DropItemEvent— Also dispatched fromInventoryPacketHandler, related to inventory manipulation.