/**
 * Copyright © 2014 tuxed <write@imaginarycode.com>
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
 */
package com.imaginarycode.minecraft.hubmagic;

import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerKickEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;

import java.util.List;

@RequiredArgsConstructor
public class ReconnectListener implements Listener {
    private final List<String> reasonList;
    private final List<String> message;

    @EventHandler(priority = EventPriority.HIGH)
    public void onServerKick(ServerKickEvent event) {
        ServerInfo kickedFrom = event.getKickedFrom();

        // May we reconnect the server to the hub?
        boolean mayReconnect = HubMagic.getPlugin().getPingManager().firstAvailable(event.getPlayer()) != null;

        if (mayReconnect) {
            boolean shouldReconnect = false;

            for (String pattern : reasonList) {
                if (event.getKickReason().contains(pattern) || event.getKickReason().matches(pattern)) {
                    shouldReconnect = true;
                    break;
                }
            }

            if (!shouldReconnect)
                return;

            ServerInfo newServer = ProxyServer.getInstance().getReconnectHandler().getServer(event.getPlayer());

            if (newServer == null)
                return;

            event.setCancelled(true);
            event.setCancelServer(newServer);
            for (String components : message) {
                event.getPlayer().sendMessage(components.replace("%kick-reason%", event.getKickReason())
                        .replace("%server%", event.getKickedFrom().getName()));
            }
        }
    }
}

@@ -697,16 +697,54 @@
 il.List;
+%0Aimport java.util.concurrent.TimeUnit;
 %0A%0A@Requi
@@ -977,16 +977,22 @@
 verKick(
+final 
 ServerKi
@@ -1657,58 +1657,54 @@
 r = 
-ProxyServer.getInstance().getReconnectHandler().ge
+HubMagic.getPlugin().getServerSelector().selec
 tSer
@@ -1872,16 +1872,17 @@
 erver);%0A
+%0A
         

Fix kicking to hub.