mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-31 21:48:08 +01:00
Finalise key in generated enums
This commit is contained in:
parent
6dd3eb8044
commit
5ac5b0ba99
@ -1,31 +1,11 @@
|
||||
package net.minestom.server.entity;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.key.Keyed;
|
||||
import net.minestom.server.entity.metadata.EntityMeta;
|
||||
import net.minestom.server.entity.metadata.PlayerMeta;
|
||||
import net.minestom.server.entity.metadata.ambient.BatMeta;
|
||||
import net.minestom.server.entity.metadata.animal.BeeMeta;
|
||||
import net.minestom.server.entity.metadata.animal.ChickenMeta;
|
||||
import net.minestom.server.entity.metadata.animal.CowMeta;
|
||||
import net.minestom.server.entity.metadata.animal.DonkeyMeta;
|
||||
import net.minestom.server.entity.metadata.animal.FoxMeta;
|
||||
import net.minestom.server.entity.metadata.animal.HoglinMeta;
|
||||
import net.minestom.server.entity.metadata.animal.HorseMeta;
|
||||
import net.minestom.server.entity.metadata.animal.LlamaMeta;
|
||||
import net.minestom.server.entity.metadata.animal.MooshroomMeta;
|
||||
import net.minestom.server.entity.metadata.animal.MuleMeta;
|
||||
import net.minestom.server.entity.metadata.animal.OcelotMeta;
|
||||
import net.minestom.server.entity.metadata.animal.PandaMeta;
|
||||
import net.minestom.server.entity.metadata.animal.PigMeta;
|
||||
import net.minestom.server.entity.metadata.animal.PolarBearMeta;
|
||||
import net.minestom.server.entity.metadata.animal.RabbitMeta;
|
||||
import net.minestom.server.entity.metadata.animal.SheepMeta;
|
||||
import net.minestom.server.entity.metadata.animal.SkeletonHorseMeta;
|
||||
import net.minestom.server.entity.metadata.animal.StriderMeta;
|
||||
import net.minestom.server.entity.metadata.animal.TurtleMeta;
|
||||
import net.minestom.server.entity.metadata.animal.ZombieHorseMeta;
|
||||
import net.minestom.server.entity.metadata.animal.*;
|
||||
import net.minestom.server.entity.metadata.animal.tameable.CatMeta;
|
||||
import net.minestom.server.entity.metadata.animal.tameable.ParrotMeta;
|
||||
import net.minestom.server.entity.metadata.animal.tameable.WolfMeta;
|
||||
@ -37,73 +17,15 @@ import net.minestom.server.entity.metadata.flying.PhantomMeta;
|
||||
import net.minestom.server.entity.metadata.golem.IronGolemMeta;
|
||||
import net.minestom.server.entity.metadata.golem.ShulkerMeta;
|
||||
import net.minestom.server.entity.metadata.golem.SnowGolemMeta;
|
||||
import net.minestom.server.entity.metadata.item.EyeOfEnderMeta;
|
||||
import net.minestom.server.entity.metadata.item.FireballMeta;
|
||||
import net.minestom.server.entity.metadata.item.ItemEntityMeta;
|
||||
import net.minestom.server.entity.metadata.item.SmallFireballMeta;
|
||||
import net.minestom.server.entity.metadata.item.SnowballMeta;
|
||||
import net.minestom.server.entity.metadata.item.ThrownEggMeta;
|
||||
import net.minestom.server.entity.metadata.item.ThrownEnderPearlMeta;
|
||||
import net.minestom.server.entity.metadata.item.ThrownExperienceBottleMeta;
|
||||
import net.minestom.server.entity.metadata.item.ThrownPotionMeta;
|
||||
import net.minestom.server.entity.metadata.minecart.ChestMinecartMeta;
|
||||
import net.minestom.server.entity.metadata.minecart.CommandBlockMinecartMeta;
|
||||
import net.minestom.server.entity.metadata.minecart.FurnaceMinecartMeta;
|
||||
import net.minestom.server.entity.metadata.minecart.HopperMinecartMeta;
|
||||
import net.minestom.server.entity.metadata.minecart.MinecartMeta;
|
||||
import net.minestom.server.entity.metadata.minecart.SpawnerMinecartMeta;
|
||||
import net.minestom.server.entity.metadata.minecart.TntMinecartMeta;
|
||||
import net.minestom.server.entity.metadata.monster.BlazeMeta;
|
||||
import net.minestom.server.entity.metadata.monster.CaveSpiderMeta;
|
||||
import net.minestom.server.entity.metadata.monster.CreeperMeta;
|
||||
import net.minestom.server.entity.metadata.monster.ElderGuardianMeta;
|
||||
import net.minestom.server.entity.metadata.monster.EndermanMeta;
|
||||
import net.minestom.server.entity.metadata.monster.EndermiteMeta;
|
||||
import net.minestom.server.entity.metadata.monster.GiantMeta;
|
||||
import net.minestom.server.entity.metadata.monster.GuardianMeta;
|
||||
import net.minestom.server.entity.metadata.monster.PiglinBruteMeta;
|
||||
import net.minestom.server.entity.metadata.monster.PiglinMeta;
|
||||
import net.minestom.server.entity.metadata.monster.SilverfishMeta;
|
||||
import net.minestom.server.entity.metadata.monster.SpiderMeta;
|
||||
import net.minestom.server.entity.metadata.monster.VexMeta;
|
||||
import net.minestom.server.entity.metadata.monster.WitherMeta;
|
||||
import net.minestom.server.entity.metadata.monster.ZoglinMeta;
|
||||
import net.minestom.server.entity.metadata.monster.raider.EvokerMeta;
|
||||
import net.minestom.server.entity.metadata.monster.raider.IllusionerMeta;
|
||||
import net.minestom.server.entity.metadata.monster.raider.PillagerMeta;
|
||||
import net.minestom.server.entity.metadata.monster.raider.RavagerMeta;
|
||||
import net.minestom.server.entity.metadata.monster.raider.VindicatorMeta;
|
||||
import net.minestom.server.entity.metadata.monster.raider.WitchMeta;
|
||||
import net.minestom.server.entity.metadata.item.*;
|
||||
import net.minestom.server.entity.metadata.minecart.*;
|
||||
import net.minestom.server.entity.metadata.monster.*;
|
||||
import net.minestom.server.entity.metadata.monster.raider.*;
|
||||
import net.minestom.server.entity.metadata.monster.skeleton.SkeletonMeta;
|
||||
import net.minestom.server.entity.metadata.monster.skeleton.StrayMeta;
|
||||
import net.minestom.server.entity.metadata.monster.skeleton.WitherSkeletonMeta;
|
||||
import net.minestom.server.entity.metadata.monster.zombie.DrownedMeta;
|
||||
import net.minestom.server.entity.metadata.monster.zombie.HuskMeta;
|
||||
import net.minestom.server.entity.metadata.monster.zombie.ZombieMeta;
|
||||
import net.minestom.server.entity.metadata.monster.zombie.ZombieVillagerMeta;
|
||||
import net.minestom.server.entity.metadata.monster.zombie.ZombifiedPiglinMeta;
|
||||
import net.minestom.server.entity.metadata.other.AreaEffectCloudMeta;
|
||||
import net.minestom.server.entity.metadata.other.ArmorStandMeta;
|
||||
import net.minestom.server.entity.metadata.other.BoatMeta;
|
||||
import net.minestom.server.entity.metadata.other.DragonFireballMeta;
|
||||
import net.minestom.server.entity.metadata.other.EndCrystalMeta;
|
||||
import net.minestom.server.entity.metadata.other.EnderDragonMeta;
|
||||
import net.minestom.server.entity.metadata.other.EvokerFangsMeta;
|
||||
import net.minestom.server.entity.metadata.other.ExperienceOrbMeta;
|
||||
import net.minestom.server.entity.metadata.other.FallingBlockMeta;
|
||||
import net.minestom.server.entity.metadata.other.FireworkRocketMeta;
|
||||
import net.minestom.server.entity.metadata.other.FishingHookMeta;
|
||||
import net.minestom.server.entity.metadata.other.ItemFrameMeta;
|
||||
import net.minestom.server.entity.metadata.other.LeashKnotMeta;
|
||||
import net.minestom.server.entity.metadata.other.LightningBoltMeta;
|
||||
import net.minestom.server.entity.metadata.other.LlamaSpitMeta;
|
||||
import net.minestom.server.entity.metadata.other.MagmaCubeMeta;
|
||||
import net.minestom.server.entity.metadata.other.PaintingMeta;
|
||||
import net.minestom.server.entity.metadata.other.PrimedTntMeta;
|
||||
import net.minestom.server.entity.metadata.other.ShulkerBulletMeta;
|
||||
import net.minestom.server.entity.metadata.other.SlimeMeta;
|
||||
import net.minestom.server.entity.metadata.other.TraderLlamaMeta;
|
||||
import net.minestom.server.entity.metadata.other.WitherSkullMeta;
|
||||
import net.minestom.server.entity.metadata.monster.zombie.*;
|
||||
import net.minestom.server.entity.metadata.other.*;
|
||||
import net.minestom.server.entity.metadata.villager.VillagerMeta;
|
||||
import net.minestom.server.entity.metadata.villager.WanderingTraderMeta;
|
||||
import net.minestom.server.entity.metadata.water.DolphinMeta;
|
||||
@ -116,6 +38,8 @@ import net.minestom.server.registry.Registries;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
/**
|
||||
* //==============================
|
||||
* // AUTOGENERATED BY EnumGenerator
|
||||
@ -354,7 +278,7 @@ public enum EntityType implements Keyed {
|
||||
@NotNull
|
||||
private final EntitySpawnType spawnType;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
EntityType(@NotNull String namespaceID, double width, double height,
|
||||
@NotNull BiFunction<Entity, Metadata, EntityMeta> metaConstructor,
|
||||
|
@ -24,7 +24,7 @@ public enum Fluid implements Keyed {
|
||||
|
||||
private final String namespaceID;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
Fluid(String namespaceID) {
|
||||
this.namespaceID = namespaceID;
|
||||
|
@ -2501,7 +2501,7 @@ public enum Block implements Keyed {
|
||||
|
||||
private List<BlockAlternative> alternatives = new java.util.ArrayList<>();
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
Block(@NotNull String namespaceID, short defaultID, double hardness, double resistance,
|
||||
boolean isAir, boolean isSolid, @Nullable NamespaceID blockEntity,
|
||||
|
@ -90,7 +90,7 @@ public enum Enchantment implements Keyed {
|
||||
|
||||
private final String namespaceID;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
Enchantment(String namespaceID) {
|
||||
this.namespaceID = namespaceID;
|
||||
|
@ -1975,7 +1975,7 @@ public enum Material implements Keyed {
|
||||
@Nullable
|
||||
private final Block correspondingBlock;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
Material(@NotNull String namespaceID, int maxDefaultStackSize,
|
||||
@Nullable Block correspondingBlock) {
|
||||
|
@ -158,7 +158,7 @@ public enum Particle implements Keyed {
|
||||
|
||||
private final String namespaceID;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
Particle(String namespaceID) {
|
||||
this.namespaceID = namespaceID;
|
||||
|
@ -78,7 +78,7 @@ public enum PotionEffect implements Keyed {
|
||||
|
||||
private final String namespaceID;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
PotionEffect(String namespaceID) {
|
||||
this.namespaceID = namespaceID;
|
||||
|
@ -100,7 +100,7 @@ public enum PotionType implements Keyed {
|
||||
|
||||
private final String namespaceID;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
PotionType(String namespaceID) {
|
||||
this.namespaceID = namespaceID;
|
||||
|
@ -1998,7 +1998,7 @@ public enum Sound implements Keyed {
|
||||
|
||||
private final String namespaceID;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
Sound(String namespaceID) {
|
||||
this.namespaceID = namespaceID;
|
||||
|
@ -162,7 +162,7 @@ public enum StatisticType implements Keyed {
|
||||
|
||||
private final String namespaceID;
|
||||
|
||||
private Key key;
|
||||
private final Key key;
|
||||
|
||||
StatisticType(String namespaceID) {
|
||||
this.namespaceID = namespaceID;
|
||||
|
@ -121,7 +121,7 @@ public abstract class BasicEnumGenerator extends MinestomEnumGenerator<BasicEnum
|
||||
|
||||
// implement Keyed
|
||||
generator.addSuperinterface(ClassName.get(Keyed.class));
|
||||
generator.addField(ClassName.get(Key.class), "key");
|
||||
generator.addField(ClassName.get(Key.class), "key", true);
|
||||
generator.appendToConstructor(code -> code.addStatement("this.key = Key.key(this.namespaceID)"));
|
||||
generator.addMethod("key", new ParameterSpec[0], ClassName.get(Key.class), code -> code.addStatement("return this.key"));
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.codegen;
|
||||
|
||||
import com.squareup.javapoet.*;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -24,7 +25,7 @@ public class EnumGenerator implements CodeGenerator {
|
||||
private List<Method> methods = new LinkedList<>();
|
||||
private List<Field> staticFields = new LinkedList<>();
|
||||
private List<Instance> instances = new LinkedList<>();
|
||||
private List<Field> fields = new LinkedList<>();
|
||||
private List<Pair<Field, Boolean>> fields = new LinkedList<>();
|
||||
private List<Field> hardcodedFields = new LinkedList<>();
|
||||
private List<AnnotationSpec> annotations = new LinkedList<>();
|
||||
private String enumPackage;
|
||||
@ -125,10 +126,15 @@ public class EnumGenerator implements CodeGenerator {
|
||||
}
|
||||
|
||||
// normal fields
|
||||
for (Field field : fields) {
|
||||
enumClass.addField(FieldSpec.builder(field.type, field.name)
|
||||
.addModifiers(Modifier.PRIVATE)
|
||||
.build());
|
||||
for (Pair<Field, Boolean> field : fields) {
|
||||
FieldSpec.Builder builder = FieldSpec.builder(field.getLeft().type, field.getLeft().name)
|
||||
.addModifiers(Modifier.PRIVATE);
|
||||
|
||||
if (field.getRight()) {
|
||||
builder.addModifiers(Modifier.FINAL);
|
||||
}
|
||||
|
||||
enumClass.addField(builder.build());
|
||||
}
|
||||
|
||||
// constructor
|
||||
@ -182,8 +188,8 @@ public class EnumGenerator implements CodeGenerator {
|
||||
constructorEnds.add(constructorEnding);
|
||||
}
|
||||
|
||||
public void addField(TypeName type, String name) {
|
||||
fields.add(new Field(type, name));
|
||||
public void addField(TypeName type, String name, boolean isFinal) {
|
||||
fields.add(Pair.of(new Field(type, name), isFinal));
|
||||
}
|
||||
|
||||
public void addHardcodedField(TypeName type, String name, String value) {
|
||||
|
@ -303,7 +303,7 @@ public class BlockEnumGenerator extends MinestomEnumGenerator<BlockContainer> {
|
||||
|
||||
// implement Keyed
|
||||
generator.addSuperinterface(ClassName.get(Keyed.class));
|
||||
generator.addField(ClassName.get(Key.class), "key");
|
||||
generator.addField(ClassName.get(Key.class), "key", true);
|
||||
generator.appendToConstructor(code -> code.addStatement("this.key = Key.key(this.namespaceID)"));
|
||||
generator.addMethod("key", new ParameterSpec[0], ClassName.get(Key.class), code -> code.addStatement("return this.key"));
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -183,7 +182,7 @@ public class EntityTypeEnumGenerator extends MinestomEnumGenerator<EntityTypeCon
|
||||
|
||||
// implement Keyed
|
||||
generator.addSuperinterface(ClassName.get(Keyed.class));
|
||||
generator.addField(ClassName.get(Key.class), "key");
|
||||
generator.addField(ClassName.get(Key.class), "key", true);
|
||||
generator.appendToConstructor(code -> code.addStatement("this.key = Key.key(this.namespaceID)"));
|
||||
generator.addMethod("key", new ParameterSpec[0], ClassName.get(Key.class), code -> code.addStatement("return this.key"));
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ public class ItemEnumGenerator extends MinestomEnumGenerator<ItemContainer> {
|
||||
|
||||
// implement Keyed
|
||||
generator.addSuperinterface(ClassName.get(Keyed.class));
|
||||
generator.addField(ClassName.get(Key.class), "key");
|
||||
generator.addField(ClassName.get(Key.class), "key", true);
|
||||
generator.appendToConstructor(code -> code.addStatement("this.key = Key.key(this.namespaceID)"));
|
||||
generator.addMethod("key", new ParameterSpec[0], ClassName.get(Key.class), code -> code.addStatement("return this.key"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user