@@ -51,16 +51,16 @@ public function onLevelLoad(LevelLoadEvent $event) : void {
51
51
if (file_exists ($ this ->plugin ->getDataFolder ()."worlds " .DIRECTORY_SEPARATOR .$ event ->getLevel ()->getFolderName ().".yml " )) {
52
52
$ this ->plugin ->getLogger ()->debug ("MyPlot level " . $ event ->getLevel ()->getFolderName () . " loaded! " );
53
53
$ settings = $ event ->getLevel ()->getProvider ()->getGeneratorOptions ();
54
- if (!isset ($ settings ["preset " ]) or empty ($ settings ["preset " ])) {
54
+ if (!isset ($ settings ["preset " ]) or ! is_string ($ settings ["preset " ]) or $ settings [ " preset " ] === "" ) {
55
55
return ;
56
56
}
57
57
$ settings = json_decode ($ settings ["preset " ], true );
58
58
if ($ settings === false ) {
59
59
return ;
60
60
}
61
61
$ levelName = $ event ->getLevel ()->getFolderName ();
62
- $ default = array_filter ($ this ->plugin ->getConfig ()->get ("DefaultWorld " , []), function ($ key ){
63
- return !in_array ($ key , ["PlotSize " , "GroundHeight " , "RoadWidth " , "RoadBlock " , "WallBlock " , "PlotFloorBlock " , "PlotFillBlock " , "BottomBlock " ]);
62
+ $ default = array_filter (( array ) $ this ->plugin ->getConfig ()->get ("DefaultWorld " , []), function ($ key ) : bool {
63
+ return !in_array ($ key , ["PlotSize " , "GroundHeight " , "RoadWidth " , "RoadBlock " , "WallBlock " , "PlotFloorBlock " , "PlotFillBlock " , "BottomBlock " ], true );
64
64
}, ARRAY_FILTER_USE_KEY );
65
65
$ config = new Config ($ this ->plugin ->getDataFolder ()."worlds " .DIRECTORY_SEPARATOR .$ levelName .".yml " , Config::YAML , $ default );
66
66
foreach (array_keys ($ default ) as $ key ) {
@@ -134,7 +134,7 @@ public function onSignChange(SignChangeEvent $event) : void {
134
134
private function onEventOnBlock ($ event ) : void {
135
135
if (!$ event ->getBlock ()->isValid ())
136
136
return ;
137
- $ levelName = $ event ->getBlock ()->getLevel ()->getFolderName ();
137
+ $ levelName = $ event ->getBlock ()->getLevelNonNull ()->getFolderName ();
138
138
if (!$ this ->plugin ->isLevelLoaded ($ levelName )) {
139
139
return ;
140
140
}
@@ -198,7 +198,7 @@ public function onExplosion(EntityExplodeEvent $event) : void {
198
198
if ($ event ->isCancelled ()) {
199
199
return ;
200
200
}
201
- $ levelName = $ event ->getEntity ()->getLevel ()->getFolderName ();
201
+ $ levelName = $ event ->getEntity ()->getLevelNonNull ()->getFolderName ();
202
202
if (!$ this ->plugin ->isLevelLoaded ($ levelName ))
203
203
return ;
204
204
$ plot = $ this ->plugin ->getPlotByPosition ($ event ->getPosition ());
@@ -208,10 +208,11 @@ public function onExplosion(EntityExplodeEvent $event) : void {
208
208
}
209
209
$ beginPos = $ this ->plugin ->getPlotPosition ($ plot );
210
210
$ endPos = clone $ beginPos ;
211
- $ plotSize = $ this ->plugin ->getLevelSettings ($ levelName )->plotSize ;
211
+ $ levelSettings = $ this ->plugin ->getLevelSettings ($ levelName );
212
+ $ plotSize = $ levelSettings ->plotSize ;
212
213
$ endPos ->x += $ plotSize ;
213
214
$ endPos ->z += $ plotSize ;
214
- $ blocks = array_filter ($ event ->getBlockList (), function ($ block ) use ($ beginPos , $ endPos ) {
215
+ $ blocks = array_filter ($ event ->getBlockList (), function ($ block ) use ($ beginPos , $ endPos ) : bool {
215
216
if ($ block ->x >= $ beginPos ->x and $ block ->z >= $ beginPos ->z and $ block ->x < $ endPos ->x and $ block ->z < $ endPos ->z ) {
216
217
return true ;
217
218
}
@@ -253,7 +254,7 @@ public function onBlockSpread(BlockSpreadEvent $event) : void {
253
254
if ($ event ->isCancelled ()) {
254
255
return ;
255
256
}
256
- $ levelName = $ event ->getBlock ()->getLevel ()->getFolderName ();
257
+ $ levelName = $ event ->getBlock ()->getLevelNonNull ()->getFolderName ();
257
258
if (!$ this ->plugin ->isLevelLoaded ($ levelName ))
258
259
return ;
259
260
$ settings = $ this ->plugin ->getLevelSettings ($ levelName );
@@ -305,16 +306,17 @@ public function onPlayerTeleport(EntityTeleportEvent $event) : void {
305
306
}
306
307
307
308
/**
309
+ * @param Player $player
308
310
* @param PlayerMoveEvent|EntityTeleportEvent $event
309
311
*/
310
312
private function onEventOnMove (Player $ player , $ event ) : void {
311
- $ levelName = $ player ->getLevel ()->getFolderName ();
313
+ $ levelName = $ player ->getLevelNonNull ()->getFolderName ();
312
314
if (!$ this ->plugin ->isLevelLoaded ($ levelName ))
313
315
return ;
314
316
$ plot = $ this ->plugin ->getPlotByPosition ($ event ->getTo ());
315
317
$ plotFrom = $ this ->plugin ->getPlotByPosition ($ event ->getFrom ());
316
318
if ($ plot !== null and ($ plotFrom === null or !$ plot ->isSame ($ plotFrom ))) {
317
- if (strpos ((string ) $ plot , "-0 " )) {
319
+ if (strpos ((string ) $ plot , "-0 " ) !== false ) {
318
320
return ;
319
321
}
320
322
$ ev = new MyPlotPlayerEnterPlotEvent ($ plot , $ player );
@@ -328,11 +330,11 @@ private function onEventOnMove(Player $player, $event) : void {
328
330
if ($ event ->isCancelled ()) {
329
331
return ;
330
332
}
331
- if (!$ this ->plugin ->getConfig ()->get ("ShowPlotPopup " , true ))
333
+ if (!( bool ) $ this ->plugin ->getConfig ()->get ("ShowPlotPopup " , true ))
332
334
return ;
333
335
$ popup = $ this ->plugin ->getLanguage ()->translateString ("popup " , [TextFormat::GREEN . $ plot ]);
334
336
$ price = TextFormat::GREEN . $ plot ->price ;
335
- if (! empty ( $ plot ->owner ) ) {
337
+ if ($ plot ->owner !== "" ) {
336
338
$ owner = TextFormat::GREEN . $ plot ->owner ;
337
339
if ($ plot ->price > 0 and $ plot ->owner !== $ player ->getName ()) {
338
340
$ ownerPopup = $ this ->plugin ->getLanguage ()->translateString ("popup.forsale " , [$ owner .TextFormat::WHITE , $ price .TextFormat::WHITE ]);
@@ -348,15 +350,15 @@ private function onEventOnMove(Player $player, $event) : void {
348
350
$ popup = TextFormat::WHITE . $ paddingPopup . $ popup . "\n" . TextFormat::WHITE . $ paddingOwnerPopup . $ ownerPopup ;
349
351
$ ev ->getPlayer ()->sendTip ($ popup );
350
352
}elseif ($ plotFrom !== null and ($ plot === null or !$ plot ->isSame ($ plotFrom ))) {
351
- if (strpos ((string ) $ plotFrom , "-0 " )) {
353
+ if (strpos ((string ) $ plotFrom , "-0 " ) !== false ) {
352
354
return ;
353
355
}
354
356
$ ev = new MyPlotPlayerLeavePlotEvent ($ plotFrom , $ player );
355
357
$ ev ->setCancelled ($ event ->isCancelled ());
356
358
$ ev ->call ();
357
359
$ event ->setCancelled ($ ev ->isCancelled ());
358
360
}elseif ($ plotFrom !== null and $ plot !== null and ($ plot ->isDenied ($ player ->getName ()) or $ plot ->isDenied ("* " )) and $ plot ->owner !== $ player ->getName () and !$ player ->hasPermission ("myplot.admin.denyplayer.bypass " )) {
359
- $ this ->plugin ->teleportPlayerToPlot ($ player , $ plot, false );
361
+ $ this ->plugin ->teleportPlayerToPlot ($ player , $ plot );
360
362
}
361
363
}
362
364
@@ -370,7 +372,7 @@ public function onEntityDamage(EntityDamageByEntityEvent $event) : void {
370
372
$ damaged = $ event ->getEntity ();
371
373
$ damager = $ event ->getDamager ();
372
374
if ($ damaged instanceof Player and $ damager instanceof Player and !$ event ->isCancelled ()) {
373
- $ levelName = $ damaged ->getLevel ()->getFolderName ();
375
+ $ levelName = $ damaged ->getLevelNonNull ()->getFolderName ();
374
376
if (!$ this ->plugin ->isLevelLoaded ($ levelName )) {
375
377
return ;
376
378
}
0 commit comments