mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-07 19:30:48 +01:00
Fix loading multiple worlds at once
This commit is contained in:
parent
3f05d215c4
commit
3f554df158
@ -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
|
||||
*/
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user