Skip to content

Commit

Permalink
Fixed Spectator mode
Browse files Browse the repository at this point in the history
  • Loading branch information
BogdanValentin committed Apr 18, 2024
1 parent 135f93e commit 168de7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/bogdanvalentin/sleepanywhere/Sleep.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Sleep {
static void scheduleSleep(ServerWorld world) {
ServerTickEvents.END_SERVER_TICK.register(server -> {
List<ServerPlayerEntity> playerList = world.getPlayers();
playerList.removeIf(ServerPlayerEntity::isSpectator);
if(!playerList.isEmpty()) {
boolean allPlayersSleeping = true;
for (ServerPlayerEntity it : playerList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
public class SleepC2SPacket {
public static void receive(MinecraftServer server, ServerPlayerEntity player, ServerPlayNetworkHandler handler,
PacketByteBuf buf, PacketSender responseSender) {
if (player.isSpectator()) {
player.sendMessage(Text.translatable("You can not sleep while in Spectator Mode"), true);
return;
}

// only allow to sleep if in overworld
if (player.getWorld().getRegistryKey() != World.OVERWORLD) {
player.sendMessage(Text.translatable("You can only sleep in the Overworld"), true);
Expand Down

0 comments on commit 168de7e

Please sign in to comment.