Fix maxInstances setting

This commit is contained in:
Daniel Saukel 2018-08-10 19:51:05 +02:00
parent b517e5e52f
commit d1528838bd
8 changed files with 51 additions and 13 deletions

View File

@ -17,10 +17,13 @@
package de.erethon.dungeonsxl.announcer;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.game.Game;
import de.erethon.dungeonsxl.player.DGamePlayer;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.util.ProgressBar;
import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.DResourceWorld;
import java.util.HashSet;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -71,7 +74,19 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
}
if (game == null) {
game = new Game(dGroup, DungeonsXL.getInstance().getDWorlds().getResourceByName(announcer.getMapName()));
DResourceWorld resource = DungeonsXL.getInstance().getDWorlds().getResourceByName(announcer.getMapName());
if (resource == null) {
dGroup.sendMessage(DMessage.ERROR_NO_SUCH_MAP.getMessage(announcer.getMapName()));
cancel();
return;
}
DGameWorld gameWorld = resource.instantiateAsGameWorld(false);
if (gameWorld == null) {
dGroup.sendMessage(DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
cancel();
return;
}
game = new Game(dGroup, gameWorld);
} else {
game.getDGroups().add(dGroup);
}

View File

@ -67,7 +67,12 @@ public class EditCommand extends DRECommand {
return;
}
DEditWorld editWorld = resource.instantiateAsEditWorld();
DEditWorld editWorld = resource.instantiateAsEditWorld(false);
if (editWorld == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
return;
}
DGroup dGroup = DGroup.getByPlayer(player);
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player);

View File

@ -28,6 +28,7 @@ import de.erethon.dungeonsxl.player.DGlobalPlayer;
import de.erethon.dungeonsxl.player.DGroup;
import de.erethon.dungeonsxl.player.DInstancePlayer;
import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.DResourceWorld;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -89,7 +90,12 @@ public class PlayCommand extends DRECommand {
}
dGroup.setDungeon(dungeon);
new Game(dGroup, dungeon.getMap());
DGameWorld gameWorld = dungeon.getMap().instantiateAsGameWorld(false);
if (gameWorld == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
return;
}
new Game(dGroup, gameWorld);
for (Player groupPlayer : dGroup.getPlayers().getOnlinePlayers()) {
DGamePlayer.create(groupPlayer, dGroup.getGameWorld());
}

View File

@ -86,7 +86,11 @@ public class TestCommand extends DRECommand {
editPlayer.leave();
DResourceWorld resource = editPlayer.getEditWorld().getResource();
Dungeon dungeon = new Dungeon(resource);
DGameWorld instance = resource.instantiateAsGameWorld();
DGameWorld instance = resource.instantiateAsGameWorld(false);
if (instance == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
return;
}
Game game = new Game(new DGroup(player, dungeon), GameTypeDefault.TEST, instance);
DGamePlayer.create(player, game.getWorld(), GameTypeDefault.TEST);
}

View File

@ -218,7 +218,11 @@ public class DPortal extends GlobalProtection {
if (target == null && dGroup.getDungeon() != null) {
DResourceWorld resource = dGroup.getDungeon().getMap();
if (resource != null) {
target = resource.instantiateAsGameWorld();
target = resource.instantiateAsGameWorld(false);
if (target == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
return;
}
dGroup.setGameWorld(target);
}
}

View File

@ -125,11 +125,6 @@ public class GameSign extends JoinSign {
}
public void onPlayerInteract(Block block, Player player) {
if (DungeonsXL.getInstance().getDWorlds().getGameWorlds().size() >= DungeonsXL.getInstance().getMainConfig().getMaxInstances()) {
MessageUtil.sendMessage(player, DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
return;
}
DGroup dGroup = DGroup.getByPlayer(player);
if (dGroup == null) {
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());

View File

@ -704,7 +704,7 @@ public class DGroup {
Game game = gameWorld.getGame();
removeUnplayedFloor(gameWorld.getResource(), false);
DGameWorld gameWorld = newFloor.instantiateAsGameWorld();
DGameWorld gameWorld = newFloor.instantiateAsGameWorld(true);
gameWorld.setType(type);
this.gameWorld = gameWorld;
game.setWorld(gameWorld);

View File

@ -262,9 +262,14 @@ public class DResourceWorld {
}
/**
* @param ignoreLimit if the global instance limit shall be ignored
* @return an old or a new instance of this world.
*/
public DEditWorld instantiateAsEditWorld() {
public DEditWorld instantiateAsEditWorld(boolean ignoreLimit) {
if (!ignoreLimit && plugin.getMainConfig().getMaxInstances() <= worlds.getInstances().size()) {
return null;
}
for (DEditWorld instance : worlds.getEditWorlds()) {
if (instance.getName().equals(getName())) {
return instance;
@ -276,9 +281,13 @@ public class DResourceWorld {
}
/**
* @param ignoreLimit if the global instance limit shall be ignored
* @return a new instance of this world
*/
public DGameWorld instantiateAsGameWorld() {
public DGameWorld instantiateAsGameWorld(boolean ignoreLimit) {
if (!ignoreLimit && plugin.getMainConfig().getMaxInstances() <= worlds.getInstances().size()) {
return null;
}
return (DGameWorld) instantiate(true);
}