package net.craftminecraft.bungee.bungeeban.listener;

import com.google.common.eventbus.Subscribe;

import net.craftminecraft.bungee.bungeeban.BanManager;
import net.craftminecraft.bungee.bungeeban.banstore.BanEntry;
import net.craftminecraft.bungee.bungeeban.util.Utils;
import net.md_5.bungee.api.event.LoginEvent;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.api.event.ServerConnectEvent;
import net.md_5.bungee.api.plugin.Listener;

public class ProxiedPlayerListener implements Listener {
	public ProxiedPlayerListener() {
	}
	
	@Subscribe
	public void onPlayerJoin(PostLoginEvent e) {
		BanEntry ban = BanManager.getBan(e.getPlayer().getName(), "(GLOBAL)");
		if (ban != null) {
			e.getPlayer().disconnect(Utils.formatMessage(ban.getReason(), ban));
			return;
		}
		ban = BanManager.getBan(e.getPlayer().getAddress().getAddress().getHostAddress(), "(GLOBAL)");
		if (ban != null) {
			e.getPlayer().disconnect(Utils.formatMessage(ban.getReason(), ban));
			return;
		}
	}
	
	@Subscribe
	public void onServerConnect(ServerConnectEvent e) {
		BanEntry ban = BanManager.getBan(e.getPlayer().getName(), e.getTarget().getName());
		if (ban != null) {
			e.getPlayer().disconnect(Utils.formatMessage(ban.getReason(), ban));
			return;
		} 
		ban = BanManager.getBan(e.getPlayer().getAddress().getAddress().getHostAddress(), e.getTarget().getName());
		if (ban != null) {
			e.getPlayer().disconnect(Utils.formatMessage(ban.getReason(), ban));
		}
		return;
	}
}

@@ -609,20 +609,16 @@
 yerJoin(
-Post
 LoginEve
@@ -658,38 +658,42 @@
 ger.getBan(e.get
-Player
+Connection
 ().getName(), %22(
@@ -726,38 +726,42 @@
 ull) %7B%0D%0A%09%09%09e.get
-Player
+Connection
 ().disconnect(Ut
@@ -843,38 +843,42 @@
 ger.getBan(e.get
-Player
+Connection
 ().getAddress().
@@ -944,38 +944,42 @@
 ull) %7B%0D%0A%09%09%09e.get
-Player
+Connection
 ().disconnect(Ut
@@ -1213,32 +1213,151 @@
 ban != null) %7B%0D%0A
+%09%09%09// Ugly workaround the player joined... player left messages%0D%0A%09%09%09e.setTarget(e.getPlayer().getServer().getInfo());%0D%0A
 %09%09%09e.getPlayer()
@@ -1556,32 +1556,151 @@
 ban != null) %7B%0D%0A
+%09%09%09// Ugly workaround the player joined... player left messages%0D%0A%09%09%09e.setTarget(e.getPlayer().getServer().getInfo());%0D%0A
 %09%09%09e.getPlayer()

Revert back to LoginEvent for global bans. Fix Player join/left messages for local bans.