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