diff --git a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java index 7b2030e5..9a486b23 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/game/Game.java @@ -20,6 +20,7 @@ import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.dungeon.Dungeon; +import io.github.dre2n.dungeonsxl.global.GameSign; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.sign.MobSign; @@ -91,6 +92,10 @@ public class Game { */ public void removeDGroup(DGroup dGroup) { dGroups.remove(dGroup); + + if (dGroups.isEmpty()) { + delete(); + } } /** @@ -252,6 +257,19 @@ public class Game { } /* Actions */ + /** + * Remove the Game from the List + */ + public void delete() { + GameSign gameSign = GameSign.getByGame(this); + + plugin.getGames().remove(this); + + if (gameSign != null) { + gameSign.update(); + } + } + /** * @param mobCountIncreaseRate * the new mob count will be increased by this rate diff --git a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java index 4ba5ae06..b4a3c47b 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/global/GameSign.java @@ -195,7 +195,7 @@ public class GameSign extends GlobalProtection { } // Set Signs - if (game != null) { + if (game != null && game.getDGroups().size() > 0) { if (game.getDGroups().get(0).isPlaying()) { sign.setLine(0, IS_PLAYING); @@ -346,6 +346,24 @@ public class GameSign extends GlobalProtection { return null; } + /** + * @param game + * the game to check + */ + public static GameSign getByGame(Game game) { + for (GlobalProtection protection : plugin.getGlobalProtections().getProtections(GameSign.class)) { + GameSign gameSign = (GameSign) protection; + + for (Game signGame : gameSign.games) { + if (signGame == game) { + return gameSign; + } + } + } + + return null; + } + /* SUBJECT TO CHANGE*/ @Deprecated public static GameSign tryToCreate(Block startSign, String mapName, int maxGames, int maxGroupsPerGame, boolean multiFloor) { @@ -523,29 +541,6 @@ public class GameSign extends GlobalProtection { return true; } - @Deprecated - public static void updatePerGame(Game gameSearch) { - for (GlobalProtection protection : protections.getProtections(GameSign.class)) { - GameSign gameSign = (GameSign) protection; - - int i = 0; - for (Game game : gameSign.games) { - if (game == null) { - continue; - } - - if (game == gameSearch) { - if (gameSearch.isEmpty()) { - gameSign.games[i] = null; - } - gameSign.update(); - } - - i++; - } - } - } - @Deprecated public static int[] getDirection(byte data) { int[] direction = new int[2]; diff --git a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 4e523c88..901ef215 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -29,7 +29,6 @@ import io.github.dre2n.dungeonsxl.event.reward.RewardAdditionEvent; import io.github.dre2n.dungeonsxl.game.Game; import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.game.GameTypeDefault; -import io.github.dre2n.dungeonsxl.global.GameSign; import io.github.dre2n.dungeonsxl.global.GroupSign; import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.reward.Reward; @@ -431,17 +430,18 @@ public class DGroup { * Remove the group from the List */ public void delete() { + Game game = Game.getByDGroup(this); + plugin.getDGroups().remove(this); + if (game != null) { + game.removeDGroup(this); + } + if (timeIsRunningTask != null) { timeIsRunningTask.cancel(); } - if (Game.getByDGroup(this) != null) { - Game.getByDGroup(this).removeDGroup(this); - } - - GameSign.updatePerGame(Game.getByDGroup(this)); GroupSign.updatePerGroup(this); }