package be.demmel.jgws.modules; import io.netty.channel.group.ChannelGroup; import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import be.demmel.jgws.GameServer; import be.demmel.jgws.MapData; public abstract class AffectingAllPlayers implements Runnable { private static final Logger LOGGER = LoggerFactory.getLogger(AffectingAllPlayers.class); private final long sleepTimeMillis; private final ChannelGroup channels; public AffectingAllPlayers(ChannelGroup channels, long sleepTimeMillis) { this.sleepTimeMillis = sleepTimeMillis; this.channels = channels; } @Override public final void run() { for(;;) { try { Thread.sleep(this.sleepTimeMillis); } catch (InterruptedException ex) { } // Retrieve all the maps of this server List maps = GameServer.getLoadedMaps(); try { handle(channels); } catch (Exception e) { LOGGER.error("Unexpected error: ", e); } } } protected abstract void handle(ChannelGroup channels) throws IllegalStateException, Exception; }