Using streams for getPlayers on SectionServer

This commit is contained in:
Jaime Martínez Rincón 2017-09-20 20:03:23 +02:00
parent e0e67eb2ce
commit a6c7cdbfac

View File

@ -1,7 +1,9 @@
package com.jaimemartz.playerbalancer.section; package com.jaimemartz.playerbalancer.section;
import com.google.common.collect.Iterables;
import com.jaimemartz.playerbalancer.settings.props.features.BalancerProps; import com.jaimemartz.playerbalancer.settings.props.features.BalancerProps;
import net.md_5.bungee.BungeeServerInfo; import net.md_5.bungee.BungeeServerInfo;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -9,6 +11,9 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class SectionServer extends BungeeServerInfo { public class SectionServer extends BungeeServerInfo {
private final BalancerProps props; private final BalancerProps props;
@ -29,13 +34,10 @@ public class SectionServer extends BungeeServerInfo {
@Override @Override
public Collection<ProxiedPlayer> getPlayers() { public Collection<ProxiedPlayer> getPlayers() {
if (props.isShowPlayers()) { if (props.isShowPlayers()) {
List<ProxiedPlayer> res = new ArrayList<>(); return section.getServers().stream()
section.getServers().forEach(server -> { .map(ServerInfo::getPlayers)
res.addAll(server.getPlayers()); .flatMap(Collection::stream)
}); .collect(Collectors.toList());
return res; } else return Collections.emptyList();
} else {
return Collections.emptyList();
}
} }
} }