Fixed GameSign updating when group is deleted

This commit is contained in:
Daniel Saukel 2016-04-29 21:10:16 +02:00
parent eed8427eb1
commit 5e2c9ff601
3 changed files with 43 additions and 30 deletions

View File

@ -20,6 +20,7 @@ import io.github.dre2n.commons.util.playerutil.PlayerUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.DungeonsXL;
import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.dungeon.Dungeon; 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.player.DGroup;
import io.github.dre2n.dungeonsxl.sign.DSign; import io.github.dre2n.dungeonsxl.sign.DSign;
import io.github.dre2n.dungeonsxl.sign.MobSign; import io.github.dre2n.dungeonsxl.sign.MobSign;
@ -91,6 +92,10 @@ public class Game {
*/ */
public void removeDGroup(DGroup dGroup) { public void removeDGroup(DGroup dGroup) {
dGroups.remove(dGroup); dGroups.remove(dGroup);
if (dGroups.isEmpty()) {
delete();
}
} }
/** /**
@ -252,6 +257,19 @@ public class Game {
} }
/* Actions */ /* 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 * @param mobCountIncreaseRate
* the new mob count will be increased by this rate * the new mob count will be increased by this rate

View File

@ -195,7 +195,7 @@ public class GameSign extends GlobalProtection {
} }
// Set Signs // Set Signs
if (game != null) { if (game != null && game.getDGroups().size() > 0) {
if (game.getDGroups().get(0).isPlaying()) { if (game.getDGroups().get(0).isPlaying()) {
sign.setLine(0, IS_PLAYING); sign.setLine(0, IS_PLAYING);
@ -346,6 +346,24 @@ public class GameSign extends GlobalProtection {
return null; 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*/ /* SUBJECT TO CHANGE*/
@Deprecated @Deprecated
public static GameSign tryToCreate(Block startSign, String mapName, int maxGames, int maxGroupsPerGame, boolean multiFloor) { 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; 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 @Deprecated
public static int[] getDirection(byte data) { public static int[] getDirection(byte data) {
int[] direction = new int[2]; int[] direction = new int[2];

View File

@ -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.Game;
import io.github.dre2n.dungeonsxl.game.GameType; import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault; 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.global.GroupSign;
import io.github.dre2n.dungeonsxl.requirement.Requirement; import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward; import io.github.dre2n.dungeonsxl.reward.Reward;
@ -431,17 +430,18 @@ public class DGroup {
* Remove the group from the List * Remove the group from the List
*/ */
public void delete() { public void delete() {
Game game = Game.getByDGroup(this);
plugin.getDGroups().remove(this); plugin.getDGroups().remove(this);
if (game != null) {
game.removeDGroup(this);
}
if (timeIsRunningTask != null) { if (timeIsRunningTask != null) {
timeIsRunningTask.cancel(); timeIsRunningTask.cancel();
} }
if (Game.getByDGroup(this) != null) {
Game.getByDGroup(this).removeDGroup(this);
}
GameSign.updatePerGame(Game.getByDGroup(this));
GroupSign.updatePerGroup(this); GroupSign.updatePerGroup(this);
} }