Fix getting game from group; resolves #896

This commit is contained in:
Daniel Saukel 2020-10-06 15:43:52 +02:00
parent 7e79b52091
commit 6bedccb29f
3 changed files with 16 additions and 8 deletions

View File

@ -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.

View File

@ -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));

View File

@ -74,6 +74,7 @@ public class DGroup implements PlayerGroup {
private PlayerCollection invitedPlayers = new PlayerCollection();
private Dungeon dungeon;
private List<ResourceWorld> 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;