diff --git a/api/src/main/java/de/erethon/dungeonsxl/api/player/PlayerGroup.java b/api/src/main/java/de/erethon/dungeonsxl/api/player/PlayerGroup.java index 54fe63a2..9601f877 100644 --- a/api/src/main/java/de/erethon/dungeonsxl/api/player/PlayerGroup.java +++ b/api/src/main/java/de/erethon/dungeonsxl/api/player/PlayerGroup.java @@ -287,9 +287,7 @@ public interface PlayerGroup { * * @return the game of the game world the group is in. */ - default Game getGame() { - return getGameWorld() != null ? getGameWorld().getGame() : null; - } + Game getGame(); /** * Returns the game world the group is in. diff --git a/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java b/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java index d1595faa..2e41027a 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java +++ b/core/src/main/java/de/erethon/dungeonsxl/dungeon/DGame.java @@ -63,11 +63,7 @@ public class DGame implements Game { tutorial = false; started = false; - groups.add(group); - group.setGameWorld(world); - group.setInitialLives(getRules().getState(GameRule.INITIAL_GROUP_LIVES)); - group.setLives(getRules().getState(GameRule.INITIAL_GROUP_LIVES)); - group.setScore(getRules().getState(GameRule.INITIAL_SCORE)); + addGroup(group); } public DGame(DungeonsXL plugin, PlayerGroup group, GameWorld world) { @@ -112,6 +108,7 @@ public class DGame implements Game { public void addGroup(PlayerGroup group) { groups.add(group); + ((DGroup) group).setGame(this); group.setGameWorld(world); group.setInitialLives(getRules().getState(GameRule.INITIAL_GROUP_LIVES)); group.setLives(getRules().getState(GameRule.INITIAL_GROUP_LIVES)); diff --git a/core/src/main/java/de/erethon/dungeonsxl/player/DGroup.java b/core/src/main/java/de/erethon/dungeonsxl/player/DGroup.java index 2ea9342c..b8bddde9 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/player/DGroup.java +++ b/core/src/main/java/de/erethon/dungeonsxl/player/DGroup.java @@ -74,6 +74,7 @@ public class DGroup implements PlayerGroup { private PlayerCollection invitedPlayers = new PlayerCollection(); private Dungeon dungeon; private List unplayedFloors = new ArrayList<>(); + private Game game; private GameWorld gameWorld; private boolean playing; private int floorCount; @@ -334,6 +335,18 @@ public class DGroup implements PlayerGroup { this.gameWorld = gameWorld; } + @Override + public Game getGame() { + if (game == null && gameWorld != null) { + game = gameWorld.getGame(); + } + return game; + } + + public void setGame(Game game) { + this.game = game; + } + @Override public Dungeon getDungeon() { return dungeon;