mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-28 13:36:33 +01:00
Fix maxInstances setting
This commit is contained in:
parent
b517e5e52f
commit
d1528838bd
@ -17,10 +17,13 @@
|
|||||||
package de.erethon.dungeonsxl.announcer;
|
package de.erethon.dungeonsxl.announcer;
|
||||||
|
|
||||||
import de.erethon.dungeonsxl.DungeonsXL;
|
import de.erethon.dungeonsxl.DungeonsXL;
|
||||||
|
import de.erethon.dungeonsxl.config.DMessage;
|
||||||
import de.erethon.dungeonsxl.game.Game;
|
import de.erethon.dungeonsxl.game.Game;
|
||||||
import de.erethon.dungeonsxl.player.DGamePlayer;
|
import de.erethon.dungeonsxl.player.DGamePlayer;
|
||||||
import de.erethon.dungeonsxl.player.DGroup;
|
import de.erethon.dungeonsxl.player.DGroup;
|
||||||
import de.erethon.dungeonsxl.util.ProgressBar;
|
import de.erethon.dungeonsxl.util.ProgressBar;
|
||||||
|
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||||
|
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
@ -71,7 +74,19 @@ public class AnnouncerStartGameTask extends BukkitRunnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (game == null) {
|
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 {
|
} else {
|
||||||
game.getDGroups().add(dGroup);
|
game.getDGroups().add(dGroup);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,12 @@ public class EditCommand extends DRECommand {
|
|||||||
return;
|
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);
|
DGroup dGroup = DGroup.getByPlayer(player);
|
||||||
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player);
|
DGlobalPlayer dPlayer = DungeonsXL.getInstance().getDPlayers().getByPlayer(player);
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import de.erethon.dungeonsxl.player.DGlobalPlayer;
|
|||||||
import de.erethon.dungeonsxl.player.DGroup;
|
import de.erethon.dungeonsxl.player.DGroup;
|
||||||
import de.erethon.dungeonsxl.player.DInstancePlayer;
|
import de.erethon.dungeonsxl.player.DInstancePlayer;
|
||||||
import de.erethon.dungeonsxl.player.DPermission;
|
import de.erethon.dungeonsxl.player.DPermission;
|
||||||
|
import de.erethon.dungeonsxl.world.DGameWorld;
|
||||||
import de.erethon.dungeonsxl.world.DResourceWorld;
|
import de.erethon.dungeonsxl.world.DResourceWorld;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -89,7 +90,12 @@ public class PlayCommand extends DRECommand {
|
|||||||
}
|
}
|
||||||
dGroup.setDungeon(dungeon);
|
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()) {
|
for (Player groupPlayer : dGroup.getPlayers().getOnlinePlayers()) {
|
||||||
DGamePlayer.create(groupPlayer, dGroup.getGameWorld());
|
DGamePlayer.create(groupPlayer, dGroup.getGameWorld());
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,11 @@ public class TestCommand extends DRECommand {
|
|||||||
editPlayer.leave();
|
editPlayer.leave();
|
||||||
DResourceWorld resource = editPlayer.getEditWorld().getResource();
|
DResourceWorld resource = editPlayer.getEditWorld().getResource();
|
||||||
Dungeon dungeon = new Dungeon(resource);
|
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);
|
Game game = new Game(new DGroup(player, dungeon), GameTypeDefault.TEST, instance);
|
||||||
DGamePlayer.create(player, game.getWorld(), GameTypeDefault.TEST);
|
DGamePlayer.create(player, game.getWorld(), GameTypeDefault.TEST);
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,11 @@ public class DPortal extends GlobalProtection {
|
|||||||
if (target == null && dGroup.getDungeon() != null) {
|
if (target == null && dGroup.getDungeon() != null) {
|
||||||
DResourceWorld resource = dGroup.getDungeon().getMap();
|
DResourceWorld resource = dGroup.getDungeon().getMap();
|
||||||
if (resource != null) {
|
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);
|
dGroup.setGameWorld(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,11 +125,6 @@ public class GameSign extends JoinSign {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onPlayerInteract(Block block, Player player) {
|
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);
|
DGroup dGroup = DGroup.getByPlayer(player);
|
||||||
if (dGroup == null) {
|
if (dGroup == null) {
|
||||||
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
MessageUtil.sendMessage(player, DMessage.ERROR_JOIN_GROUP.getMessage());
|
||||||
|
@ -704,7 +704,7 @@ public class DGroup {
|
|||||||
|
|
||||||
Game game = gameWorld.getGame();
|
Game game = gameWorld.getGame();
|
||||||
removeUnplayedFloor(gameWorld.getResource(), false);
|
removeUnplayedFloor(gameWorld.getResource(), false);
|
||||||
DGameWorld gameWorld = newFloor.instantiateAsGameWorld();
|
DGameWorld gameWorld = newFloor.instantiateAsGameWorld(true);
|
||||||
gameWorld.setType(type);
|
gameWorld.setType(type);
|
||||||
this.gameWorld = gameWorld;
|
this.gameWorld = gameWorld;
|
||||||
game.setWorld(gameWorld);
|
game.setWorld(gameWorld);
|
||||||
|
@ -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.
|
* @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()) {
|
for (DEditWorld instance : worlds.getEditWorlds()) {
|
||||||
if (instance.getName().equals(getName())) {
|
if (instance.getName().equals(getName())) {
|
||||||
return instance;
|
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
|
* @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);
|
return (DGameWorld) instantiate(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user