From ce1e075d0601d71c262909855349b506503dc60a Mon Sep 17 00:00:00 2001 From: Yannick Lamprecht Date: Thu, 7 Nov 2024 17:39:55 +0100 Subject: [PATCH] task: extract dynamic registries and deprecate old methods --- .../net/minestom/server/ServerProcess.java | 8 +- .../minestom/server/ServerProcessImpl.java | 74 +++------ ...eprecatedServerProcessDynamicRegistry.java | 133 +++++++++++++++ .../server/registry/DynamicRegistries.java | 155 ++++++++++++++++++ 4 files changed, 320 insertions(+), 50 deletions(-) create mode 100644 src/main/java/net/minestom/server/registry/DeprecatedServerProcessDynamicRegistry.java create mode 100644 src/main/java/net/minestom/server/registry/DynamicRegistries.java diff --git a/src/main/java/net/minestom/server/ServerProcess.java b/src/main/java/net/minestom/server/ServerProcess.java index c700f316410..4c800bb720b 100644 --- a/src/main/java/net/minestom/server/ServerProcess.java +++ b/src/main/java/net/minestom/server/ServerProcess.java @@ -17,6 +17,7 @@ import net.minestom.server.network.PacketProcessor; import net.minestom.server.network.socket.Server; import net.minestom.server.recipe.RecipeManager; +import net.minestom.server.registry.DeprecatedServerProcessDynamicRegistry; import net.minestom.server.registry.Registries; import net.minestom.server.scoreboard.TeamManager; import net.minestom.server.snapshot.Snapshotable; @@ -29,7 +30,7 @@ import java.net.SocketAddress; @ApiStatus.NonExtendable -public interface ServerProcess extends Registries, Snapshotable { +public interface ServerProcess extends DeprecatedServerProcessDynamicRegistry, Snapshotable { /** * Handles incoming connections/players. */ @@ -61,6 +62,11 @@ public interface ServerProcess extends Registries, Snapshotable { */ @NotNull TeamManager team(); + /** + * Provides the registries + */ + @NotNull Registries registries(); + /** * Gets the global event handler. *

diff --git a/src/main/java/net/minestom/server/ServerProcessImpl.java b/src/main/java/net/minestom/server/ServerProcessImpl.java index 9040c041827..20ad06940c5 100644 --- a/src/main/java/net/minestom/server/ServerProcessImpl.java +++ b/src/main/java/net/minestom/server/ServerProcessImpl.java @@ -37,7 +37,9 @@ import net.minestom.server.network.PacketProcessor; import net.minestom.server.network.socket.Server; import net.minestom.server.recipe.RecipeManager; +import net.minestom.server.registry.DynamicRegistries; import net.minestom.server.registry.DynamicRegistry; +import net.minestom.server.registry.Registries; import net.minestom.server.scoreboard.TeamManager; import net.minestom.server.snapshot.*; import net.minestom.server.terminal.MinestomTerminal; @@ -59,22 +61,7 @@ final class ServerProcessImpl implements ServerProcess { private final ExceptionManager exception; - private final DynamicRegistry> enchantmentLevelBasedValues; - private final DynamicRegistry> enchantmentValueEffects; - private final DynamicRegistry> enchantmentEntityEffects; - private final DynamicRegistry> enchantmentLocationEffects; - - private final DynamicRegistry chatType; - private final DynamicRegistry dimensionType; - private final DynamicRegistry biome; - private final DynamicRegistry damageType; - private final DynamicRegistry trimMaterial; - private final DynamicRegistry trimPattern; - private final DynamicRegistry bannerPattern; - private final DynamicRegistry wolfVariant; - private final DynamicRegistry enchantment; - private final DynamicRegistry paintingVariant; - private final DynamicRegistry jukeboxSong; + private final DynamicRegistries dynamicRegistries; private final ExtensionManager extension; private final ConnectionManager connection; @@ -107,28 +94,12 @@ final class ServerProcessImpl implements ServerProcess { public ServerProcessImpl() throws IOException { this.exception = new ExceptionManager(); this.extension = new ExtensionManager(this); - // The order of initialization here is relevant, we must load the enchantment util registries before the vanilla data is loaded. - this.enchantmentLevelBasedValues = LevelBasedValue.createDefaultRegistry(); - this.enchantmentValueEffects = ValueEffect.createDefaultRegistry(); - this.enchantmentEntityEffects = EntityEffect.createDefaultRegistry(); - this.enchantmentLocationEffects = LocationEffect.createDefaultRegistry(); - - this.chatType = ChatType.createDefaultRegistry(); - this.dimensionType = DimensionType.createDefaultRegistry(); - this.biome = Biome.createDefaultRegistry(); - this.damageType = DamageType.createDefaultRegistry(); - this.trimMaterial = TrimMaterial.createDefaultRegistry(); - this.trimPattern = TrimPattern.createDefaultRegistry(); - this.bannerPattern = BannerPattern.createDefaultRegistry(); - this.wolfVariant = WolfMeta.Variant.createDefaultRegistry(); - this.enchantment = Enchantment.createDefaultRegistry(this); - this.paintingVariant = PaintingMeta.Variant.createDefaultRegistry(); - this.jukeboxSong = JukeboxSong.createDefaultRegistry(); + this.dynamicRegistries = new DynamicRegistries(); this.connection = new ConnectionManager(); this.packetListener = new PacketListenerManager(); this.packetProcessor = new PacketProcessor(packetListener); - this.instance = new InstanceManager(this); + this.instance = new InstanceManager(this.dynamicRegistries); this.block = new BlockManager(); this.command = new CommandManager(); this.recipe = new RecipeManager(); @@ -154,62 +125,62 @@ public ServerProcessImpl() throws IOException { @Override public @NotNull DynamicRegistry damageType() { - return damageType; + return dynamicRegistries.damageType(); } @Override public @NotNull DynamicRegistry trimMaterial() { - return trimMaterial; + return dynamicRegistries.trimMaterial(); } @Override public @NotNull DynamicRegistry trimPattern() { - return trimPattern; + return dynamicRegistries.trimPattern(); } @Override public @NotNull DynamicRegistry bannerPattern() { - return bannerPattern; + return dynamicRegistries.bannerPattern(); } @Override public @NotNull DynamicRegistry wolfVariant() { - return wolfVariant; + return dynamicRegistries.wolfVariant(); } @Override public @NotNull DynamicRegistry enchantment() { - return enchantment; + return dynamicRegistries.enchantment(); } @Override public @NotNull DynamicRegistry paintingVariant() { - return paintingVariant; + return dynamicRegistries.paintingVariant(); } @Override public @NotNull DynamicRegistry jukeboxSong() { - return jukeboxSong; + return dynamicRegistries.jukeboxSong(); } @Override public @NotNull DynamicRegistry> enchantmentLevelBasedValues() { - return enchantmentLevelBasedValues; + return dynamicRegistries.enchantmentLevelBasedValues(); } @Override public @NotNull DynamicRegistry> enchantmentValueEffects() { - return enchantmentValueEffects; + return dynamicRegistries.enchantmentValueEffects(); } @Override public @NotNull DynamicRegistry> enchantmentEntityEffects() { - return enchantmentEntityEffects; + return dynamicRegistries.enchantmentEntityEffects(); } @Override public @NotNull DynamicRegistry> enchantmentLocationEffects() { - return enchantmentLocationEffects; + return dynamicRegistries.enchantmentLocationEffects(); } @Override @@ -242,6 +213,11 @@ public ServerProcessImpl() throws IOException { return team; } + @Override + public @NotNull Registries registries() { + return dynamicRegistries; + } + @Override public @NotNull GlobalEventHandler eventHandler() { return eventHandler; @@ -279,17 +255,17 @@ public ServerProcessImpl() throws IOException { @Override public @NotNull DynamicRegistry chatType() { - return chatType; + return dynamicRegistries.chatType(); } @Override public @NotNull DynamicRegistry dimensionType() { - return dimensionType; + return dynamicRegistries.dimensionType(); } @Override public @NotNull DynamicRegistry biome() { - return biome; + return dynamicRegistries.biome(); } @Override diff --git a/src/main/java/net/minestom/server/registry/DeprecatedServerProcessDynamicRegistry.java b/src/main/java/net/minestom/server/registry/DeprecatedServerProcessDynamicRegistry.java new file mode 100644 index 00000000000..2b6a5d5aa61 --- /dev/null +++ b/src/main/java/net/minestom/server/registry/DeprecatedServerProcessDynamicRegistry.java @@ -0,0 +1,133 @@ +package net.minestom.server.registry; + +import net.minestom.server.entity.damage.DamageType; +import net.minestom.server.entity.metadata.animal.tameable.WolfMeta; +import net.minestom.server.entity.metadata.other.PaintingMeta; +import net.minestom.server.instance.block.banner.BannerPattern; +import net.minestom.server.instance.block.jukebox.JukeboxSong; +import net.minestom.server.item.armor.TrimMaterial; +import net.minestom.server.item.armor.TrimPattern; +import net.minestom.server.item.enchant.Enchantment; +import net.minestom.server.item.enchant.EntityEffect; +import net.minestom.server.item.enchant.LevelBasedValue; +import net.minestom.server.item.enchant.LocationEffect; +import net.minestom.server.item.enchant.ValueEffect; +import net.minestom.server.message.ChatType; +import net.minestom.server.utils.nbt.BinaryTagSerializer; +import net.minestom.server.world.DimensionType; +import net.minestom.server.world.biome.Biome; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +/** + * Interface to represent the deprecated ServerProcess registry methods + */ +@Deprecated(forRemoval = true, since = "1.6.0") +@ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") +public interface DeprecatedServerProcessDynamicRegistry extends Registries { + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#chatType()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry chatType(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#dimensionType()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry dimensionType(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#biome()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry biome(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#damageType()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry damageType(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#trimMaterial()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry trimMaterial(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#trimPattern()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry trimPattern(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#bannerPattern()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry bannerPattern(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#wolfVariant()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry wolfVariant(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#enchantment()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry enchantment(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#paintingVariant()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry paintingVariant(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#jukeboxSong()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry jukeboxSong(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#enchantmentLevelBasedValues()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry> enchantmentLevelBasedValues(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#enchantmentValueEffects()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry> enchantmentValueEffects(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#enchantmentEntityEffects()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry> enchantmentEntityEffects(); + + /** + * @deprecated Use {@link net.minestom.server.ServerProcess#registries()} and {@link Registries#enchantmentLocationEffects()} ()} + */ + @Deprecated(forRemoval = true, since = "1.6.0") + @ApiStatus.ScheduledForRemoval(inVersion = "1.7.0") + @NotNull DynamicRegistry> enchantmentLocationEffects(); + +} diff --git a/src/main/java/net/minestom/server/registry/DynamicRegistries.java b/src/main/java/net/minestom/server/registry/DynamicRegistries.java new file mode 100644 index 00000000000..8473b883960 --- /dev/null +++ b/src/main/java/net/minestom/server/registry/DynamicRegistries.java @@ -0,0 +1,155 @@ +package net.minestom.server.registry; + +import net.minestom.server.entity.damage.DamageType; +import net.minestom.server.entity.metadata.animal.tameable.WolfMeta; +import net.minestom.server.entity.metadata.other.PaintingMeta; +import net.minestom.server.instance.block.banner.BannerPattern; +import net.minestom.server.instance.block.jukebox.JukeboxSong; +import net.minestom.server.item.armor.TrimMaterial; +import net.minestom.server.item.armor.TrimPattern; +import net.minestom.server.item.enchant.Enchantment; +import net.minestom.server.item.enchant.EntityEffect; +import net.minestom.server.item.enchant.LevelBasedValue; +import net.minestom.server.item.enchant.LocationEffect; +import net.minestom.server.item.enchant.ValueEffect; +import net.minestom.server.message.ChatType; +import net.minestom.server.utils.nbt.BinaryTagSerializer; +import net.minestom.server.world.DimensionType; +import net.minestom.server.world.biome.Biome; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +public final class DynamicRegistries implements Registries { + private final DynamicRegistry> enchantmentLevelBasedValues; + private final DynamicRegistry> enchantmentValueEffects; + private final DynamicRegistry> enchantmentEntityEffects; + private final DynamicRegistry> enchantmentLocationEffects; + private final DynamicRegistry chatType; + private final DynamicRegistry dimensionType; + private final DynamicRegistry biome; + private final DynamicRegistry damageType; + private final DynamicRegistry trimMaterial; + private final DynamicRegistry trimPattern; + private final DynamicRegistry bannerPattern; + private final DynamicRegistry wolfVariant; + private final DynamicRegistry enchantment; + private final DynamicRegistry paintingVariant; + private final DynamicRegistry jukeboxSong; + + public DynamicRegistries() { + // The order of initialization here is relevant, we must load the enchantment util registries before the vanilla data is loaded. + this.enchantmentLevelBasedValues = LevelBasedValue.createDefaultRegistry(); + this.enchantmentValueEffects = ValueEffect.createDefaultRegistry(); + this.enchantmentEntityEffects = EntityEffect.createDefaultRegistry(); + this.enchantmentLocationEffects = LocationEffect.createDefaultRegistry(); + this.chatType = ChatType.createDefaultRegistry(); + this.dimensionType = DimensionType.createDefaultRegistry(); + this.biome = Biome.createDefaultRegistry(); + this.damageType = DamageType.createDefaultRegistry(); + this.trimMaterial = TrimMaterial.createDefaultRegistry(); + this.trimPattern = TrimPattern.createDefaultRegistry(); + this.bannerPattern = BannerPattern.createDefaultRegistry(); + this.wolfVariant = WolfMeta.Variant.createDefaultRegistry(); + this.enchantment = Enchantment.createDefaultRegistry(this); + this.paintingVariant = PaintingMeta.Variant.createDefaultRegistry(); + this.jukeboxSong = JukeboxSong.createDefaultRegistry(); + } + + @Override + public @NotNull DynamicRegistry> enchantmentLevelBasedValues() { + return enchantmentLevelBasedValues; + } + + @Override + public @NotNull DynamicRegistry> enchantmentValueEffects() { + return enchantmentValueEffects; + } + + @Override + public @NotNull DynamicRegistry> enchantmentEntityEffects() { + return enchantmentEntityEffects; + } + + @Override + public @NotNull DynamicRegistry> enchantmentLocationEffects() { + return enchantmentLocationEffects; + } + + @Override + public @NotNull DynamicRegistry chatType() { + return chatType; + } + + @Override + public @NotNull DynamicRegistry dimensionType() { + return dimensionType; + } + + @Override + public @NotNull DynamicRegistry biome() { + return biome; + } + + @Override + public @NotNull DynamicRegistry damageType() { + return damageType; + } + + @Override + public @NotNull DynamicRegistry trimMaterial() { + return trimMaterial; + } + + @Override + public @NotNull DynamicRegistry trimPattern() { + return trimPattern; + } + + @Override + public @NotNull DynamicRegistry bannerPattern() { + return bannerPattern; + } + + @Override + public @NotNull DynamicRegistry wolfVariant() { + return wolfVariant; + } + + @Override + public @NotNull DynamicRegistry enchantment() { + return enchantment; + } + + @Override + public @NotNull DynamicRegistry paintingVariant() { + return paintingVariant; + } + + @Override + public @NotNull DynamicRegistry jukeboxSong() { + return jukeboxSong; + } + + @Override + public boolean equals(Object obj) { + if (obj == this) return true; + if (obj == null || obj.getClass() != this.getClass()) return false; + var that = (DynamicRegistries) obj; + return Objects.equals(this.enchantmentLevelBasedValues, that.enchantmentLevelBasedValues) && + Objects.equals(this.enchantmentValueEffects, that.enchantmentValueEffects) && + Objects.equals(this.enchantmentEntityEffects, that.enchantmentEntityEffects) && + Objects.equals(this.enchantmentLocationEffects, that.enchantmentLocationEffects) && + Objects.equals(this.chatType, that.chatType) && + Objects.equals(this.dimensionType, that.dimensionType) && + Objects.equals(this.biome, that.biome) && + Objects.equals(this.damageType, that.damageType) && + Objects.equals(this.trimMaterial, that.trimMaterial) && + Objects.equals(this.trimPattern, that.trimPattern) && + Objects.equals(this.bannerPattern, that.bannerPattern) && + Objects.equals(this.wolfVariant, that.wolfVariant) && + Objects.equals(this.enchantment, that.enchantment) && + Objects.equals(this.paintingVariant, that.paintingVariant) && + Objects.equals(this.jukeboxSong, that.jukeboxSong); + } +}