Package ch.njol.skript.registrations
Class EventValues
java.lang.Object
ch.njol.skript.registrations.EventValues
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe future time of an event value.static final intThe current time of an event value.static final intThe past time of an event value. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleandoesEventValueHaveTimeStates(Class<? extends Event> event, Class<?> c) static booleandoesExactEventValueHaveTimeStates(Class<? extends Event> event, Class<?> c) static <T,E extends Event>
TgetEventValue(E e, Class<T> c, int time) Gets a specific value from an event.getEventValueGetter(Class<E> event, Class<T> type, int time) Returns a getter to get a value from in an event.static List<ch.njol.skript.registrations.EventValues.EventValueInfo<?, ?>> getEventValuesListForTime(int time) Get Event Values list for the specified timegetExactEventValueGetter(Class<E> event, Class<T> c, int time) Checks that a getter exists for the exact type.hasMultipleGetters(Class<E> event, Class<T> type, int time) Checks if an event has multiple getters, including default ones.static <T,E extends Event>
voidregisterEventValue(Class<E> event, Class<T> type, Getter<T, E> getter, int time) Registers an event value.static <T,E extends Event>
voidregisterEventValue(Class<E> event, Class<T> type, Getter<T, E> getter, int time, @Nullable String excludeErrorMessage, @Nullable Class<? extends E>... excludes) Registers an event value and with excluded events.
-
Field Details
-
TIME_PAST
public static final int TIME_PASTThe past time of an event value. Represented by "past" or "former".- See Also:
-
TIME_NOW
public static final int TIME_NOWThe current time of an event value.- See Also:
-
TIME_FUTURE
public static final int TIME_FUTUREThe future time of an event value.- See Also:
-
-
Method Details
-
getEventValuesListForTime
public static List<ch.njol.skript.registrations.EventValues.EventValueInfo<?,?>> getEventValuesListForTime(int time) Get Event Values list for the specified time- Parameters:
time- The time of the event values. One ofTIME_PAST,TIME_NOWorTIME_FUTURE.- Returns:
- An immutable copy of the event values list for the specified time
-
registerEventValue
public static <T,E extends Event> void registerEventValue(Class<E> event, Class<T> type, Getter<T, E> getter, int time) Registers an event value.- Parameters:
event- the event type class.type- the return type of the getter for the event value.getter- the getter to get the value with the provided event.time- value of TIME_PAST if this is the value before the event, TIME_FUTURE if after, and TIME_NOW if it's the default or this value doesn't have distinct states. Always register a default state! You can leave out one of the other states instead, e.g. only register a default and a past state. The future state will default to the default state in this case.
-
registerEventValue
@SafeVarargs public static <T,E extends Event> void registerEventValue(Class<E> event, Class<T> type, Getter<T, E> getter, int time, @Nullable @Nullable String excludeErrorMessage, @Nullable @Nullable Class<? extends E>... excludes) Registers an event value and with excluded events. Excluded events are events that this event value can't operate in.- Parameters:
event- the event type class.type- the return type of the getter for the event value.getter- the getter to get the value with the provided event.time- value of TIME_PAST if this is the value before the event, TIME_FUTURE if after, and TIME_NOW if it's the default or this value doesn't have distinct states. Always register a default state! You can leave out one of the other states instead, e.g. only register a default and a past state. The future state will default to the default state in this case.excludeErrorMessage- The error message to display when used in the excluded events.excludes- subclasses of the event for which this event value should not be registered for
-
getEventValue
Gets a specific value from an event. Returns null if the event doesn't have such a value (conversions are done to try and get the desired value).It is recommended to use
getEventValueGetter(Class, Class, int)orEventValueExpression(Class)instead of invoking this method repeatedly.- Parameters:
e- eventc- return type of gettertime- -1 if this is the value before the event, 1 if after, and 0 if it's the default or this value doesn't have distinct states. Always register a default state! You can leave out one of the other states instead, e.g. only register a default and a past state. The future state will default to the default state in this case.- Returns:
- The event's value
- See Also:
-
getExactEventValueGetter
@Nullable public static <T,E extends Event> @Nullable Getter<? extends T,? super E> getExactEventValueGetter(Class<E> event, Class<T> c, int time) Checks that a getter exists for the exact type. No converting or subclass checking.- Parameters:
event- the event class the getter will be getting fromc- type of gettertime- the event-value's time- Returns:
- A getter to get values for a given type of events
- See Also:
-
hasMultipleGetters
public static <T,E extends Event> Kleenean hasMultipleGetters(Class<E> event, Class<T> type, int time) Checks if an event has multiple getters, including default ones.- Parameters:
event- the event class the getter will be getting from.type- type of getter.time- the event-value's time.- Returns:
- true or false if the event and type have multiple getters.
-
getEventValueGetter
@Nullable public static <T,E extends Event> @Nullable Getter<? extends T,? super E> getEventValueGetter(Class<E> event, Class<T> type, int time) Returns a getter to get a value from in an event.Can print an error if the event value is blocked for the given event.
- Parameters:
event- the event class the getter will be getting from.type- type of getter.time- the event-value's time.- Returns:
- A getter to get values for a given type of events.
- See Also:
-
doesExactEventValueHaveTimeStates
-
doesEventValueHaveTimeStates
-