mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-16 04:33:56 -07:00
Fix NPE with enchantable (#11557)
This commit is contained in:
@@ -39,7 +39,6 @@ public interface Generators {
|
||||
// built-ins
|
||||
simpleKey("GameEventKeys", GameEvent.class, Registries.GAME_EVENT, RegistryKey.GAME_EVENT, true),
|
||||
simpleKey("StructureTypeKeys", StructureType.class, Registries.STRUCTURE_TYPE, RegistryKey.STRUCTURE_TYPE, false),
|
||||
simpleKey("InstrumentKeys", MusicInstrument.class, Registries.INSTRUMENT, RegistryKey.INSTRUMENT, false),
|
||||
simpleKey("MobEffectKeys", PotionEffectType.class, Registries.MOB_EFFECT, RegistryKey.MOB_EFFECT, false),
|
||||
simpleKey("BlockTypeKeys", BlockType.class, Registries.BLOCK, RegistryKey.BLOCK, false),
|
||||
simpleKey("ItemTypeKeys", ItemType.class, Registries.ITEM, RegistryKey.ITEM, false),
|
||||
@@ -60,10 +59,11 @@ public interface Generators {
|
||||
simpleKey("TrimPatternKeys", TrimPattern.class, Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN, true),
|
||||
simpleKey("DamageTypeKeys", DamageType.class, Registries.DAMAGE_TYPE, RegistryKey.DAMAGE_TYPE, true),
|
||||
simpleKey("WolfVariantKeys", Wolf.Variant.class, Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT, true),
|
||||
simpleKey("EnchantmentKeys", Enchantment.class, Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT, false),
|
||||
simpleKey("EnchantmentKeys", Enchantment.class, Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT, true),
|
||||
simpleKey("JukeboxSongKeys", JukeboxSong.class, Registries.JUKEBOX_SONG, RegistryKey.JUKEBOX_SONG, true),
|
||||
simpleKey("BannerPatternKeys", PatternType.class, Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN, true),
|
||||
simpleKey("PaintingVariantKeys", Art.class, Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT, true),
|
||||
simpleKey("InstrumentKeys", MusicInstrument.class, Registries.INSTRUMENT, RegistryKey.INSTRUMENT, true),
|
||||
|
||||
// tags
|
||||
simpleTagKey("EnchantmentTagKeys", Enchantment.class, Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT),
|
||||
|
@@ -42,7 +42,6 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static com.squareup.javapoet.TypeSpec.classBuilder;
|
||||
import static io.papermc.generator.utils.Annotations.EXPERIMENTAL_API_ANNOTATION;
|
||||
import static io.papermc.generator.utils.Annotations.NOT_NULL;
|
||||
import static io.papermc.generator.utils.Annotations.experimentalAnnotations;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static javax.lang.model.element.Modifier.FINAL;
|
||||
@@ -96,14 +95,14 @@ public class GeneratedKeyType<T, A> extends SimpleGenerator {
|
||||
}
|
||||
|
||||
private MethodSpec.Builder createMethod(final TypeName returnType) {
|
||||
final TypeName keyType = TypeName.get(Key.class).annotated(NOT_NULL);
|
||||
final TypeName keyType = TypeName.get(Key.class);
|
||||
|
||||
final ParameterSpec keyParam = ParameterSpec.builder(keyType, "key", FINAL).build();
|
||||
final MethodSpec.Builder create = MethodSpec.methodBuilder("create")
|
||||
.addModifiers(this.publicCreateKeyMethod ? PUBLIC : PRIVATE, STATIC)
|
||||
.addParameter(keyParam)
|
||||
.addCode("return $T.create($T.$L, $N);", TypedKey.class, RegistryKey.class, requireNonNull(REGISTRY_KEY_FIELD_NAMES.get(this.apiRegistryKey), "Missing field for " + this.apiRegistryKey), keyParam)
|
||||
.returns(returnType.annotated(NOT_NULL));
|
||||
.returns(returnType);
|
||||
if (this.publicCreateKeyMethod) {
|
||||
create.addAnnotation(EXPERIMENTAL_API_ANNOTATION); // TODO remove once not experimental
|
||||
create.addJavadoc(CREATE_JAVADOC, this.apiType, this.registryKey.location().toString());
|
||||
|
@@ -26,7 +26,6 @@ import org.bukkit.MinecraftExperimental;
|
||||
|
||||
import static com.squareup.javapoet.TypeSpec.classBuilder;
|
||||
import static io.papermc.generator.utils.Annotations.EXPERIMENTAL_API_ANNOTATION;
|
||||
import static io.papermc.generator.utils.Annotations.NOT_NULL;
|
||||
import static io.papermc.generator.utils.Annotations.experimentalAnnotations;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static javax.lang.model.element.Modifier.FINAL;
|
||||
@@ -73,14 +72,14 @@ public class GeneratedTagKeyType<T, A> extends SimpleGenerator {
|
||||
}
|
||||
|
||||
private MethodSpec.Builder createMethod(final TypeName returnType) {
|
||||
final TypeName keyType = TypeName.get(Key.class).annotated(NOT_NULL);
|
||||
final TypeName keyType = TypeName.get(Key.class);
|
||||
|
||||
final ParameterSpec keyParam = ParameterSpec.builder(keyType, "key", FINAL).build();
|
||||
final MethodSpec.Builder create = MethodSpec.methodBuilder("create")
|
||||
.addModifiers(this.publicCreateKeyMethod ? PUBLIC : PRIVATE, STATIC)
|
||||
.addParameter(keyParam)
|
||||
.addCode("return $T.create($T.$L, $N);", TagKey.class, RegistryKey.class, requireNonNull(REGISTRY_KEY_FIELD_NAMES.get(this.apiRegistryKey), "Missing field for " + this.apiRegistryKey), keyParam)
|
||||
.returns(returnType.annotated(NOT_NULL));
|
||||
.returns(returnType);
|
||||
if (this.publicCreateKeyMethod) {
|
||||
create.addAnnotation(EXPERIMENTAL_API_ANNOTATION); // TODO remove once not experimental
|
||||
create.addJavadoc(CREATE_JAVADOC, this.apiType, this.registryKey.location().toString());
|
||||
|
@@ -50,10 +50,8 @@ public class MobGoalGenerator extends SimpleGenerator {
|
||||
.addAnnotations(Annotations.CLASS_HEADER)
|
||||
.addJavadoc(CLASS_HEADER);
|
||||
|
||||
TypeName mobType = ParameterizedTypeName.get(ClassName.get(Class.class), type)
|
||||
.annotated(Annotations.NOT_NULL);
|
||||
TypeName keyType = TypeName.get(String.class)
|
||||
.annotated(Annotations.NOT_NULL);
|
||||
TypeName mobType = ParameterizedTypeName.get(ClassName.get(Class.class), type);
|
||||
TypeName keyType = TypeName.get(String.class);
|
||||
|
||||
ParameterSpec keyParam = ParameterSpec.builder(keyType, "key", FINAL).build();
|
||||
ParameterSpec typeParam = ParameterSpec.builder(mobType, "type", FINAL).build();
|
||||
@@ -63,7 +61,7 @@ public class MobGoalGenerator extends SimpleGenerator {
|
||||
.addParameter(typeParam)
|
||||
.addCode("return $T.of($N, $T.minecraft($N));", GoalKey.class, typeParam, NamespacedKey.class, keyParam)
|
||||
.addTypeVariable(type)
|
||||
.returns(ParameterizedTypeName.get(ClassName.get(GoalKey.class), type).annotated(Annotations.NOT_NULL));
|
||||
.returns(ParameterizedTypeName.get(ClassName.get(GoalKey.class), type));
|
||||
|
||||
List<Class<Goal>> classes;
|
||||
try (ScanResult scanResult = new ClassGraph().enableAllInfo().whitelistPackages("net.minecraft").scan()) {
|
||||
|
@@ -7,9 +7,9 @@ import java.util.List;
|
||||
import io.papermc.paper.generated.GeneratedFrom;
|
||||
import net.minecraft.SharedConstants;
|
||||
import org.bukkit.MinecraftExperimental;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
public final class Annotations {
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class Annotations {
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public static final AnnotationSpec EXPERIMENTAL_API_ANNOTATION = AnnotationSpec.builder(ApiStatus.Experimental.class).build();
|
||||
public static final AnnotationSpec NOT_NULL = AnnotationSpec.builder(NonNull.class).build();
|
||||
public static final AnnotationSpec NULL_MARKED = AnnotationSpec.builder(NullMarked.class).build();
|
||||
private static final AnnotationSpec SUPPRESS_WARNINGS = AnnotationSpec.builder(SuppressWarnings.class)
|
||||
.addMember("value", "$S", "unused")
|
||||
.addMember("value", "$S", "SpellCheckingInspection")
|
||||
@@ -56,7 +56,8 @@ public final class Annotations {
|
||||
.build();
|
||||
public static final Iterable<AnnotationSpec> CLASS_HEADER = List.of(
|
||||
SUPPRESS_WARNINGS,
|
||||
GENERATED_FROM
|
||||
GENERATED_FROM,
|
||||
NULL_MARKED
|
||||
);
|
||||
|
||||
private Annotations() {
|
||||
|
Reference in New Issue
Block a user