This commit is contained in:
Anuken
2019-08-20 19:42:39 -04:00
parent bae88ec416
commit 014e2ac8b8
4 changed files with 6 additions and 5 deletions

Binary file not shown.

View File

@@ -84,7 +84,7 @@ public class Control implements ApplicationListener{
}); });
Events.on(PlayEvent.class, event -> { Events.on(PlayEvent.class, event -> {
player.setTeam(state.rules.pvp ? netServer.assignTeam(playerGroup.all()) : defaultTeam); player.setTeam(state.rules.pvp ? netServer.assignTeam(player, playerGroup.all()) : defaultTeam);
player.setDead(true); player.setDead(true);
player.add(); player.add();

View File

@@ -176,7 +176,7 @@ public class NetServer implements ApplicationListener{
//playing in pvp mode automatically assigns players to teams //playing in pvp mode automatically assigns players to teams
if(state.rules.pvp){ if(state.rules.pvp){
player.setTeam(assignTeam(playerGroup.all())); player.setTeam(assignTeam(player, playerGroup.all()));
Log.info("Auto-assigned player {0} to team {1}.", player.name, player.getTeam()); Log.info("Auto-assigned player {0} to team {1}.", player.name, player.getTeam());
} }
@@ -194,13 +194,13 @@ public class NetServer implements ApplicationListener{
}); });
} }
public Team assignTeam(Iterable<Player> players){ public Team assignTeam(Player current, Iterable<Player> players){
//find team with minimum amount of players and auto-assign player to that. //find team with minimum amount of players and auto-assign player to that.
return Structs.findMin(Team.all, team -> { return Structs.findMin(Team.all, team -> {
if(state.teams.isActive(team) && !state.teams.get(team).cores.isEmpty()){ if(state.teams.isActive(team) && !state.teams.get(team).cores.isEmpty()){
int count = 0; int count = 0;
for(Player other : players){ for(Player other : players){
if(other.getTeam() == team){ if(other.getTeam() == team && other != current){
count++; count++;
} }
} }

View File

@@ -700,10 +700,11 @@ public class ServerControl implements ApplicationListener{
run.run(); run.run();
logic.play(); logic.play();
state.rules = world.getMap().applyRules(lastMode); state.rules = world.getMap().applyRules(lastMode);
for(Player p : players){ for(Player p : players){
p.reset(); p.reset();
if(state.rules.pvp){ if(state.rules.pvp){
p.setTeam(netServer.assignTeam(new ArrayIterable<>(players))); p.setTeam(netServer.assignTeam(p, new ArrayIterable<>(players)));
} }
netServer.sendWorldData(p, p.con.id); netServer.sendWorldData(p, p.con.id);
} }