---
title: Enums and Events
---

---
Lifetime
---

The `Lifetime` enum is used to tell Mixson how to handle the event after it has been registered. The enum is defined
as follows:
```java
public enum Lifetime {
    PERSISTENT,
    ONCE,
    DEFERRED
}
```
If an event is registered with a `Lifetime` of `PERSISTENT`, then Mixson will not unregister the event automatically.

If an event is registered with a `Lifetime` of `ONCE`, then Mixson will unregister the event automatically after the
event has been fired once.

If an event is registered with a `Lifetime` of `DEFERRED`, then Mixson will not add the event to the event poll on its
own. The developer will need to pull the event into the event queue manually via the `EventContext#pullIntoRuntime`
method. Event pulling will be explained in more detail in the next section. The `DEFERRED` lifetime is treated as a
`ONCE` lifetime once pulled.

---
ErrorPolicy
---

An `ErrorPolicy` must be stated for each event that is registered. The error policy tells Mixson what to due in case
the given event throws an exception. The `EventPolicy` enum is defined as follows:
```java
public enum ErrorPolicy {
    IGNORE,
    LOG,
    THROW
}
```
If an event is registered with an `ErrorPolicy` of `IGNORE`, then Mixson will not log or throw the exception.
It will be as if it never happened.

If an event is registered with an `ErrorPolicy` of `LOG`, then Mixson will log the exception, but continue execution.

If an event is registered with an `ErrorPolicy` of `THROW`, then Mixson will throw the exception with extra details as
to what file in particular it failed to operate on.

---
Event
---

All events in Mixson leverage the `Event` interface. The interface is defined as follows:
```java
public interface Event<T> {
    void runEvent(EventContext<T> context);
}
```
The interface is a `FunctionalInterface`, meaning it can be represented with a lambda expression. The `EventContext` is
explored in the following. The generic type `T` is the deserialized resource type that the event will
operate on. Example types include `JsonElement`, `BufferedImage`, and `NbtTag`.