Skip to content

Commit

Permalink
chore: include PendingMatch in MatchmakingSession creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakShearman committed Aug 21, 2024
1 parent d045ab7 commit 8079333
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}

withSourcesJar()
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minestom.server.entity.Player;
import net.minestom.server.timer.TaskSchedule;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.time.Instant;
import java.util.concurrent.Executors;
Expand All @@ -33,7 +34,7 @@ public final class DefaultMatchmakingSessionImpl extends MatchmakingSession {
private final @NotNull ScheduledFuture<?> notificationTask;
private final @NotNull GameModeConfig gameMode;

public DefaultMatchmakingSessionImpl(@NotNull Player player, @NotNull GameModeConfig gameMode, @NotNull Ticket ticket) {
public DefaultMatchmakingSessionImpl(@NotNull Player player, @NotNull GameModeConfig gameMode, @NotNull Ticket ticket, @Nullable PendingMatch pendingMatch) {
super(player, ticket);

this.notificationTask = SCHEDULER.scheduleAtFixedRate(this::notifyPlayer, 30, 30, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.emortal.api.model.matchmaker.Ticket;
import net.minestom.server.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class MatchmakingSession {

Expand Down Expand Up @@ -54,6 +55,6 @@ public void setTicket(@NotNull Ticket ticket) {
@FunctionalInterface
public interface Creator {

@NotNull MatchmakingSession create(@NotNull Player player, @NotNull GameModeConfig gameMode, @NotNull Ticket ticket);
@NotNull MatchmakingSession create(@NotNull Player player, @NotNull GameModeConfig gameMode, @NotNull Ticket ticket, @Nullable PendingMatch pendingMatch);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minestom.server.event.EventNode;
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
import net.minestom.server.event.player.PlayerDisconnectEvent;
import net.minestom.server.event.player.PlayerSpawnEvent;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -54,7 +55,7 @@ public MatchmakingSessionManager(@NotNull EventNode<Event> eventNode, @NotNull M
this.sessionCreator = sessionCreator;
this.gameModes = gameModes;

eventNode.addListener(AsyncPlayerConfigurationEvent.class, this::handlePlayerLogin);
eventNode.addListener(PlayerSpawnEvent.class, this::handlePlayerLogin);

eventNode.addListener(PlayerDisconnectEvent.class, event -> {
UUID playerId = event.getPlayer().getUuid();
Expand Down Expand Up @@ -104,7 +105,7 @@ private void onTicketCreate(@NotNull Ticket ticket) {
if (player == null) continue;

GameModeConfig gameMode = this.gameModes.getConfig(ticket.getGameModeId());
MatchmakingSession session = this.sessionCreator.create(player, gameMode, ticket);
MatchmakingSession session = this.sessionCreator.create(player, gameMode, ticket, null);
this.sessions.put(uuid, session);
shouldCache = true;
}
Expand Down Expand Up @@ -146,7 +147,7 @@ private void onTicketUpdated(@NotNull Ticket newTicket) {
Player player = MinecraftServer.getConnectionManager().getOnlinePlayerByUuid(uuid);
if (player == null) continue;

session = this.sessionCreator.create(player, gameMode, newTicket);
session = this.sessionCreator.create(player, gameMode, newTicket, null);
this.sessions.put(uuid, session);
}

Expand Down Expand Up @@ -197,7 +198,7 @@ private void destroySession(@NotNull MatchmakingSession session) {
session.destroy();
}

private void handlePlayerLogin(@NotNull AsyncPlayerConfigurationEvent event) {
private void handlePlayerLogin(@NotNull PlayerSpawnEvent event) {
Player player = event.getPlayer();
UUID playerId = player.getUuid();

Expand All @@ -206,7 +207,7 @@ private void handlePlayerLogin(@NotNull AsyncPlayerConfigurationEvent event) {
queueInfo = this.matchmaker.getPlayerQueueInfo(playerId);
} catch (StatusRuntimeException exception) {
LOGGER.error("Failed to get queue info for '{}'", player.getUsername(), exception);
player.sendMessage(Component.text("An unknown error occurred", NamedTextColor.RED));
player.sendMessage(Component.text("An unknown error occurred retrieving queue info", NamedTextColor.RED));
return;
}

Expand All @@ -223,7 +224,7 @@ private void handlePlayerLogin(@NotNull AsyncPlayerConfigurationEvent event) {
return;
}

MatchmakingSession session = this.sessionCreator.create(player, mode, ticket);
MatchmakingSession session = this.sessionCreator.create(player, mode, ticket, queueInfo.getPendingMatch());
this.sessions.put(playerId, session);
this.ticketCache.put(ticket.getId(), ticket);

Expand Down

0 comments on commit 8079333

Please sign in to comment.