-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathWorld.java
More file actions
4624 lines (4306 loc) · 183 KB
/
World.java
File metadata and controls
4624 lines (4306 loc) · 183 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 org.bukkit;
import io.papermc.paper.raytracing.PositionedRayTraceConfigurationBuilder;
import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Predicate;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.boss.DragonBattle;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Item;
import org.bukkit.entity.LightningStrike;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.generator.BiomeProvider;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.generator.WorldInfo;
import org.bukkit.generator.structure.GeneratedStructure;
import org.bukkit.generator.structure.Structure;
import org.bukkit.generator.structure.StructureType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.MaterialData;
import org.bukkit.metadata.Metadatable;
import org.bukkit.persistence.PersistentDataHolder;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.messaging.PluginMessageRecipient;
import org.bukkit.util.BiomeSearchResult;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.StructureSearchResult;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a world, which may contain entities, chunks and blocks
*/
public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient, Metadatable, PersistentDataHolder, Keyed, net.kyori.adventure.audience.ForwardingAudience { // Paper
// Paper start - void damage configuration
/**
* Checks if void damage is enabled on this world.
*
* @return true if enabled
*/
boolean isVoidDamageEnabled();
/**
* Sets whether void damage is enabled on this world.
*
* @param enabled true to enable void damage
*/
void setVoidDamageEnabled(boolean enabled);
/**
* Gets the damage applied to the entities when they are in the void in this world.
* Check {@link #isVoidDamageEnabled()} to see if void damage is enabled.
*
* @return amount of damage to apply
* @see #isVoidDamageEnabled()
*/
float getVoidDamageAmount();
/**
* Sets the damage applied to the entities when they are in the void in this world.
* Check {@link #isVoidDamageEnabled()} to see if void damage is enabled.
*
* @param voidDamageAmount amount of damage to apply
*/
void setVoidDamageAmount(float voidDamageAmount);
/**
* Gets the offset applied to {@link #getMinHeight()} to determine the height at which void damage starts to apply.
*
* @return offset from min build height
* @see #isVoidDamageEnabled()
*/
double getVoidDamageMinBuildHeightOffset();
/**
* Sets the offset applied to {@link #getMinHeight()} to determine the height at which void damage starts to apply.
*
* @param minBuildHeightOffset offset from min build height
*/
void setVoidDamageMinBuildHeightOffset(double minBuildHeightOffset);
// Paper end - void damage configuration
// Paper start
/**
* @return The amount of entities in this world
*/
int getEntityCount();
/**
* @return The amount of block entities in this world
*/
int getTileEntityCount();
/**
* @return The amount of tickable block entities in this world
*/
int getTickableTileEntityCount();
/**
* @return The amount of chunks in this world
*/
int getChunkCount();
/**
* @return The amount of players in this world
*/
int getPlayerCount();
// Paper end
// Paper start - structure check API
/**
* Check if the naturally-generated structure exists at the position.
* <p>
* Note that if the position is not loaded, this may cause chunk loads/generation
* to check if a structure is at that position. Use {@link #isPositionLoaded(io.papermc.paper.math.Position)}
* to check if a position is loaded
*
* @param position the position to check at
* @param structure the structure to check for
* @return true if that structure exists at the position
*/
boolean hasStructureAt(io.papermc.paper.math.@NotNull Position position, @NotNull Structure structure);
/**
* Checks if this position is loaded.
*
* @param position position to check
* @return true if loaded
*/
default boolean isPositionLoaded(io.papermc.paper.math.@NotNull Position position) {
return this.isChunkLoaded(position.blockX() >> 4, position.blockZ() >> 4);
}
// Paper end
/**
* Gets the {@link Block} at the given coordinates
*
* @param x X-coordinate of the block
* @param y Y-coordinate of the block
* @param z Z-coordinate of the block
* @return Block at the given coordinates
*/
@NotNull
public Block getBlockAt(int x, int y, int z);
/**
* Gets the {@link Block} at the given {@link Location}
*
* @param location Location of the block
* @return Block at the given location
*/
@NotNull
default Block getBlockAt(@NotNull Location location) {
return this.getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
// Paper start
/**
* Gets the {@link Block} at the given block key
*
* @param key The block key. See {@link Block#getBlockKey()}
* @return Block at the key
* @see Block#getBlockKey(int, int, int)
* @deprecated only encodes y block ranges from -512 to 511 and represents an already changed implementation detail
*/
@NotNull
@Deprecated(since = "1.18.1")
public default Block getBlockAtKey(long key) {
int x = Block.getBlockKeyX(key);
int y = Block.getBlockKeyY(key);
int z = Block.getBlockKeyZ(key);
return getBlockAt(x, y, z);
}
/**
* Gets the {@link Location} at the given block key
*
* @param key The block key. See {@link Location#toBlockKey()}
* @return Location at the key
* @see Block#getBlockKey(int, int, int)
*/
@NotNull
@Deprecated(since = "1.18.1")
public default Location getLocationAtKey(long key) {
int x = Block.getBlockKeyX(key);
int y = Block.getBlockKeyY(key);
int z = Block.getBlockKeyZ(key);
return new Location(this, x, y, z);
}
// Paper end
/**
* Gets the highest non-empty (impassable) block at the given coordinates.
*
* @param x X-coordinate of the block
* @param z Z-coordinate of the block
* @return Highest non-empty block
*/
@NotNull
default Block getHighestBlockAt(int x, int z) {
return this.getBlockAt(x, this.getHighestBlockYAt(x, z), z);
}
/**
* Gets the highest non-empty (impassable) block at the given coordinates.
*
* @param location Coordinates to get the highest block
* @return Highest non-empty block
*/
@NotNull
default Block getHighestBlockAt(@NotNull Location location) {
return this.getHighestBlockAt(location.getBlockX(), location.getBlockZ());
}
/**
* Gets the highest block corresponding to the {@link HeightMap} at the
* given coordinates.
*
* @param x X-coordinate of the block
* @param z Z-coordinate of the block
* @param heightMap the heightMap that is used to determine the highest
* point
* @return Highest block corresponding to the {@link HeightMap}
*/
@NotNull
default Block getHighestBlockAt(int x, int z, @NotNull HeightMap heightMap) {
return this.getBlockAt(x, this.getHighestBlockYAt(x, z, heightMap), z);
}
/**
* Gets the highest block corresponding to the {@link HeightMap} at the
* given coordinates.
*
* @param location Coordinates to get the highest block
* @param heightMap the heightMap that is used to determine the highest
* point
* @return Highest block corresponding to the {@link HeightMap}
*/
@NotNull
default Block getHighestBlockAt(@NotNull Location location, @NotNull HeightMap heightMap) {
return this.getHighestBlockAt(location.getBlockX(), location.getBlockZ(), heightMap);
}
/**
* Gets the {@link Chunk} at the given coordinates
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return Chunk at the given coordinates
*/
@NotNull
public Chunk getChunkAt(int x, int z);
/**
* Gets the {@link Chunk} at the given coordinates
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @param generate Whether the chunk should be fully generated or not
* @return Chunk at the given coordinates
*/
@NotNull
public Chunk getChunkAt(int x, int z, boolean generate);
/**
* Gets the {@link Chunk} at the given {@link Location}
*
* @param location Location of the chunk
* @return Chunk at the given location
*/
@NotNull
default Chunk getChunkAt(@NotNull Location location) {
return this.getChunkAt(location.getBlockX() >> 4, location.getBlockZ() >> 4);
}
/**
* Gets the {@link Chunk} that contains the given {@link Block}
*
* @param block Block to get the containing chunk from
* @return The chunk that contains the given block
*/
@NotNull
public Chunk getChunkAt(@NotNull Block block);
// Paper start - chunk long key API
/**
* Gets the chunk at the specified chunk key, which is the X and Z packed into a long.
* <p>
* See {@link Chunk#getChunkKey()} for easy access to the key, or you may calculate it as:
* long chunkKey = (long) chunkX & 0xffffffffL | ((long) chunkZ & 0xffffffffL) >> 32;
*
* @param chunkKey The Chunk Key to look up the chunk by
* @return The chunk at the specified key
*/
@NotNull
default Chunk getChunkAt(long chunkKey) {
return getChunkAt(chunkKey, true);
}
/**
* Gets the chunk at the specified chunk key, which is the X and Z packed into a long.
* <p>
* See {@link Chunk#getChunkKey()} for easy access to the key, or you may calculate it as:
* long chunkKey = (long) chunkX & 0xffffffffL | ((long) chunkZ & 0xffffffffL) >> 32;
*
* @param chunkKey The Chunk Key to look up the chunk by
* @param generate Whether the chunk should be fully generated or not
* @return The chunk at the specified key
*/
@NotNull
default Chunk getChunkAt(long chunkKey, boolean generate) {
return getChunkAt((int) chunkKey, (int) (chunkKey >> 32), generate);
}
// Paper end - chunk long key API
// Paper start - isChunkGenerated API
/**
* Checks if a {@link Chunk} has been generated at the specified chunk key,
* which is the X and Z packed into a long.
*
* @param chunkKey The Chunk Key to look up the chunk by
* @return true if the chunk has been generated, otherwise false
*/
default boolean isChunkGenerated(long chunkKey) {
return isChunkGenerated((int) chunkKey, (int) (chunkKey >> 32));
}
// Paper end - isChunkGenerated API
/**
* Checks if the specified {@link Chunk} is loaded
*
* @param chunk The chunk to check
* @return true if the chunk is loaded, otherwise false
*/
public boolean isChunkLoaded(@NotNull Chunk chunk);
/**
* Gets an array of all loaded {@link Chunk}s
*
* @return Chunk[] containing all loaded chunks
*/
public @NotNull Chunk @NotNull [] getLoadedChunks();
/**
* Loads the specified {@link Chunk}.
* <p>
* <b>This method will keep the specified chunk loaded until one of the
* unload methods is manually called. Callers are advised to instead use
* getChunkAt which will only temporarily load the requested chunk.</b>
*
* @param chunk The chunk to load
*/
public void loadChunk(@NotNull Chunk chunk);
/**
* Checks if the {@link Chunk} at the specified coordinates is loaded
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return true if the chunk is loaded, otherwise false
*/
public boolean isChunkLoaded(int x, int z);
/**
* Checks if the {@link Chunk} at the specified coordinates is generated
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return true if the chunk is generated, otherwise false
*/
public boolean isChunkGenerated(int x, int z);
/**
* Checks if the {@link Chunk} at the specified coordinates is loaded and
* in use by one or more players
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return true if the chunk is loaded and in use by one or more players,
* otherwise false
* @deprecated This method was added to facilitate chunk garbage collection.
* As of the current Minecraft version chunks are now strictly managed and
* will not be loaded for more than 1 tick unless they are in use.
*/
@Deprecated(since = "1.14")
public boolean isChunkInUse(int x, int z);
/**
* Loads the {@link Chunk} at the specified coordinates.
* <p>
* <b>This method will keep the specified chunk loaded until one of the
* unload methods is manually called. Callers are advised to instead use
* getChunkAt which will only temporarily load the requested chunk.</b>
* <p>
* If the chunk does not exist, it will be generated.
* <p>
* This method is analogous to {@link #loadChunk(int, int, boolean)} where
* generate is true.
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
*/
default void loadChunk(int x, int z) {
this.loadChunk(x, z, true);
}
/**
* Loads the {@link Chunk} at the specified coordinates.
* <p>
* <b>This method will keep the specified chunk loaded until one of the
* unload methods is manually called. Callers are advised to instead use
* getChunkAt which will only temporarily load the requested chunk.</b>
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @param generate Whether or not to generate a chunk if it doesn't
* already exist
* @return true if the chunk has loaded successfully, otherwise false
*/
public boolean loadChunk(int x, int z, boolean generate);
/**
* Safely unloads and saves the {@link Chunk} at the specified coordinates
* <p>
* This method is analogous to {@link #unloadChunk(int, int, boolean)}
* where save is true.
*
* @param chunk the chunk to unload
* @return true if the chunk has unloaded successfully, otherwise false
*/
default boolean unloadChunk(@NotNull Chunk chunk) {
return this.unloadChunk(chunk.getX(), chunk.getZ());
}
/**
* Safely unloads and saves the {@link Chunk} at the specified coordinates
* <p>
* This method is analogous to {@link #unloadChunk(int, int, boolean)}
* where save is true.
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return true if the chunk has unloaded successfully, otherwise false
*/
default boolean unloadChunk(int x, int z) {
return this.unloadChunk(x, z, true);
}
/**
* Safely unloads and optionally saves the {@link Chunk} at the specified
* coordinates.
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @param save Whether or not to save the chunk
* @return true if the chunk has unloaded successfully, otherwise false
*/
public boolean unloadChunk(int x, int z, boolean save);
/**
* Safely queues the {@link Chunk} at the specified coordinates for
* unloading.
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return true is the queue attempt was successful, otherwise false
*/
public boolean unloadChunkRequest(int x, int z);
/**
* Regenerates the {@link Chunk} at the specified coordinates
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return Whether the chunk was actually regenerated
*
* @throws UnsupportedOperationException not implemented
* @deprecated regenerating a single chunk is not likely to produce the same
* chunk as before as terrain decoration may be spread across chunks. It may
* or may not change blocks in the adjacent chunks as well.
*/
@Deprecated(since = "1.13", forRemoval = true)
default boolean regenerateChunk(int x, int z) {
throw new UnsupportedOperationException("Not supported in this Minecraft version! This is not a bug.");
}
/**
* Resends the {@link Chunk} to all clients
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return Whether the chunk was actually refreshed
*
*/
public boolean refreshChunk(int x, int z);
/**
* Get a list of all players who are can view the specified chunk from their
* client
* <p>
* This list will be empty if no players are viewing the chunk, or the chunk
* is unloaded.
*
* @param chunk the chunk to check
* @return collection of players who can see the chunk
*/
@NotNull
public Collection<Player> getPlayersSeeingChunk(@NotNull Chunk chunk);
/**
* Get a list of all players who are can view the specified chunk from their
* client
* <p>
* This list will be empty if no players are viewing the chunk, or the chunk
* is unloaded.
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return collection of players who can see the chunk
*/
@NotNull
public Collection<Player> getPlayersSeeingChunk(int x, int z);
/**
* Gets whether the chunk at the specified chunk coordinates is force
* loaded.
* <p>
* A force loaded chunk will not be unloaded due to lack of player activity.
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return force load status
*/
public boolean isChunkForceLoaded(int x, int z);
/**
* Sets whether the chunk at the specified chunk coordinates is force
* loaded.
* <p>
* A force loaded chunk will not be unloaded due to lack of player activity.
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @param forced force load status
*/
public void setChunkForceLoaded(int x, int z, boolean forced);
/**
* Returns all force loaded chunks in this world.
* <p>
* A force loaded chunk will not be unloaded due to lack of player activity.
*
* @return unmodifiable collection of force loaded chunks
*/
@NotNull
public Collection<Chunk> getForceLoadedChunks();
/**
* Adds a plugin ticket for the specified chunk, loading the chunk if it is
* not already loaded.
* <p>
* A plugin ticket will prevent a chunk from unloading until it is
* explicitly removed. A plugin instance may only have one ticket per chunk,
* but each chunk can have multiple plugin tickets.
* </p>
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @param plugin Plugin which owns the ticket
* @return {@code true} if a plugin ticket was added, {@code false} if the
* ticket already exists for the plugin
* @throws IllegalStateException If the specified plugin is not enabled
* @see #removePluginChunkTicket(int, int, Plugin)
*/
public boolean addPluginChunkTicket(int x, int z, @NotNull Plugin plugin);
/**
* Removes the specified plugin's ticket for the specified chunk
* <p>
* A plugin ticket will prevent a chunk from unloading until it is
* explicitly removed. A plugin instance may only have one ticket per chunk,
* but each chunk can have multiple plugin tickets.
* </p>
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @param plugin Plugin which owns the ticket
* @return {@code true} if the plugin ticket was removed, {@code false} if
* there is no plugin ticket for the chunk
* @see #addPluginChunkTicket(int, int, Plugin)
*/
public boolean removePluginChunkTicket(int x, int z, @NotNull Plugin plugin);
/**
* Removes all plugin tickets for the specified plugin
* <p>
* A plugin ticket will prevent a chunk from unloading until it is
* explicitly removed. A plugin instance may only have one ticket per chunk,
* but each chunk can have multiple plugin tickets.
* </p>
*
* @param plugin Specified plugin
* @see #addPluginChunkTicket(int, int, Plugin)
* @see #removePluginChunkTicket(int, int, Plugin)
*/
public void removePluginChunkTickets(@NotNull Plugin plugin);
/**
* Retrieves a collection specifying which plugins have tickets for the
* specified chunk. This collection is not updated when plugin tickets are
* added or removed to the chunk.
* <p>
* A plugin ticket will prevent a chunk from unloading until it is
* explicitly removed. A plugin instance may only have one ticket per chunk,
* but each chunk can have multiple plugin tickets.
* </p>
*
* @param x X-coordinate of the chunk
* @param z Z-coordinate of the chunk
* @return unmodifiable collection containing which plugins have tickets for
* the chunk
* @see #addPluginChunkTicket(int, int, Plugin)
* @see #removePluginChunkTicket(int, int, Plugin)
*/
@NotNull
public Collection<Plugin> getPluginChunkTickets(int x, int z);
/**
* Returns a map of which plugins have tickets for what chunks. The returned
* map is not updated when plugin tickets are added or removed to chunks. If
* a plugin has no tickets, it will be absent from the map.
* <p>
* A plugin ticket will prevent a chunk from unloading until it is
* explicitly removed. A plugin instance may only have one ticket per chunk,
* but each chunk can have multiple plugin tickets.
* </p>
*
* @return unmodifiable map containing which plugins have tickets for what
* chunks
* @see #addPluginChunkTicket(int, int, Plugin)
* @see #removePluginChunkTicket(int, int, Plugin)
*/
@NotNull
public Map<Plugin, Collection<Chunk>> getPluginChunkTickets();
/**
* Gets all Chunks intersecting the given BoundingBox.
*
* @param box BoundingBox to check
* @return A collection of Chunks intersecting the given BoundingBox
*/
@NotNull
public Collection<Chunk> getIntersectingChunks(@NotNull BoundingBox box);
/**
* Drops an item at the specified {@link Location}
*
* @param location Location to drop the item
* @param item ItemStack to drop
* @return ItemDrop entity created as a result of this method
*/
@NotNull
default Item dropItem(@NotNull Location location, @NotNull ItemStack item) {
return this.dropItem(location, item, null);
}
/**
* Drops an item at the specified {@link Location}
* Note that functions will run before the entity is spawned
*
* @param location Location to drop the item
* @param item ItemStack to drop
* @param function the function to be run before the entity is spawned.
* @return ItemDrop entity created as a result of this method
*/
@NotNull
public Item dropItem(@NotNull Location location, @NotNull ItemStack item, @Nullable Consumer<? super Item> function);
/**
* Drops an item at the specified {@link Location} with a random offset
*
* @param location Location to drop the item
* @param item ItemStack to drop
* @return ItemDrop entity created as a result of this method
*/
@NotNull
default Item dropItemNaturally(@NotNull Location location, @NotNull ItemStack item) {
return this.dropItemNaturally(location, item, null);
}
/**
* Drops an item at the specified {@link Location} with a random offset
* Note that functions will run before the entity is spawned
*
* @param location Location to drop the item
* @param item ItemStack to drop
* @param function the function to be run before the entity is spawned.
* @return ItemDrop entity created as a result of this method
*/
@NotNull
public Item dropItemNaturally(@NotNull Location location, @NotNull ItemStack item, @Nullable Consumer<? super Item> function);
/**
* Creates an {@link Arrow} entity at the given {@link Location}
*
* @param location Location to spawn the arrow
* @param direction Direction to shoot the arrow in
* @param speed Speed of the arrow. A recommend speed is 0.6
* @param spread Spread of the arrow. A recommend spread is 12
* @return Arrow entity spawned as a result of this method
*/
@NotNull
default Arrow spawnArrow(@NotNull Location location, @NotNull Vector direction, float speed, float spread) {
return this.spawnArrow(location, direction, speed, spread, Arrow.class);
}
/**
* Creates an arrow entity of the given class at the given {@link Location}
*
* @param <T> type of arrow to spawn
* @param location Location to spawn the arrow
* @param direction Direction to shoot the arrow in
* @param speed Speed of the arrow. A recommend speed is 0.6
* @param spread Spread of the arrow. A recommend spread is 12
* @param clazz the Entity class for the arrow
* {@link org.bukkit.entity.SpectralArrow},{@link org.bukkit.entity.Arrow},{@link org.bukkit.entity.TippedArrow}
* @return Arrow entity spawned as a result of this method
*/
@NotNull
public <T extends AbstractArrow> T spawnArrow(@NotNull Location location, @NotNull Vector direction, float speed, float spread, @NotNull Class<T> clazz);
/**
* Creates a tree at the given {@link Location}
*
* @param location Location to spawn the tree
* @param type Type of the tree to create
* @return true if the tree was created successfully, otherwise false
* @deprecated in favor of {@link #generateTree(Location, java.util.Random, TreeType)} to specify its own random instance
* and this method is not accessible through {@link RegionAccessor}
*/
@Deprecated(since = "1.21.6")
public boolean generateTree(@NotNull Location location, @NotNull TreeType type);
/**
* Creates a tree at the given {@link Location}
*
* @param loc Location to spawn the tree
* @param type Type of the tree to create
* @param delegate A class to call for each block changed as a result of
* this method
* @return true if the tree was created successfully, otherwise false
* @see #generateTree(org.bukkit.Location, java.util.Random, org.bukkit.TreeType, java.util.function.Consumer)
* @deprecated this method does not handle block entities (bee nests)
*/
@Deprecated(since = "1.17.1")
public boolean generateTree(@NotNull Location loc, @NotNull TreeType type, @NotNull BlockChangeDelegate delegate);
/**
* Strikes lightning at the given {@link Location}
*
* @param loc The location to strike lightning
* @return The lightning entity.
*/
@NotNull
public LightningStrike strikeLightning(@NotNull Location loc);
/**
* Strikes lightning at the given {@link Location} without doing damage
*
* @param loc The location to strike lightning
* @return The lightning entity.
*/
@NotNull
public LightningStrike strikeLightningEffect(@NotNull Location loc);
// Paper start
/**
* Finds the location of the nearest unobstructed Lightning Rod in a 128-block
* radius around the given location. Returns {@code null} if no Lightning Rod is found.
*
* <p>Note: To activate a Lightning Rod, the position one block above it must be struck by lightning.</p>
*
* @param location {@link Location} to search for Lightning Rod around
* @return {@link Location} of Lightning Rod or {@code null}
*/
@Nullable
public Location findLightningRod(@NotNull Location location);
/**
* Finds a target {@link Location} for lightning to strike.
* <p>It selects from (in the following order):</p>
* <ol>
* <li>the block above the nearest Lightning Rod, found using {@link World#findLightningRod(Location)}</li>
* <li>a random {@link LivingEntity} that can see the sky in a 6x6 cuboid
* around input X/Z coordinates. Y ranges from <i>the highest motion-blocking
* block at the input X/Z - 3</i> to <i>the height limit + 3</i></li>
* </ol>
* <p>Returns {@code null} if no target is found.</p>
*
* @param location {@link Location} to search for target around
* @return lightning target or {@code null}
*/
@Nullable
public Location findLightningTarget(@NotNull Location location);
// Paper end
/**
* Get a list of all entities in this World
*
* @return A List of all Entities currently residing in this world
*/
@NotNull
public List<Entity> getEntities();
/**
* Get a list of all living entities in this World
*
* @return A List of all LivingEntities currently residing in this world
*/
@NotNull
public List<LivingEntity> getLivingEntities();
/**
* Get a collection of all entities in this World matching the given
* class/interface
*
* @param <T> an entity subclass
* @param classes The classes representing the types of entity to match
* @return A List of all Entities currently residing in this world that
* match the given class/interface
*/
@Deprecated(since = "1.1")
@NotNull
public <T extends Entity> Collection<T> getEntitiesByClass(@NotNull Class<T>... classes);
/**
* Get a collection of all entities in this World matching the given
* class/interface
*
* @param <T> an entity subclass
* @param cls The class representing the type of entity to match
* @return A List of all Entities currently residing in this world that
* match the given class/interface
*/
@NotNull
public <T extends Entity> Collection<T> getEntitiesByClass(@NotNull Class<T> cls);
/**
* Get a collection of all entities in this World matching any of the
* given classes/interfaces
*
* @param classes The classes representing the types of entity to match
* @return A List of all Entities currently residing in this world that
* match one or more of the given classes/interfaces
*/
@NotNull
public Collection<Entity> getEntitiesByClasses(@NotNull Class<?>... classes);
// Paper start - additional getNearbyEntities API
/**
* Gets nearby LivingEntities within the specified radius (bounding box)
*
* @param loc Center location
* @param radius Radius
* @return the collection of entities near location. This will always be a non-null collection.
*/
default @NotNull Collection<LivingEntity> getNearbyLivingEntities(final @NotNull Location loc, final double radius) {
return this.getNearbyEntitiesByType(LivingEntity.class, loc, radius, radius, radius);
}
/**
* Gets nearby LivingEntities within the specified radius (bounding box)
*
* @param loc Center location
* @param xzRadius X/Z Radius
* @param yRadius Y Radius
* @return the collection of entities near location. This will always be a non-null collection.
*/
default @NotNull Collection<LivingEntity> getNearbyLivingEntities(final @NotNull Location loc, final double xzRadius, final double yRadius) {
return this.getNearbyEntitiesByType(LivingEntity.class, loc, xzRadius, yRadius, xzRadius);
}
/**
* Gets nearby LivingEntities within the specified radius (bounding box)
*
* @param loc Center location
* @param xRadius X Radius
* @param yRadius Y Radius
* @param zRadius Z radius
* @return the collection of entities near location. This will always be a non-null collection.
*/
default @NotNull Collection<LivingEntity> getNearbyLivingEntities(final @NotNull Location loc, final double xRadius, final double yRadius, final double zRadius) {
return this.getNearbyEntitiesByType(LivingEntity.class, loc, xRadius, yRadius, zRadius);
}
/**
* Gets nearby LivingEntities within the specified radius (bounding box)
*
* @param loc Center location
* @param radius X Radius
* @param predicate a predicate used to filter results
* @return the collection of living entities near location. This will always be a non-null collection
*/
default @NotNull Collection<LivingEntity> getNearbyLivingEntities(final @NotNull Location loc, final double radius, final @Nullable Predicate<? super LivingEntity> predicate) {
return this.getNearbyEntitiesByType(LivingEntity.class, loc, radius, radius, radius, predicate);
}
/**
* Gets nearby LivingEntities within the specified radius (bounding box)
*
* @param loc Center location
* @param xzRadius X/Z Radius
* @param yRadius Y Radius
* @param predicate a predicate used to filter results
* @return the collection of living entities near location. This will always be a non-null collection
*/
default @NotNull Collection<LivingEntity> getNearbyLivingEntities(final @NotNull Location loc, final double xzRadius, final double yRadius, final @Nullable Predicate<? super LivingEntity> predicate) {
return this.getNearbyEntitiesByType(LivingEntity.class, loc, xzRadius, yRadius, xzRadius, predicate);
}
/**
* Gets nearby LivingEntities within the specified radius (bounding box)
*
* @param loc Center location
* @param xRadius X Radius
* @param yRadius Y Radius
* @param zRadius Z radius
* @param predicate a predicate used to filter results
* @return the collection of living entities near location. This will always be a non-null collection.
*/
default @NotNull Collection<LivingEntity> getNearbyLivingEntities(final @NotNull Location loc, final double xRadius, final double yRadius, final double zRadius, final @Nullable Predicate<? super LivingEntity> predicate) {
return this.getNearbyEntitiesByType(LivingEntity.class, loc, xRadius, yRadius, zRadius, predicate);
}
/**
* Gets nearby players within the specified radius (bounding box)
*
* @param loc Center location
* @param radius X/Y/Z Radius
* @return the collection of living entities near location. This will always be a non-null collection.
*/
default @NotNull Collection<Player> getNearbyPlayers(final @NotNull Location loc, final double radius) {
return this.getNearbyEntitiesByType(Player.class, loc, radius, radius, radius);
}
/**
* Gets nearby players within the specified radius (bounding box)
*
* @param loc Center location
* @param xzRadius X/Z Radius
* @param yRadius Y Radius
* @return the collection of living entities near location. This will always be a non-null collection.
*/
default @NotNull Collection<Player> getNearbyPlayers(final @NotNull Location loc, final double xzRadius, final double yRadius) {
return this.getNearbyEntitiesByType(Player.class, loc, xzRadius, yRadius, xzRadius);
}
/**
* Gets nearby players within the specified radius (bounding box)
*
* @param loc Center location
* @param xRadius X Radius
* @param yRadius Y Radius
* @param zRadius Z Radius
* @return the collection of players near location. This will always be a non-null collection.
*/
default @NotNull Collection<Player> getNearbyPlayers(final @NotNull Location loc, final double xRadius, final double yRadius, final double zRadius) {
return this.getNearbyEntitiesByType(Player.class, loc, xRadius, yRadius, zRadius);
}
/**
* Gets nearby players within the specified radius (bounding box)
*
* @param loc Center location
* @param radius X/Y/Z Radius
* @param predicate a predicate used to filter results
* @return the collection of players near location. This will always be a non-null collection.
*/
default @NotNull Collection<Player> getNearbyPlayers(final @NotNull Location loc, final double radius, final @Nullable Predicate<? super Player> predicate) {
return this.getNearbyEntitiesByType(Player.class, loc, radius, radius, radius, predicate);