This repository was archived by the owner on Nov 28, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathEvent.kt
More file actions
48 lines (40 loc) · 1.54 KB
/
Event.kt
File metadata and controls
48 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package io.github.dockyardmc.events
import io.github.dockyardmc.entity.Entity
import io.github.dockyardmc.events.system.EventFilter
import io.github.dockyardmc.location.Location
import io.github.dockyardmc.player.Player
import io.github.dockyardmc.world.World
interface Event {
val context: Context
class Context(
players: Set<Player> = setOf<Player>(),
entities: Set<Entity> = setOf<Entity>(),
worlds: Set<World> = setOf<World>(),
locations: Set<Location> = setOf<Location>(),
other: Set<Any> = setOf<Any>(),
val isGlobalEvent: Boolean = false
) {
// combining sets is expensive and is done in initialization of every event.
// In most cases, either none or only one is accessed. Let's make them lazy so they are
// computed only when needed
val players: Set<Player> by lazy {
players + entities.filterIsInstance<Player>()
}
val entities: Set<Entity> by lazy {
entities + players
}
val locations: Set<Location> by lazy {
locations + this.entities.map { entity -> entity.location }
}
val worlds: Set<World> by lazy {
worlds + this.locations.map { location -> location.world }
}
val other: Set<Any> by lazy {
this.players + this.entities + this.worlds + this.locations + other
}
operator fun contains(element: Any) = other.contains(element)
}
}
operator fun EventFilter.not(): EventFilter {
return EventFilter { !this.check(it) }
}