@Test public void playerConnect() { OnlineIndexingRepository repository = mock(OnlineIndexingRepository.class); ProxyServer proxyServer = mock(ProxyServer.class); LobbyBalancer lobbyBalancer = new LobbyBalancer(repository, proxyServer); ServerConnectEvent event = mock(ServerConnectEvent.class); when(event.getTarget()).thenAnswer(invocation -> { ServerInfo serverInfo = mock(ServerInfo.class); when(serverInfo.getName()).thenReturn("lobby-6"); return serverInfo; }); when(repository.getMostFreeServer(any())).thenReturn("lobby-3"); when(event.getPlayer()).thenReturn(mock(ProxiedPlayer.class)); ServerInfo target =mock(ServerInfo.class); when(proxyServer.getServerInfo(eq("lobby-3"))).thenReturn(target); lobbyBalancer.playerConnect(event); verify(event).setTarget(eq(target)); }
@EventHandler public void playerConnect(ServerConnectEvent event) { if (ServerType.LOBBY.matches(event.getTarget().getName())) { String mostFreeServer = onlineRepository.getMostFreeServer(ServerType.LOBBY); log.info("Connecting {} to {}", event.getPlayer().getName(), mostFreeServer); event.setTarget(bungeeCord.getServerInfo(mostFreeServer)); } }
LobbyBalancer implements Listener { @EventHandler public void playerConnect(ServerConnectEvent event) { if (ServerType.LOBBY.matches(event.getTarget().getName())) { String mostFreeServer = onlineRepository.getMostFreeServer(ServerType.LOBBY); log.info("Connecting {} to {}", event.getPlayer().getName(), mostFreeServer); event.setTarget(bungeeCord.getServerInfo(mostFreeServer)); } } }
LobbyBalancer implements Listener { @EventHandler public void playerConnect(ServerConnectEvent event) { if (ServerType.LOBBY.matches(event.getTarget().getName())) { String mostFreeServer = onlineRepository.getMostFreeServer(ServerType.LOBBY); log.info("Connecting {} to {}", event.getPlayer().getName(), mostFreeServer); event.setTarget(bungeeCord.getServerInfo(mostFreeServer)); } }  }
LobbyBalancer implements Listener { @EventHandler public void playerConnect(ServerConnectEvent event) { if (ServerType.LOBBY.matches(event.getTarget().getName())) { String mostFreeServer = onlineRepository.getMostFreeServer(ServerType.LOBBY); log.info("Connecting {} to {}", event.getPlayer().getName(), mostFreeServer); event.setTarget(bungeeCord.getServerInfo(mostFreeServer)); } }  @EventHandler void playerConnect(ServerConnectEvent event); }
LobbyBalancer implements Listener { @EventHandler public void playerConnect(ServerConnectEvent event) { if (ServerType.LOBBY.matches(event.getTarget().getName())) { String mostFreeServer = onlineRepository.getMostFreeServer(ServerType.LOBBY); log.info("Connecting {} to {}", event.getPlayer().getName(), mostFreeServer); event.setTarget(bungeeCord.getServerInfo(mostFreeServer)); } }  @EventHandler void playerConnect(ServerConnectEvent event);  }