From e1bd03cbefaf15c80e14d7940ac494f6a701941d Mon Sep 17 00:00:00 2001 From: altrisi Date: Sat, 4 Nov 2023 14:47:03 +0100 Subject: [PATCH] Simplify handling of spawning not online fake players --- src/main/java/carpet/commands/PlayerCommand.java | 8 +++++--- src/main/java/carpet/patches/EntityPlayerMPFake.java | 7 ++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/carpet/commands/PlayerCommand.java b/src/main/java/carpet/commands/PlayerCommand.java index 6bbde955..ca62991d 100644 --- a/src/main/java/carpet/commands/PlayerCommand.java +++ b/src/main/java/carpet/commands/PlayerCommand.java @@ -293,10 +293,12 @@ public class PlayerCommand Messenger.m(source, "rb Player " + playerName + " cannot be placed outside of the world"); return 0; } - EntityPlayerMPFake.createFake(playerName, source.getServer(), pos, facing.y, facing.x, dimType, mode, flying, () -> { + boolean success = EntityPlayerMPFake.createFake(playerName, source.getServer(), pos, facing.y, facing.x, dimType, mode, flying); + if (!success) { Messenger.m(source, "rb Player " + playerName + " doesn't exist and cannot spawn in online mode. " + - "Turn the server offline to spawn non-existing players"); - }); + "Turn the server offline or the allowSpawningOfflinePlayers on to spawn non-existing players"); + return 0; + }; return 1; } diff --git a/src/main/java/carpet/patches/EntityPlayerMPFake.java b/src/main/java/carpet/patches/EntityPlayerMPFake.java index 62cffb72..abe09dd9 100644 --- a/src/main/java/carpet/patches/EntityPlayerMPFake.java +++ b/src/main/java/carpet/patches/EntityPlayerMPFake.java @@ -42,7 +42,8 @@ public class EntityPlayerMPFake extends ServerPlayer public Runnable fixStartingPosition = () -> {}; public boolean isAShadow; - public static void createFake(String username, MinecraftServer server, Vec3 pos, double yaw, double pitch, ResourceKey dimensionId, GameType gamemode, boolean flying, Runnable onError) + // Returns true if it was successful, false if couldn't spawn due to the player not existing in Mojang servers + public static boolean createFake(String username, MinecraftServer server, Vec3 pos, double yaw, double pitch, ResourceKey dimensionId, GameType gamemode, boolean flying) { //prolly half of that crap is not necessary, but it works ServerLevel worldIn = server.getLevel(dimensionId); @@ -58,8 +59,7 @@ public class EntityPlayerMPFake extends ServerPlayer { if (!CarpetSettings.allowSpawningOfflinePlayers) { - onError.run(); - return; + return false; } else { gameprofile = new GameProfile(UUIDUtil.createOfflinePlayerUUID(username), username); } @@ -85,6 +85,7 @@ public class EntityPlayerMPFake extends ServerPlayer instance.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes) instance.getAbilities().flying = flying; }); + return true; } private static CompletableFuture> fetchGameProfile(final String name) {