3
0
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:
Moulberry 2024-05-26 22:37:06 +08:00
Ursprung 1d2a4e83d3
Commit bcdc42f65b
2 geänderte Dateien mit 11 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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));
}