Fix loading multiple worlds at once

This commit is contained in:
Daniel Saukel 2019-06-14 23:55:11 +02:00
parent 3f05d215c4
commit 3f554df158
3 changed files with 35 additions and 1 deletions

View File

@ -60,6 +60,7 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
@ -88,6 +89,8 @@ public class DungeonsXL extends DREPlugin {
public static File MOBS;
public static File SIGNS;
private boolean loadingWorld;
private GlobalData globalData;
private MainConfig mainConfig;
@ -287,6 +290,26 @@ public class DungeonsXL extends DREPlugin {
}
}
/**
* Returns true if the plugin is currently loading a world, false if not.<p>
* If the plugin is loading a world, it is locked in order to prevent loading two at once.
*
* @return true if the plugin is currently loading a world, false if not
*/
public boolean isLoadingWorld() {
return loadingWorld;
}
/**
* Notifies the plugin that a world is being loaded.<p>
* If the plugin is loading a world, it is locked in order to prevent loading two at once.
*
* @param loadingWorld if a world is being loaded
*/
public void setLoadingWorld(boolean loadingWorld) {
this.loadingWorld = loadingWorld;
}
/**
* @return the loaded instance of GlobalData
*/

View File

@ -205,8 +205,11 @@ public class DPortal extends GlobalProtection {
* @param player the player to teleport into his dungeon
*/
public void teleport(Player player) {
DGroup dGroup = DGroup.getByPlayer(player);
if (plugin.isLoadingWorld()) {
return;
}
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
return;

View File

@ -198,6 +198,7 @@ public class DResourceWorld {
* @return an instance of this world
*/
public DInstanceWorld instantiate(boolean game) {
plugin.setLoadingWorld(true);
int id = worlds.generateId();
String name = worlds.generateName(game, id);
@ -235,6 +236,7 @@ public class DResourceWorld {
signData.deserializeSigns((DEditWorld) instance);
}
plugin.setLoadingWorld(false);
return instance;
}
@ -243,6 +245,9 @@ public class DResourceWorld {
* @return an old or a new instance of this world.
*/
public DEditWorld instantiateAsEditWorld(boolean ignoreLimit) {
if (plugin.isLoadingWorld()) {
return null;
}
if (!ignoreLimit && plugin.getMainConfig().getMaxInstances() <= worlds.getInstances().size()) {
return null;
}
@ -262,6 +267,9 @@ public class DResourceWorld {
* @return a new instance of this world
*/
public DGameWorld instantiateAsGameWorld(boolean ignoreLimit) {
if (plugin.isLoadingWorld()) {
return null;
}
if (!ignoreLimit && plugin.getMainConfig().getMaxInstances() <= worlds.getInstances().size()) {
return null;
}