Mirror von
https://github.com/Moulberry/AxiomPaperPlugin.git
synchronisiert 2024-11-17 05:40:06 +01:00
Use WeakReference in ServerWorldPropertiesRegistry
Dieser Commit ist enthalten in:
Ursprung
e3a0b57067
Commit
55d5ffd2ee
@ -42,6 +42,7 @@ import org.incendo.cloud.paper.LegacyPaperCommandManager;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -401,7 +402,7 @@ public class AxiomPaper extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ServerWorldPropertiesRegistry createWorldProperties(World world) {
|
private ServerWorldPropertiesRegistry createWorldProperties(World world) {
|
||||||
ServerWorldPropertiesRegistry registry = new ServerWorldPropertiesRegistry(world);
|
ServerWorldPropertiesRegistry registry = new ServerWorldPropertiesRegistry(new WeakReference<>(world));
|
||||||
|
|
||||||
AxiomCreateWorldPropertiesEvent createEvent = new AxiomCreateWorldPropertiesEvent(world, registry);
|
AxiomCreateWorldPropertiesEvent createEvent = new AxiomCreateWorldPropertiesEvent(world, registry);
|
||||||
Bukkit.getPluginManager().callEvent(createEvent);
|
Bukkit.getPluginManager().callEvent(createEvent);
|
||||||
|
@ -13,15 +13,16 @@ import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.lang.ref.Reference;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ServerWorldPropertiesRegistry {
|
public class ServerWorldPropertiesRegistry {
|
||||||
|
|
||||||
private final LinkedHashMap<WorldPropertyCategory, List<ServerWorldPropertyHolder<?>>> propertyList = new LinkedHashMap<>();
|
private final LinkedHashMap<WorldPropertyCategory, List<ServerWorldPropertyHolder<?>>> propertyList = new LinkedHashMap<>();
|
||||||
private final Map<ResourceLocation, ServerWorldPropertyHolder<?>> propertyMap = new HashMap<>();
|
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.world = world;
|
||||||
this.registerDefault();
|
this.registerDefault();
|
||||||
}
|
}
|
||||||
@ -32,9 +33,14 @@ public class ServerWorldPropertiesRegistry {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void addCategory(WorldPropertyCategory category, List<ServerWorldPropertyBase<?>> properties) {
|
public void addCategory(WorldPropertyCategory category, List<ServerWorldPropertyBase<?>> properties) {
|
||||||
|
World world = this.world.get();
|
||||||
|
if (world == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
List<ServerWorldPropertyHolder<?>> holders = new ArrayList<>();
|
List<ServerWorldPropertyHolder<?>> holders = new ArrayList<>();
|
||||||
for (ServerWorldPropertyBase<?> property : properties) {
|
for (ServerWorldPropertyBase<?> property : properties) {
|
||||||
Object defaultValue = property.getDefaultValue(this.world);
|
Object defaultValue = property.getDefaultValue(world);
|
||||||
holders.add(new ServerWorldPropertyHolder<>(defaultValue, (ServerWorldPropertyBase<Object>) property));
|
holders.add(new ServerWorldPropertyHolder<>(defaultValue, (ServerWorldPropertyBase<Object>) property));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren