Skip to content

Commit

Permalink
Small change
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed Oct 29, 2024
1 parent e7b0d6e commit 10219b2
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/main/java/me/despical/tntrun/arena/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import java.text.MessageFormat;
import java.util.*;
import java.util.function.Predicate;
import java.util.logging.Level;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -215,31 +216,31 @@ public ScoreboardManager getScoreboardManager() {
return scoreboardManager;
}

public List<User> getPlayers() {
return this.players.stream().filter(user -> {
public Set<User> getPlayers() {
return players.stream().filter(user -> {
Player player = user.getPlayer();

return player != null && player.isOnline();
}).collect(Collectors.toList());
}).collect(Collectors.toSet());
}

public void addUser(final User user) {
public void addUser(User user) {
this.players.add(user);
}

public void removeUser(final User user) {
public void removeUser(User user) {
this.players.remove(user);
}

public boolean isForceStart() {
return this.forceStart;
}

public void setForceStart(final boolean forceStart) {
public void setForceStart(boolean forceStart) {
this.forceStart = forceStart;
}

public void addDeathPlayer(final User user) {
public void addDeathPlayer(User user) {
deaths.add(user);

if (this.getPlayersLeft().size() < 4) {
Expand All @@ -250,15 +251,15 @@ public void addDeathPlayer(final User user) {
this.addSpectator(user);
}

public boolean isDeathPlayer(final User user) {
public boolean isDeathPlayer(User user) {
return this.deaths.contains(user);
}

public List<User> getWinners() {
return winners;
}

public void addSpectator(final User user) {
public void addSpectator(User user) {
this.spectators.add(user);

final var nightVision = user.getStat(StatsStorage.StatisticType.SPECTATOR_NIGHT_VISION);
Expand All @@ -274,11 +275,11 @@ public void addSpectator(final User user) {
player.addPotionEffect(XPotion.SPEED.buildInvisible(Integer.MAX_VALUE, level));
}

public void removeSpectator(final User user) {
public void removeSpectator(User user) {
this.spectators.remove(user);
}

public boolean isSpectator(final User user) {
public boolean isSpectator(User user) {
return spectators.contains(user);
}

Expand Down Expand Up @@ -306,7 +307,7 @@ private void startBlockRemoving() {

@Override
public void run() {
for (final var user : getPlayersLeft()) {
for (var user : getPlayersLeft()) {
if (stopped) cancel();
if (arenaState != ArenaState.IN_GAME) return;
if (getTimer() <= startBlockRemoving) return;
Expand Down Expand Up @@ -371,7 +372,7 @@ private Block getBlockUnderPlayer(int y, Location location) {
}

public Set<User> getPlayersLeft() {
return this.getPlayers().stream().filter(user -> !user.isSpectator()).collect(Collectors.toSet());
return this.getPlayers().stream().filter(Predicate.not(User::isSpectator)).collect(Collectors.toSet());
}

public void playSound(XSound sound) {
Expand Down

0 comments on commit 10219b2

Please sign in to comment.