Skip to content

Commit 20cffbb

Browse files
committed
AFK feature and bugfixes
Bugfixes: - Days will no longer be resetted - Notification works perfect now AFK feature - Compatible with my AFK Announcer datapack, so you can change if players who are afk have to sleep or not
1 parent bae3432 commit 20cffbb

10 files changed

Lines changed: 20 additions & 10 deletions

File tree

data/jodek/advancement/sleep.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"color": "dark_green"
3636
},
3737
{
38-
"text": "v.2.4.2",
38+
"text": "v.2.5.2",
3939
"color": "green"
4040
},
4141
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# get number of players online
2+
execute store result score &playerNum sleep.players_online run list
3+
4+
# get number of players who have afk tag
5+
execute store result score &playerNumAFK sleep.players_online if entity @a[tag=afkannouncer.afk]
6+
7+
scoreboard players operation &playerNum sleep.players_online -= &playerNumAFK sleep.players_online

data/sleep/function/load.mcfunction

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tellraw @a ["",{"text":"Sleep","color":"blue","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}},{"text":" loaded - ","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}},{"text":"[1.21]","color":"green","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}},{"text":" ","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}},{"text":"v.2.4.2","color":"dark_green","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}}]
1+
tellraw @a ["",{"text":"Sleep","color":"blue","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}},{"text":" loaded - ","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}},{"text":"[1.21]","color":"green","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}},{"text":" ","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}},{"text":"v.2.5.2","color":"dark_green","clickEvent":{"action":"open_url","value":"https://modrinth.com/datapack/sleep/"},"hoverEvent":{"action":"show_text","contents":"modrinth.com/datapack/sleep/"}}]
22

33
scoreboard objectives add sleep.time_since_rest custom:time_since_rest
44

@@ -39,6 +39,9 @@ execute as @a unless score &amount_to_sleep sleep.config = &amount_to_sleep slee
3939
# time skip or accelerated
4040
execute as @a unless score &time_control sleep.config = &time_control sleep.config run scoreboard players set &time_control sleep.config 0
4141

42+
# afk players are included in online players or not
43+
execute as @a unless score &afk_players_sleep sleep.config = &afk_players_sleep sleep.config run scoreboard players set &afk_players_sleep sleep.config 0
44+
4245
# setting to disable phantoms
4346
# execute as @a unless score &phantoms_spawning sleep.config = &phantoms_spawning sleep.config run scoreboard players set &phantoms_spawning sleep.config 0
4447
# This is WIP

data/sleep/function/main.mcfunction

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
execute as @a unless score @s sleep_notification = @s sleep_notification run scoreboard players set @s sleep_notification 0
33
scoreboard players enable @a sleep_notification
44

5-
execute as @a[scores={sleep_notification=1..}] at @s if score $global sleep.total_speeping matches 0 run function sleep:timeofday
5+
schedule function sleep:timeofday 1t
66

7+
execute if score &afk_players_sleep sleep.config matches 1 run function sleep:calc_online_players_afk
78

89
# How long does one player sleep
910
scoreboard players set @a[scores={sleep.time_since_rest=1..}] sleep.time_in_bed 0
@@ -26,7 +27,7 @@ execute if score &sleep_amount sleep.sleeping_players = &amount_to_sleep sleep.c
2627
execute if entity @a[tag=sleeping] run function sleep:actionbar/main_actionbar
2728

2829
# check how many players --> if only 1 then skip when 1 sleeps
29-
execute store result score &playerNum sleep.players_online run list
30+
execute if score &afk_players_sleep sleep.config matches 0 run execute store result score &playerNum sleep.players_online run list
3031
execute if score &playerNum sleep.players_online < &amount_to_sleep sleep.config if score &sleep_amount sleep.sleeping_players < &amount_to_sleep sleep.config run function sleep:time_control/time_control
3132
execute as @a[scores={sleep.time_in_bed=1..}] run execute if score &playerNum sleep.players_online < &amount_to_sleep sleep.config if score &sleep_amount sleep.sleeping_players < &amount_to_sleep sleep.config run function sleep:actionbar/main_actionbar
3233

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
execute if score &time_control sleep.config matches 0 run function sleep:time_control/time_skip
2-
execute if score &time_control sleep.config matches 0 run function sleep:time_control/time_skip
32

43
execute if score &time_control sleep.config matches 1 run function sleep:time_control/time_accelerate
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
execute as @a[scores={sleep.time_in_bed=200..}] run time set 0
1+
execute as @a[scores={sleep.time_in_bed=200}] run time add 11000
22

33
# weather clear
44
execute if predicate sleep:weather_check_thunder run execute as @a[scores={sleep.time_in_bed=200..}] run weather clear
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
execute as @a[scores={sleep.time_in_bed=20..}] run time set 0
1+
execute as @a[scores={sleep.time_in_bed=20}] run time add 11000
22

33
# weather clear
44
execute if predicate sleep:weather_check_thunder run execute as @a[scores={sleep.time_in_bed=20..}] run weather clear
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
execute as @a[scores={sleep.time_in_bed=100..}] run time set 0
1+
execute as @a[scores={sleep.time_in_bed=100}] run time add 11000
22

33
# weather clear
44
execute if predicate sleep:weather_check_thunder run execute as @a[scores={sleep.time_in_bed=100..}] run weather clear

data/sleep/function/timeofday.mcfunction

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ execute as @a[scores={sleep_notification=1}] at @s if score Timeofday sleep.cloc
66
execute as @a[scores={sleep_notification=2}] at @s if score Timeofday sleep.clock matches 12542 run playsound minecraft:block.note_block.cow_bell voice
77

88

9-
execute as @a[scores={sleep_notification=3}] at @s if score Timeofday sleep.clock matches 12542 run tellraw @s {"text":"You can sleep now","color":"yellow", "hoverEvent":{"action":"show_text","value":[{"text":"by clicking on a bed"}]}}
9+
# execute as @a[scores={sleep_notification=3}] at @s if score Timeofday sleep.clock matches 12542 run tellraw @s {"text":"You can sleep now","color":"yellow", "hoverEvent":{"action":"show_text","value":[{"text":"by clicking on a bed"}]}}
1010

1111
execute as @a[scores={sleep_notification=3}] at @s if score Timeofday sleep.clock matches 12542 run playsound minecraft:block.note_block.cow_bell voice
1212

pack.mcmeta

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"pack": {
33
"pack_format": 48,
4-
"description": "Simple Multiplayer Sleep - [1.21] v.2.4.2"
4+
"description": "Simple Multiplayer Sleep - [1.21] v.2.5.2"
55
}
66
}

0 commit comments

Comments
 (0)