From 80e6cb54cda3a1993968890896dbbdb0c8b1aa9c Mon Sep 17 00:00:00 2001 From: Chris Kearney <chris@kearneymail.com> Date: Mon, 16 May 2016 20:33:30 -0700 Subject: [PATCH] this is because someone was abusing this command --- .../creeper/command/CountdownCommand.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/comandante/creeper/command/CountdownCommand.java b/src/main/java/com/comandante/creeper/command/CountdownCommand.java index f6de1c1f..bf6a26ca 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); } } } -- GitLab