Cleanup EventContextKey and builder.
*/
package org.spongepowered.api.event.cause;
+import com.google.common.reflect.TypeToken;
import org.spongepowered.api.CatalogType;
import org.spongepowered.api.Sponge;
-import org.spongepowered.api.util.CopyableBuilder;
+import org.spongepowered.api.util.CatalogBuilder;
import org.spongepowered.api.util.annotation.CatalogedBy;
/**
/**
* Creates a builder to be used for creating a new {@link EventContextKey}.
*
- * @param clazz The class the key will allow access to
- * @param <T> The type of the value stored with this key
* @return The constructed builder
*/
@SuppressWarnings("unchecked")
- static <T> Builder<T> builder(Class<T> clazz) {
- return Sponge.getRegistry().createBuilder(Builder.class).type(clazz);
+ static Builder<?> builder() {
+ return Sponge.getRegistry().createBuilder(Builder.class);
}
/**
*
* @return The allowed type
*/
- Class<T> getAllowedType();
-
- interface Builder<T> extends CopyableBuilder<EventContextKey<T>, Builder<T>> {
-
- Builder<T> type(Class<T> tClass);
+ TypeToken<T> getAllowedType();
- Builder<T> id(String id);
+ interface Builder<T> extends CatalogBuilder<EventContextKey<T>, Builder<T>> {
- Builder<T> name(String name);
-
- EventContextKey<T> build();
-
- @Override
- Builder<T> from(EventContextKey<T> value) throws UnsupportedOperationException;
+ default <N> Builder<N> type(Class<N> allowedType) {
+ return type(TypeToken.of(allowedType));
+ }
- @Override
- Builder<T> reset();
+ <N> Builder<N> type(TypeToken<N> allowedType);
}
}
