Permalink
Browse files

Implement automatic game mode changes when leaving, losing or winning.

Also fixed readyTimeout.
  • Loading branch information...
1 parent 0d39ba2 commit 941300fc307b518d5d93fd3eb5cd6d3ab77b6b78 @mkalus committed Mar 3, 2012
@@ -115,6 +115,11 @@
private Set<Player> teleportOkList;
/**
+ * list of players which may change their game mode - used by onGameModeChange
+ */
+ private Set<Player> gamemodeChangeOkList;
+
+ /**
* arena cuboid
*/
private Cuboid arena;
@@ -180,6 +185,7 @@ public GameStandard(String name) {
this.spleefers = new SpleeferList();
this.spectators = new LinkedList<Player>();
this.teleportOkList = new HashSet<Player>();
+ this.gamemodeChangeOkList = new HashSet<Player>();
this.trackers = new LinkedList<Tracker>();
}
@@ -710,6 +716,7 @@ public boolean leave(Player player) {
// teleport him/her back to original position, if supported
if (configuration.getBoolean("enableBackCommand", true)) {
// get original position
+ boolean wasInCreativeBefore = SimpleSpleef.getOriginalPositionKeeper().wasInCreativeBefore(player);
Location originalLocation = SimpleSpleef.getOriginalPositionKeeper().getOriginalPosition(player);
if (originalLocation == null) { // no position
player.sendMessage(ChatColor.DARK_RED + SimpleSpleef.ll("errors.backNoLocation"));
@@ -720,6 +727,9 @@ public boolean leave(Player player) {
// teleport player to original position
SimpleSpleef.simpleSpleefTeleport(player, originalLocation);
player.sendMessage(ChatColor.GREEN + SimpleSpleef.ll("feedback.back"));
+ // change game mode back, if needed
+ if (wasInCreativeBefore)
+ changeGameModeToCreative(player);
}
// check game status
@@ -1252,9 +1262,14 @@ public boolean onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
// players and spectators may not change game mode
if (hasPlayer(player) || hasSpectator(player)) {
- event.getPlayer().sendMessage(ChatColor.DARK_RED + SimpleSpleef.ll("errors.gamemodeChange"));
- event.setCancelled(true); //cancel event
- return true;
+ // ... if they are not in the game mode change ok list
+ if (gamemodeChangeOkList.contains(player)) {
+ gamemodeChangeOkList.remove(player);
+ } else {
+ event.getPlayer().sendMessage(ChatColor.DARK_RED + SimpleSpleef.ll("errors.gamemodeChange"));
+ event.setCancelled(true); //cancel event
+ return true;
+ }
}
return false;
}
@@ -1648,6 +1663,9 @@ protected void playerLoses(Player player, boolean teleport) {
restoreInventory(player);
// teleport player to lose spawn
if (teleport) teleportPlayer(player, "lose");
+ // update player's game mode
+ if (SimpleSpleef.getOriginalPositionKeeper().wasInCreativeBefore(player))
+ changeGameModeToCreative(player);
// determine if game is over...
if (checkGameOver()) gameOver();
}
@@ -1699,6 +1717,10 @@ protected void gameOver() {
// notify statistics
if (SimpleSpleef.getStatisticsModule() != null)
SimpleSpleef.getStatisticsModule().playerWonGame(player, this);
+
+ // change player's game mode, if it was creative before
+ if (SimpleSpleef.getOriginalPositionKeeper().wasInCreativeBefore(player))
+ changeGameModeToCreative(player);
// teleport winners back to winner's point or to lounge
if (configuration.isConfigurationSection("winnerSpawn") && configuration.getBoolean("winnerSpawn.enabled", false))
@@ -2043,6 +2065,15 @@ private void refundPlayer(Player player) {
}
}
+ /**
+ * change game mode to creative and add player to gamemodeChangeOkList
+ * @param player
+ */
+ private void changeGameModeToCreative(Player player) {
+ gamemodeChangeOkList.add(player); // may change game mode
+ player.setGameMode(GameMode.CREATIVE);
+ }
+
@Override
public long getStartTime() {
return startTime;
@@ -139,7 +139,8 @@ public boolean tick() {
// reset timer
counterStarted = false;
count = originalCount;
- }
+ } else
+ return true; // game in progress now - kill timer
}
if (count % 60 == 0) { // announce full minutes
@@ -111,7 +111,7 @@ feedback:
refund: 'Dir wurden [AMOUNT] gutgeschrieben.'
gamemodeChanged: 'Dein game mode wurde geändert.'
ready: 'Du bist bereit für das Spiel!'
- readyTimeoutStart: 'Der erste Spieler ist bereit zum Spiel in der Arena [ARENA! Macht euch jetzt ebenfalls möglichst schnell bereit!'
+ readyTimeoutStart: 'Der erste Spieler ist bereit zum Spiel in der Arena [ARENA]! Macht euch jetzt ebenfalls möglichst schnell bereit!'
readyTimeoutStop: 'Keine bereiten Spieler mehr vorhanden in der Arena [ARENA].'
readyCountdown: 'Verbleibende Zeit zum Anmelden: [COUNT]'
readyMinutes: 'Noch [COUNT] Minuten verbleiben, um sich in der [ARENA] bereit zu erklären.'

0 comments on commit 941300f

Please sign in to comment.