Mirror von
https://github.com/Moulberry/AxiomPaperPlugin.git
synchronisiert 2024-11-14 12:10:05 +01:00
Use WeakReference in ServerWorldPropertiesRegistry
Dieser Commit ist enthalten in:
Ursprung
1d2a4e83d3
Commit
bcdc42f65b
@ -44,6 +44,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
@ -399,7 +400,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);
|
||||
|
@ -13,15 +13,16 @@ import org.bukkit.craftbukkit.v1_20_R3.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<WorldPropertyCategory, List<ServerWorldPropertyHolder<?>>> propertyList = new LinkedHashMap<>();
|
||||
private final Map<ResourceLocation, ServerWorldPropertyHolder<?>> propertyMap = new HashMap<>();
|
||||
private final World world;
|
||||
private final Reference<World> world;
|
||||
|
||||
public ServerWorldPropertiesRegistry(World world) {
|
||||
public ServerWorldPropertiesRegistry(Reference<World> world) {
|
||||
this.world = world;
|
||||
this.registerDefault();
|
||||
}
|
||||
@ -32,9 +33,14 @@ public class ServerWorldPropertiesRegistry {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addCategory(WorldPropertyCategory category, List<ServerWorldPropertyBase<?>> properties) {
|
||||
World world = this.world.get();
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ServerWorldPropertyHolder<?>> holders = new ArrayList<>();
|
||||
for (ServerWorldPropertyBase<?> property : properties) {
|
||||
Object defaultValue = property.getDefaultValue(this.world);
|
||||
Object defaultValue = property.getDefaultValue(world);
|
||||
holders.add(new ServerWorldPropertyHolder<>(defaultValue, (ServerWorldPropertyBase<Object>) property));
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren