forked from Maxlego08/zEssentials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZUser.java
More file actions
1045 lines (845 loc) · 31.4 KB
/
ZUser.java
File metadata and controls
1045 lines (845 loc) · 31.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package fr.maxlego08.essentials.user;
import com.tcoded.folialib.impl.PlatformScheduler;
import fr.maxlego08.essentials.api.EssentialsPlugin;
import fr.maxlego08.essentials.api.commands.Permission;
import fr.maxlego08.essentials.api.discord.DiscordAccount;
import fr.maxlego08.essentials.api.dto.*;
import fr.maxlego08.essentials.api.economy.Economy;
import fr.maxlego08.essentials.api.event.events.user.UserEconomyPostUpdateEvent;
import fr.maxlego08.essentials.api.event.events.user.UserEconomyUpdateEvent;
import fr.maxlego08.essentials.api.home.Home;
import fr.maxlego08.essentials.api.kit.Kit;
import fr.maxlego08.essentials.api.mailbox.MailBoxItem;
import fr.maxlego08.essentials.api.messages.Message;
import fr.maxlego08.essentials.api.sanction.Sanction;
import fr.maxlego08.essentials.api.storage.IStorage;
import fr.maxlego08.essentials.api.user.Option;
import fr.maxlego08.essentials.api.user.PrivateMessage;
import fr.maxlego08.essentials.api.user.TeleportRequest;
import fr.maxlego08.essentials.api.user.User;
import fr.maxlego08.essentials.api.utils.DynamicCooldown;
import fr.maxlego08.essentials.api.utils.SafeLocation;
import fr.maxlego08.essentials.api.worldedit.Selection;
import fr.maxlego08.essentials.api.worldedit.WorldEditTask;
import fr.maxlego08.essentials.module.modules.TeleportationModule;
import fr.maxlego08.essentials.module.modules.economy.EconomyModule;
import fr.maxlego08.essentials.zutils.utils.ZUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
public class ZUser extends ZUtils implements User {
private final EssentialsPlugin plugin;
private final Map<UUID, TeleportRequest> teleports = new HashMap<>();
private final Map<String, Long> cooldowns = new HashMap<>();
private final UUID uniqueId;
private final Map<Option, Boolean> options = new HashMap<>();
private final Map<String, BigDecimal> balances = new HashMap<>();
private final List<Home> homes = new ArrayList<>();
private final List<MailBoxItem> mailBoxItems = new ArrayList<>();
private final DynamicCooldown dynamicCooldown = new DynamicCooldown();
private final Selection selection = new ZSelection();
private WorldEditTask worldEditTask;
private String name;
private TeleportRequest teleportRequest;
private User targetUser;
private BigDecimal targetAmount;
private Economy targetEconomy;
private SafeLocation lastLocation;
private boolean firstJoin;
private int banId;
private int muteId;
private Sanction muteSanction;
private Sanction banSanction;
private List<Sanction> fakeSanctions;
private String lastMessage;
private PrivateMessage privateMessage;
private long playTime;
private long currentSessionPlayTime;
private String address;
private Kit previewKit;
private Map<Material, String> powerTools = new HashMap<>();
private long vote;
private long offlineVote;
private Map<String, Long> lastVotes = new HashMap<>();
private Home currentDeleteHome;
private long flySeconds;
private DiscordAccount discordAccount;
private long lastActiveTime = System.currentTimeMillis();
private boolean manualAfk;
private long protectionDuration;
private boolean freeze;
public ZUser(EssentialsPlugin plugin, UUID uniqueId) {
this.plugin = plugin;
this.uniqueId = uniqueId;
}
public static User fakeUser(EssentialsPlugin plugin, UUID uniqueId, String userName) {
User user = new ZUser(plugin, uniqueId);
user.setName(userName);
return user;
}
private IStorage getStorage() {
return this.plugin.getStorageManager().getStorage();
}
@Override
public UUID getUniqueId() {
return this.uniqueId;
}
@Override
public String getName() {
return this.name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public Player getPlayer() {
return Bukkit.getPlayer(this.uniqueId);
}
@Override
public boolean isOnline() {
return Bukkit.getOfflinePlayer(this.uniqueId).isOnline();
}
@Override
public boolean isIgnore(UUID uniqueId) {
return false;
}
@Override
public void sendTeleportRequest(User targetUser) {
if (targetUser == null || !targetUser.isOnline()) {
message(this, Message.COMMAND_TPA_ERROR_SAME);
return;
}
if (targetUser.getUniqueId().equals(this.uniqueId)) {
message(this, Message.COMMAND_TPA_ERROR_SAME);
return;
}
if (targetUser.isIgnore(this.uniqueId)) {
message(this, Message.COMMAND_TELEPORT_IGNORE_PLAYER, targetUser);
return;
}
// Check if target user has disabled teleport requests
if (targetUser.getOption(Option.TELEPORT_REQUEST_DISABLE)) {
message(this, Message.COMMAND_TELEPORT_REQUEST_DISABLED, targetUser);
return;
}
this.teleports.entrySet().removeIf(next -> !next.getValue().isValid());
if (this.teleports.containsKey(targetUser.getUniqueId())) {
message(this, Message.COMMAND_TPA_ERROR, targetUser);
return;
}
TeleportationModule teleportationModule = this.plugin.getModuleManager().getModule(TeleportationModule.class);
long expired = System.currentTimeMillis() + (teleportationModule.getTeleportTpaExpire() * 1000L);
TeleportRequest teleportRequest = new ZTeleportRequest(this.plugin, targetUser, this, expired);
targetUser.setTeleportRequest(teleportRequest);
this.teleports.put(targetUser.getUniqueId(), teleportRequest);
message(this, Message.COMMAND_TPA_SENDER, targetUser);
message(targetUser, Message.COMMAND_TPA_RECEIVER, getPlayer());
}
@Override
public void sendTeleportHereRequest(User targetUser) {
if (targetUser == null || !targetUser.isOnline()) {
message(this, Message.COMMAND_TPA_HERE_ERROR_SAME);
return;
}
if (targetUser.getUniqueId().equals(this.uniqueId)) {
message(this, Message.COMMAND_TPA_HERE_ERROR_SAME);
return;
}
if (targetUser.isIgnore(this.uniqueId)) {
message(this, Message.COMMAND_TELEPORT_IGNORE_PLAYER, targetUser);
return;
}
// Check if target user has disabled teleport requests
if (targetUser.getOption(Option.TELEPORT_REQUEST_DISABLE)) {
message(this, Message.COMMAND_TELEPORT_REQUEST_DISABLED, targetUser);
return;
}
this.teleports.entrySet().removeIf(next -> !next.getValue().isValid());
if (this.teleports.containsKey(targetUser.getUniqueId())) {
message(this, Message.COMMAND_TPA_HERE_ERROR, targetUser);
return;
}
TeleportationModule teleportationModule = this.plugin.getModuleManager().getModule(TeleportationModule.class);
long expired = System.currentTimeMillis() + (teleportationModule.getTeleportTpaExpire() * 1000L);
TeleportRequest teleportRequest = new ZTeleportHereRequest(this.plugin, targetUser, this, expired);
targetUser.setTeleportRequest(teleportRequest);
this.teleports.put(targetUser.getUniqueId(), teleportRequest);
message(this, Message.COMMAND_TPA_HERE_SENDER, targetUser);
message(targetUser, Message.COMMAND_TPA_HERE_RECEIVER, getPlayer());
}
@Override
public void cancelTeleportRequest(User targetUser) {
if (!this.teleports.containsKey(targetUser.getUniqueId())) {
message(this, Message.COMMAND_TP_CANCEL_ERROR, targetUser);
return;
}
var request = targetUser.getTeleportRequest();
if (request == null) {
message(this, Message.COMMAND_TP_CANCEL_ERROR, targetUser);
return;
}
if (!request.isValid()) {
message(this, Message.COMMAND_TP_CANCEL_ERROR, targetUser);
this.teleports.remove(targetUser.getUniqueId());
return;
}
if (request.getFromUser() == this) {
targetUser.setTeleportRequest(null);
this.teleports.remove(targetUser.getUniqueId());
message(this, Message.COMMAND_TP_CANCEL_SENDER, targetUser);
message(targetUser, Message.COMMAND_TP_CANCEL_RECEIVER, this);
} else {
message(this, Message.COMMAND_TP_CANCEL_ERROR, targetUser);
}
}
@Override
public Collection<TeleportRequest> getTeleportRequests() {
return this.teleports.values();
}
@Override
public TeleportRequest getTeleportRequest() {
return teleportRequest;
}
@Override
public void setTeleportRequest(TeleportRequest teleportRequest) {
this.teleportRequest = teleportRequest;
}
@Override
public void removeTeleportRequest(User user) {
this.teleports.remove(user.getUniqueId());
}
@Override
public void teleportNow(Location location) {
// ToDo, https://github.com/PaperMC/Folia/?tab=readme-ov-file#current-broken-api
// When folia API is update, remove this
if (this.plugin.isFolia()) {
this.setLastLocation();
}
this.plugin.getScheduler().teleportAsync(this.getPlayer(), location);
int duration = this.plugin.getModuleManager().getModule(TeleportationModule.class).getTeleportProtectionDelay(this.getPlayer());
if (duration == 0) return;
this.protectionDuration = System.currentTimeMillis() + duration;
}
@Override
public void teleport(Location location) {
this.teleport(location, Message.TELEPORT_MESSAGE, Message.TELEPORT_SUCCESS);
}
@Override
public void teleport(Location location, Message message, Message successMessage, Object... args) {
TeleportationModule teleportationModule = this.plugin.getModuleManager().getModule(TeleportationModule.class);
Location playerLocation = getPlayer().getLocation();
AtomicInteger atomicInteger = new AtomicInteger(teleportationModule.getTeleportDelay(getPlayer()));
if (teleportationModule.isTeleportDelayBypass() && this.hasPermission(Permission.ESSENTIALS_TELEPORT_BYPASS) || atomicInteger.get() <= 0) {
this.teleport(teleportationModule, location, successMessage, args);
return;
}
PlatformScheduler platformScheduler = this.plugin.getScheduler();
platformScheduler.runAtLocationTimer(location, wrappedTask -> {
if (!this.isOnline()) {
wrappedTask.cancel();
return;
}
if (!same(playerLocation, getPlayer().getLocation())) {
message(this, Message.TELEPORT_MOVE);
wrappedTask.cancel();
return;
}
int currentSecond = atomicInteger.getAndDecrement();
if (currentSecond == 0) {
wrappedTask.cancel();
this.teleport(teleportationModule, location, successMessage, args);
} else {
List<Object> objects = new ArrayList<>(Arrays.asList(args));
objects.add("%seconds%");
objects.add(currentSecond);
message(this, message, objects.toArray());
}
}, 1, 20);
}
private void teleport(TeleportationModule teleportationModule, Location toLocation, Message message, Object... args) {
Location location = getPlayer().isFlying() ? toLocation : teleportationModule.isTeleportSafety() ? toSafeLocation(toLocation) : toLocation;
if (teleportationModule.isTeleportToCenter()) {
location = location.getBlock().getLocation().add(0.5, 0, 0.5);
location.setYaw(toLocation.getYaw());
location.setPitch(toLocation.getPitch());
}
this.teleportNow(location);
if (message != null) {
message(this, message, args);
}
}
@Override
public boolean hasPermission(Permission permission) {
return getPlayer().hasPermission(permission.asPermission());
}
@Override
public User getTargetUser() {
return targetUser;
}
@Override
public void setTargetUser(User targetUser) {
this.targetUser = targetUser;
}
@Override
public boolean getOption(Option option) {
return options.getOrDefault(option, false);
}
@Override
public void setOption(Option option, boolean value) {
this.options.put(option, value);
this.getStorage().updateOption(this.uniqueId, option, value);
}
@Override
public void setFakeOption(Option option, boolean value) {
this.options.put(option, value);
}
@Override
public Map<Option, Boolean> getOptions() {
return this.options;
}
@Override
public void setOptions(List<OptionDTO> options) {
options.forEach((optionDTO) -> this.options.put(optionDTO.option_name(), optionDTO.option_value()));
}
@Override
public Map<String, Long> getCooldowns() {
long currentTime = System.currentTimeMillis();
cooldowns.entrySet().removeIf(entry -> entry.getValue() <= currentTime);
return this.cooldowns;
}
@Override
public void setCooldowns(List<CooldownDTO> cooldowns) {
long currentTime = System.currentTimeMillis();
cooldowns.stream().filter(cooldownDTO -> cooldownDTO.cooldown_value() > currentTime).forEach(cooldownDTO -> this.cooldowns.put(cooldownDTO.cooldown_name(), cooldownDTO.cooldown_value()));
}
@Override
public void setCooldown(String key, long expiredAt) {
this.cooldowns.put(key, expiredAt);
this.getStorage().updateCooldown(this.uniqueId, key, expiredAt);
}
@Override
public void setCooldownSilent(String key, long expiredAt) {
this.cooldowns.put(key, expiredAt);
}
@Override
public boolean isCooldown(String key) {
return this.cooldowns.containsKey(key) && this.cooldowns.get(key) >= System.currentTimeMillis();
}
@Override
public long getCooldown(String key) {
return this.cooldowns.getOrDefault(key, 0L);
}
@Override
public long getCooldownSeconds(String key) {
long cooldown = getCooldown(key);
return cooldown == 0 ? 0 : (cooldown - System.currentTimeMillis()) / 1000;
}
@Override
public void addCooldown(String key, long seconds) {
setCooldown(key, System.currentTimeMillis() + (1000L * seconds));
}
@Override
public BigDecimal getBalance(Economy economy) {
return this.balances.getOrDefault(economy.getName(), BigDecimal.ZERO);
}
@Override
public boolean has(Economy economy, BigDecimal bigDecimal) {
return getBalance(economy).compareTo(bigDecimal) >= 0;
}
@Override
public void set(UUID fromUuid, Economy economy, BigDecimal bigDecimal, String reason) {
Economy finalEconomy;
BigDecimal finalBigDecimal;
if (isOnline() && this.plugin.getServer().isPrimaryThread()) {
UserEconomyUpdateEvent event = new UserEconomyUpdateEvent(this, economy, bigDecimal);
event.callEvent();
if (event.isCancelled()) return;
finalEconomy = event.getEconomy();
finalBigDecimal = event.getAmount();
} else {
finalBigDecimal = bigDecimal;
finalEconomy = economy;
}
BigDecimal fromAmount = this.balances.getOrDefault(finalEconomy.getName(), BigDecimal.ZERO);
BigDecimal toAmount = (finalBigDecimal.compareTo(finalEconomy.getMinValue()) < 0) ? finalEconomy.getMinValue() : (finalBigDecimal.compareTo(finalEconomy.getMaxValue()) > 0) ? finalEconomy.getMaxValue() : finalBigDecimal;
this.balances.put(finalEconomy.getName(), toAmount);
getStorage().updateEconomy(this.uniqueId, finalEconomy, finalBigDecimal);
getStorage().storeTransactions(fromUuid, this.uniqueId, finalEconomy, fromAmount, toAmount, reason);
if (isOnline() && this.plugin.getServer().isPrimaryThread()) {
UserEconomyPostUpdateEvent postUpdateEvent = new UserEconomyPostUpdateEvent(this, finalEconomy, finalBigDecimal);
postUpdateEvent.callEvent(this.plugin);
}
}
@Override
public void set(UUID fromUuid, Economy economy, BigDecimal bigDecimal) {
set(fromUuid, economy, bigDecimal, EconomyModule.NO_REASON);
}
@Override
public void withdraw(UUID fromUuid, Economy economy, BigDecimal bigDecimal, String reason) {
set(fromUuid, economy, getBalance(economy).subtract(bigDecimal), reason);
}
@Override
public void withdraw(UUID fromUuid, Economy economy, BigDecimal bigDecimal) {
set(fromUuid, economy, getBalance(economy).subtract(bigDecimal));
}
@Override
public void deposit(UUID fromUuid, Economy economy, BigDecimal bigDecimal, String reason) {
set(fromUuid, economy, getBalance(economy).add(bigDecimal), reason);
}
@Override
public void deposit(UUID fromUuid, Economy economy, BigDecimal bigDecimal) {
set(fromUuid, economy, getBalance(economy).add(bigDecimal));
}
@Override
public void set(Economy economy, BigDecimal bigDecimal) {
set(this.plugin.getConsoleUniqueId(), economy, bigDecimal);
}
@Override
public void deposit(Economy economy, BigDecimal bigDecimal) {
deposit(this.plugin.getConsoleUniqueId(), economy, bigDecimal);
}
@Override
public void withdraw(Economy economy, BigDecimal bigDecimal) {
withdraw(this.plugin.getConsoleUniqueId(), economy, bigDecimal);
}
@Override
public void set(Economy economy, BigDecimal bigDecimal, String reason) {
set(this.plugin.getConsoleUniqueId(), economy, bigDecimal, reason);
}
@Override
public void deposit(Economy economy, BigDecimal bigDecimal, String reason) {
deposit(this.plugin.getConsoleUniqueId(), economy, bigDecimal, reason);
}
@Override
public void withdraw(Economy economy, BigDecimal bigDecimal, String reason) {
withdraw(this.plugin.getConsoleUniqueId(), economy, bigDecimal, reason);
}
@Override
public Map<String, BigDecimal> getBalances() {
return this.balances;
}
@Override
public void setBalance(String key, BigDecimal value) {
this.balances.put(key, value);
}
@Override
public void setEconomies(List<EconomyDTO> economyDTOS) {
economyDTOS.forEach(economyDTO -> this.balances.put(economyDTO.economy_name(), economyDTO.amount()));
}
@Override
public void setTargetPay(User user, Economy economy, BigDecimal bigDecimal) {
this.targetUser = user;
this.targetEconomy = economy;
this.targetAmount = bigDecimal;
}
@Override
public @Nullable Economy getTargetEconomy() {
return this.targetEconomy;
}
@Override
public @Nullable BigDecimal getTargetDecimal() {
return this.targetAmount;
}
@Override
public void setLastLocation() {
Player player = this.getPlayer();
if (player == null) return;
if (this.plugin.getConfiguration().getDisableBackWorld().contains(player.getWorld().getName())) {
return;
}
this.lastLocation = new SafeLocation(player.getLocation().clone());
this.getStorage().upsertUser(this);
}
@Override
public Location getLastLocation() {
return this.lastLocation.getLocation();
}
@Override
public void setLastLocation(SafeLocation location) {
this.lastLocation = location;
}
@Override
public boolean isFirstJoin() {
return this.firstJoin;
}
@Override
public void setFirstJoin() {
this.firstJoin = true;
}
@Override
public boolean setHome(String name, Location location, boolean force) {
if (!force && isHomeName(name)) {
message(this, Message.COMMAND_SET_HOME_CREATE_CONFIRM, "%name%", name);
return false;
}
AtomicReference<Material> material = new AtomicReference<>(null);
getHome(name).ifPresent(home -> material.set(home.getMaterial()));
// Delete home with the same name before
this.homes.removeIf(home -> home.getName().equalsIgnoreCase(name));
Home home = new ZHome(new SafeLocation(location), name, material.get());
this.homes.add(home);
this.getStorage().upsertHome(this.uniqueId, home);
return true;
}
@Override
public Optional<Home> getHome(String name) {
return this.homes.stream().filter(home -> home.getName().equalsIgnoreCase(name)).findFirst();
}
@Override
public List<Home> getHomes() {
return this.homes;
}
@Override
public void setHomes(List<HomeDTO> homeDTOS) {
this.homes.addAll(homeDTOS.stream().map(homeDTO -> {
try {
return new ZHome(stringAsLocation(homeDTO.location()), homeDTO.name(), homeDTO.material() == null ? null : Material.valueOf(homeDTO.material()));
} catch (Exception exception) {
plugin.getLogger().severe("Impossible to load the home " + homeDTO.name() + " for " + this.name + " Debug: " + homeDTO);
exception.printStackTrace();
}
return null;
}).filter(Objects::nonNull).toList());
}
@Override
public int countHomes() {
return this.homes.size();
}
@Override
public void removeHome(String name) {
this.homes.removeIf(home -> home.getName().equalsIgnoreCase(name));
this.getStorage().deleteHome(this.uniqueId, name);
}
@Override
public boolean isHomeName(String homeName) {
return getHome(homeName).isPresent();
}
@Override
public int getActiveBanId() {
return this.banId;
}
@Override
public int getActiveMuteId() {
return this.muteId;
}
@Override
public void setSanction(Integer banId, Integer muteId) {
this.banId = banId == null ? 0 : banId;
this.muteId = muteId == null ? 0 : muteId;
}
@Override
public Sanction getMuteSanction() {
return this.muteSanction;
}
@Override
public void setMuteSanction(Sanction sanction) {
this.muteId = sanction == null ? 0 : sanction.getId();
this.muteSanction = sanction;
}
@Override
public boolean isMute() {
return this.muteSanction != null && this.muteSanction.isActive();
}
@Override
public List<Sanction> getFakeSanctions() {
return this.fakeSanctions;
}
@Override
public void setFakeSanctions(List<SanctionDTO> sanctions) {
this.fakeSanctions = sanctions.stream().map(Sanction::fromDTO).toList();
}
@Override
public Sanction getBanSanction() {
return banSanction;
}
@Override
public void setBanSanction(Sanction banSanction) {
this.banId = banSanction != null ? banSanction.getId() : 0;
this.banSanction = banSanction;
}
@Override
public String getLastMessage() {
return lastMessage;
}
@Override
public void setLastMessage(String lastMessage) {
this.lastMessage = lastMessage;
}
@Override
public PrivateMessage setPrivateMessage(UUID uuid, String userName) {
return this.privateMessage = new PrivateMessage(uuid, userName);
}
@Override
public PrivateMessage getPrivateMessage() {
return this.privateMessage;
}
@Override
public boolean hasPrivateMessage() {
return this.privateMessage != null;
}
@Override
public long getPlayTime() {
return this.playTime + ((System.currentTimeMillis() - this.currentSessionPlayTime) / 1000);
}
@Override
public void setPlayTime(long playtime) {
this.playTime = playtime;
}
@Override
public long getCurrentSessionPlayTime() {
return this.currentSessionPlayTime;
}
@Override
public void startCurrentSessionPlayTime() {
this.currentSessionPlayTime = System.currentTimeMillis();
}
@Override
public String getAddress() {
return address;
}
@Override
public void setAddress(String address) {
this.address = address;
}
@Override
public long getKitCooldown(Kit kit) {
return this.getCooldown("kit:" + kit.getName());
}
@Override
public boolean isKitCooldown(Kit kit) {
return isCooldown("kit:" + kit.getName());
}
@Override
public void addKitCooldown(Kit kit, long cooldown) {
this.addCooldown("kit:" + kit.getName(), cooldown);
}
@Override
public void openKitPreview(Kit kit) {
this.previewKit = kit;
this.plugin.openInventory(getPlayer(), "kit_preview");
}
@Override
public void removeCooldown(String cooldownName) {
this.cooldowns.remove(cooldownName);
}
@Override
public void setPowerTools(Material type, String command) {
this.powerTools.put(type, command);
this.getStorage().setPowerTools(this.uniqueId, type, command);
}
@Override
public Map<Material, String> getPowerTools() {
return this.powerTools;
}
@Override
public void setPowerTools(Map<Material, String> powerTools) {
this.powerTools = powerTools;
}
@Override
public Optional<String> getPowerTool(Material material) {
return Optional.ofNullable(this.powerTools.get(material));
}
@Override
public Kit getKitPreview() {
return this.previewKit;
}
@Override
public void deletePowerTools(Material material) {
this.powerTools.remove(material);
this.getStorage().deletePowerTools(this.uniqueId, material);
}
@Override
public List<MailBoxItem> getMailBoxItems() {
return this.mailBoxItems;
}
@Override
public void setMailBoxItems(List<MailBoxDTO> mailBoxItems) {
this.mailBoxItems.clear();
this.mailBoxItems.addAll(mailBoxItems.stream().map(MailBoxItem::new).toList());
}
@Override
public void addMailBoxItem(MailBoxItem mailBoxItem) {
this.mailBoxItems.add(mailBoxItem);
this.getStorage().addMailBoxItem(mailBoxItem);
}
@Override
public DynamicCooldown getDynamicCooldown() {
return dynamicCooldown;
}
@Override
public long getVote() {
return vote;
}
@Override
public void setVote(long amount) {
this.vote = amount;
this.getStorage().setVote(this.uniqueId, this.vote, 0);
}
@Override
public void addVote(long amount) {
this.setVote(this.vote + amount);
}
@Override
public void removeVote(long amount) {
this.setVote(this.vote - amount);
}
@Override
public void setWithDTO(UserDTO userDTO) {
this.vote = userDTO.vote();
this.offlineVote = userDTO.vote_offline();
this.playTime = userDTO.play_time();
this.lastLocation = stringAsLocation(userDTO.last_location());
this.freeze = userDTO.frozen() != null && userDTO.frozen();
this.flySeconds = userDTO.fly_seconds();
}
@Override
public void setVoteSite(String site) {
long ms = System.currentTimeMillis();
if (this.lastVotes.containsKey(site) && ms - this.lastVotes.get(site) < 500) return;
this.lastVotes.put(site, ms);
this.getStorage().setLastVote(this.uniqueId, site);
}
@Override
public long getLastVoteSite(String site) {
return this.lastVotes.getOrDefault(site, 0L);
}
@Override
public long getOfflineVotes() {
return this.offlineVote;
}
@Override
public void setVoteSites(List<VoteSiteDTO> select) {
this.lastVotes = select.stream().collect(Collectors.toMap(VoteSiteDTO::site, value -> value.last_vote_at().getTime()));
}
@Override
public void resetOfflineVote() {
this.getStorage().setVote(this.uniqueId, -1, 0);
}
@Override
public Selection getSelection() {
return this.selection;
}
@Override
public boolean hasWorldeditTask() {
return this.worldEditTask != null && this.worldEditTask.getWorldeditStatus().isRunning();
}
@Override
public WorldEditTask getWorldeditTask() {
return this.worldEditTask;
}
@Override
public void setWorldeditTask(WorldEditTask worldEditTask) {
this.worldEditTask = worldEditTask;
}
@Override
public ItemStack getItemInMainHand() {
return getPlayer().getInventory().getItemInMainHand();
}
@Override
public void setItemInMainHand(ItemStack itemStack) {
getPlayer().getInventory().setItemInMainHand(itemStack);
}
@Override
public void playSound(Sound sound, float volume, float pitch) {
var player = getPlayer();
player.playSound(player.getLocation(), sound, volume, pitch);
}
@Override
public boolean isFrozen() {
return freeze;
}
@Override
public void setFrozen(boolean isFrozen) {
freeze = isFrozen;
}
@Override
public Optional<Home> getCurrentDeleteHome() {
return Optional.ofNullable(this.currentDeleteHome);
}
@Override
public void setCurrentDeleteHome(Home currentDeleteHome) {
this.currentDeleteHome = currentDeleteHome;
}
@Override
public long getFlySeconds() {
return this.flySeconds;
}
@Override
public void setFlySeconds(long seconds) {
this.flySeconds = seconds;
getStorage().upsertFlySeconds(this.uniqueId, this.flySeconds);
}
@Override
public void addFlySeconds(long seconds) {
this.flySeconds += seconds;
getStorage().upsertFlySeconds(this.uniqueId, this.flySeconds);
}
@Override
public void removeFlySeconds(long seconds) {
this.flySeconds -= seconds;
getStorage().upsertFlySeconds(this.uniqueId, this.flySeconds);
}
@Override
public DiscordAccount getDiscordAccount() {
return discordAccount;
}
@Override
public void setDiscordAccount(DiscordAccount discordAccount) {
this.discordAccount = discordAccount;
}
@Override
public boolean isDiscordLinked() {
return this.discordAccount != null;
}
@Override
public void removeDiscordAccount() {
this.discordAccount = null;
}