mirror of
https://github.com/BGHDDevelopment/PlayerBalancer.git
synced 2024-11-09 04:20:32 +01:00
Using streams for getPlayers on SectionServer
This commit is contained in:
parent
e0e67eb2ce
commit
a6c7cdbfac
@ -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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user