Skip to content

Commit

Permalink
Update logic for getting players' position
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgeiss0702 committed Jun 1, 2024
1 parent 656f583 commit 27089fe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
10 changes: 9 additions & 1 deletion api/src/main/java/us/ajg0702/queue/api/players/QueuePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public interface QueuePlayer {
* Gets the player's position in the queue
* @return The player's position. 1 being 1st, 2 being 2nd, etc
*/
int getPosition();
default int getPosition() {
return getQueueServer().getPosition(this);
}

/**
* Get the player this represents.
Expand Down Expand Up @@ -81,4 +83,10 @@ public interface QueuePlayer {
* Attempts a connection to the provided AdaptedServer, calling PreConnectEvent before AdaptedPlayer.connect(...)
*/
void connect(@NotNull AdaptedServer server);

/**
* Returns the estimated time until a player is connected
* @return The number of seconds (estimated) until the player is connected to the server. -1 means that no estimate is available currently
*/
int getEstimatedTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public QueuePlayer findPlayer(AdaptedPlayer player) {
*/
public abstract int getQueueSize();

public abstract int getPosition(QueuePlayer player);

/**
* Get all players that are in the queue
* @return a list of players in the queue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ default boolean isOnline() {
*/
QueueHolder getQueueHolder();

default int getPosition(QueuePlayer player) {
return getQueueHolder().getPosition(player);
}


/**
* elliot is bad
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public int getQueueSize() {
return queue.size();
}

@Override
public int getPosition(QueuePlayer player) {
return queue.indexOf(player) + 1;
}

@Override
public List<QueuePlayer> getAllPlayers() {
return ImmutableList.copyOf(queue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public QueueServer getQueueServer() {
return server;
}

@Override
public int getPosition() {
return getQueueServer().getQueue().indexOf(this)+1;
}

@Nullable
@Override
public AdaptedPlayer getPlayer() {
Expand Down

0 comments on commit 27089fe

Please sign in to comment.