Simplify handling of spawning not online fake players
This commit is contained in:
2 files changed
+9
-6
No files matched your search
@@ -293,10 +293,12 @@ public class PlayerCommand
|
|||||||
Messenger.m(source, "rb Player " + playerName + " cannot be placed outside of the world");
|
Messenger.m(source, "rb Player " + playerName + " cannot be placed outside of the world");
|
||||||
return 0;
|
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. " +
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,8 @@ public class EntityPlayerMPFake extends ServerPlayer
|
|||||||
public Runnable fixStartingPosition = () -> {};
|
public Runnable fixStartingPosition = () -> {};
|
||||||
public boolean isAShadow;
|
public boolean isAShadow;
|
||||||
|
|
||||||
public static void createFake(String username, MinecraftServer server, Vec3 pos, double yaw, double pitch, ResourceKey<Level> 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<Level> dimensionId, GameType gamemode, boolean flying)
|
||||||
{
|
{
|
||||||
//prolly half of that crap is not necessary, but it works
|
//prolly half of that crap is not necessary, but it works
|
||||||
ServerLevel worldIn = server.getLevel(dimensionId);
|
ServerLevel worldIn = server.getLevel(dimensionId);
|
||||||
@@ -58,8 +59,7 @@ public class EntityPlayerMPFake extends ServerPlayer
|
|||||||
{
|
{
|
||||||
if (!CarpetSettings.allowSpawningOfflinePlayers)
|
if (!CarpetSettings.allowSpawningOfflinePlayers)
|
||||||
{
|
{
|
||||||
onError.run();
|
return false;
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
gameprofile = new GameProfile(UUIDUtil.createOfflinePlayerUUID(username), username);
|
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.entityData.set(DATA_PLAYER_MODE_CUSTOMISATION, (byte) 0x7f); // show all model layers (incl. capes)
|
||||||
instance.getAbilities().flying = flying;
|
instance.getAbilities().flying = flying;
|
||||||
});
|
});
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CompletableFuture<Optional<GameProfile>> fetchGameProfile(final String name) {
|
private static CompletableFuture<Optional<GameProfile>> fetchGameProfile(final String name) {
|
||||||
|
|||||||
Reference in new issue
Block a user