-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathBlockChanger.java
3285 lines (2987 loc) · 120 KB
/
BlockChanger.java
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 me.blockchanger;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
/**
* @version 1.8.2
* @author TheGaming999
* @apiNote 1.7 - 1.20.4 easy to use class to take advantage of different
* methods
* that allow you to change blocks at rocket speeds
* <p>
* Made with the help of <a href=
* "https://github.com/CryptoMorin/XSeries/blob/master/src/main/java/com/cryptomorin/xseries/ReflectionUtils.java">ReflectionUtils</a>
* by <a href="https://github.com/CryptoMorin">CryptoMorin</a>
* </p>
* <p>
* Uses the methods found
* <a href="https://www.spigotmc.org/threads/395868/">here</a> by
* <a href="https://www.spigotmc.org/members/220001/">NascentNova</a>
* </p>
* <p>
* Async methods were made using
* <a href="https://www.spigotmc.org/threads/409003/">How to handle
* heavy splittable tasks</a> by
* <a href="https://www.spigotmc.org/members/43809/">7smile7</a>
* </p>
*/
public class BlockChanger {
private static final Map<Material, Object> NMS_BLOCK_MATERIALS = new HashMap<>();
private static final Map<String, Object> NMS_BLOCK_NAMES = new HashMap<>();
private static final Map<World, Object> NMS_WORLDS = new HashMap<>();
private static final Map<String, Object> NMS_WORLD_NAMES = new HashMap<>();
private static final MethodHandle WORLD_GET_HANDLE;
/**
* <p>
* Invoked parameters ->
* <i>CraftItemStack.asNMSCopy({@literal<org.bukkit.inventory.ItemStack>})</i>
*/
private static final MethodHandle NMS_ITEM_STACK_COPY;
/**
* <p>
* Invoked parameters ->
* <i>Block.asBlock({@literal<net.minecraft.world.item.Item>})</i>
*/
private static final MethodHandle NMS_BLOCK_FROM_ITEM;
/**
* <p>
* Invoked parameters ->
* <i>Block.getByName({@literal<net.minecraft.world.item.Item>})</i>
*/
private static final MethodHandle NMS_BLOCK_FROM_NAME;
/**
* <p>
* Invoked parameters ->
* <i>{@literal<net.minecraft.world.block.Block>}.getName()</i>
*/
private static final MethodHandle NMS_BLOCK_NAME;
/**
* <p>
* Invoked parameters ->
* <i>{@literal<net.minecraft.world.item.ItemStack>}.getItem()</i>
*/
private static final MethodHandle NMS_ITEM_STACK_TO_ITEM;
/**
* <p>
* Changes block data / durability
* </p>
* <p>
* Invoked parameters ->
* <i>{@literal<net.minecraft.world.block.Block>}.fromLegacyData({@literal<int>});</i>
* </p>
*/
private static final MethodHandle BLOCK_DATA_FROM_LEGACY_DATA;
/**
* <p>
* Invoked parameters ->
* <i>{@literal<net.minecraft.world.level.block.Block>}.getBlockData()</i>
*/
private static final MethodHandle ITEM_TO_BLOCK_DATA;
private static final MethodHandle SET_TYPE_AND_DATA;
private static final MethodHandle WORLD_GET_CHUNK;
private static final MethodHandle CHUNK_GET_SECTIONS;
private static final MethodHandle CHUNK_SECTION_SET_TYPE;
/**
* <p>
* Behavior -> <i>{@literal<Chunk>}.getLevelHeightAccessor()</i>
*/
private static final MethodHandle GET_LEVEL_HEIGHT_ACCESSOR;
/**
* <p>
* Behavior -> <i>{@literal<Chunk>}.getSectionIndex()</i> or
* <i>{@literal<LevelHeightAccessor>}.getSectionIndex()</i>
*/
private static final MethodHandle GET_SECTION_INDEX;
/**
* <p>
* Behavior -> <i>Chunk.getSections[{@literal<index>}] =
* {@literal<ChunkSection>}</i>
* </p>
*/
private static final MethodHandle SET_SECTION_ELEMENT;
private static final MethodHandle CHUNK_SECTION;
private static final MethodHandle CHUNK_SET_TYPE;
private static final MethodHandle BLOCK_NOTIFY;
private static final MethodHandle CRAFT_BLOCK_GET_NMS_BLOCK;
private static final MethodHandle NMS_BLOCK_GET_BLOCK_DATA;
/**
* A map containing placed tile entities, world.capturedTileEntities;
*/
private static final MethodHandle WORLD_CAPTURED_TILE_ENTITIES;
/**
* Check if tile entity is in a map, world.capturedTileEntities.containsKey(x);
*/
private static final MethodHandle IS_TILE_ENTITY;
/**
* Remove a title entity from a map, world.capturedTileEntities.remove(x);
*/
private static final MethodHandle WORLD_REMOVE_TILE_ENTITY;
private static final MethodHandle GET_NMS_TILE_ENTITY;
private static final MethodHandle GET_SNAPSHOT_NBT;
private static final MethodHandle GET_SNAPSHOT;
private static final BlockUpdater BLOCK_UPDATER;
private static final BlockPositionConstructor BLOCK_POSITION_CONSTRUCTOR;
private static final BlockDataRetriever BLOCK_DATA_GETTER;
private static final TileEntityManager TILE_ENTITY_MANAGER;
private static final String AVAILABLE_BLOCKS;
private static final UncheckedSetters UNCHECKED_SETTERS;
private static final WorkloadRunnable WORKLOAD_RUNNABLE;
private static final JavaPlugin PLUGIN;
private static final Object AIR_BLOCK_DATA;
static {
Class<?> worldServer = ReflectionUtils.getNMSClass("server.level", "WorldServer");
Class<?> world = ReflectionUtils.getNMSClass("world.level", "World");
Class<?> craftWorld = ReflectionUtils.getCraftClass("CraftWorld");
Class<?> craftBlock = ReflectionUtils.getCraftClass("block.CraftBlock");
Class<?> blockPosition = ReflectionUtils.supports(8) ? ReflectionUtils.getNMSClass("core", "BlockPosition")
: null;
Class<?> blocks = ReflectionUtils.getNMSClass("world.level.block", "Blocks");
Class<?> mutableBlockPosition = ReflectionUtils.supports(8)
? ReflectionUtils.getNMSClass("core", "BlockPosition$MutableBlockPosition") : null;
Class<?> blockData = ReflectionUtils.supports(8)
? ReflectionUtils.getNMSClass("world.level.block.state", "IBlockData") : null;
Class<?> craftItemStack = ReflectionUtils.getCraftClass("inventory.CraftItemStack");
Class<?> worldItemStack = ReflectionUtils.getNMSClass("world.item", "ItemStack");
Class<?> item = ReflectionUtils.getNMSClass("world.item", "Item");
Class<?> block = ReflectionUtils.getNMSClass("world.level.block", "Block");
Class<?> chunk = ReflectionUtils.getNMSClass("world.level.chunk", "Chunk");
Class<?> chunkSection = ReflectionUtils.getNMSClass("world.level.chunk", "ChunkSection");
Class<?> levelHeightAccessor = ReflectionUtils.supports(17)
? ReflectionUtils.getNMSClass("world.level.LevelHeightAccessor") : null;
Class<?> blockDataReference = ReflectionUtils.supports(13) ? craftBlock : block;
Class<?> craftBlockEntityState = ReflectionUtils.supports(12)
? ReflectionUtils.getCraftClass("block.CraftBlockEntityState")
: ReflectionUtils.getCraftClass("block.CraftBlockState");
Class<?> nbtTagCompound = ReflectionUtils.getNMSClass("nbt", "NBTTagCompound");
Method getNMSBlockMethod = null;
if (ReflectionUtils.MINOR_NUMBER <= 12) {
try {
getNMSBlockMethod = craftBlock.getDeclaredMethod("getNMSBlock");
getNMSBlockMethod.setAccessible(true);
} catch (NoSuchMethodException | SecurityException e2) {
e2.printStackTrace();
}
}
MethodHandles.Lookup lookup = MethodHandles.lookup();
Object airBlockData = null;
try {
airBlockData = lookup
.findStatic(block, ReflectionUtils.supports(18) ? "a" : "getByCombinedId",
MethodType.methodType(blockData, int.class))
.invoke(0);
} catch (Throwable e1) {
e1.printStackTrace();
}
AIR_BLOCK_DATA = airBlockData;
MethodHandle worldGetHandle = null;
MethodHandle blockPositionXYZ = null;
MethodHandle nmsItemStackCopy = null;
MethodHandle blockFromItem = null;
MethodHandle blockFromName = null;
MethodHandle blockName = null;
MethodHandle nmsItemStackToItem = null;
MethodHandle itemToBlockData = null;
MethodHandle setTypeAndData = null;
MethodHandle worldGetChunk = null;
MethodHandle chunkSetTypeM = null;
MethodHandle blockNotify = null;
MethodHandle chunkGetSections = null;
MethodHandle chunkSectionSetType = null;
MethodHandle getLevelHeightAccessor = null;
MethodHandle getSectionIndex = null;
MethodHandle setSectionElement = null;
MethodHandle chunkSectionConstructor = null;
MethodHandle blockDataFromLegacyData = null;
MethodHandle mutableBlockPositionSet = null;
MethodHandle mutableBlockPositionXYZ = null;
MethodHandle craftBlockGetNMSBlock = null;
MethodHandle nmsBlockGetBlockData = null;
MethodHandle worldRemoveTileEntity = null;
MethodHandle worldCapturedTileEntities = null;
MethodHandle capturedTileEntitiesContainsKey = null;
MethodHandle getNMSTileEntity = null;
MethodHandle getSnapshot = null;
MethodHandle getSnapshotNBT = null;
// Method names
String asBlock = ReflectionUtils.supports(18) || ReflectionUtils.MINOR_NUMBER < 8 ? "a" : "asBlock";
String blockGetByName = ReflectionUtils.supports(8) ? "getByName" : "idk";
String blockGetName = ReflectionUtils.supports(20) ? ReflectionUtils.supportsPatch(4) ? "h" : "f"
: ReflectionUtils.supports(18) ? "h" : "a";
String getBlockData = ReflectionUtils.supports(20) ? ReflectionUtils.supportsPatch(4) ? "o" : "n"
: ReflectionUtils.supports(19) ? ReflectionUtils.supportsPatch(3) ? "o" : "m"
: ReflectionUtils.supports(18) ? "n" : "getBlockData";
String getItem = ReflectionUtils.supports(20) ? "d" : ReflectionUtils.supports(18) ? "c" : "getItem";
String setType = ReflectionUtils.supports(18) ? "a" : "setTypeAndData";
String getChunkAt = ReflectionUtils.supports(18) ? "d" : "getChunkAt";
String chunkSetType = ReflectionUtils.supports(18) ? "a" : ReflectionUtils.MINOR_NUMBER < 8 ? "setTypeId"
: ReflectionUtils.MINOR_NUMBER <= 12 ? "a" : "setType";
String notify = ReflectionUtils.supports(18) ? "a" : "notify";
String getSections = ReflectionUtils.supports(18) ? "d" : "getSections";
String sectionSetType = ReflectionUtils.supports(18) ? "a" : ReflectionUtils.MINOR_NUMBER < 8 ? "setTypeId"
: "setType";
String setXYZ = ReflectionUtils.supports(13) ? "d" : "c";
String getBlockData2 = ReflectionUtils.supports(13) ? "getNMS" : "getBlockData";
String removeTileEntity = ReflectionUtils.supports(20) && ReflectionUtils.supportsPatch(4) ? "o"
: ReflectionUtils.supports(19) ? "n" : ReflectionUtils.supports(18) ? "m"
: ReflectionUtils.supports(14) ? "removeTileEntity" : ReflectionUtils.supports(13) ? "n"
: ReflectionUtils.supports(9) ? "s" : ReflectionUtils.supports(8) ? "t" : "p";
MethodType notifyMethodType = ReflectionUtils.MINOR_NUMBER >= 14 ? MethodType.methodType(void.class,
blockPosition, blockData, blockData, int.class)
: ReflectionUtils.MINOR_NUMBER < 8 ? MethodType.methodType(void.class, int.class, int.class, int.class)
: ReflectionUtils.MINOR_NUMBER == 8 ? MethodType.methodType(void.class, blockPosition)
: MethodType.methodType(void.class, blockPosition, blockData, blockData, int.class);
MethodType chunkSetTypeMethodType = ReflectionUtils.MINOR_NUMBER <= 12
? ReflectionUtils.MINOR_NUMBER >= 8 ? MethodType.methodType(blockData, blockPosition, blockData)
: MethodType.methodType(boolean.class, int.class, int.class, int.class, block, int.class)
: MethodType.methodType(blockData, blockPosition, blockData, boolean.class);
MethodType chunkSectionSetTypeMethodType = ReflectionUtils.MINOR_NUMBER >= 14 ? MethodType.methodType(blockData,
int.class, int.class, int.class, blockData)
: ReflectionUtils.MINOR_NUMBER < 8
? MethodType.methodType(void.class, int.class, int.class, int.class, block)
: MethodType.methodType(void.class, int.class, int.class, int.class, blockData);
MethodType chunkSectionConstructorMT = ReflectionUtils.supports(18) ? null
: ReflectionUtils.supports(14) ? MethodType.methodType(void.class, int.class)
: MethodType.methodType(void.class, int.class, boolean.class);
MethodType removeTileEntityMethodType = ReflectionUtils.supports(8)
? MethodType.methodType(void.class, blockPosition)
: MethodType.methodType(void.class, int.class, int.class, int.class);
MethodType fromLegacyDataMethodType = ReflectionUtils.MINOR_NUMBER <= 12
? MethodType.methodType(blockData, int.class) : null;
BlockPositionConstructor blockPositionConstructor = null;
try {
worldGetHandle = lookup.findVirtual(craftWorld, "getHandle", MethodType.methodType(worldServer));
worldGetChunk = lookup.findVirtual(worldServer, getChunkAt,
MethodType.methodType(chunk, int.class, int.class));
nmsItemStackCopy = lookup.findStatic(craftItemStack, "asNMSCopy",
MethodType.methodType(worldItemStack, ItemStack.class));
blockFromItem = lookup.findStatic(block, asBlock, MethodType.methodType(block, item));
blockName = lookup.findVirtual(block, blockGetName, MethodType.methodType(String.class));
if (ReflectionUtils.MINOR_NUMBER < 18) {
blockFromName = lookup.findStatic(block, blockGetByName, MethodType.methodType(block, String.class));
}
if (ReflectionUtils.supports(8)) {
blockPositionXYZ = lookup.findConstructor(blockPosition,
MethodType.methodType(void.class, int.class, int.class, int.class));
mutableBlockPositionXYZ = lookup.findConstructor(mutableBlockPosition,
MethodType.methodType(void.class, int.class, int.class, int.class));
itemToBlockData = lookup.findVirtual(block, getBlockData, MethodType.methodType(blockData));
setTypeAndData = lookup.findVirtual(worldServer, setType,
MethodType.methodType(boolean.class, blockPosition, blockData, int.class));
mutableBlockPositionSet = lookup.findVirtual(mutableBlockPosition, setXYZ,
MethodType.methodType(mutableBlockPosition, int.class, int.class, int.class));
blockPositionConstructor = new BlockPositionNormal(blockPositionXYZ, mutableBlockPositionXYZ,
mutableBlockPositionSet);
} else {
blockPositionXYZ = lookup.findConstructor(Location.class,
MethodType.methodType(void.class, World.class, double.class, double.class, double.class));
mutableBlockPositionXYZ = lookup.findConstructor(Location.class,
MethodType.methodType(void.class, World.class, double.class, double.class, double.class));
blockPositionConstructor = new BlockPositionAncient(blockPositionXYZ, mutableBlockPositionXYZ);
}
nmsItemStackToItem = lookup.findVirtual(worldItemStack, getItem, MethodType.methodType(item));
blockDataFromLegacyData = ReflectionUtils.MINOR_NUMBER <= 12
? lookup.findVirtual(block, "fromLegacyData", fromLegacyDataMethodType) : null;
chunkSetTypeM = lookup.findVirtual(chunk, chunkSetType, chunkSetTypeMethodType);
blockNotify = lookup.findVirtual(worldServer, notify, notifyMethodType);
chunkGetSections = lookup.findVirtual(chunk, getSections,
MethodType.methodType(ReflectionUtils.toArrayClass(chunkSection)));
chunkSectionSetType = lookup.findVirtual(chunkSection, sectionSetType, chunkSectionSetTypeMethodType);
setSectionElement = MethodHandles.arrayElementSetter(ReflectionUtils.toArrayClass(chunkSection));
chunkSectionConstructor = !ReflectionUtils.supports(18)
? lookup.findConstructor(chunkSection, chunkSectionConstructorMT) : null;
if (ReflectionUtils.supports(18)) {
getLevelHeightAccessor = lookup.findVirtual(chunk, "z", MethodType.methodType(levelHeightAccessor));
getSectionIndex = lookup.findVirtual(levelHeightAccessor, "e",
MethodType.methodType(int.class, int.class));
} else if (ReflectionUtils.supports(17)) {
getSectionIndex = lookup.findVirtual(chunk, "getSectionIndex",
MethodType.methodType(int.class, int.class));
}
craftBlockGetNMSBlock = ReflectionUtils.MINOR_NUMBER <= 12 ? lookup.unreflect(getNMSBlockMethod) : null;
nmsBlockGetBlockData = lookup.findVirtual(blockDataReference, getBlockData2,
MethodType.methodType(blockData));
worldRemoveTileEntity = lookup.findVirtual(world, removeTileEntity, removeTileEntityMethodType);
worldCapturedTileEntities = ReflectionUtils.supports(8)
? lookup.findGetter(world, "capturedTileEntities", Map.class) : null;
capturedTileEntitiesContainsKey = ReflectionUtils.supports(8)
? lookup.findVirtual(Map.class, "containsKey", MethodType.methodType(boolean.class, Object.class))
: null;
Method getTileEntityMethod = craftBlockEntityState.getDeclaredMethod("getTileEntity");
Method getSnapshotMethod = ReflectionUtils.supports(12)
? craftBlockEntityState.getDeclaredMethod("getSnapshot") : null;
if (getTileEntityMethod != null) getTileEntityMethod.setAccessible(true);
if (getSnapshotMethod != null) getSnapshotMethod.setAccessible(true);
getNMSTileEntity = lookup.unreflect(getTileEntityMethod);
getSnapshot = ReflectionUtils.supports(12) ? lookup.unreflect(getSnapshotMethod) : null;
getSnapshotNBT = ReflectionUtils.supports(12)
? lookup.findVirtual(craftBlockEntityState, "getSnapshotNBT", MethodType.methodType(nbtTagCompound))
: null;
} catch (NoSuchMethodException | IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}
WORLD_GET_HANDLE = worldGetHandle;
WORLD_GET_CHUNK = worldGetChunk;
NMS_ITEM_STACK_COPY = nmsItemStackCopy;
NMS_BLOCK_FROM_ITEM = blockFromItem;
NMS_BLOCK_FROM_NAME = blockFromName;
NMS_BLOCK_NAME = blockName;
NMS_ITEM_STACK_TO_ITEM = nmsItemStackToItem;
ITEM_TO_BLOCK_DATA = itemToBlockData;
SET_TYPE_AND_DATA = setTypeAndData;
CHUNK_SET_TYPE = chunkSetTypeM;
BLOCK_NOTIFY = blockNotify;
CHUNK_GET_SECTIONS = chunkGetSections;
CHUNK_SECTION_SET_TYPE = chunkSectionSetType;
GET_LEVEL_HEIGHT_ACCESSOR = getLevelHeightAccessor;
GET_SECTION_INDEX = getSectionIndex;
SET_SECTION_ELEMENT = setSectionElement;
CHUNK_SECTION = chunkSectionConstructor;
BLOCK_POSITION_CONSTRUCTOR = blockPositionConstructor;
BLOCK_DATA_FROM_LEGACY_DATA = blockDataFromLegacyData;
CRAFT_BLOCK_GET_NMS_BLOCK = craftBlockGetNMSBlock;
NMS_BLOCK_GET_BLOCK_DATA = nmsBlockGetBlockData;
WORLD_REMOVE_TILE_ENTITY = worldRemoveTileEntity;
WORLD_CAPTURED_TILE_ENTITIES = worldCapturedTileEntities;
IS_TILE_ENTITY = capturedTileEntitiesContainsKey;
GET_NMS_TILE_ENTITY = getNMSTileEntity;
GET_SNAPSHOT = getSnapshot;
GET_SNAPSHOT_NBT = getSnapshotNBT;
BLOCK_DATA_GETTER = ReflectionUtils.supports(13) ? new BlockDataGetter()
: ReflectionUtils.supports(8) ? new BlockDataGetterLegacy() : new BlockDataGetterAncient();
BLOCK_UPDATER = ReflectionUtils.supports(18) ? new BlockUpdaterLatest(BLOCK_NOTIFY, CHUNK_SET_TYPE,
GET_SECTION_INDEX, GET_LEVEL_HEIGHT_ACCESSOR)
: ReflectionUtils.supports(17) ? new BlockUpdater17(BLOCK_NOTIFY, CHUNK_SET_TYPE, GET_SECTION_INDEX,
CHUNK_SECTION, SET_SECTION_ELEMENT)
: ReflectionUtils.supports(13)
? new BlockUpdater13(BLOCK_NOTIFY, CHUNK_SET_TYPE, CHUNK_SECTION, SET_SECTION_ELEMENT)
: ReflectionUtils.supports(9)
? new BlockUpdater9(BLOCK_NOTIFY, CHUNK_SET_TYPE, CHUNK_SECTION, SET_SECTION_ELEMENT)
: ReflectionUtils.supports(8)
? new BlockUpdaterLegacy(BLOCK_NOTIFY, CHUNK_SET_TYPE, CHUNK_SECTION, SET_SECTION_ELEMENT)
: new BlockUpdaterAncient(BLOCK_NOTIFY, CHUNK_SET_TYPE, CHUNK_SECTION, SET_SECTION_ELEMENT);
TILE_ENTITY_MANAGER = ReflectionUtils.supports(8) ? new TileEntityManagerSupported()
: new TileEntityManagerDummy();
Arrays.stream(Material.values()).filter(Material::isBlock).forEach(BlockChanger::addNMSBlockData);
NMS_BLOCK_MATERIALS.put(Material.AIR, AIR_BLOCK_DATA);
AVAILABLE_BLOCKS = String.join(", ",
NMS_BLOCK_MATERIALS.keySet()
.stream()
.map(Material::name)
.map(String::toLowerCase)
.collect(Collectors.toList()));
Arrays.stream(blocks.getDeclaredFields()).filter(field -> field.getType() == block).map(field -> {
try {
return field.get(block);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
}).forEach(nmsBlock -> {
try {
String name = (String) NMS_BLOCK_NAME.invoke(nmsBlock);
name = name.substring(name.lastIndexOf(".") + 1, name.length()).toUpperCase();
NMS_BLOCK_NAMES.put(name, nmsBlock);
} catch (Throwable e) {
e.printStackTrace();
}
});
Bukkit.getWorlds().forEach(BlockChanger::addNMSWorld);
UNCHECKED_SETTERS = new UncheckedSetters();
WORKLOAD_RUNNABLE = new WorkloadRunnable();
PLUGIN = JavaPlugin.getProvidingPlugin(BlockChanger.class);
Bukkit.getScheduler().runTaskTimer(PLUGIN, WORKLOAD_RUNNABLE, 1, 1);
}
/**
* Simply calls <b>static {}</b> so methods get cached, and ensures that the
* first setBlock method call is executed as fast as possible. In addition to
* that, it checks whether methods have been initalized correctly or not by
* spitting exceptions if there is any issue.
* <p>
* This already happens when calling a method for the first time.
* </p>
* <p>
* Added for debugging purposes.
* </p>
*/
public static void test() {}
private static void addNMSBlockData(Material material) {
ItemStack itemStack = new ItemStack(material);
Object nmsData = getNMSBlockData(itemStack);
if (nmsData != null) NMS_BLOCK_MATERIALS.put(material, nmsData);
}
private static void addNMSWorld(World world) {
if (world == null) return;
Object nmsWorld = getNMSWorld(world);
if (nmsWorld != null) {
NMS_WORLDS.put(world, nmsWorld);
NMS_WORLD_NAMES.put(world.getName(), nmsWorld);
}
}
/**
* If a material fails to pass this method, then it cannot be placed using any
* of the setBlock methods.
*
* @param material to check
* @return whether the given material can be placed or not
*/
public static boolean isPlaceable(Material material) {
try {
return NMS_BLOCK_MATERIALS.containsKey(material) || NMS_BLOCK_NAMES.containsKey(material.name())
|| BLOCK_DATA_GETTER.getNMSItem(new ItemStack(material)) != null;
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}
/**
* If an ItemStack fails to pass this method, then it cannot be placed using any
* of this class methods.
*
* @param itemStack to check
* @return whether the given ItemStack can be placed or not
*/
public static boolean isPlaceable(ItemStack itemStack) {
Material mat = itemStack.getType();
try {
return NMS_BLOCK_MATERIALS.containsKey(mat) || NMS_BLOCK_NAMES.containsKey(mat.name())
|| BLOCK_DATA_GETTER.getNMSItem(itemStack) != null;
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}
public static boolean isValidNMSBlockName(String name) {
return NMS_BLOCK_NAMES.containsKey(name);
}
public static boolean isValidNMSBlockName(ItemStack itemStack) {
return NMS_BLOCK_NAMES.containsKey(itemStack.getType().name());
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the block is located
* @param x x location point
* @param y y location point
* @param z z location point
* @param material block material to apply on the created block
* @throws IllegalArgumentException if material is not perceived as a block
* material
*/
public static void setBlock(World world, int x, int y, int z, Material material) {
setBlock(world, x, y, z, material, true);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the block is located
* @param x x location point
* @param y y location point
* @param z z location point
* @param itemStack ItemStack to apply on the created block
* @throws IllegalArgumentException if material is not perceived as a block
* material
*/
public static void setBlock(World world, int x, int y, int z, ItemStack itemStack) {
setBlock(world, x, y, z, itemStack, true);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the block is located
* @param x x location point
* @param y y location point
* @param z z location point
* @param material block material to apply on the created block
* @param physics whether physics such as gravity should be applied or not
* @throws IllegalArgumentException if material is not perceived as a block
* material
*/
public static void setBlock(World world, int x, int y, int z, Material material, boolean physics) {
if (!material.isBlock()) throw new IllegalArgumentException("The specified material is not a placeable block!");
Object nmsWorld = getWorld(world);
Object blockPosition = newBlockPosition(world, x, y, z);
Object blockData = getBlockData(material);
removeIfTileEntity(nmsWorld, blockPosition);
setTypeAndData(nmsWorld, blockPosition, blockData, physics ? 3 : 2);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the block is located
* @param x x location point
* @param y y location point
* @param z z location point
* @param itemStack ItemStack to apply on the created block
* @param physics whether physics such as gravity should be applied or not
*/
public static void setBlock(World world, int x, int y, int z, ItemStack itemStack, boolean physics) {
Object nmsWorld = getWorld(world);
Object blockPosition = newBlockPosition(world, x, y, z);
Object blockData = getBlockData(itemStack);
removeIfTileEntity(nmsWorld, blockPosition);
setTypeAndData(nmsWorld, blockPosition, blockData, physics ? 3 : 2);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the block is located
* @param location location to put the block at
* @param material block material to apply on the created block
* @throws IllegalArgumentException if material is not perceived as a block
* material
* @throws NullPointerException if the specified material has no block data
* assigned to it
*/
public static void setBlock(World world, Location location, Material material) {
setBlock(world, location, material, true);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the block is located
* @param location location to put the block at
* @param itemStack ItemStack to apply on the created block
*/
public static void setBlock(World world, Location location, ItemStack itemStack) {
setBlock(world, location, itemStack, true);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the block is located
* @param location location to put the block at
* @param material block material to apply on the created block
* @param physics whether physics such as gravity should be applied or not
* @throws IllegalArgumentException if material is not perceived as a block
* material
* @throws NullPointerException if the specified material has no block data
* assigned to it
*/
public static void setBlock(World world, Location location, Material material, boolean physics) {
if (!material.isBlock()) throw new IllegalArgumentException("The specified material is not a placeable block!");
Object nmsWorld = getWorld(world);
Object blockPosition = newBlockPosition(world, location.getBlockX(), location.getBlockY(),
location.getBlockZ());
Object blockData = getBlockData(material);
if (blockData == null)
throw new NullPointerException("Unable to retrieve block data for the corresponding material.");
removeIfTileEntity(nmsWorld, blockPosition);
setTypeAndData(nmsWorld, blockPosition, blockData, physics ? 3 : 2);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the block is located
* @param location location to put the block at
* @param itemStack ItemStack to apply on the created block
* @param physics whether physics such as gravity should be applied or not
*/
public static void setBlock(World world, Location location, ItemStack itemStack, boolean physics) {
Object nmsWorld = getWorld(world);
Object blockPosition = newBlockPosition(world, location.getBlockX(), location.getBlockY(),
location.getBlockZ());
Object blockData = getBlockData(itemStack);
removeIfTileEntity(nmsWorld, blockPosition);
setTypeAndData(nmsWorld, blockPosition, blockData, physics ? 3 : 2);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param location location to put the block at
* @param material block material to apply on the created block
* @throws IllegalArgumentException if material is not perceived as a block
* material
* @throws NullPointerException if the specified material has no block data
* assigned to it
*/
public static void setBlock(Location location, Material material) {
setBlock(location, material, true);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param location location to put the block at
* @param itemStack ItemStack to apply on the created block
*/
public static void setBlock(Location location, ItemStack itemStack) {
setBlock(location, itemStack, true);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param location location to put the block at
* @param material block material to apply on the created block
* @param physics whether physics such as gravity should be applied or not
* @throws IllegalArgumentException if material is not perceived as a block
* material
* @throws NullPointerException if the specified material has no block data
* assigned to it
*/
public static void setBlock(Location location, Material material, boolean physics) {
if (!material.isBlock()) throw new IllegalArgumentException("The specified material is not a placeable block!");
Object nmsWorld = getWorld(location.getWorld());
Object blockPosition = newBlockPosition(location.getWorld(), location.getBlockX(), location.getBlockY(),
location.getBlockZ());
Object blockData = getBlockData(material);
if (blockData == null)
throw new NullPointerException("Unable to retrieve block data for the corresponding material.");
removeIfTileEntity(nmsWorld, blockPosition);
setTypeAndData(nmsWorld, blockPosition, blockData, physics ? 3 : 2);
}
/**
* Changes block type using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param location location to put the block at
* @param itemStack ItemStack to apply on the created block
* @param physics whether physics such as gravity should be applied or not
*/
public static void setBlock(Location location, ItemStack itemStack, boolean physics) {
Object nmsWorld = getWorld(location.getWorld());
Object blockPosition = newBlockPosition(location.getWorld(), location.getBlockX(), location.getBlockY(),
location.getBlockZ());
Object blockData = getBlockData(itemStack);
removeIfTileEntity(nmsWorld, blockPosition);
setTypeAndData(nmsWorld, blockPosition, blockData, physics ? 3 : 2);
}
/**
* Asynchronously changes block type using native NMS world block type and data
* setter {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
* <br>
* <br>
* Async within this context means:
* <ul>
* <li>There won't be any TPS loss no matter the amount of blocks being set</li>
* <li>It can be safely executed inside an asynchronous task</li>
* </ul>
*
* @param location location to put the block at
* @param itemStack ItemStack to apply on the created block
* @param physics whether physics such as gravity should be applied or not
*/
public static CompletableFuture<Void> setBlockAsynchronously(Location location, ItemStack itemStack,
boolean physics) {
Object nmsWorld = getWorld(location.getWorld());
Object blockPosition = newMutableBlockPosition(location.getWorld(), location.getBlockX(), location.getBlockY(),
location.getBlockZ());
Object blockData = getBlockData(itemStack);
CompletableFuture<Void> workloadFinishFuture = new CompletableFuture<>();
WORKLOAD_RUNNABLE.addWorkload(new BlockSetWorkload(nmsWorld, blockPosition, blockData, location, physics));
WORKLOAD_RUNNABLE.whenComplete(() -> workloadFinishFuture.complete(null));
return workloadFinishFuture;
}
/**
* Mass changes block types using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the blocks are located at
* @param locations locations to put the block at
* @param material block material to apply on the created blocks
* @param physics whether physics such as gravity should be applied or not
* @throws IllegalArgumentException if material is not perceived as a block
* material
* @throws NullPointerException if the specified material has no block data
* assigned to it
*/
public static void setBlocks(World world, Collection<Location> locations, Material material, boolean physics) {
if (!material.isBlock()) throw new IllegalArgumentException("The specified material is not a placeable block!");
Object nmsWorld = getWorld(world);
Object blockData = getBlockData(material);
if (blockData == null)
throw new NullPointerException("Unable to retrieve block data for the corresponding material.");
Object blockPosition = newMutableBlockPosition(world, 0, 0, 0);
int applyPhysics = physics ? 3 : 2;
locations.forEach(location -> {
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
setBlockPosition(blockPosition, x, y, z);
removeIfTileEntity(nmsWorld, blockPosition);
setTypeAndData(nmsWorld, blockPosition, blockData, applyPhysics);
});
}
/**
* Mass changes block types using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
*
* @param world world where the blocks are located at
* @param locations locations to put the block at
* @param itemStack ItemStack to apply on the created blocks
* @param physics whether physics such as gravity should be applied or not
* @throws IllegalArgumentException if material is not perceived as a block
* material
* @throws NullPointerException if the specified material has no block data
* assigned to it
*/
public static void setBlocks(World world, Collection<Location> locations, ItemStack itemStack, boolean physics) {
Object nmsWorld = getWorld(world);
Object blockData = getBlockData(itemStack);
Object blockPosition = newMutableBlockPosition(world, 0, 0, 0);
int applyPhysics = physics ? 3 : 2;
locations.forEach(location -> {
int x = location.getBlockX();
int y = location.getBlockY();
int z = location.getBlockZ();
setBlockPosition(blockPosition, x, y, z);
removeIfTileEntity(nmsWorld, blockPosition);
setTypeAndData(nmsWorld, blockPosition, blockData, applyPhysics);
});
}
/**
* Asynchronously changes block types using native NMS world block type and data
* setter {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
* <br>
* <br>
* Async within this context means:
* <ul>
* <li>There won't be any TPS loss no matter the amount of blocks being set</li>
* <li>It can be safely executed inside an asynchronous task</li>
* </ul>
*
* @param world world where the blocks are located at
* @param locations locations to put the block at
* @param itemStack ItemStack to apply on the created blocks
* @param physics whether physics such as gravity should be applied or not
* @throws IllegalArgumentException if material is not perceived as a block
* material
* @throws NullPointerException if the specified material has no block data
* assigned to it
*/
public static CompletableFuture<Void> setBlocksAsynchronously(World world, Collection<Location> locations,
ItemStack itemStack, boolean physics) {
Object nmsWorld = getWorld(world);
Object blockData = getBlockData(itemStack);
Object blockPosition = newMutableBlockPosition(world, 0, 0, 0);
CompletableFuture<Void> workloadFinishFuture = new CompletableFuture<>();
WorkloadRunnable workloadRunnable = new WorkloadRunnable();
BukkitTask workloadTask = Bukkit.getScheduler().runTaskTimer(PLUGIN, workloadRunnable, 1, 1);
locations.forEach(location -> workloadRunnable
.addWorkload(new BlockSetWorkload(nmsWorld, blockPosition, blockData, location, physics)));
workloadRunnable.whenComplete(() -> {
workloadFinishFuture.complete(null);
workloadTask.cancel();
});
return workloadFinishFuture;
}
/**
* Asynchronously fills a cuboid from a corner to another with blocks retrieved
* from the given ItemStack
* using native NMS world block type and data setter
* {@code nmsWorld.setTypeAndData(...)},
* which surpasses bukkit's {@linkplain org.bukkit.block.Block#setType(Material)
* Block.setType(Material)} speed.
* <br>
* <br>
* Async within this context means:
* <ul>
* <li>There won't be any TPS loss no matter the amount of blocks being set</li>
* <li>It can be safely executed inside an asynchronous task</li>
* </ul>
*
* @param world world where the blocks are located at
* @param loc1 first corner
* @param loc2 second corner
* @param itemStack ItemStack to apply on the created blocks
* @param physics whether physics such as gravity should be applied or not
* @throws IllegalArgumentException if material is not perceived as a block
* material
* @throws NullPointerException if the specified material has no block data
* assigned to it
*/
public static CompletableFuture<Void> setCuboidAsynchronously(Location loc1, Location loc2, ItemStack itemStack,
boolean physics) {
World world = loc1.getWorld();
Object nmsWorld = getWorld(world);
Object blockData = getBlockData(itemStack);
int x1 = Math.min(loc1.getBlockX(), loc2.getBlockX());
int y1 = Math.min(loc1.getBlockY(), loc2.getBlockY());
int z1 = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
int x2 = Math.max(loc1.getBlockX(), loc2.getBlockX());
int y2 = Math.max(loc1.getBlockY(), loc2.getBlockY());
int z2 = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
int baseX = x1;
int baseY = y1;
int baseZ = z1;
int sizeX = Math.abs(x2 - x1) + 1;
int sizeY = Math.abs(y2 - y1) + 1;
int sizeZ = Math.abs(z2 - z1) + 1;
int x3 = 0, y3 = 0, z3 = 0;
Location location = new Location(world, baseX + x3, baseY + y3, baseZ + z3);
int cuboidSize = sizeX * sizeY * sizeZ;
Object blockPosition = newMutableBlockPosition(location);
CompletableFuture<Void> workloadFinishFuture = new CompletableFuture<>();
WorkloadRunnable workloadRunnable = new WorkloadRunnable();
BukkitTask workloadTask = Bukkit.getScheduler().runTaskTimer(PLUGIN, workloadRunnable, 1, 1);
for (int i = 0; i < cuboidSize; i++) {
BlockSetWorkload workload = new BlockSetWorkload(nmsWorld, blockPosition, blockData, location.clone(),
physics);
if (++x3 >= sizeX) {
x3 = 0;
if (++y3 >= sizeY) {
y3 = 0;
++z3;
}
}
location.setX(baseX + x3);
location.setY(baseY + y3);
location.setZ(baseZ + z3);
workloadRunnable.addWorkload(workload);
}
workloadRunnable.whenComplete(() -> {
workloadFinishFuture.complete(null);
workloadTask.cancel();
});
return workloadFinishFuture;
}
/**
* <p>
* Changes block type using Chunk block setter, which in an NMS code, reads as
* follows {@code nmsChunk.setType(...)} which surpasses
* {@code nmsWorld.setTypeAndData(...)}
* speed due to absence of light updates, the method that
* {@link #setBlock(Location, Material)} uses. Then,
* notifies the world of the updated blocks so they can be seen by the players.
*
* @param location location to put the block at
* @param material material to apply on the block
*/
public static void setChunkBlock(Location location, Material material) {
setChunkBlock(location, material, false);
}
/**
* <p>
* Changes block type using Chunk block setter, which in an NMS code, reads as
* follows {@code nmsChunk.setType(...)} which surpasses
* {@code nmsWorld.setTypeAndData(...)}
* speed due to absence of light updates, the method that
* {@link #setBlock(Location, ItemStack)} uses. Then,
* notifies the world of the updated blocks so they can be seen by the players.
*
* @param location location to put the block at
* @param itemStack ItemStack to apply on the block
*/
public static void setChunkBlock(Location location, ItemStack itemStack) {
setChunkBlock(location, itemStack, false);
}
/**
* <p>
* Changes block type using Chunk block setter, which in an NMS code, reads as
* follows {@code nmsChunk.setType(...)} which surpasses