diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index 2b5c20c..cccef8c 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -44,6 +44,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.*; @@ -400,7 +401,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 f8fa272..f26aaee 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.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)); }