@@ -21,6 +21,14 @@ local function get_look_yaw(pos)
21
21
end
22
22
end
23
23
24
+ local function is_night_skip_enabled ()
25
+ local enable_night_skip = minetest .setting_getbool (" enable_bed_night_skip" )
26
+ if enable_night_skip == nil then
27
+ enable_night_skip = true
28
+ end
29
+ return enable_night_skip
30
+ end
31
+
24
32
local function check_in_beds (players )
25
33
local in_bed = beds .player
26
34
if not players then
@@ -56,7 +64,7 @@ local function lay_down(player, pos, bed_pos, state, skip)
56
64
if skip then
57
65
return
58
66
end
59
- if p then
67
+ if p then
60
68
player :setpos (p )
61
69
end
62
70
@@ -100,8 +108,8 @@ local function update_formspecs(finished)
100
108
" label[2.7,11; Good morning.]"
101
109
else
102
110
form_n = beds .formspec ..
103
- " label[2.2,11;" .. tostring (player_in_bed ).. " of " .. tostring (ges ).. " players are in bed]"
104
- if is_majority then
111
+ " label[2.2,11;" .. tostring (player_in_bed ).. " of " .. tostring (ges ).. " players are in bed]"
112
+ if is_majority and is_night_skip_enabled () then
105
113
form_n = form_n ..
106
114
" button_exit[2,8;4,0.75;force;Force night skip]"
107
115
end
@@ -154,11 +162,13 @@ function beds.on_rightclick(pos, player)
154
162
-- skip the night and let all players stand up
155
163
if check_in_beds () then
156
164
minetest .after (2 , function ()
157
- beds .skip_night ()
158
165
if not is_sp then
159
- update_formspecs (true )
166
+ update_formspecs (is_night_skip_enabled ())
167
+ end
168
+ if is_night_skip_enabled () then
169
+ beds .skip_night ()
170
+ beds .kick_players ()
160
171
end
161
- beds .kick_players ()
162
172
end )
163
173
end
164
174
end
@@ -189,9 +199,11 @@ minetest.register_on_leaveplayer(function(player)
189
199
beds .player [name ] = nil
190
200
if check_in_beds () then
191
201
minetest .after (2 , function ()
192
- beds .skip_night ()
193
- update_formspecs (true )
194
- beds .kick_players ()
202
+ update_formspecs (is_night_skip_enabled ())
203
+ if is_night_skip_enabled () then
204
+ beds .skip_night ()
205
+ beds .kick_players ()
206
+ end
195
207
end )
196
208
end
197
209
end )
@@ -206,8 +218,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
206
218
end
207
219
208
220
if fields .force then
209
- beds .skip_night ()
210
- update_formspecs (true )
211
- beds .kick_players ()
221
+ update_formspecs (is_night_skip_enabled ())
222
+ if is_night_skip_enabled () then
223
+ beds .skip_night ()
224
+ beds .kick_players ()
225
+ end
212
226
end
213
227
end )
0 commit comments