forked from CloudburstMC/Nukkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
7233 lines (6222 loc) · 282 KB
/
Player.java
File metadata and controls
7233 lines (6222 loc) · 282 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 cn.nukkit;
import cn.nukkit.AdventureSettings.Type;
import cn.nukkit.block.*;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityItemFrame;
import cn.nukkit.blockentity.BlockEntityLectern;
import cn.nukkit.blockentity.BlockEntitySpawnable;
import cn.nukkit.command.Command;
import cn.nukkit.command.CommandSender;
import cn.nukkit.command.data.CommandDataVersions;
import cn.nukkit.entity.*;
import cn.nukkit.entity.custom.EntityManager;
import cn.nukkit.entity.data.*;
import cn.nukkit.entity.item.*;
import cn.nukkit.entity.projectile.EntityArrow;
import cn.nukkit.entity.projectile.EntityProjectile;
import cn.nukkit.entity.projectile.EntityThrownTrident;
import cn.nukkit.event.block.WaterFrostEvent;
import cn.nukkit.event.entity.*;
import cn.nukkit.event.entity.EntityDamageEvent.DamageCause;
import cn.nukkit.event.entity.EntityDamageEvent.DamageModifier;
import cn.nukkit.event.inventory.InventoryCloseEvent;
import cn.nukkit.event.inventory.InventoryPickupArrowEvent;
import cn.nukkit.event.inventory.InventoryPickupItemEvent;
import cn.nukkit.event.inventory.InventoryPickupTridentEvent;
import cn.nukkit.event.player.*;
import cn.nukkit.event.player.PlayerAsyncPreLoginEvent.LoginResult;
import cn.nukkit.event.player.PlayerInteractEvent.Action;
import cn.nukkit.event.player.PlayerTeleportEvent.TeleportCause;
import cn.nukkit.event.server.DataPacketReceiveEvent;
import cn.nukkit.event.server.DataPacketSendEvent;
import cn.nukkit.form.handler.FormResponseHandler;
import cn.nukkit.form.window.FormWindow;
import cn.nukkit.form.window.FormWindowCustom;
import cn.nukkit.inventory.*;
import cn.nukkit.inventory.transaction.*;
import cn.nukkit.inventory.transaction.action.InventoryAction;
import cn.nukkit.inventory.transaction.data.ReleaseItemData;
import cn.nukkit.inventory.transaction.data.UseItemData;
import cn.nukkit.inventory.transaction.data.UseItemOnEntityData;
import cn.nukkit.item.*;
import cn.nukkit.item.custom.CustomItemManager;
import cn.nukkit.item.enchantment.Enchantment;
import cn.nukkit.lang.TextContainer;
import cn.nukkit.lang.TranslationContainer;
import cn.nukkit.level.*;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.level.format.generic.BaseFullChunk;
import cn.nukkit.level.particle.ItemBreakParticle;
import cn.nukkit.level.particle.PunchBlockParticle;
import cn.nukkit.math.*;
import cn.nukkit.metadata.MetadataValue;
import cn.nukkit.nbt.NBTIO;
import cn.nukkit.nbt.tag.*;
import cn.nukkit.network.CompressionProvider;
import cn.nukkit.network.SourceInterface;
import cn.nukkit.network.encryption.PrepareEncryptionTask;
import cn.nukkit.network.protocol.*;
import cn.nukkit.network.protocol.types.*;
import cn.nukkit.network.session.NetworkPlayerSession;
import cn.nukkit.permission.PermissibleBase;
import cn.nukkit.permission.Permission;
import cn.nukkit.permission.PermissionAttachment;
import cn.nukkit.permission.PermissionAttachmentInfo;
import cn.nukkit.plugin.Plugin;
import cn.nukkit.potion.Effect;
import cn.nukkit.resourcepacks.ResourcePack;
import cn.nukkit.scheduler.AsyncTask;
import cn.nukkit.utils.*;
import com.google.common.base.Strings;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import io.netty.util.internal.PlatformDependent;
import it.unimi.dsi.fastutil.bytes.ByteOpenHashSet;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongIterator;
import it.unimi.dsi.fastutil.objects.ObjectIterator;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;
import javax.annotation.Nullable;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.nio.ByteOrder;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.stream.Stream;
/**
* The Player class
*
* @author MagicDroidX & Box
* Nukkit Project
*/
@Log4j2
public class Player extends EntityHuman implements CommandSender, InventoryHolder, ChunkLoader, IPlayer {
public static final int SURVIVAL = 0;
public static final int CREATIVE = 1;
public static final int ADVENTURE = 2;
public static final int SPECTATOR = 3;
public static final int CRAFTING_SMALL = 0;
public static final int CRAFTING_BIG = 1;
public static final int CRAFTING_ANVIL = 2;
public static final int CRAFTING_ENCHANT = 3;
public static final int CRAFTING_BEACON = 4;
public static final int CRAFTING_SMITHING = 1003;
public static final int CRAFTING_LOOM = 1004;
public static final float DEFAULT_SPEED = 0.1f;
public static final float MAXIMUM_SPEED = 6f; // TODO: Decrease when block collisions are fixed
public static final float DEFAULT_FLY_SPEED = 0.05f;
public static final float DEFAULT_VERTICAL_FLY_SPEED = 1f;
public static final int PERMISSION_CUSTOM = 3;
public static final int PERMISSION_OPERATOR = 2;
public static final int PERMISSION_MEMBER = 1;
public static final int PERMISSION_VISITOR = 0;
public static final int ANVIL_WINDOW_ID = 2;
public static final int ENCHANT_WINDOW_ID = 3;
public static final int BEACON_WINDOW_ID = 4;
public static final int LOOM_WINDOW_ID = 2;
public static final int SMITHING_WINDOW_ID = 6;
protected static final int RESOURCE_PACK_CHUNK_SIZE = 8192; // 8KB
protected final SourceInterface interfaz;
protected final NetworkPlayerSession networkSession;
@Deprecated
public long creationTime;
public boolean playedBefore;
public boolean spawned;
public boolean loggedIn;
private boolean loginVerified;
private boolean loginPacketReceived;
protected boolean networkSettingsRequested;
public int gamemode;
protected long randomClientId;
private String unverifiedUsername = "";
protected final BiMap<Inventory, Integer> windows = HashBiMap.create();
protected final BiMap<Integer, Inventory> windowIndex = windows.inverse();
protected final Set<Integer> permanentWindows = new IntOpenHashSet();
private boolean inventoryOpen;
protected int windowCnt = 4;
protected int closingWindowId = Integer.MIN_VALUE;
public final HashSet<String> achievements = new HashSet<>();
public int craftingType = CRAFTING_SMALL;
protected PlayerUIInventory playerUIInventory;
protected CraftingGrid craftingGrid;
protected CraftingTransaction craftingTransaction;
protected EnchantTransaction enchantTransaction;
protected RepairItemTransaction repairItemTransaction;
protected LoomTransaction loomTransaction;
protected SmithingTransaction smithingTransaction;
public Vector3 speed;
protected Vector3 forceMovement;
protected Vector3 teleportPosition;
protected Vector3 newPosition;
protected Vector3 sleeping;
private BlockVector3 lastRightClickPos;
private final Queue<Vector3> clientMovements = PlatformDependent.newMpscQueue(4);
protected boolean connected = true;
protected final InetSocketAddress socketAddress;
protected boolean removeFormat = true;
protected String username;
protected String iusername;
protected String displayName;
private boolean hasSpawnChunks;
private final int loaderId;
private int chunksSent;
protected int nextChunkOrderRun = 1;
protected int chunkRadius;
protected int viewDistance;
public final Map<Long, Boolean> usedChunks = new Long2ObjectOpenHashMap<>();
protected final Long2ObjectLinkedOpenHashMap<Boolean> loadQueue = new Long2ObjectLinkedOpenHashMap<>();
protected final Map<UUID, Player> hiddenPlayers = new HashMap<>();
protected Position spawnPosition;
protected int inAirTicks;
protected int startAirTicks = 10;
protected AdventureSettings adventureSettings;
private PermissibleBase perm;
/**
* Option not to update shield blocking status.
*/
@Getter
@Setter
private boolean canTickShield = true;
/**
* Player's client-side walk speed. Remember to call getAdventureSettings().update() if changed.
*/
@Getter
@Setter
private float walkSpeed = DEFAULT_SPEED;
/**
* Player's client-side fly speed. Remember to call getAdventureSettings().update() if changed.
*/
@Getter
@Setter
private float flySpeed = DEFAULT_FLY_SPEED;
/**
* Player's client-side vertical fly speed. Remember to call getAdventureSettings().update() if changed.
*/
@Getter
@Setter
private float verticalFlySpeed = DEFAULT_VERTICAL_FLY_SPEED;
private int exp;
private int expLevel;
protected PlayerFood foodData;
private Entity killer;
private final AtomicReference<Locale> locale = new AtomicReference<>(null);
private int hash;
private String buttonText = "";
protected boolean enableClientCommand = true;
private BlockEnderChest viewingEnderChest;
private LoginChainData loginChainData;
public int pickedXPOrb;
private boolean canPickupXP = true;
protected int formWindowCount;
protected Map<Integer, FormWindow> formWindows = new Int2ObjectOpenHashMap<>();
protected Map<Integer, FormWindow> serverSettings = new Int2ObjectOpenHashMap<>();
protected Map<Long, DummyBossBar> dummyBossBars = new Long2ObjectLinkedOpenHashMap<>();
private AsyncTask preLoginEventTask;
protected boolean shouldLogin;
private static Stream<Field> pkIDs;
protected int startAction = -1;
private int lastEmote;
protected int lastEnderPearl = 20;
protected int lastChorusFruitTeleport = 20;
protected int lastFireworkBoost = 20;
public long lastSkinChange = -1;
private double lastRightClickTime;
public long lastBreak = -1; // When last block break was started
private BlockVector3 lastBreakPosition = new BlockVector3();
public Block breakingBlock; // Block player is breaking currently
private BlockFace breakingBlockFace; // Block face player is breaking currently
private PlayerBlockActionData lastBlockAction;
public EntityFishingHook fishing;
@Getter
private boolean formOpen;
private boolean flySneaking;
public boolean locallyInitialized;
private boolean foodEnabled = true;
protected boolean checkMovement = true;
private int timeSinceRest;
private boolean inSoulSand;
private boolean dimensionChangeInProgress;
private boolean awaitingDimensionAck;
private boolean awaitingEncryptionHandshake;
private int riderJumpTick;
private int riptideTicks;
private int blockingDelay;
private int fireworkBoostTicks;
private int fireworkBoostLevel;
@Setter
private boolean needSendData;
private boolean needSendAdventureSettings;
private boolean needSendFoodLevel;
@Setter
private boolean needSendInventory;
private boolean needSendHeldItem;
private boolean needSendRotation;
private boolean dimensionFix560;
/**
* Save last crossbow load tick (used to prevent loading a crossbow launching it immediately afterward)
*/
private int crossbowLoadTick;
/**
* Packets that can be received before the player has logged in
*/
private static final ByteOpenHashSet PRE_LOGIN_PACKETS = new ByteOpenHashSet(new byte[]{ProtocolInfo.BATCH_PACKET, ProtocolInfo.LOGIN_PACKET, ProtocolInfo.REQUEST_NETWORK_SETTINGS_PACKET, ProtocolInfo.REQUEST_CHUNK_RADIUS_PACKET, ProtocolInfo.SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET, ProtocolInfo.RESOURCE_PACK_CHUNK_REQUEST_PACKET, ProtocolInfo.RESOURCE_PACK_CLIENT_RESPONSE_PACKET, ProtocolInfo.CLIENT_CACHE_STATUS_PACKET, ProtocolInfo.PACKET_VIOLATION_WARNING_PACKET, ProtocolInfo.CLIENT_TO_SERVER_HANDSHAKE_PACKET});
/**
* Default kick message for flying
*/
private static final String MSG_FLYING_NOT_ENABLED = "Flying is not enabled on this server";
/**
* Get action start tick
* @return action start tick, -1 = no action in progress
*/
public int getStartActionTick() {
return startAction;
}
/**
* Set action start tick to current tick
*/
public void startAction() {
this.startAction = this.server.getTick();
}
/**
* Reset action start tick
*/
public void stopAction() {
this.startAction = -1;
}
/**
* Get last tick an ender pearl was used
* @return last ender pearl used tick
*/
public int getLastEnderPearlThrowingTick() {
return lastEnderPearl;
}
/**
* Set last ender pearl throw tick to current tick
*/
public void onThrowEnderPearl() {
this.lastEnderPearl = this.server.getTick();
}
/**
* Get last chorus fruit teleport tick
* @return last chorus fruit teleport tick
*/
public int getLastChorusFruitTeleport() {
return lastChorusFruitTeleport;
}
/**
* Set last chorus fruit teleport tick to current tick
*/
public void onChorusFruitTeleport() {
this.lastChorusFruitTeleport = this.server.getTick();
}
/**
* Get last tick firework boost for elytra was used
* @return last firework boost tick
*/
public int getLastFireworkBoostTick() {
return lastFireworkBoost;
}
/**
* Set last firework boost tick to current tick
*/
public void onFireworkBoost(int boostLevel) {
this.lastFireworkBoost = this.server.getTick();
this.fireworkBoostLevel = boostLevel;
this.fireworkBoostTicks = boostLevel == 3 ? 44 : boostLevel == 2 ? 29 : 23;
}
/**
* Set last spin attack tick to current tick
*/
public void onSpinAttack(int riptideLevel) {
this.riptideTicks = 50 + (riptideLevel << 5);
}
/**
* Get ender chest the player is viewing
* @return the ender chest player is viewing or null if player is not viewing an ender chest
*/
public BlockEnderChest getViewingEnderChest() {
return viewingEnderChest;
}
/**
* Add player to ender chest viewers
*/
public void setViewingEnderChest(BlockEnderChest chest) {
if (chest == null && this.viewingEnderChest != null) {
this.viewingEnderChest.getViewers().remove(this);
} else if (chest != null) {
chest.getViewers().add(this);
}
this.viewingEnderChest = chest;
}
/**
* Get player quit message
* @return quit message
*/
public TranslationContainer getLeaveMessage() {
return new TranslationContainer(TextFormat.YELLOW + "%multiplayer.player.left", this.displayName);
}
@Deprecated
public String getClientSecret() {
return null;
}
/**
* This might disappear in the future.
* Please use getUniqueId() instead (IP + clientId + name combo, in the future it'll change to real UUID for online auth)
* @return random client id
*/
@Deprecated
public Long getClientId() {
return randomClientId;
}
@Override
public boolean isBanned() {
return this.server.getNameBans().isBanned(this.username);
}
@Override
public void setBanned(boolean value) {
if (value) {
this.server.getNameBans().addBan(this.username, null, null, null);
this.kick(PlayerKickEvent.Reason.NAME_BANNED, "You are banned!");
} else {
this.server.getNameBans().remove(this.username);
}
}
@Override
public boolean isWhitelisted() {
return this.server.isWhitelisted(this.iusername);
}
@Override
public void setWhitelisted(boolean value) {
if (value) {
this.server.addWhitelist(this.iusername);
} else {
this.server.removeWhitelist(this.iusername);
}
}
@Override
public Player getPlayer() {
return this;
}
@Override
public Long getFirstPlayed() {
return this.namedTag != null ? this.namedTag.getLong("firstPlayed") : null;
}
@Override
public Long getLastPlayed() {
return this.namedTag != null ? this.namedTag.getLong("lastPlayed") : null;
}
@Override
public boolean hasPlayedBefore() {
return this.playedBefore;
}
/**
* Get current adventure settings
* @return adventure settings
*/
public AdventureSettings getAdventureSettings() {
return adventureSettings;
}
/**
* Set and send adventure settings
* @param adventureSettings new adventure settings
*/
public void setAdventureSettings(AdventureSettings adventureSettings) {
this.adventureSettings = adventureSettings.clone(this);
this.adventureSettings.update();
}
/**
* Reset in air ticks
*/
public void resetInAirTicks() {
if (this.inAirTicks != 0) {
this.startAirTicks = 10;
}
this.inAirTicks = 0;
}
/**
* Set allow flight adventure setting
* @param value allow flight enabled
*/
@Deprecated
public void setAllowFlight(boolean value) {
this.adventureSettings.set(Type.ALLOW_FLIGHT, value);
this.adventureSettings.update();
}
/**
* Check wether allow flight adventure setting is enabled
* @return allow flight enabled
*/
@Deprecated
public boolean getAllowFlight() {
return this.adventureSettings.get(Type.ALLOW_FLIGHT);
}
/**
* Set can modify world adventure setting(s)
* @param value can modify world
*/
public void setAllowModifyWorld(boolean value) {
this.adventureSettings.set(Type.WORLD_IMMUTABLE, !value);
this.adventureSettings.set(Type.MINE, value);
this.adventureSettings.set(Type.BUILD, value);
this.adventureSettings.update();
}
/**
* Set can interact adventure setting(s)
* @param value can interact
*/
public void setAllowInteract(boolean value) {
this.setAllowInteract(value, value);
}
/**
* Set can interact adventure setting(s)
* @param value can interact
* @param containers can open containers
*/
public void setAllowInteract(boolean value, boolean containers) {
this.adventureSettings.set(Type.WORLD_IMMUTABLE, !value);
this.adventureSettings.set(Type.DOORS_AND_SWITCHED, value);
this.adventureSettings.set(Type.OPEN_CONTAINERS, containers);
this.adventureSettings.update();
}
/**
* Set auto jump adventure setting (adventureSettings.set(Type.AUTO_JUMP) + adventureSettings.update())
* @param value auto jump enabled
*/
@Deprecated
public void setAutoJump(boolean value) {
this.adventureSettings.set(Type.AUTO_JUMP, value);
this.adventureSettings.update();
}
/**
* Check whether auto jump adventure setting is enabled (adventureSettings.get(Type.AUTO_JUMP))
* @return auto jump enabled
*/
@Deprecated
public boolean hasAutoJump() {
return this.adventureSettings.get(Type.AUTO_JUMP);
}
@Override
public void spawnTo(Player player) {
if (this.spawned && player.spawned && this.isAlive() && player.isAlive() && player.getLevel() == this.level && player.canSee(this) && !this.isSpectator()) {
super.spawnTo(player);
}
}
/**
* Check whether player can use text formatting
* @return player can use text formatting
*/
public boolean getRemoveFormat() {
return removeFormat;
}
/**
* Make player unable to use text formatting (color codes etc.)
*/
public void setRemoveFormat() {
this.setRemoveFormat(true);
}
/**
* Set whether player can use text formatting (color codes etc.)
* @param remove remove formatting from received texts
*/
public void setRemoveFormat(boolean remove) {
this.removeFormat = remove;
}
/**
* Check whether player can see another player (not hidden)
* @param player target player
* @return player can see the target player
*/
public boolean canSee(Player player) {
return !this.hiddenPlayers.containsKey(player.getUniqueId());
}
/**
* Hide this player from target player
* @param player target player
*/
public void hidePlayer(Player player) {
if (this == player) {
return;
}
this.hiddenPlayers.put(player.getUniqueId(), player);
player.despawnFrom(this);
}
/**
* Allow target player to see this player
* @param player target player
*/
public void showPlayer(Player player) {
if (this == player) {
return;
}
this.hiddenPlayers.remove(player.getUniqueId());
if (player.isOnline()) {
player.spawnTo(this);
}
}
@Override
public boolean canCollideWith(Entity entity) {
return false;
}
/**
* Check whether player can pick up xp orbs
* @return can pick up xp orbs
*/
public boolean canPickupXP() {
return this.canPickupXP;
}
/**
* Set whether player can pick up xp orbs
* @param canPickupXP can pick up xp orbs
*/
public void setCanPickupXP(boolean canPickupXP) {
this.canPickupXP = canPickupXP;
}
@Override
public void resetFallDistance() {
super.resetFallDistance();
this.resetInAirTicks();
}
@Override
public boolean isOnline() {
return this.connected && this.loggedIn;
}
@Override
public boolean isOp() {
return this.server.isOp(this.username);
}
@Override
public void setOp(boolean value) {
if (value == this.isOp()) {
return;
}
if (value) {
this.server.addOp(this.username);
} else {
this.server.removeOp(this.username);
}
this.recalculatePermissions();
this.adventureSettings.update();
this.sendCommandData();
}
@Override
public boolean isPermissionSet(String name) {
return this.perm.isPermissionSet(name);
}
@Override
public boolean isPermissionSet(Permission permission) {
return this.perm.isPermissionSet(permission);
}
@Override
public boolean hasPermission(String name) {
return this.perm != null && this.perm.hasPermission(name);
}
@Override
public boolean hasPermission(Permission permission) {
return this.perm.hasPermission(permission);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
return this.addAttachment(plugin, null);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name) {
return this.addAttachment(plugin, name, null);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, Boolean value) {
return this.perm.addAttachment(plugin, name, value);
}
@Override
public void removeAttachment(PermissionAttachment attachment) {
this.perm.removeAttachment(attachment);
}
@Override
public void recalculatePermissions() {
this.server.getPluginManager().unsubscribeFromPermission(Server.BROADCAST_CHANNEL_USERS, this);
this.server.getPluginManager().unsubscribeFromPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE, this);
if (this.perm == null) {
return;
}
this.perm.recalculatePermissions();
if (this.hasPermission(Server.BROADCAST_CHANNEL_USERS)) {
this.server.getPluginManager().subscribeToPermission(Server.BROADCAST_CHANNEL_USERS, this);
}
if (this.hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE)) {
this.server.getPluginManager().subscribeToPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE, this);
}
if (this.enableClientCommand && spawned) this.sendCommandData();
}
/**
* Are commands enabled for this player on the client side
* @return commands enabled
*/
public boolean isEnableClientCommand() {
return this.enableClientCommand;
}
/**
* Set commands enabled client side. This does not necessarily prevent commands from being used.
* @param enable can use commands
*/
public void setEnableClientCommand(boolean enable) {
this.enableClientCommand = enable;
SetCommandsEnabledPacket pk = new SetCommandsEnabledPacket();
pk.enabled = enable;
this.dataPacket(pk);
if (enable) this.sendCommandData();
}
/**
* Send updated command data (AvailableCommandsPacket)
*/
public void sendCommandData() {
AvailableCommandsPacket pk = new AvailableCommandsPacket();
Map<String, CommandDataVersions> data = new HashMap<>();
for (Command command : this.server.getCommandMap().getCommands().values()) {
if (command.isRegistered()) {
if ("help".equals(command.getName())) {
continue; // The client will add this
}
CommandDataVersions commandData = command.generateCustomCommandData(this);
if (commandData != null) { // No permission
data.put(command.getName(), commandData);
}
}
}
if (!data.isEmpty()) {
pk.commands = data;
this.dataPacket(pk);
}
}
@Override
public Map<String, PermissionAttachmentInfo> getEffectivePermissions() {
return this.perm.getEffectivePermissions();
}
public Player(SourceInterface interfaz, Long clientID, InetSocketAddress socketAddress) {
super(null, new CompoundTag());
this.interfaz = interfaz;
this.networkSession = interfaz.getSession(socketAddress);
this.perm = new PermissibleBase(this);
this.server = Server.getInstance();
this.socketAddress = socketAddress;
this.loaderId = Level.generateChunkLoaderId(this);
this.gamemode = this.server.getGamemode();
this.setLevel(this.server.getDefaultLevel());
this.viewDistance = this.server.getViewDistance();
this.chunkRadius = this.viewDistance;
this.boundingBox = new SimpleAxisAlignedBB(0, 0, 0, 0, 0, 0);
}
@Override
protected void initEntity() {
super.initEntity();
this.addDefaultWindows();
}
public boolean isPlayer() {
return true;
}
/**
* Remove achievement from player if the player has it
* @param achievementId achievement id
*/
public void removeAchievement(String achievementId) {
achievements.remove(achievementId);
}
/**
* Check whether player has an achievement
* @param achievementId achievement id
* @return has achievement
*/
public boolean hasAchievement(String achievementId) {
return achievements.contains(achievementId);
}
/**
* Check whether player is still connected
* @return connected
*/
public boolean isConnected() {
return connected;
}
/**
* Get player's display name. Default value is player's username.
* @return display name
*/
public String getDisplayName() {
return this.displayName;
}
/**
* Set player's display name
* @param displayName display name
*/
public void setDisplayName(String displayName) {
if (displayName == null) {
displayName = "";
server.getLogger().debug("Warning: setDisplayName: argument is null", new Throwable(""));
}
this.displayName = displayName;
if (this.spawned) {
this.server.updatePlayerListData(this.getUniqueId(), this.getId(), this.displayName, this.getSkin(), this.loginChainData.getXUID());
}
}
@Override
public void setSkin(Skin skin) {
super.setSkin(skin);
if (this.spawned) {
this.server.updatePlayerListData(this.getUniqueId(), this.getId(), this.displayName, skin, this.loginChainData.getXUID());
}
}
/**
* Get player's host address
* @return host address
*/
public String getAddress() {
return this.socketAddress.getAddress().getHostAddress();
}
/**
* Get the port of player's connection
* @return port
*/
public int getPort() {
return this.socketAddress.getPort();
}
/**
* Get player's socket address
* @return socket address
*/
public InetSocketAddress getSocketAddress() {
return this.socketAddress;
}
/**
* Get most recent position of received movements
* @return next position or current position if no next position has been received
*/
public Position getNextPosition() {
return this.newPosition != null ? new Position(this.newPosition.x, this.newPosition.y, this.newPosition.z, this.level) : this.getPosition();
}
public AxisAlignedBB getNextPositionBB() {
if (this.newPosition == null) {
return this.boundingBox;
}
Vector3 diff = this.newPosition.subtract(this);
return this.boundingBox.getOffsetBoundingBox(diff.x, diff.y, diff.z);
}
/**
* Check whether player is sleeping
* @return is sleeping
*/
public boolean isSleeping() {
return this.sleeping != null;
}
/**
* Get in air ticks
* @return in air ticks
*/
public int getInAirTicks() {
return this.inAirTicks;
}
/**
* Returns whether the player is currently using an item (right-click and hold).
*
* @return whether the player is currently using an item
*/
public boolean isUsingItem() {
return this.startAction > -1 && this.getDataFlag(DATA_FLAGS, DATA_FLAG_ACTION);
}
/**
* Set using item flag
* @param value is using item
*/
public void setUsingItem(boolean value) {
this.startAction = value ? this.server.getTick() : -1;
this.setDataFlag(DATA_FLAGS, DATA_FLAG_ACTION, value);
}
/**
* Get interaction button text
* @return button text
*/
public String getButtonText() {
return this.buttonText;
}
/**
* Set interaction button text
* @param text button text
*/
public void setButtonText(String text) {
if (text == null) {
text = "";
server.getLogger().debug("Warning: setButtonText: argument is null", new Throwable(""));
}
if (!text.equals(buttonText)) {
this.buttonText = text;
this.setDataPropertyAndSendOnlyToSelf(new StringEntityData(Entity.DATA_INTERACTIVE_TAG, this.buttonText));
}
}