From 2368b63ad5f6f1d3f0a15d203aac1ea0fcc9b39d Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Sun, 18 Jun 2023 17:45:25 -0400 Subject: [PATCH] Allow deferred registries to be loaded/set more than once (#3892) --- .../geyser/registry/DeferredRegistry.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/DeferredRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/DeferredRegistry.java index bf3050a61..6a2f2ae37 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/DeferredRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/DeferredRegistry.java @@ -69,6 +69,12 @@ public final class DeferredRegistry implements IRegistry { this.loader = () -> deferredLoader.get().load(input); } + /** + * Gets the underlying value held by this registry. + * + * @return the underlying value held by this registry + * @throws IllegalStateException if this deferred registry has not been loaded yet + */ @Override public M get() { if (!this.loaded) { @@ -80,13 +86,15 @@ public final class DeferredRegistry implements IRegistry { @Override public void set(M mappings) { - if (!this.loaded) { - throw new IllegalStateException("Registry has not been loaded yet!"); - } - this.backingRegistry.set(mappings); } + /** + * Registers what is specified in the given {@link Consumer} into the underlying value. + * + * @param consumer the consumer + * @throws IllegalStateException if this deferred registry has not been loaded yet + */ @Override public void register(Consumer consumer) { if (!this.loaded) { @@ -100,10 +108,6 @@ public final class DeferredRegistry implements IRegistry { * Loads the registry. */ public void load() { - if (this.loaded) { - throw new IllegalStateException("Registry has already been loaded!"); - } - this.backingRegistry.set(this.loader.get()); this.loaded = true; }