-
Notifications
You must be signed in to change notification settings - Fork 30
/
NBTEditor.java
1583 lines (1427 loc) · 57.6 KB
/
NBTEditor.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 io.github.bananapuncher714.nbteditor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Base64;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
/**
* Sets/Gets NBT tags from ItemStacks
* Supports 1.8-1.18
*
* Github: https://github.com/BananaPuncher714/NBTEditor
* Spigot: https://www.spigotmc.org/threads/269621/
*
* @version 7.18.2
* @author BananaPuncher714
*/
public final class NBTEditor {
private static final Map< String, Class< ? > > classCache;
private static final Map< String, Method > methodCache;
private static final Map< Class< ? >, Constructor< ? > > constructorCache;
private static final Map< Class< ? >, Class< ? > > NBTClasses;
private static final Map< Class< ? >, Field > NBTTagFieldCache;
private static Field NBTListData;
private static Field NBTCompoundMap;
private static final String VERSION;
private static final MinecraftVersion LOCAL_VERSION;
public static final Type COMPOUND = Type.COMPOUND;
public static final Type LIST = Type.LIST;
public static final Type NEW_ELEMENT = Type.NEW_ELEMENT;
public static final Type DELETE = Type.DELETE;
static {
VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
LOCAL_VERSION = MinecraftVersion.get( VERSION );
classCache = new HashMap< String, Class<?> >();
try {
if ( LOCAL_VERSION.lessThanOrEqualTo( MinecraftVersion.v1_16 ) ) {
classCache.put( "NBTBase", Class.forName( "net.minecraft.server." + VERSION + "." + "NBTBase" ) );
classCache.put( "NBTTagCompound", Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagCompound" ) );
classCache.put( "NBTTagList", Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagList" ) );
classCache.put( "NBTTagEnd", Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagEnd" ) );
classCache.put( "MojangsonParser", Class.forName( "net.minecraft.server." + VERSION + "." + "MojangsonParser" ) );
classCache.put( "ItemStack", Class.forName( "net.minecraft.server." + VERSION + "." + "ItemStack" ) );
classCache.put( "Entity", Class.forName( "net.minecraft.server." + VERSION + "." + "Entity" ) );
classCache.put( "EntityLiving", Class.forName( "net.minecraft.server." + VERSION + "." + "EntityLiving" ) );
classCache.put( "BlockPosition", Class.forName( "net.minecraft.server." + VERSION + "." + "BlockPosition" ) );
classCache.put( "TileEntity", Class.forName( "net.minecraft.server." + VERSION + "." + "TileEntity" ) );
classCache.put( "World", Class.forName( "net.minecraft.server." + VERSION + "." + "World" ) );
classCache.put( "IBlockData", Class.forName( "net.minecraft.server." + VERSION + "." + "IBlockData" ) );
classCache.put( "TileEntitySkull", Class.forName( "net.minecraft.server." + VERSION + "." + "TileEntitySkull" ) );
} else {
classCache.put( "BlockPosition", Class.forName( "net.minecraft.core.BlockPosition" ) );
classCache.put( "NBTBase", Class.forName( "net.minecraft.nbt.NBTBase" ) );
classCache.put( "NBTTagCompound", Class.forName( "net.minecraft.nbt.NBTTagCompound" ) );
classCache.put( "NBTTagList", Class.forName( "net.minecraft.nbt.NBTTagList" ) );
classCache.put( "NBTTagEnd", Class.forName( "net.minecraft.nbt.NBTTagEnd" ) );
classCache.put( "MojangsonParser", Class.forName( "net.minecraft.nbt.MojangsonParser" ) );
classCache.put( "ItemStack", Class.forName( "net.minecraft.world.item.ItemStack" ) );
classCache.put( "Entity", Class.forName( "net.minecraft.world.entity.Entity" ) );
classCache.put( "EntityLiving", Class.forName( "net.minecraft.world.entity.EntityLiving" ) );
classCache.put( "World", Class.forName( "net.minecraft.world.level.World" ) );
classCache.put( "IBlockData", Class.forName( "net.minecraft.world.level.block.state.IBlockData" ) );
classCache.put( "TileEntity", Class.forName( "net.minecraft.world.level.block.entity.TileEntity" ) );
classCache.put( "TileEntitySkull", Class.forName( "net.minecraft.world.level.block.entity.TileEntitySkull" ) );
}
classCache.put( "CraftItemStack", Class.forName( "org.bukkit.craftbukkit." + VERSION + ".inventory." + "CraftItemStack" ) );
classCache.put( "CraftMetaSkull", Class.forName( "org.bukkit.craftbukkit." + VERSION + ".inventory." + "CraftMetaSkull" ) );
classCache.put( "CraftEntity", Class.forName( "org.bukkit.craftbukkit." + VERSION + ".entity." + "CraftEntity" ) );
classCache.put( "CraftWorld", Class.forName( "org.bukkit.craftbukkit." + VERSION + "." + "CraftWorld" ) );
classCache.put( "CraftBlockState", Class.forName( "org.bukkit.craftbukkit." + VERSION + ".block." + "CraftBlockState" ) );
classCache.put( "GameProfile", Class.forName( "com.mojang.authlib.GameProfile" ) );
classCache.put( "Property", Class.forName( "com.mojang.authlib.properties.Property" ) );
classCache.put( "PropertyMap", Class.forName( "com.mojang.authlib.properties.PropertyMap" ) );
} catch ( ClassNotFoundException e ) {
e.printStackTrace();
}
NBTClasses = new HashMap< Class< ? >, Class< ? > >();
try {
if ( LOCAL_VERSION.lessThanOrEqualTo( MinecraftVersion.v1_16 ) ) {
NBTClasses.put( Byte.class, Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagByte" ) );
NBTClasses.put( Boolean.class, Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagByte" ) );
NBTClasses.put( String.class, Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagString" ) );
NBTClasses.put( Double.class, Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagDouble" ) );
NBTClasses.put( Integer.class, Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagInt" ) );
NBTClasses.put( Long.class, Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagLong" ) );
NBTClasses.put( Short.class, Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagShort" ) );
NBTClasses.put( Float.class, Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagFloat" ) );
NBTClasses.put( Class.forName( "[B" ), Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagByteArray" ) );
NBTClasses.put( Class.forName( "[I" ), Class.forName( "net.minecraft.server." + VERSION + "." + "NBTTagIntArray" ) );
} else {
NBTClasses.put( Byte.class, Class.forName( "net.minecraft.nbt.NBTTagByte" ) );
NBTClasses.put( Boolean.class, Class.forName( "net.minecraft.nbt.NBTTagByte" ) );
NBTClasses.put( String.class, Class.forName( "net.minecraft.nbt.NBTTagString" ) );
NBTClasses.put( Double.class, Class.forName( "net.minecraft.nbt.NBTTagDouble" ) );
NBTClasses.put( Integer.class, Class.forName( "net.minecraft.nbt.NBTTagInt" ) );
NBTClasses.put( Long.class, Class.forName( "net.minecraft.nbt.NBTTagLong" ) );
NBTClasses.put( Short.class, Class.forName( "net.minecraft.nbt.NBTTagShort" ) );
NBTClasses.put( Float.class, Class.forName( "net.minecraft.nbt.NBTTagFloat" ) );
NBTClasses.put( Class.forName( "[B" ), Class.forName( "net.minecraft.nbt.NBTTagByteArray" ) );
NBTClasses.put( Class.forName( "[I" ), Class.forName( "net.minecraft.nbt.NBTTagIntArray" ) );
}
} catch ( ClassNotFoundException e ) {
e.printStackTrace();
}
methodCache = new HashMap< String, Method >();
try {
if ( LOCAL_VERSION.lessThanOrEqualTo( MinecraftVersion.v1_17 ) ) {
methodCache.put( "get", getNMSClass( "NBTTagCompound" ).getMethod( "get", String.class ) );
methodCache.put( "set", getNMSClass( "NBTTagCompound" ).getMethod( "set", String.class, getNMSClass( "NBTBase" ) ) );
methodCache.put( "hasKey", getNMSClass( "NBTTagCompound" ).getMethod( "hasKey", String.class ) );
} else {
methodCache.put( "get", getNMSClass( "NBTTagCompound" ).getMethod( "c", String.class ) );
methodCache.put( "set", getNMSClass( "NBTTagCompound" ).getMethod( "a", String.class, getNMSClass( "NBTBase" ) ) );
methodCache.put( "hasKey", getNMSClass( "NBTTagCompound" ).getMethod( "e", String.class ) );
}
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "setIndex", getNMSClass( "NBTTagList" ).getMethod( "d", int.class, getNMSClass( "NBTBase" ) ) );
} else if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_17 ) ) {
methodCache.put( "setIndex", getNMSClass( "NBTTagList" ).getMethod( "set", int.class, getNMSClass( "NBTBase" ) ) );
} else {
methodCache.put( "setIndex", getNMSClass( "NBTTagList" ).getMethod( "a", int.class, getNMSClass( "NBTBase" ) ) );
}
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "getTypeId", getNMSClass( "NBTBase" ).getMethod( "a" ) );
methodCache.put( "add", getNMSClass( "NBTTagList" ).getMethod( "c", int.class, getNMSClass( "NBTBase" ) ) );
} else if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_14 ) ) {
methodCache.put( "getTypeId", getNMSClass( "NBTBase" ).getMethod( "getTypeId" ) );
methodCache.put( "add", getNMSClass( "NBTTagList" ).getMethod( "add", int.class, getNMSClass( "NBTBase" ) ) );
} else {
methodCache.put( "add", getNMSClass( "NBTTagList" ).getMethod( "add", getNMSClass( "NBTBase" ) ) );
}
methodCache.put( "size", getNMSClass( "NBTTagList" ).getMethod( "size" ) );
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "listRemove", getNMSClass( "NBTTagList" ).getMethod( "c", int.class ) );
} else if ( LOCAL_VERSION == MinecraftVersion.v1_8 ) {
methodCache.put( "listRemove", getNMSClass( "NBTTagList" ).getMethod( "a", int.class ) );
} else {
methodCache.put( "listRemove", getNMSClass( "NBTTagList" ).getMethod( "remove", int.class ) );
}
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "remove", getNMSClass( "NBTTagCompound" ).getMethod( "r", String.class ) );
} else {
methodCache.put( "remove", getNMSClass( "NBTTagCompound" ).getMethod( "remove", String.class ) );
}
if ( LOCAL_VERSION.lessThanOrEqualTo( MinecraftVersion.v1_12 ) ) {
methodCache.put( "getKeys", getNMSClass( "NBTTagCompound" ).getMethod( "c" ) );
} else if ( LOCAL_VERSION.lessThanOrEqualTo( MinecraftVersion.v1_17 ) ) {
methodCache.put( "getKeys", getNMSClass( "NBTTagCompound" ).getMethod( "getKeys" ) );
} else {
methodCache.put( "getKeys", getNMSClass( "NBTTagCompound" ).getMethod( "d" ) );
}
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18_2 ) ) {
methodCache.put( "hasTag", getNMSClass( "ItemStack" ).getMethod( "s" ) );
methodCache.put( "getTag", getNMSClass( "ItemStack" ).getMethod( "t" ) );
methodCache.put( "setTag", getNMSClass( "ItemStack" ).getMethod( "c", getNMSClass( "NBTTagCompound" ) ) );
} else if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "hasTag", getNMSClass( "ItemStack" ).getMethod( "r" ) );
methodCache.put( "getTag", getNMSClass( "ItemStack" ).getMethod( "s" ) );
methodCache.put( "setTag", getNMSClass( "ItemStack" ).getMethod( "c", getNMSClass( "NBTTagCompound" ) ) );
} else {
methodCache.put( "hasTag", getNMSClass( "ItemStack" ).getMethod( "hasTag" ) );
methodCache.put( "getTag", getNMSClass( "ItemStack" ).getMethod( "getTag" ) );
methodCache.put( "setTag", getNMSClass( "ItemStack" ).getMethod( "setTag", getNMSClass( "NBTTagCompound" ) ) );
}
methodCache.put( "asNMSCopy", getNMSClass( "CraftItemStack" ).getMethod( "asNMSCopy", ItemStack.class ) );
methodCache.put( "asBukkitCopy", getNMSClass( "CraftItemStack" ).getMethod( "asBukkitCopy", getNMSClass( "ItemStack" ) ) );
methodCache.put( "getEntityHandle", getNMSClass( "CraftEntity" ).getMethod( "getHandle" ) );
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "getEntityTag", getNMSClass( "Entity" ).getMethod( "f", getNMSClass( "NBTTagCompound" ) ) );
methodCache.put( "setEntityTag", getNMSClass( "Entity" ).getMethod( "g", getNMSClass( "NBTTagCompound" ) ) );
} else if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_16 ) ) {
methodCache.put( "getEntityTag", getNMSClass( "Entity" ).getMethod( "save", getNMSClass( "NBTTagCompound" ) ) );
methodCache.put( "setEntityTag", getNMSClass( "Entity" ).getMethod( "load", getNMSClass( "NBTTagCompound" ) ) );
} else {
methodCache.put( "getEntityTag", getNMSClass( "Entity" ).getMethod( "c", getNMSClass( "NBTTagCompound" ) ) );
methodCache.put( "setEntityTag", getNMSClass( "Entity" ).getMethod( "f", getNMSClass( "NBTTagCompound" ) ) );
}
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "save", getNMSClass( "ItemStack" ).getMethod( "b", getNMSClass( "NBTTagCompound" ) ) );
} else {
methodCache.put( "save", getNMSClass( "ItemStack" ).getMethod( "save", getNMSClass( "NBTTagCompound" ) ) );
}
if ( LOCAL_VERSION.lessThanOrEqualTo( MinecraftVersion.v1_10 ) ) {
methodCache.put( "createStack", getNMSClass( "ItemStack" ).getMethod( "createStack", getNMSClass( "NBTTagCompound" ) ) );
} else if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_13 ) ) {
methodCache.put( "createStack", getNMSClass( "ItemStack" ).getMethod( "a", getNMSClass( "NBTTagCompound" ) ) );
}
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "setTileTag", getNMSClass( "TileEntity" ).getMethod( "a", getNMSClass( "NBTTagCompound" ) ) );
} else if ( LOCAL_VERSION == MinecraftVersion.v1_16 ) {
methodCache.put( "setTileTag", getNMSClass( "TileEntity" ).getMethod( "load", getNMSClass( "IBlockData" ), getNMSClass( "NBTTagCompound" ) ) );
methodCache.put( "getType", getNMSClass( "World" ).getMethod( "getType", getNMSClass( "BlockPosition" ) ) );
} else if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_12 ) ) {
methodCache.put( "setTileTag", getNMSClass( "TileEntity" ).getMethod( "load", getNMSClass( "NBTTagCompound" ) ) );
} else {
methodCache.put( "setTileTag", getNMSClass( "TileEntity" ).getMethod( "a", getNMSClass( "NBTTagCompound" ) ) );
}
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "getTileTag", getNMSClass( "TileEntity" ).getMethod( "m" ) );
} else if ( LOCAL_VERSION == MinecraftVersion.v1_8 ) {
methodCache.put( "getTileTag", getNMSClass( "TileEntity" ).getMethod( "b", getNMSClass( "NBTTagCompound" ) ) );
} else {
methodCache.put( "getTileTag", getNMSClass( "TileEntity" ).getMethod( "save", getNMSClass( "NBTTagCompound" ) ) );
}
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "getTileEntity", getNMSClass( "World" ).getMethod( "c_", getNMSClass( "BlockPosition" ) ) );
} else {
methodCache.put( "getTileEntity", getNMSClass( "World" ).getMethod( "getTileEntity", getNMSClass( "BlockPosition" ) ) );
}
methodCache.put( "getWorldHandle", getNMSClass( "CraftWorld" ).getMethod( "getHandle" ) );
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "setGameProfile", getNMSClass( "TileEntitySkull" ).getMethod( "a", getNMSClass( "GameProfile" ) ) );
} else {
methodCache.put( "setGameProfile", getNMSClass( "TileEntitySkull" ).getMethod( "setGameProfile", getNMSClass( "GameProfile" ) ) );
}
methodCache.put( "getProperties", getNMSClass( "GameProfile" ).getMethod( "getProperties" ) );
methodCache.put( "getName", getNMSClass( "Property" ).getMethod( "getName" ) );
methodCache.put( "getValue", getNMSClass( "Property" ).getMethod( "getValue" ) );
methodCache.put( "values", getNMSClass( "PropertyMap" ).getMethod( "values" ) );
methodCache.put( "put", getNMSClass( "PropertyMap" ).getMethod( "put", Object.class, Object.class ) );
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
methodCache.put( "loadNBTTagCompound", getNMSClass( "MojangsonParser" ).getMethod( "a", String.class ) );
} else {
methodCache.put( "loadNBTTagCompound", getNMSClass( "MojangsonParser" ).getMethod( "parse", String.class ) );
}
} catch( Exception e ) {
e.printStackTrace();
}
try {
methodCache.put( "setProfile", getNMSClass( "CraftMetaSkull" ).getDeclaredMethod( "setProfile", getNMSClass( "GameProfile" ) ) );
methodCache.get( "setProfile" ).setAccessible( true );
} catch( NoSuchMethodException exception ) {
// The method doesn't exist, so it's before 1.15.2
}
constructorCache = new HashMap< Class< ? >, Constructor< ? > >();
try {
constructorCache.put( getNBTTag( Byte.class ), getNBTTag( Byte.class ).getDeclaredConstructor( byte.class ) );
constructorCache.put( getNBTTag( Boolean.class ), getNBTTag( Boolean.class ).getDeclaredConstructor( byte.class ) );
constructorCache.put( getNBTTag( String.class ), getNBTTag( String.class ).getDeclaredConstructor( String.class ) );
constructorCache.put( getNBTTag( Double.class ), getNBTTag( Double.class ).getDeclaredConstructor( double.class ) );
constructorCache.put( getNBTTag( Integer.class ), getNBTTag( Integer.class ).getDeclaredConstructor( int.class ) );
constructorCache.put( getNBTTag( Long.class ), getNBTTag( Long.class ).getDeclaredConstructor( long.class ) );
constructorCache.put( getNBTTag( Float.class ), getNBTTag( Float.class ).getDeclaredConstructor( float.class ) );
constructorCache.put( getNBTTag( Short.class ), getNBTTag( Short.class ).getDeclaredConstructor( short.class ) );
constructorCache.put( getNBTTag( Class.forName( "[B" ) ), getNBTTag( Class.forName( "[B" ) ).getDeclaredConstructor( Class.forName( "[B" ) ) );
constructorCache.put( getNBTTag( Class.forName( "[I" ) ), getNBTTag( Class.forName( "[I" ) ).getDeclaredConstructor( Class.forName( "[I" ) ) );
// This is for 1.15 since Mojang decided to make the constructors private
for ( Constructor< ? > cons : constructorCache.values() ) {
cons.setAccessible( true );
}
constructorCache.put( getNMSClass( "BlockPosition" ), getNMSClass( "BlockPosition" ).getConstructor( int.class, int.class, int.class ) );
constructorCache.put( getNMSClass( "GameProfile" ), getNMSClass( "GameProfile" ).getConstructor( UUID.class, String.class ) );
constructorCache.put( getNMSClass( "Property" ), getNMSClass( "Property" ).getConstructor( String.class, String.class ) );
if ( LOCAL_VERSION == MinecraftVersion.v1_11 || LOCAL_VERSION == MinecraftVersion.v1_12 ) {
constructorCache.put( getNMSClass( "ItemStack" ), getNMSClass( "ItemStack" ).getConstructor( getNMSClass( "NBTTagCompound" ) ) );
}
} catch( Exception e ) {
e.printStackTrace();
}
NBTTagFieldCache = new HashMap< Class< ? >, Field >();
try {
if ( LOCAL_VERSION.lessThanOrEqualTo( MinecraftVersion.v1_16 ) ) {
for ( Class< ? > clazz : NBTClasses.values() ) {
Field data = clazz.getDeclaredField( "data" );
data.setAccessible( true );
NBTTagFieldCache.put( clazz, data );
}
} else {
NBTTagFieldCache.put( NBTClasses.get( Byte.class ), NBTClasses.get( Byte.class ).getDeclaredField( "x" ) );
NBTTagFieldCache.put( NBTClasses.get( Boolean.class ), NBTClasses.get( Boolean.class ).getDeclaredField( "x" ) );
NBTTagFieldCache.put( NBTClasses.get( String.class ), NBTClasses.get( String.class ).getDeclaredField( "A" ) );
NBTTagFieldCache.put( NBTClasses.get( Double.class ), NBTClasses.get( Double.class ).getDeclaredField( "w" ) );
NBTTagFieldCache.put( NBTClasses.get( Integer.class ), NBTClasses.get( Integer.class ).getDeclaredField( "c" ) );
NBTTagFieldCache.put( NBTClasses.get( Long.class ), NBTClasses.get( Long.class ).getDeclaredField( "c" ) );
NBTTagFieldCache.put( NBTClasses.get( Float.class ), NBTClasses.get( Float.class ).getDeclaredField( "w" ) );
NBTTagFieldCache.put( NBTClasses.get( Short.class ), NBTClasses.get( Short.class ).getDeclaredField( "c" ) );
NBTTagFieldCache.put( NBTClasses.get( Class.forName( "[B" ) ), NBTClasses.get( Class.forName( "[B" ) ).getDeclaredField( "c" ) );
NBTTagFieldCache.put( NBTClasses.get( Class.forName( "[I" ) ), NBTClasses.get( Class.forName( "[I" ) ).getDeclaredField( "c" ) );
for ( Field field : NBTTagFieldCache.values() ) {
field.setAccessible( true );
}
}
} catch( Exception e ) {
e.printStackTrace();
}
try {
if ( LOCAL_VERSION.lessThanOrEqualTo( MinecraftVersion.v1_16 ) ) {
NBTListData = getNMSClass( "NBTTagList" ).getDeclaredField( "list" );
NBTCompoundMap = getNMSClass( "NBTTagCompound" ).getDeclaredField( "map" );
} else {
NBTListData = getNMSClass( "NBTTagList" ).getDeclaredField( "c" );
NBTCompoundMap = getNMSClass( "NBTTagCompound" ).getDeclaredField( "x" );
}
NBTListData.setAccessible( true );
NBTCompoundMap.setAccessible( true );
} catch( Exception e ) {
e.printStackTrace();
}
}
private static Class< ? > getNBTTag( Class< ? > primitiveType ) {
if ( NBTClasses.containsKey( primitiveType ) )
return NBTClasses.get( primitiveType );
return primitiveType;
}
private static Object getNBTVar( Object object ) {
if ( object == null ) {
return null;
}
Class< ? > clazz = object.getClass();
try {
if ( NBTTagFieldCache.containsKey( clazz ) ) {
return NBTTagFieldCache.get( clazz ).get( object );
}
} catch ( Exception exception ) {
exception.printStackTrace();
}
return null;
}
private static Method getMethod( String name ) {
return methodCache.containsKey( name ) ? methodCache.get( name ) : null;
}
private static Constructor< ? > getConstructor( Class< ? > clazz ) {
return constructorCache.containsKey( clazz ) ? constructorCache.get( clazz ) : null;
}
private static Class<?> getNMSClass(String name) {
if ( classCache.containsKey( name ) ) {
return classCache.get( name );
}
try {
return Class.forName("net.minecraft.server." + VERSION + "." + name);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
private static String getMatch( String string, String regex ) {
Pattern pattern = Pattern.compile( regex );
Matcher matcher = pattern.matcher( string );
if ( matcher.find() ) {
return matcher.group( 1 );
} else {
return null;
}
}
private static Object createItemStack( Object compound ) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
if ( LOCAL_VERSION == MinecraftVersion.v1_11 || LOCAL_VERSION == MinecraftVersion.v1_12 ) {
return getConstructor( getNMSClass( "ItemStack" ) ).newInstance( compound );
}
return getMethod( "createStack" ).invoke( null, compound );
}
/**
* Gets the Bukkit version
*
* @return
* The Bukkit version in standard package format
*/
public static String getVersion() {
return VERSION;
}
public static MinecraftVersion getMinecraftVersion() {
return LOCAL_VERSION;
}
/**
* Creates a skull with the given url as the skin
*
* @param skinURL
* The URL of the skin, must be from mojang
* @return
* An item stack with count of 1
*/
public static ItemStack getHead( String skinURL ) {
Material material = Material.getMaterial( "SKULL_ITEM" );
if ( material == null ) {
// Most likely 1.13 materials
material = Material.getMaterial( "PLAYER_HEAD" );
}
ItemStack head = new ItemStack( material, 1, ( short ) 3 );
if ( skinURL == null || skinURL.isEmpty() ) {
return head;
}
ItemMeta headMeta = head.getItemMeta();
Object profile = null;
try {
profile = getConstructor( getNMSClass( "GameProfile" ) ).newInstance( UUID.randomUUID(), null );
Object propertyMap = getMethod( "getProperties" ).invoke( profile );
Object textureProperty = getConstructor( getNMSClass( "Property" ) ).newInstance( "textures", new String( Base64.getEncoder().encode( String.format( "{textures:{SKIN:{\"url\":\"%s\"}}}", skinURL ).getBytes() ) ) );
getMethod( "put" ).invoke( propertyMap, "textures", textureProperty );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e1 ) {
e1.printStackTrace();
}
if ( methodCache.containsKey( "setProfile" ) ) {
try {
getMethod( "setProfile" ).invoke( headMeta, profile );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
e.printStackTrace();
}
} else {
Field profileField = null;
try {
profileField = headMeta.getClass().getDeclaredField("profile");
} catch ( NoSuchFieldException | SecurityException e ) {
e.printStackTrace();
}
profileField.setAccessible(true);
try {
profileField.set(headMeta, profile);
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}
head.setItemMeta(headMeta);
return head;
}
/**
* Fetches the texture of a skull
*
* @param head
* The item stack itself
* @return
* The URL of the texture
*/
public static String getTexture( ItemStack head ) {
ItemMeta meta = head.getItemMeta();
Field profileField = null;
try {
profileField = meta.getClass().getDeclaredField("profile");
} catch ( NoSuchFieldException | SecurityException e ) {
e.printStackTrace();
throw new IllegalArgumentException( "Item is not a player skull!" );
}
profileField.setAccessible(true);
try {
Object profile = profileField.get( meta );
if ( profile == null ) {
return null;
}
Collection< Object > properties = ( Collection< Object > ) getMethod( "values" ).invoke( getMethod( "getProperties" ).invoke( profile ) );
for ( Object prop : properties ) {
if ( "textures".equals( getMethod( "getName" ).invoke( prop ) ) ) {
String texture = new String( Base64.getDecoder().decode( ( String ) getMethod( "getValue" ).invoke( prop ) ) );
return getMatch( texture, "\\{\"url\":\"(.*?)\"\\}" );
}
}
return null;
} catch ( IllegalArgumentException | IllegalAccessException | SecurityException | InvocationTargetException e) {
e.printStackTrace();
return null;
}
}
/**
* Gets an NBT tag in a given item with the specified keys
*
* @param item
* The itemstack to get the keys from
* @param keys
* The keys to fetch; an integer after a key value indicates that it should get the nth place of
* the previous compound because it is a list;
* @return
* The item represented by the keys, and an integer if it is showing how long a list is.
*/
private static Object getItemTag( ItemStack item, Object... keys ) {
try {
return getTag( getCompound( item ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
e.printStackTrace();
return null;
}
}
// Gets the NBTTagCompound
private static Object getCompound( ItemStack item ) {
if ( item == null ) {
return null;
}
try {
Object stack = null;
stack = getMethod( "asNMSCopy" ).invoke( null, item );
Object tag = null;
if ( getMethod( "hasTag" ).invoke( stack ).equals( true ) ) {
tag = getMethod( "getTag" ).invoke( stack );
} else {
tag = getNMSClass( "NBTTagCompound" ).newInstance();
}
return tag;
} catch ( Exception exception ) {
exception.printStackTrace();
return null;
}
}
/**
* Gets an NBTCompound from the item provided. Use {@link #getNBTCompound(Object, Object...)} instead.
*
* @param item
* Itemstack
* @param keys
* Keys in descending order
* @return
* An NBTCompound
*/
private static NBTCompound getItemNBTTag( ItemStack item, Object... keys ) {
if ( item == null ) {
return null;
}
try {
Object stack = null;
stack = getMethod( "asNMSCopy" ).invoke( null, item );
Object tag = getNMSClass( "NBTTagCompound" ).newInstance();
tag = getMethod( "save" ).invoke( stack, tag );
return getNBTTag( tag, keys );
} catch ( Exception exception ) {
exception.printStackTrace();
return null;
}
}
/**
* Sets an NBT tag in an item with the provided keys and value
* Should use the {@link #set(Object, Object, Object...)} method instead
*
* @param item
* The itemstack to set
* @param value
* The value to set
* @param keys
* The keys to set, String for NBTCompound, int or null for an NBTTagList
* @return
* A new ItemStack with the updated NBT tags
*/
private static ItemStack setItemTag( ItemStack item, Object value, Object... keys ) {
if ( item == null ) {
return null;
}
try {
Object stack = getMethod( "asNMSCopy" ).invoke( null, item );
Object tag = null;
if ( getMethod( "hasTag" ).invoke( stack ).equals( true ) ) {
tag = getMethod( "getTag" ).invoke( stack );
} else {
tag = getNMSClass( "NBTTagCompound" ).newInstance();
}
if ( keys.length == 0 && value instanceof NBTCompound ) {
tag = ( ( NBTCompound ) value ).tag;
} else {
setTag( tag, value, keys );
}
getMethod( "setTag" ).invoke( stack, tag );
return ( ItemStack ) getMethod( "asBukkitCopy" ).invoke( null, stack );
} catch ( Exception exception ) {
exception.printStackTrace();
return null;
}
}
/**
* Constructs an ItemStack from a given NBTCompound
*
* @param compound
* An NBTCompound following an ItemStack structure
* @return
* A new ItemStack
*/
public static ItemStack getItemFromTag( NBTCompound compound ) {
if ( compound == null ) {
return null;
}
try {
Object tag = compound.tag;
Object count = getTag( tag, "Count" );
Object id = getTag( tag, "id" );
if ( count == null || id == null ) {
return null;
}
if ( count instanceof Byte && id instanceof String ) {
return ( ItemStack ) getMethod( "asBukkitCopy" ).invoke( null, createItemStack( tag ) );
}
return null;
} catch ( Exception exception ) {
exception.printStackTrace();
return null;
}
}
/**
* Gets an NBT tag in a given entity with the specified keys
*
* @param entity
* The entity to get the keys from
* @param keys
* The keys to fetch; an integer after a key value indicates that it should get the nth place of
* the previous compound because it is a list;
* @return
* The item represented by the keys, and an integer if it is showing how long a list is.
*/
private static Object getEntityTag( Entity entity, Object... keys ) {
try {
return getTag( getCompound( entity ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
e.printStackTrace();
return null;
}
}
// Gets the NBTTagCompound
private static Object getCompound( Entity entity ) {
if ( entity == null ) {
return entity;
}
try {
Object NMSEntity = getMethod( "getEntityHandle" ).invoke( entity );
Object tag = getNMSClass( "NBTTagCompound" ).newInstance();
getMethod( "getEntityTag" ).invoke( NMSEntity, tag );
return tag;
} catch ( Exception exception ) {
exception.printStackTrace();
return null;
}
}
/**
* Gets an NBTCompound from the entity provided. Use {@link #getNBTCompound(Object, Object...)} instead.
*
* @param entity
* The Bukkit entity provided
* @param keys
* Keys in descending order
* @return
* An NBTCompound
*/
private static NBTCompound getEntityNBTTag( Entity entity, Object...keys ) {
if ( entity == null ) {
return null;
}
try {
Object NMSEntity = getMethod( "getEntityHandle" ).invoke( entity );
Object tag = getNMSClass( "NBTTagCompound" ).newInstance();
getMethod( "getEntityTag" ).invoke( NMSEntity, tag );
return getNBTTag( tag, keys );
} catch ( Exception exception ) {
exception.printStackTrace();
return null;
}
}
/**
* Sets an NBT tag in an entity with the provided keys and value
* Should use the {@link #set(Object, Object, Object...)} method instead
*
* @param entity
* The entity to set
* @param value
* The value to set
* @param keys
* The keys to set, String for NBTCompound, int or null for an NBTTagList
*/
private static void setEntityTag( Entity entity, Object value, Object... keys ) {
if ( entity == null ) {
return;
}
try {
Object NMSEntity = getMethod( "getEntityHandle" ).invoke( entity );
Object tag = getNMSClass( "NBTTagCompound" ).newInstance() ;
getMethod( "getEntityTag" ).invoke( NMSEntity, tag );
if ( keys.length == 0 && value instanceof NBTCompound ) {
tag = ( ( NBTCompound ) value ).tag;
} else {
setTag( tag, value, keys );
}
getMethod( "setEntityTag" ).invoke( NMSEntity, tag );
} catch ( Exception exception ) {
exception.printStackTrace();
return;
}
}
/**
* Gets an NBT tag in a given block with the specified keys. Use {@link #getNBTCompound(Object, Object...)} instead.
*
* @param block
* The block to get the keys from
* @param keys
* The keys to fetch; an integer after a key value indicates that it should get the nth place of
* the previous compound because it is a list;
* @return
* The item represented by the keys, and an integer if it is showing how long a list is.
*/
private static Object getBlockTag( Block block, Object... keys ) {
try {
return getTag( getCompound( block ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
e.printStackTrace();
return null;
}
}
// Gets the NBTTagCompound
private static Object getCompound( Block block ) {
try {
if ( block == null || !getNMSClass( "CraftBlockState" ).isInstance( block.getState() ) ) {
return null;
}
Location location = block.getLocation();
Object blockPosition = getConstructor( getNMSClass( "BlockPosition" ) ).newInstance( location.getBlockX(), location.getBlockY(), location.getBlockZ() );
Object nmsWorld = getMethod( "getWorldHandle" ).invoke( location.getWorld() );
Object tileEntity = getMethod( "getTileEntity" ).invoke( nmsWorld, blockPosition );
Object tag;
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
tag = getMethod( "getTileTag" ).invoke( tileEntity );
} else {
tag = getNMSClass( "NBTTagCompound" ).newInstance();
getMethod( "getTileTag" ).invoke( tileEntity, tag );
}
return tag;
} catch( Exception exception ) {
exception.printStackTrace();
return null;
}
}
/**
* Gets an NBTCompound from the block provided
*
* @param block
* The block provided
* @param keys
* Keys in descending order
* @return
* An NBTCompound
*/
private static NBTCompound getBlockNBTTag( Block block, Object... keys ) {
try {
if ( block == null || !getNMSClass( "CraftBlockState" ).isInstance( block.getState() ) ) {
return null;
}
Location location = block.getLocation();
Object blockPosition = getConstructor( getNMSClass( "BlockPosition" ) ).newInstance( location.getBlockX(), location.getBlockY(), location.getBlockZ() );
Object nmsWorld = getMethod( "getWorldHandle" ).invoke( location.getWorld() );
Object tileEntity = getMethod( "getTileEntity" ).invoke( nmsWorld, blockPosition );
Object tag;
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
tag = getMethod( "getTileTag" ).invoke( tileEntity );
} else {
tag = getNMSClass( "NBTTagCompound" ).newInstance();
getMethod( "getTileTag" ).invoke( tileEntity, tag );
}
return getNBTTag( tag, keys );
} catch( Exception exception ) {
exception.printStackTrace();
return null;
}
}
/**
* Sets an NBT tag in an block with the provided keys and value
* Should use the {@link #set(Object, Object, Object...)} method instead
*
* @param block
* The block to set
* @param value
* The value to set
* @param keys
* The keys to set, String for NBTCompound, int or null for an NBTTagList
*/
private static void setBlockTag( Block block, Object value, Object... keys ) {
try {
if ( block == null || !getNMSClass( "CraftBlockState" ).isInstance( block.getState() ) ) {
return;
}
Location location = block.getLocation();
Object blockPosition = getConstructor( getNMSClass( "BlockPosition" ) ).newInstance( location.getBlockX(), location.getBlockY(), location.getBlockZ() );
Object nmsWorld = getMethod( "getWorldHandle" ).invoke( location.getWorld() );
Object tileEntity = getMethod( "getTileEntity" ).invoke( nmsWorld, blockPosition );
Object tag;
if ( LOCAL_VERSION.greaterThanOrEqualTo( MinecraftVersion.v1_18 ) ) {
tag = getMethod( "getTileTag" ).invoke( tileEntity );
} else {
tag = getNMSClass( "NBTTagCompound" ).newInstance();
getMethod( "getTileTag" ).invoke( tileEntity, tag );
}
if ( keys.length == 0 && value instanceof NBTCompound ) {
tag = ( ( NBTCompound ) value ).tag;
} else {
setTag( tag, value, keys );
}
if ( LOCAL_VERSION == MinecraftVersion.v1_16 ) {
getMethod( "setTileTag" ).invoke( tileEntity, getMethod( "getType" ).invoke( nmsWorld, blockPosition ), tag );
} else {
getMethod( "setTileTag" ).invoke( tileEntity, tag );
}
} catch( Exception exception ) {
exception.printStackTrace();
return;
}
}
/**
* Sets the texture of a skull block
*
* @param block
* The block, must be a skull
* @param texture
* The URL of the skin
*/
public static void setSkullTexture( Block block, String texture ) {
try {
Object profile = getConstructor( getNMSClass( "GameProfile" ) ).newInstance( UUID.randomUUID(), null );
Object propertyMap = getMethod( "getProperties" ).invoke( profile );
Object textureProperty = getConstructor( getNMSClass( "Property" ) ).newInstance( "textures", new String( Base64.getEncoder().encode( String.format( "{textures:{SKIN:{\"url\":\"%s\"}}}", texture ).getBytes() ) ) );
getMethod( "put" ).invoke( propertyMap, "textures", textureProperty );
Location location = block.getLocation();
Object blockPosition = getConstructor( getNMSClass( "BlockPosition" ) ).newInstance( location.getBlockX(), location.getBlockY(), location.getBlockZ() );
Object nmsWorld = getMethod( "getWorldHandle" ).invoke( location.getWorld() );
Object tileEntity = getMethod( "getTileEntity" ).invoke( nmsWorld, blockPosition );
getMethod( "setGameProfile" ).invoke( tileEntity, profile );
} catch( Exception exception ) {
exception.printStackTrace();
}
}
private static Object getValue( Object object, Object... keys ) {
if ( object instanceof ItemStack ) {
return getItemTag( ( ItemStack ) object, keys );
} else if ( object instanceof Entity ) {
return getEntityTag( ( Entity ) object, keys );
} else if ( object instanceof Block ) {
return getBlockTag( ( Block ) object, keys );
} else if ( object instanceof NBTCompound ) {
try {
return getTag( ( ( NBTCompound ) object ).tag, keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
e.printStackTrace();
return null;
}
} else {
throw new IllegalArgumentException( "Object provided must be of type ItemStack, Entity, Block, or NBTCompound!" );
}
}
/**
* Gets an NBTCompound from an object
*
* @param object
* Must be an ItemStack, Entity, Block, or NBTCompound
* @param keys
* Keys in descending order
* @return
* An NBTCompound, or null if none is stored at the provided location
*/
public static NBTCompound getNBTCompound( Object object, Object... keys ) {
if ( object instanceof ItemStack ) {
return getItemNBTTag( ( ItemStack ) object, keys );
} else if ( object instanceof Entity ) {
return getEntityNBTTag( ( Entity ) object, keys );
} else if ( object instanceof Block ) {
return getBlockNBTTag( ( Block ) object, keys );
} else if ( object instanceof NBTCompound ) {
try {
return getNBTTag( ( ( NBTCompound ) object ).tag, keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
e.printStackTrace();
return null;
}
} else if ( getNMSClass( "NBTTagCompound" ).isInstance( object ) ) {
try {
return getNBTTag( object, keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
e.printStackTrace();
return null;
}
} else {
throw new IllegalArgumentException( "Object provided must be of type ItemStack, Entity, Block, or NBTCompound!" );
}
}
/**
* Gets a string from an object
*
* @param object
* Must be an ItemStack, Entity, Block, or NBTCompound
* @param keys
* Keys in descending order
* @return
* A string, or null if none is stored at the provided location
*/
public static String getString( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof String ? ( String ) result : null;
}
/**
* Gets an int from an object