Package org.spongepowered.api.event
Class EventContext
- java.lang.Object
 - 
- org.spongepowered.api.event.EventContext
 
 
- 
@DoNotStore public final class EventContext extends java.lang.Object
Provides context for an event outside of the direct chain of causes present in the event'sCause. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEventContext.Builder 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<EventContextKey<?>,java.lang.Object>asMap()Gets this event context as aMapof EventContextKeys to Objects.static EventContext.Builderbuilder()Creates a new builder for creating anEventContext.booleancontainsKey(java.util.function.Supplier<? extends EventContextKey<?>> key)Gets whether the providedEventContextKeyis included in this context.booleancontainsKey(EventContextKey<?> key)Gets whether the providedEventContextKeyis included in this context.static EventContextempty()Gets an empty context.booleanequals(@Nullable java.lang.Object object)<T> java.util.Optional<T>get(java.util.function.Supplier<EventContextKey<T>> key)Gets the value corresponding to the given key from the context.<T> java.util.Optional<T>get(EventContextKey<T> key)Gets the value corresponding to the given key from the context.inthashCode()java.util.Set<EventContextKey<?>>keySet()Gets allEventContextKeys present in this context.static EventContextof(java.util.Map<EventContextKey<?>,java.lang.Object> entries)Creates a newEventContextfrom the given map of entries.<T> Trequire(java.util.function.Supplier<EventContextKey<T>> key)Gets the value corresponding to the given key from the context.<T> Trequire(EventContextKey<T> key)Gets the value corresponding to the given key from the context.java.lang.StringtoString() 
 - 
 
- 
- 
Method Detail
- 
empty
public static EventContext empty()
Gets an empty context.- Returns:
 - The empty context
 
 
- 
of
public static EventContext of(java.util.Map<EventContextKey<?>,java.lang.Object> entries)
Creates a newEventContextfrom the given map of entries.- Parameters:
 entries- The context entries- Returns:
 - The new EventContext
 
 
- 
builder
public static EventContext.Builder builder()
Creates a new builder for creating anEventContext.- Returns:
 - The new builder
 
 
- 
get
public <T> java.util.Optional<T> get(EventContextKey<T> key)
Gets the value corresponding to the given key from the context.- Type Parameters:
 T- The type of the value stored with the key- Parameters:
 key- The key- Returns:
 - The context value, if found
 
 
- 
get
public <T> java.util.Optional<T> get(java.util.function.Supplier<EventContextKey<T>> key)
Gets the value corresponding to the given key from the context.- Type Parameters:
 T- The type of the value stored with the key- Parameters:
 key- The key- Returns:
 - The context value, if found
 
 
- 
require
public <T> T require(EventContextKey<T> key)
Gets the value corresponding to the given key from the context.If the key is not available,
NoSuchElementExceptionwill be thrown.- Type Parameters:
 T- The type of the value stored with the key- Parameters:
 key- The key- Returns:
 - The context value, if found
 
 
- 
require
public <T> T require(java.util.function.Supplier<EventContextKey<T>> key)
Gets the value corresponding to the given key from the context.If the key is not available,
NoSuchElementExceptionwill be thrown.- Type Parameters:
 T- The type of the value stored with the key- Parameters:
 key- The key- Returns:
 - The context value, if found
 
 
- 
containsKey
public boolean containsKey(EventContextKey<?> key)
Gets whether the providedEventContextKeyis included in this context.- Parameters:
 key- The context key to check- Returns:
 - True if the key is used and there is an entry for it
 
 
- 
containsKey
public boolean containsKey(java.util.function.Supplier<? extends EventContextKey<?>> key)
Gets whether the providedEventContextKeyis included in this context.- Parameters:
 key- The context key to check- Returns:
 - True if the key is used and there is an entry for it
 
 
- 
keySet
public java.util.Set<EventContextKey<?>> keySet()
Gets allEventContextKeys present in this context.- Returns:
 - All present keys
 
 
- 
asMap
public java.util.Map<EventContextKey<?>,java.lang.Object> asMap()
Gets this event context as aMapof EventContextKeys to Objects.- Returns:
 - A map view of this context
 
 
- 
equals
public boolean equals(@Nullable java.lang.Object object)
- Overrides:
 equalsin classjava.lang.Object
 
- 
hashCode
public int hashCode()
- Overrides:
 hashCodein classjava.lang.Object
 
- 
toString
public java.lang.String toString()
- Overrides:
 toStringin classjava.lang.Object
 
 - 
 
 -