diff --git a/src/main/java/com/comandante/creeper/command/CountdownCommand.java b/src/main/java/com/comandante/creeper/command/CountdownCommand.java index f6de1c1f85e0549c4628fab860b2e527e14c2ac3..bf6a26ca1df8d2b86e927f24ae881913205fc93b 100644 --- a/src/main/java/com/comandante/creeper/command/CountdownCommand.java +++ b/src/main/java/com/comandante/creeper/command/CountdownCommand.java @@ -1,10 +1,10 @@ package com.comandante.creeper.command; -import com.comandante.creeper.Items.Item; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.Player; +import com.comandante.creeper.player.PlayerManager; +import com.comandante.creeper.server.ChannelUtils; import com.comandante.creeper.server.Color; -import com.google.common.base.Joiner; import com.google.common.collect.Lists; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -25,18 +25,37 @@ public class CountdownCommand extends Command { public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { configure(e); try { + new Thread(new PrintCountdown(playerManager, channelUtils)).start(); + } finally { + super.messageReceived(ctx, e); + } + } + + public static class PrintCountdown implements Runnable { + + private PlayerManager playerManager; + private ChannelUtils channelUtils; + + public PrintCountdown(PlayerManager playerManager, ChannelUtils channelUtils) { + this.playerManager = playerManager; + this.channelUtils = channelUtils; + } + + @Override + public void run() { ArrayList<String> strings = Lists.newArrayList("... ***** COUNTDOWN ***** ...", ". 5 .", ". 4 .", ". 3 .", ". 2 .", ". 1 .", "... ***** SMOKE! ***** ..."); - for (String s: strings) { + for (String s : strings) { Iterator<Map.Entry<String, Player>> players = playerManager.getPlayers(); while (players.hasNext()) { Map.Entry<String, Player> next = players.next(); channelUtils.write(next.getValue().getPlayerId(), Color.BOLD_ON + Color.GREEN + s + Color.RESET + "\r\n", true); } - Thread.sleep(900); + try { + Thread.sleep(900); + } catch (InterruptedException e) { + e.printStackTrace(); + } } - - } finally { - super.messageReceived(ctx, e); } } }