Passed
Push — dev ( c4f015...eeaa0f )
by Janko
27:51
created

User::hasAward()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\Index;
14
use Doctrine\ORM\Mapping\JoinColumn;
15
use Doctrine\ORM\Mapping\ManyToOne;
16
use Doctrine\ORM\Mapping\OneToMany;
17
use Doctrine\ORM\Mapping\OneToOne;
18
use Doctrine\ORM\Mapping\OrderBy;
19
use Doctrine\ORM\Mapping\Table;
20
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Stu\Component\Game\GameEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Game\GameEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Stu\Component\Game\ModuleViewEnum;
23
use Stu\Component\Map\MapEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Map\MapEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Stu\Component\Player\UserAwardEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Player\UserAwardEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Stu\Component\Player\UserCssClassEnum;
26
use Stu\Component\Player\UserRpgBehaviorEnum;
27
use Stu\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use Stu\Module\PlayerSetting\Lib\UserSettingEnum;
29
use Stu\Orm\Repository\UserRepository;
30
31
#[Table(name: 'stu_user')]
32
#[Index(name: 'user_alliance_idx', columns: ['allys_id'])]
33
#[Entity(repositoryClass: UserRepository::class)]
34
class User implements UserInterface
35
{
36
    #[Id]
37
    #[Column(type: 'integer')]
38
    #[GeneratedValue(strategy: 'IDENTITY')]
39
    private int $id;
40
41
    #[Column(type: 'string')]
42
    private string $username = '';
43
44
    #[Column(type: 'string', length: 20)]
45
    private string $login = '';
46
47
    #[Column(type: 'string', length: 255)]
48
    private string $pass = '';
49
50
    #[Column(type: 'string', length: 6, nullable: true)]
51
    private ?string $sms_code = null;
52
53
    #[Column(type: 'string', length: 200)]
54
    private string $email = '';
55
56
    #[Column(type: 'string', length: 255, nullable: true)]
57
    private ?string $mobile = null;
58
59
    #[Column(type: 'integer', nullable: true)]
60
    private ?int $allys_id = null;
61
62
    #[Column(type: 'integer')]
63
    private int $race = 9;
64
65
    #[Column(type: 'smallint')]
66
    private int $state = UserEnum::USER_STATE_NEW;
67
68
    #[Column(type: 'integer')]
69
    private int $lastaction = 0;
70
71
    #[Column(type: 'integer')]
72
    private int $creation = 0;
73
74
    #[Column(type: 'integer')]
75
    private int $kn_lez = 0;
76
77
    #[Column(type: 'smallint')]
78
    private int $delmark = 0;
79
80
    #[Column(type: 'boolean')]
81
    private bool $vac_active = false;
82
83
    #[Column(type: 'integer')]
84
    private int $vac_request_date = 0;
85
86
    #[Column(type: 'text')]
87
    private string $description = '';
88
89
    #[Column(type: 'smallint')]
90
    private int $tick = 1;
91
92
    #[Column(type: 'smallint', nullable: true)]
93
    private ?int $maptype = MapEnum::MAPTYPE_INSERT;
0 ignored issues
show
introduced by
The private property $maptype is not used, and could be removed.
Loading history...
94
95
    #[Column(type: 'text')]
96
    private string $sessiondata = '';
97
98
    #[Column(type: 'string', length: 255)]
99
    private string $password_token = '';
100
101
    #[Column(type: 'integer')]
102
    private int $prestige = 0;
103
104
    #[Column(type: 'boolean', options: ['default' => false])]
105
    private bool $deals = false;
106
107
    #[Column(type: 'integer', nullable: true)]
108
    private ?int $last_boarding = null;
109
110
    #[ManyToOne(targetEntity: 'Alliance', inversedBy: 'members')]
111
    #[JoinColumn(name: 'allys_id', referencedColumnName: 'id')]
112
    private ?AllianceInterface $alliance = null;
113
114
    #[ManyToOne(targetEntity: 'Faction')]
115
    #[JoinColumn(name: 'race', referencedColumnName: 'id')]
116
    private FactionInterface $faction;
117
118
    /**
119
     * @var ArrayCollection<int, BuoyInterface>
120
     */
121
    #[OneToMany(targetEntity: 'Buoy', mappedBy: 'user')]
122
    private Collection $buoys;
123
124
    /**
125
     * @var ArrayCollection<int, UserAwardInterface>
126
     */
127
    #[OneToMany(targetEntity: 'UserAward', mappedBy: 'user', indexBy: 'award_id')]
128
    #[OrderBy(['award_id' => 'ASC'])]
129
    private Collection $awards;
130
131
    /**
132
     * @var ArrayCollection<int, ColonyInterface>
133
     */
134
    #[OneToMany(targetEntity: 'Colony', mappedBy: 'user', indexBy: 'id')]
135
    #[OrderBy(['colonies_classes_id' => 'ASC', 'id' => 'ASC'])]
136
    private Collection $colonies;
137
138
    /**
139
     * @var ArrayCollection<int, UserLayerInterface>
140
     */
141
    #[OneToMany(targetEntity: 'UserLayer', mappedBy: 'user', indexBy: 'layer_id')]
142
    private Collection $userLayers;
143
144
    #[OneToOne(targetEntity: 'UserLock', mappedBy: 'user')]
145
    private ?UserLockInterface $userLock = null;
146
147
    /**
148
     * @var ArrayCollection<string, UserSettingInterface>
149
     */
150
    #[OneToMany(targetEntity: 'UserSetting', mappedBy: 'user', indexBy: 'setting')]
151
    private Collection $settings;
152
153
    /**
154
     * @var ArrayCollection<int, UserCharactersInterface>
155
     */
156
    #[OneToMany(targetEntity: 'UserCharacters', mappedBy: 'user', cascade: ['persist'])]
157
    private Collection $characters;
158
159
    /**
160
     * @var ArrayCollection<int, ColonyScanInterface>
161
     */
162
    #[OneToMany(targetEntity: 'ColonyScan', mappedBy: 'user', indexBy: 'id', fetch: 'EXTRA_LAZY')]
163
    #[OrderBy(['colony_id' => 'ASC', 'date' => 'ASC'])]
164
    private Collection $colonyScans;
165
166
    #[OneToOne(targetEntity: 'PirateWrath', mappedBy: 'user')]
167
    private ?PirateWrathInterface $pirateWrath = null;
168
169
    /** @var null|array<mixed> */
170
    private $sessiondataUnserialized;
171
172
    public function __construct()
173
    {
174
        $this->awards = new ArrayCollection();
175
        $this->colonies = new ArrayCollection();
176
        $this->userLayers = new ArrayCollection();
177
        $this->settings = new ArrayCollection();
178
        $this->characters = new ArrayCollection();
179
        $this->buoys = new ArrayCollection();
180
        $this->colonyScans = new ArrayCollection();
181
    }
182
183
    #[Override]
184
    public function getId(): int
185
    {
186
        return $this->id;
187
    }
188
189
    #[Override]
190
    public function getName(): string
191
    {
192
        //if UMODE active, add info to user name
193
        if ($this->isVacationRequestOldEnough()) {
194
            return $this->username . '[b][color=red] (UMODE)[/color][/b]';
195
        }
196
        return $this->username;
197
    }
198
199
    #[Override]
200
    public function setUsername(string $username): UserInterface
201
    {
202
        $this->username = $username;
203
        return $this;
204
    }
205
206
    #[Override]
207
    public function getLogin(): string
208
    {
209
        return $this->login;
210
    }
211
212
    #[Override]
213
    public function setLogin(string $login): UserInterface
214
    {
215
        $this->login = $login;
216
        return $this;
217
    }
218
219
    #[Override]
220
    public function getPassword(): string
221
    {
222
        return $this->pass;
223
    }
224
225
    #[Override]
226
    public function setPassword(string $password): UserInterface
227
    {
228
        $this->pass = $password;
229
        return $this;
230
    }
231
232
    #[Override]
233
    public function getSmsCode(): ?string
234
    {
235
        return $this->sms_code;
236
    }
237
238
    #[Override]
239
    public function setSmsCode(?string $code): UserInterface
240
    {
241
        $this->sms_code = $code;
242
        return $this;
243
    }
244
245
    #[Override]
246
    public function getEmail(): string
247
    {
248
        return $this->email;
249
    }
250
251
    #[Override]
252
    public function setEmail(string $email): UserInterface
253
    {
254
        $this->email = $email;
255
        return $this;
256
    }
257
258
    #[Override]
259
    public function getMobile(): ?string
260
    {
261
        return $this->mobile;
262
    }
263
264
    #[Override]
265
    public function setMobile(?string $mobile): UserInterface
266
    {
267
        $this->mobile = $mobile;
268
        return $this;
269
    }
270
271
    #[Override]
272
    public function getRgbCode(): string
273
    {
274
        $setting = $this->getSettings()->get(UserSettingEnum::RGB_CODE->value);
275
        if ($setting !== null) {
276
            return $setting->getValue();
277
        }
278
279
        return '';
280
    }
281
282
    #[Override]
283
    public function getCss(): string
284
    {
285
        $setting = $this->getSettings()->get(UserSettingEnum::CSS_COLOR_SHEET->value);
286
        if ($setting !== null) {
287
            return $setting->getValue();
288
        }
289
290
        return UserCssClassEnum::BLACK->value;
291
    }
292
293
    #[Override]
294
    public function getFactionId(): int
295
    {
296
        return $this->race;
297
    }
298
299
    #[Override]
300
    public function setFaction(FactionInterface $faction): UserInterface
301
    {
302
        $this->faction = $faction;
303
        return $this;
304
    }
305
306
    #[Override]
307
    public function getFaction(): FactionInterface
308
    {
309
        return $this->faction;
310
    }
311
312
    #[Override]
313
    public function getAwards(): Collection
314
    {
315
        return $this->awards;
316
    }
317
318
    #[Override]
319
    public function getColonies(): Collection
320
    {
321
        return $this->colonies;
322
    }
323
324
    #[Override]
325
    public function hasColony(): bool
326
    {
327
        if (
328
            $this->getState() === UserEnum::USER_STATE_COLONIZATION_SHIP
329
            || $this->getState() === UserEnum::USER_STATE_UNCOLONIZED
330
        ) {
331
            return false;
332
        }
333
334
        return !$this->getColonies()->isEmpty();
335
    }
336
337
    #[Override]
338
    public function getState(): int
339
    {
340
        return $this->state;
341
    }
342
343
    #[Override]
344
    public function isLocked(): bool
345
    {
346
        return $this->getUserLock() !== null && $this->getUserLock()->getRemainingTicks() > 0;
347
    }
348
349
    #[Override]
350
    public function getUserStateDescription(): string
351
    {
352
        if ($this->isLocked()) {
353
            return _('GESPERRT');
354
        }
355
        return UserEnum::getUserStateDescription($this->getState());
356
    }
357
358
    #[Override]
359
    public function setState(int $state): UserInterface
360
    {
361
        $this->state = $state;
362
        return $this;
363
    }
364
365
    #[Override]
366
    public function getAvatar(): string
367
    {
368
        $setting = $this->getSettings()->get(UserSettingEnum::AVATAR->value);
369
        if ($setting !== null) {
370
            return $setting->getValue();
371
        }
372
373
        return '';
374
    }
375
376
    #[Override]
377
    public function isEmailNotification(): bool
378
    {
379
        $setting = $this->getSettings()->get(UserSettingEnum::EMAIL_NOTIFICATION->value);
380
        if ($setting !== null) {
381
            return (bool)$setting->getValue();
382
        }
383
384
        return false;
385
    }
386
387
    #[Override]
388
    public function getLastaction(): int
389
    {
390
        return $this->lastaction;
391
    }
392
393
    #[Override]
394
    public function setLastaction(int $lastaction): UserInterface
395
    {
396
        $this->lastaction = $lastaction;
397
        return $this;
398
    }
399
400
    #[Override]
401
    public function getCreationDate(): int
402
    {
403
        return $this->creation;
404
    }
405
406
    #[Override]
407
    public function setCreationDate(int $creationDate): UserInterface
408
    {
409
        $this->creation = $creationDate;
410
        return $this;
411
    }
412
413
    #[Override]
414
    public function getKnMark(): int
415
    {
416
        return $this->kn_lez;
417
    }
418
419
    #[Override]
420
    public function setKnMark(int $knMark): UserInterface
421
    {
422
        $this->kn_lez = $knMark;
423
        return $this;
424
    }
425
426
    #[Override]
427
    public function getDeletionMark(): int
428
    {
429
        return $this->delmark;
430
    }
431
432
    #[Override]
433
    public function setDeletionMark(int $deletionMark): UserInterface
434
    {
435
        $this->delmark = $deletionMark;
436
        return $this;
437
    }
438
439
    #[Override]
440
    public function isVacationMode(): bool
441
    {
442
        return $this->vac_active;
443
    }
444
445
    #[Override]
446
    public function setVacationMode(bool $vacationMode): UserInterface
447
    {
448
        $this->vac_active = $vacationMode;
449
        return $this;
450
    }
451
452
    #[Override]
453
    public function getVacationRequestDate(): int
454
    {
455
        return $this->vac_request_date;
456
    }
457
458
    #[Override]
459
    public function setVacationRequestDate(int $date): UserInterface
460
    {
461
        $this->vac_request_date = $date;
462
463
        return $this;
464
    }
465
466
    #[Override]
467
    public function isVacationRequestOldEnough(): bool
468
    {
469
        return $this->isVacationMode() && (time() - $this->getVacationRequestDate() > UserEnum::VACATION_DELAY_IN_SECONDS);
470
    }
471
472
    #[Override]
473
    public function isStorageNotification(): bool
474
    {
475
        $setting = $this->getSettings()->get(UserSettingEnum::STORAGE_NOTIFICATION->value);
476
        if ($setting !== null) {
477
            return (bool)$setting->getValue();
478
        }
479
480
        return false;
481
    }
482
483
    #[Override]
484
    public function getDescription(): string
485
    {
486
        return $this->description;
487
    }
488
489
    #[Override]
490
    public function setDescription(string $description): UserInterface
491
    {
492
        $this->description = $description;
493
        return $this;
494
    }
495
496
    #[Override]
497
    public function isShowOnlineState(): bool
498
    {
499
        $setting = $this->getSettings()->get(UserSettingEnum::SHOW_ONLINE_STATUS->value);
500
        if ($setting !== null) {
501
            return (bool)$setting->getValue();
502
        }
503
504
        return false;
505
    }
506
507
    #[Override]
508
    public function isShowPmReadReceipt(): bool
509
    {
510
        $setting = $this->getSettings()->get(UserSettingEnum::SHOW_PM_READ_RECEIPT->value);
511
        if ($setting !== null) {
512
            return (bool)$setting->getValue();
513
        }
514
515
        return false;
516
    }
517
518
    #[Override]
519
    public function isSaveLogin(): bool
520
    {
521
        $setting = $this->getSettings()->get(UserSettingEnum::SAVE_LOGIN->value);
522
        if ($setting !== null) {
523
            return (bool)$setting->getValue();
524
        }
525
526
        return false;
527
    }
528
529
    #[Override]
530
    public function getFleetFixedDefault(): bool
531
    {
532
        $setting = $this->getSettings()->get(UserSettingEnum::FLEET_FIXED_DEFAULT->value);
533
        if ($setting !== null) {
534
            return (bool)$setting->getValue();
535
        }
536
537
        return false;
538
    }
539
540
    #[Override]
541
    public function getWarpsplitAutoCarryoverDefault(): bool
542
    {
543
        $setting = $this->getSettings()->get(UserSettingEnum::WARPSPLIT_AUTO_CARRYOVER_DEFAULT->value);
544
        if ($setting !== null) {
545
            return (bool)$setting->getValue();
546
        }
547
548
        return false;
549
    }
550
551
    #[Override]
552
    public function getTick(): int
553
    {
554
        return $this->tick;
555
    }
556
557
    #[Override]
558
    public function setTick(int $tick): UserInterface
559
    {
560
        $this->tick = $tick;
561
        return $this;
562
    }
563
564
    #[Override]
565
    public function getUserLayers(): Collection
566
    {
567
        return $this->userLayers;
568
    }
569
570
    #[Override]
571
    public function hasSeen(int $layerId): bool
572
    {
573
        return $this->getUserLayers()->containsKey($layerId);
574
    }
575
576
    #[Override]
577
    public function hasExplored(int $layerId): bool
578
    {
579
        return $this->hasSeen($layerId) && $this->getUserLayers()->get($layerId)->isExplored();
580
    }
581
582
    #[Override]
583
    public function getSettings(): Collection
584
    {
585
        return $this->settings;
586
    }
587
588
    #[Override]
589
    public function getSessiondata(): string
590
    {
591
        return $this->sessiondata;
592
    }
593
594
    #[Override]
595
    public function setSessiondata(string $sessiondata): UserInterface
596
    {
597
        $this->sessiondata = $sessiondata;
598
        $this->sessiondataUnserialized = null;
599
        return $this;
600
    }
601
602
    #[Override]
603
    public function getPasswordToken(): string
604
    {
605
        return $this->password_token;
606
    }
607
608
    #[Override]
609
    public function setPasswordToken(string $password_token): UserInterface
610
    {
611
        $this->password_token = $password_token;
612
        return $this;
613
    }
614
615
    #[Override]
616
    public function getPrestige(): int
617
    {
618
        return $this->prestige;
619
    }
620
621
    #[Override]
622
    public function setPrestige(int $prestige): UserInterface
623
    {
624
        $this->prestige = $prestige;
625
        return $this;
626
    }
627
628
    #[Override]
629
    public function getDefaultView(): ModuleViewEnum
630
    {
631
        $setting = $this->getSettings()->get(UserSettingEnum::DEFAULT_VIEW->value);
632
        if ($setting !== null) {
633
            return ModuleViewEnum::from($setting->getValue());
634
        }
635
636
        return ModuleViewEnum::MAINDESK;
637
    }
638
639
    #[Override]
640
    public function getRpgBehavior(): UserRpgBehaviorEnum
641
    {
642
        $setting = $this->getSettings()->get(UserSettingEnum::RPG_BEHAVIOR->value);
643
        if ($setting !== null) {
644
            return UserRpgBehaviorEnum::from((int)$setting->getValue());
645
        }
646
647
        return UserRpgBehaviorEnum::RPG_BEHAVIOR_NOT_SET;
648
    }
649
650
    #[Override]
651
    public function getDeals(): bool
652
    {
653
        return $this->deals;
654
    }
655
656
    #[Override]
657
    public function setDeals(bool $deals): UserInterface
658
    {
659
        $this->deals = $deals;
660
        return $this;
661
    }
662
663
    #[Override]
664
    public function getLastBoarding(): ?int
665
    {
666
        return $this->last_boarding;
667
    }
668
669
    #[Override]
670
    public function setLastBoarding(int $lastBoarding): UserInterface
671
    {
672
        $this->last_boarding = $lastBoarding;
673
        return $this;
674
    }
675
676
    #[Override]
677
    public function isOnline(): bool
678
    {
679
        return !($this->getLastAction() < time() - GameEnum::USER_ONLINE_PERIOD);
680
    }
681
682
    #[Override]
683
    public function getAlliance(): ?AllianceInterface
684
    {
685
        return $this->alliance;
686
    }
687
688
    #[Override]
689
    public function setAlliance(?AllianceInterface $alliance): UserInterface
690
    {
691
        $this->alliance = $alliance;
692
        return $this;
693
    }
694
695
    #[Override]
696
    public function setAllianceId(?int $allianceId): UserInterface
697
    {
698
        $this->allys_id = $allianceId;
699
        return $this;
700
    }
701
702
    #[Override]
703
    public function getSessionDataUnserialized(): array
704
    {
705
        if ($this->sessiondataUnserialized === null) {
706
            $this->sessiondataUnserialized = unserialize($this->getSessionData());
707
            if (!is_array($this->sessiondataUnserialized)) {
708
                $this->sessiondataUnserialized = [];
709
            }
710
        }
711
        return $this->sessiondataUnserialized;
712
    }
713
714
    #[Override]
715
    public function isContactable(): bool
716
    {
717
        return $this->getId() != UserEnum::USER_NOONE;
718
    }
719
720
    #[Override]
721
    public function hasAward(int $awardId): bool
722
    {
723
        return $this->awards->containsKey($awardId) === true;
724
    }
725
726
    #[Override]
727
    public function hasStationsNavigation(): bool
728
    {
729
        if ($this->isNpc()) {
730
            return true;
731
        }
732
733
        return $this->hasAward(UserAwardEnum::RESEARCHED_STATIONS);
734
    }
735
736 6
    public static function isUserNpc(int $userId): bool
737
    {
738 6
        return $userId < UserEnum::USER_FIRST_ID;
739
    }
740
741
    #[Override]
742
    public function isNpc(): bool
743
    {
744
        return self::isUserNpc($this->getId());
745
    }
746
747
    #[Override]
748
    public function getUserLock(): ?UserLockInterface
749
    {
750
        return $this->userLock;
751
    }
752
753
    #[Override]
754
    public function __toString(): string
755
    {
756
        return sprintf('userName: %s', $this->getName());
757
    }
758
759
    #[Override]
760
    public function hasTranslation(): bool
761
    {
762
        $text = $this->getDescription();
763
        return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false;
764
    }
765
766
    #[Override]
767
    public function isShowPirateHistoryEntrys(): bool
768
    {
769
        $setting = $this->getSettings()->get(UserSettingEnum::SHOW_PIRATE_HISTORY_ENTRYS->value);
770
        if ($setting !== null) {
771
            return (bool)$setting->getValue();
772
        }
773
774
        return false;
775
    }
776
777
    #[Override]
778
    public function getCharacters(): Collection
779
    {
780
        return $this->characters;
781
    }
782
783
    #[Override]
784
    public function getColonyScans(): Collection
785
    {
786
        return $this->colonyScans;
787
    }
788
789
    /**
790
     * @return Collection<int, BuoyInterface>
791
     */
792
    public function getBuoys(): Collection
793
    {
794
        return $this->buoys;
795
    }
796
797
    #[Override]
798
    public function getPirateWrath(): ?PirateWrathInterface
799
    {
800
        return $this->pirateWrath;
801
    }
802
803
    #[Override]
804
    public function setPirateWrath(PirateWrathInterface $wrath): UserInterface
805
    {
806
        $this->pirateWrath = $wrath;
807
808
        return $this;
809
    }
810
811
    #[Override]
812
    public function isProtectedAgainstPirates(): bool
813
    {
814
        $pirateWrath = $this->pirateWrath;
815
        if ($pirateWrath === null) {
816
            return false;
817
        }
818
819
        $timeout = $pirateWrath->getProtectionTimeout();
820
        if ($timeout === null) {
821
            return false;
822
        }
823
824
        return $timeout > time();
825
    }
826
}
827