Skip to content

Commit

Permalink
Return Set instead of Collection in JoinOffer
Browse files Browse the repository at this point in the history
  • Loading branch information
pufmat authored and Patbox committed Nov 5, 2024
1 parent c063434 commit 5e1ef9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/main/java/xyz/nucleoid/plasmid/game/player/JoinOffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import xyz.nucleoid.plasmid.game.event.GamePlayerEvents;

import java.util.Collection;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
* Represents a request for of a player or group of players to join a {@link GameSpace}.
Expand All @@ -25,26 +27,26 @@ public interface JoinOffer {
/**
* @return the set of {@link GameProfile} of the players that are requesting access to this {@link GameSpace}
*/
Collection<GameProfile> players();
Set<GameProfile> players();

/**
* @return the {@link UUID profile UUID} of the players that are requesting access to this {@link GameSpace}
*/
default Collection<UUID> playerIds() {
default Set<UUID> playerIds() {
return this.players()
.stream()
.map(GameProfile::getId)
.toList();
.collect(Collectors.toSet());
}

/**
* @return the usernames of the players that are requesting access to this {@link GameSpace}
*/
default Collection<String> playerNames() {
default Set<String> playerNames() {
return this.players()
.stream()
.map(GameProfile::getName)
.toList();
.collect(Collectors.toSet());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@

import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

public record LocalJoinOffer(Collection<ServerPlayerEntity> serverPlayers, JoinIntent intent) implements JoinOffer {
@Override
public Collection<GameProfile> players() {
public Set<GameProfile> players() {
return this.serverPlayers
.stream()
.map(PlayerEntity::getGameProfile)
.toList();
.collect(Collectors.toSet());
}

@Override
public Collection<UUID> playerIds() {
public Set<UUID> playerIds() {
return this.serverPlayers
.stream()
.map(player -> player.getGameProfile().getId())
.toList();
.collect(Collectors.toSet());
}

@Override
public Collection<String> playerNames() {
public Set<String> playerNames() {
return this.serverPlayers
.stream()
.map(player -> player.getGameProfile().getName())
.toList();
.collect(Collectors.toSet());
}

@Override
Expand Down

0 comments on commit 5e1ef9e

Please sign in to comment.