21
21
import cn .nukkit .math .BlockFace ;
22
22
import cn .nukkit .math .SimpleAxisAlignedBB ;
23
23
import cn .nukkit .nbt .tag .CompoundTag ;
24
+ import cn .nukkit .potion .Effect ;
24
25
import cn .nukkit .utils .BlockColor ;
25
26
import cn .nukkit .utils .DyeColor ;
26
27
import cn .nukkit .utils .Faceable ;
@@ -173,33 +174,35 @@ public boolean onActivate(@Nonnull Item item, Player player) {
173
174
explosion .explodeB ();
174
175
return true ;
175
176
}
176
-
177
- if (player != null ) {
178
- AxisAlignedBB accessArea = new SimpleAxisAlignedBB (head .x - 2 , head .y - 5.5 , head .z - 2 , head .x + 3 , head .y + 2.5 , head .z + 3 )
179
- .addCoord (footPart .getXOffset (), 0 , footPart .getZOffset ());
180
-
181
- if (!accessArea .isVectorInside (player )) {
182
- player .sendMessage (new TranslationContainer (TextFormat .GRAY + "%tile.bed.tooFar" ));
183
- return true ;
184
- }
185
-
186
- Location spawn = Location .fromObject (head .add (0.5 , 0.5 , 0.5 ), player .getLevel (), player .getYaw (), player .getPitch ());
187
- if (!player .getSpawn ().equals (spawn )) {
188
- player .setSpawn (spawn );
189
- }
190
- player .sendMessage (new TranslationContainer (TextFormat .GRAY + "%tile.bed.respawnSet" ));
177
+
178
+ if (player == null || !player .hasEffect (Effect .CONDUIT_POWER ) && getLevelBlockAtLayer (1 ) instanceof BlockWater ) {
179
+ return true ;
180
+ }
181
+
182
+ AxisAlignedBB accessArea = new SimpleAxisAlignedBB (head .x - 2 , head .y - 5.5 , head .z - 2 , head .x + 3 , head .y + 2.5 , head .z + 3 )
183
+ .addCoord (footPart .getXOffset (), 0 , footPart .getZOffset ());
184
+
185
+ if (!accessArea .isVectorInside (player )) {
186
+ player .sendMessage (new TranslationContainer (TextFormat .GRAY + "%tile.bed.tooFar" ));
187
+ return true ;
188
+ }
189
+
190
+ Location spawn = Location .fromObject (head .add (0.5 , 0.5 , 0.5 ), player .getLevel (), player .getYaw (), player .getPitch ());
191
+ if (!player .getSpawn ().equals (spawn )) {
192
+ player .setSpawn (spawn );
191
193
}
194
+ player .sendMessage (new TranslationContainer (TextFormat .GRAY + "%tile.bed.respawnSet" ));
192
195
193
196
int time = this .getLevel ().getTime () % Level .TIME_FULL ;
194
197
195
198
boolean isNight = (time >= Level .TIME_NIGHT && time < Level .TIME_SUNRISE );
196
199
197
- if (player != null && !isNight ) {
200
+ if (!isNight ) {
198
201
player .sendMessage (new TranslationContainer (TextFormat .GRAY + "%tile.bed.noSleep" ));
199
202
return true ;
200
203
}
201
204
202
- if (player != null && !player .isCreative ()) {
205
+ if (!player .isCreative ()) {
203
206
AxisAlignedBB checkMonsterArea = new SimpleAxisAlignedBB (head .x - 8 , head .y - 6.5 , head .z - 8 , head .x + 9 , head .y + 5.5 , head .z + 9 )
204
207
.addCoord (footPart .getXOffset (), 0 , footPart .getZOffset ());
205
208
@@ -212,11 +215,10 @@ public boolean onActivate(@Nonnull Item item, Player player) {
212
215
}
213
216
}
214
217
215
- if (player != null && !player .sleepOn (head )) {
218
+ if (!player .sleepOn (head )) {
216
219
player .sendMessage (new TranslationContainer (TextFormat .GRAY + "%tile.bed.occupied" ));
217
220
}
218
221
219
-
220
222
return true ;
221
223
}
222
224
0 commit comments