package com.imaginarycode.minecraft.redisbungee;

import redis.clients.jedis.Jedis;

public class UpdateCountTask implements Runnable {

    private RedisBungee plugin;
    private Jedis rsc;
    private boolean kill = false;

    public UpdateCountTask(RedisBungee plugin) {
        this.plugin = plugin;
        rsc = plugin.getPool().getResource();
    }

    @Override
    public void run() {
        if (kill) return;
        int c = plugin.getProxy().getOnlineCount();
        rsc.set("server:" + plugin.getServerId() + ":playerCount", String.valueOf(c));
        for (String i : plugin.getServers()) {
            if (i.equals(plugin.getServerId())) continue;
            if (rsc.exists("server:" + i + ":playerCount"))
                c += Integer.valueOf(rsc.get("server:" + i + ":playerCount"));
        }
        plugin.setCount(c);
    }

    protected void kill() {
        kill = true;
    }
}

@@ -1,8 +1,289 @@
+/**%0A * Copyright %C2%A9 2013 tuxed %3Cwrite@imaginarycode.com%3E%0A * This work is free. You can redistribute it and/or modify it under the%0A * terms of the Do What The Fuck You Want To Public License, Version 2,%0A * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.%0A */%0A
 package 

Add WTFPL header