Event System
Přehled event systému v Hytale.
Typy Eventů
| Typ | Registrace | Thread | Soubor |
|-----|------------|--------|--------|
| Sync Events | register() | World thread | Různé |
| Async Events | registerAsync() | Async thread | PLAYER_EVENTS.md |
| ECS Events | EntityEventSystem | World thread | ECS_EVENTS.md |
Soubory
- PLAYER_EVENTS.md - Hráčské eventy (join, chat, interact, permissions)
- ECS_EVENTS.md - ECS eventy (block break/place, damage, death)
- WORLD_EVENTS.md - Světové eventy (load, chunk, zone)
- INVENTORY_EVENTS.md - Inventářové eventy (craft, pickup, drop)
Registrační Metody
register() / registerGlobal()
Pro synchronní eventy. Bezpečný přístup ke komponentům.
getEventRegistry().registerGlobal(PlayerReadyEvent.class, event -> {
Player player = event.getPlayer();
// Bezpečné - jsme na world threadu
});
registerAsync() / registerAsyncGlobal()
Pro asynchronní eventy (např.
PlayerChatEvent). BEZ přímého přístupu ke komponentům!getEventRegistry().registerAsyncGlobal(PlayerChatEvent.class, future -> {
future.thenAccept(event -> {
// Pro komponenty použij world.execute()
event.getPlayer().getWorld().execute(() -> {
// Teď bezpečné
});
});
});
EntityEventSystem
Pro ECS eventy (např.
BreakBlockEvent). Nelze použít register().public class MySystem extends EntityEventSystem {
public MySystem() { super(BreakBlockEvent.class); } @Override
public void handle(int i, ArchetypeChunk chunk,
Store store, CommandBuffer buffer,
BreakBlockEvent event) {
// Bezpečné - jsme na world threadu
}
@Override
public Query getQuery() {
return PlayerRef.getComponentType();
}
}
// Registrace
getEntityStoreRegistry().registerSystem(new MySystem());
Event Priority
getEventRegistry().register(EventPriority.HIGH, PlayerReadyEvent.class, event -> {
// Běží po NORMAL priority
});
| Priorita | Pořadí |
|----------|--------|
| LOWEST | 1. (první) |
| LOW | 2. |
| NORMAL | 3. (výchozí) |
| HIGH | 4. |
| HIGHEST | 5. (poslední) |
Cancellable Eventy
getEventRegistry().registerAsync(PlayerChatEvent.class, future -> {
future.thenAccept(event -> {
if (shouldBlock(event)) {
event.cancel(); // Zruší event
}
});
});
Časté Chyby
| Problém | Řešení |
|---------|--------|
| Chat event nefunguje | Použij registerAsync() ne register() |
| BreakBlockEvent nefunguje | Použij EntityEventSystem |
| "Assert not in thread!" | Použij world.execute() pro async eventy |
| DeathEvent nefunguje | Přidej závislost Hytale:DamageModule |
| BreakBlockEvent pro vzduch | Kontroluj BlockType.EMPTY |