Skip to content

Commit

Permalink
Merge pull request #94 from yannicklamprecht/task/extract-dynamic-reg…
Browse files Browse the repository at this point in the history
…istries-and-deprecate-old-methods

task: extract dynamic registries and deprecate old methods
  • Loading branch information
TheMeinerLP authored Nov 11, 2024
2 parents df11046 + aeec4a2 commit 029c818
Show file tree
Hide file tree
Showing 4 changed files with 296 additions and 50 deletions.
8 changes: 7 additions & 1 deletion src/main/java/net/minestom/server/ServerProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -61,6 +62,11 @@ public interface ServerProcess extends Registries, Snapshotable {
*/
@NotNull TeamManager team();

/**
* Provides the registries
*/
@NotNull Registries registries();

/**
* Gets the global event handler.
* <p>
Expand Down
74 changes: 25 additions & 49 deletions src/main/java/net/minestom/server/ServerProcessImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -59,22 +61,7 @@ final class ServerProcessImpl implements ServerProcess {

private final ExceptionManager exception;

private final DynamicRegistry<BinaryTagSerializer<? extends LevelBasedValue>> enchantmentLevelBasedValues;
private final DynamicRegistry<BinaryTagSerializer<? extends ValueEffect>> enchantmentValueEffects;
private final DynamicRegistry<BinaryTagSerializer<? extends EntityEffect>> enchantmentEntityEffects;
private final DynamicRegistry<BinaryTagSerializer<? extends LocationEffect>> enchantmentLocationEffects;

private final DynamicRegistry<ChatType> chatType;
private final DynamicRegistry<DimensionType> dimensionType;
private final DynamicRegistry<Biome> biome;
private final DynamicRegistry<DamageType> damageType;
private final DynamicRegistry<TrimMaterial> trimMaterial;
private final DynamicRegistry<TrimPattern> trimPattern;
private final DynamicRegistry<BannerPattern> bannerPattern;
private final DynamicRegistry<WolfMeta.Variant> wolfVariant;
private final DynamicRegistry<Enchantment> enchantment;
private final DynamicRegistry<PaintingMeta.Variant> paintingVariant;
private final DynamicRegistry<JukeboxSong> jukeboxSong;
private final DynamicRegistries dynamicRegistries;

private final ExtensionManager extension;
private final ConnectionManager connection;
Expand Down Expand Up @@ -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();
Expand All @@ -154,62 +125,62 @@ public ServerProcessImpl() throws IOException {

@Override
public @NotNull DynamicRegistry<DamageType> damageType() {
return damageType;
return dynamicRegistries.damageType();
}

@Override
public @NotNull DynamicRegistry<TrimMaterial> trimMaterial() {
return trimMaterial;
return dynamicRegistries.trimMaterial();
}

@Override
public @NotNull DynamicRegistry<TrimPattern> trimPattern() {
return trimPattern;
return dynamicRegistries.trimPattern();
}

@Override
public @NotNull DynamicRegistry<BannerPattern> bannerPattern() {
return bannerPattern;
return dynamicRegistries.bannerPattern();
}

@Override
public @NotNull DynamicRegistry<WolfMeta.Variant> wolfVariant() {
return wolfVariant;
return dynamicRegistries.wolfVariant();
}

@Override
public @NotNull DynamicRegistry<Enchantment> enchantment() {
return enchantment;
return dynamicRegistries.enchantment();
}

@Override
public @NotNull DynamicRegistry<PaintingMeta.Variant> paintingVariant() {
return paintingVariant;
return dynamicRegistries.paintingVariant();
}

@Override
public @NotNull DynamicRegistry<JukeboxSong> jukeboxSong() {
return jukeboxSong;
return dynamicRegistries.jukeboxSong();
}

@Override
public @NotNull DynamicRegistry<BinaryTagSerializer<? extends LevelBasedValue>> enchantmentLevelBasedValues() {
return enchantmentLevelBasedValues;
return dynamicRegistries.enchantmentLevelBasedValues();
}

@Override
public @NotNull DynamicRegistry<BinaryTagSerializer<? extends ValueEffect>> enchantmentValueEffects() {
return enchantmentValueEffects;
return dynamicRegistries.enchantmentValueEffects();
}

@Override
public @NotNull DynamicRegistry<BinaryTagSerializer<? extends EntityEffect>> enchantmentEntityEffects() {
return enchantmentEntityEffects;
return dynamicRegistries.enchantmentEntityEffects();
}

@Override
public @NotNull DynamicRegistry<BinaryTagSerializer<? extends LocationEffect>> enchantmentLocationEffects() {
return enchantmentLocationEffects;
return dynamicRegistries.enchantmentLocationEffects();
}

@Override
Expand Down Expand Up @@ -242,6 +213,11 @@ public ServerProcessImpl() throws IOException {
return team;
}

@Override
public @NotNull Registries registries() {
return dynamicRegistries;
}

@Override
public @NotNull GlobalEventHandler eventHandler() {
return eventHandler;
Expand Down Expand Up @@ -279,17 +255,17 @@ public ServerProcessImpl() throws IOException {

@Override
public @NotNull DynamicRegistry<ChatType> chatType() {
return chatType;
return dynamicRegistries.chatType();
}

@Override
public @NotNull DynamicRegistry<DimensionType> dimensionType() {
return dimensionType;
return dynamicRegistries.dimensionType();
}

@Override
public @NotNull DynamicRegistry<Biome> biome() {
return biome;
return dynamicRegistries.biome();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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> 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> 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> 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> 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> 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> 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> 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<WolfMeta.Variant> 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> 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<PaintingMeta.Variant> 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> 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<BinaryTagSerializer<? extends LevelBasedValue>> 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<BinaryTagSerializer<? extends ValueEffect>> 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<BinaryTagSerializer<? extends EntityEffect>> 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<BinaryTagSerializer<? extends LocationEffect>> enchantmentLocationEffects();

}
Loading

0 comments on commit 029c818

Please sign in to comment.