Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1958 #1959

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/carpet/commands/PlayerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ private static boolean cantSpawn(CommandContext<CommandSourceStack> context)
MinecraftServer server = context.getSource().getServer();
PlayerList manager = server.getPlayerList();

if (EntityPlayerMPFake.isSpawningPlayer(playerName))
{
Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is currently logging on");
return true;
}
if (manager.getPlayerByName(playerName) != null)
{
Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r is already logged on");
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/carpet/patches/EntityPlayerMPFake.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@
import carpet.fakes.ServerPlayerInterface;
import carpet.utils.Messenger;

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;

@SuppressWarnings("EntityConstructor")
public class EntityPlayerMPFake extends ServerPlayer
{
private static final Set<String> spawning = new HashSet<>();

public Runnable fixStartingPosition = () -> {};
public boolean isAShadow;

Expand All @@ -68,7 +72,21 @@ public static boolean createFake(String username, MinecraftServer server, Vec3 p
}
}
GameProfile finalGP = gameprofile;
fetchGameProfile(gameprofile.getName()).thenAcceptAsync(p -> {

// We need to mark this player as spawning so that we do not
// try to spawn another player with the name while the profile
// is being fetched - preventing multiple players spawning
String name = gameprofile.getName();
spawning.add(name);

fetchGameProfile(name).whenCompleteAsync((p, t) -> {
// Always remove the name, even if exception occurs
spawning.remove(name);
if (t != null)
{
return;
}

GameProfile current = finalGP;
if (p.isPresent())
{
Expand Down Expand Up @@ -126,6 +144,11 @@ public static EntityPlayerMPFake respawnFake(MinecraftServer server, ServerLevel
return new EntityPlayerMPFake(server, level, profile, cli, false);
}

public static boolean isSpawningPlayer(String username)
{
return spawning.contains(username);
}

private EntityPlayerMPFake(MinecraftServer server, ServerLevel worldIn, GameProfile profile, ClientInformation cli, boolean shadow)
{
super(server, worldIn, profile, cli);
Expand Down
Loading