Skip to content

Commit

Permalink
Narrow SCREEN_JOINS event to receive only GameProfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Gegy committed Jul 15, 2024
1 parent 07f5845 commit c13e2a4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nucleoid.plasmid.game.common;

import com.mojang.authlib.GameProfile;
import net.minecraft.entity.boss.BossBar;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -169,7 +170,7 @@ private GameResult requestStart() {
}
}

private GameResult screenJoins(Collection<ServerPlayerEntity> players) {
private GameResult screenJoins(Collection<GameProfile> players) {
int newPlayerCount = this.gameSpace.getPlayers().size() + players.size();
if (newPlayerCount > this.playerConfig.maxPlayers()) {
return GameResult.error(GameTexts.Join.gameFull());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package xyz.nucleoid.plasmid.game.event;

import com.mojang.authlib.GameProfile;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -174,7 +175,7 @@ public interface Remove {
}

public interface ScreenJoins {
GameResult screenJoins(Collection<ServerPlayerEntity> players);
GameResult screenJoins(Collection<GameProfile> players);
}

public interface Offer {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package xyz.nucleoid.plasmid.game.manager;

import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -195,7 +197,7 @@ public GameBehavior getBehavior() {
}

GameResult screenJoins(Collection<ServerPlayerEntity> players) {
var result = this.attemptScreenJoins(players);
var result = this.attemptScreenJoins(players.stream().map(PlayerEntity::getGameProfile).toList());

if (result.isError()) {
this.players.attemptGarbageCollection();
Expand All @@ -204,7 +206,7 @@ GameResult screenJoins(Collection<ServerPlayerEntity> players) {
return result;
}

private GameResult attemptScreenJoins(Collection<ServerPlayerEntity> players) {
private GameResult attemptScreenJoins(Collection<GameProfile> players) {
if (this.closed) {
return GameResult.error(GameTexts.Join.gameClosed());
}
Expand Down

0 comments on commit c13e2a4

Please sign in to comment.