diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index a9d28c2..da6e6d5 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -42,6 +42,7 @@ import org.incendo.cloud.paper.LegacyPaperCommandManager; import org.jetbrains.annotations.Nullable; import java.io.IOException; +import java.lang.ref.WeakReference; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -401,7 +402,7 @@ public class AxiomPaper extends JavaPlugin implements Listener { } private ServerWorldPropertiesRegistry createWorldProperties(World world) { - ServerWorldPropertiesRegistry registry = new ServerWorldPropertiesRegistry(world); + ServerWorldPropertiesRegistry registry = new ServerWorldPropertiesRegistry(new WeakReference<>(world)); AxiomCreateWorldPropertiesEvent createEvent = new AxiomCreateWorldPropertiesEvent(world, registry); Bukkit.getPluginManager().callEvent(createEvent); diff --git a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java index 78fef4f..d20b70e 100644 --- a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java +++ b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java @@ -13,15 +13,16 @@ import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import java.lang.ref.Reference; import java.util.*; public class ServerWorldPropertiesRegistry { private final LinkedHashMap>> propertyList = new LinkedHashMap<>(); private final Map> propertyMap = new HashMap<>(); - private final World world; + private final Reference world; - public ServerWorldPropertiesRegistry(World world) { + public ServerWorldPropertiesRegistry(Reference world) { this.world = world; this.registerDefault(); } @@ -32,9 +33,14 @@ public class ServerWorldPropertiesRegistry { @SuppressWarnings("unchecked") public void addCategory(WorldPropertyCategory category, List> properties) { + World world = this.world.get(); + if (world == null) { + return; + } + List> holders = new ArrayList<>(); for (ServerWorldPropertyBase property : properties) { - Object defaultValue = property.getDefaultValue(this.world); + Object defaultValue = property.getDefaultValue(world); holders.add(new ServerWorldPropertyHolder<>(defaultValue, (ServerWorldPropertyBase) property)); }