Use world name instead of WeakReference

This commit is contained in:
Daniel Saukel 2020-05-01 00:20:44 +02:00
parent f491c53e33
commit 1920f73859
4 changed files with 13 additions and 18 deletions

View File

@ -21,8 +21,8 @@ import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGlobalPlayer;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.Collection;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.file.FileConfiguration;
@ -39,7 +39,7 @@ public abstract class GlobalProtection {
public static final String SIGN_TAG = "[DXL]";
private WeakReference<World> world;
private String world;
private int id;
protected GlobalProtection(DungeonsXL plugin, World world, int id) {
@ -47,7 +47,7 @@ public abstract class GlobalProtection {
protections = plugin.getGlobalProtectionCache();
config = plugin.getGlobalData().getConfig();
this.world = new WeakReference<>(world);
this.world = world.getName();
this.id = id;
protections.addProtection(this);
@ -57,7 +57,7 @@ public abstract class GlobalProtection {
* @return the world
*/
public World getWorld() {
return world.get();
return Bukkit.getWorld(world);
}
/**

View File

@ -96,13 +96,8 @@ public class DGameWorld extends DInstanceWorld implements GameWorld {
private boolean readySign;
DGameWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, World world, int id) {
super(plugin, resourceWorld, folder, world, id);
caliburn = plugin.getCaliburn();
}
DGameWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, int id) {
this(plugin, resourceWorld, folder, null, id);
super(plugin, resourceWorld, folder, id);
caliburn = plugin.getCaliburn();
}

View File

@ -28,7 +28,6 @@ import de.erethon.dungeonsxl.api.player.PlayerCache;
import de.erethon.dungeonsxl.api.sign.DungeonSign;
import de.erethon.dungeonsxl.api.world.InstanceWorld;
import java.io.File;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
@ -51,17 +50,16 @@ public abstract class DInstanceWorld implements InstanceWorld {
protected Map<Block, DungeonSign> signs = new HashMap<>();
private DResourceWorld resourceWorld;
private File folder;
WeakReference<World> world;
String world;
private int id;
private Location lobby;
DInstanceWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, World world, int id) {
DInstanceWorld(DungeonsXL plugin, DResourceWorld resourceWorld, File folder, int id) {
this.plugin = plugin;
dPlayers = plugin.getPlayerCache();
this.resourceWorld = resourceWorld;
this.folder = folder;
this.world = new WeakReference<>(world);
this.id = id;
plugin.getInstanceCache().add(id, this);
@ -85,7 +83,10 @@ public abstract class DInstanceWorld implements InstanceWorld {
@Override
public World getWorld() {
return world.get();
if (world == null) {
return null;
}
return Bukkit.getWorld(world);
}
/**

View File

@ -29,7 +29,6 @@ import de.erethon.dungeonsxl.api.world.GameWorld;
import de.erethon.dungeonsxl.api.world.ResourceWorld;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.OfflinePlayer;
@ -201,7 +200,7 @@ public class DResourceWorld implements ResourceWorld {
DInstanceWorld instance = game ? new DGameWorld(plugin, this, instanceFolder, id) : new DEditWorld(plugin, this, instanceFolder, id);
FileUtil.copyDir(folder, instanceFolder, DungeonsXL.EXCLUDED_FILES);
instance.world = new WeakReference<>(Bukkit.createWorld(WorldCreator.name(name).environment(getWorldEnvironment())));
instance.world = Bukkit.createWorld(WorldCreator.name(name).environment(getWorldEnvironment())).getName();
instance.getWorld().setGameRule(GameRule.DO_FIRE_TICK, false);
if (Bukkit.getPluginManager().isPluginEnabled("dynmap")) {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "dynmap pause all");
@ -292,7 +291,7 @@ public class DResourceWorld implements ResourceWorld {
}
FileUtil.copyDir(RAW, folder, DungeonsXL.EXCLUDED_FILES);
editWorld.generateIdFile();
editWorld.world = new WeakReference<>(creator.createWorld());
editWorld.world = creator.createWorld().getName();
editWorld.generateIdFile();
return editWorld;