3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-08 17:40:04 +01:00

Use WeakReference in ServerWorldPropertiesRegistry

Dieser Commit ist enthalten in:
Moulberry 2024-05-26 22:37:06 +08:00
Ursprung 632a17e112
Commit 26eb24f208
2 geänderte Dateien mit 11 neuen und 4 gelöschten Zeilen

Datei anzeigen

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

Datei anzeigen

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