12
12
import java .util .stream .Collectors ;
13
13
14
14
import org .bukkit .Material ;
15
+ import org .bukkit .Tag ;
15
16
import org .bukkit .World ;
16
17
import org .bukkit .entity .EntityType ;
17
18
import org .bukkit .event .inventory .ClickType ;
@@ -699,13 +700,24 @@ private String buildDescription(String descriptionTemplate, BlockRec blockCount,
699
700
"|" );
700
701
}
701
702
703
+ /**
704
+ * Block data record
705
+ * @param icon - itemstack
706
+ * @param blockId - Block ID string
707
+ * @param blockValue - int value
708
+ * @param displayMaterial - user friendly name
709
+ * @param extraDesc - extra description
710
+ */
702
711
private record BlockDataRec (ItemStack icon , String blockId , int blockValue , int blockLimit , String displayMaterial ,
703
712
String extraDesc ) {
704
713
}
705
714
706
715
private BlockDataRec getBlockData (Object key ) {
707
716
final String ref = "level.gui.buttons.material." ;
708
717
if (key instanceof Material m ) {
718
+ if (!m .isItem ()) {
719
+ m = convertItem (m );
720
+ }
709
721
return new BlockDataRec (PanelUtils .getMaterialItem (m ),
710
722
this .user .getTranslationOrNothing (ref + "id" , "[id]" , m .name ()),
711
723
Objects .requireNonNullElse (this .addon .getBlockConfig ().getValue (world , m ), 0 ),
@@ -727,14 +739,80 @@ private BlockDataRec getBlockData(Object key) {
727
739
this .addon .getBlockConfig ().getBlockValues ().getOrDefault (s , 0 ),
728
740
Objects .requireNonNullElse (this .addon .getBlockConfig ().getLimit (s ), 0 ), disp , "" );
729
741
}
730
- return new BlockDataRec (null , "" , 0 , 0 , Utils .prettifyObject (key , this .user ), "" );
742
+ return new BlockDataRec (new ItemStack ( Material . PAPER ) , "" , 0 , 0 , Utils .prettifyObject (key , this .user ), "" );
731
743
}
732
744
733
745
734
746
// ---------------------------------------------------------------------
735
747
// Section: Other Methods
736
748
// ---------------------------------------------------------------------
737
749
750
+ private Material convertItem (Material m ) {
751
+ if (Tag .CROPS .isTagged (m )) {
752
+ return Material .FARMLAND ;
753
+ }
754
+ if (Tag .CANDLE_CAKES .isTagged (m )) {
755
+ return Material .CAKE ;
756
+ }
757
+ if (Tag .CAULDRONS .isTagged (m )) {
758
+ return Material .CAULDRON ;
759
+ }
760
+ if (Tag .FLOWER_POTS .isTagged (m )) {
761
+ return Material .FLOWER_POT ;
762
+ }
763
+ if (Tag .SNOW .isTagged (m )) {
764
+ return Material .SNOW_BLOCK ;
765
+ }
766
+ if (Tag .WALL_CORALS .isTagged (m )) {
767
+ // Wall corals end in _WALL_FAN
768
+ return Objects .requireNonNullElse (Material .getMaterial (m .name ().substring (0 , m .name ().length () - 9 )),
769
+ Material .BRAIN_CORAL );
770
+ }
771
+ if (Tag .WALL_SIGNS .isTagged (m )) {
772
+ // Wall signs end in _WALL_SIGN
773
+ return Objects .requireNonNullElse (
774
+ Material .getMaterial (m .name ().substring (0 , m .name ().length () - 10 ) + "_SIGN" ), Material .OAK_SIGN );
775
+ }
776
+ if (Tag .WALL_HANGING_SIGNS .isTagged (m )) {
777
+ // Wall signs end in _HANGING_WALL_SIGN
778
+ return Objects .requireNonNullElse (
779
+ Material .getMaterial (m .name ().substring (0 , m .name ().length () - 18 ) + "_SIGN" ), Material .OAK_SIGN );
780
+ }
781
+
782
+ return switch (m ) {
783
+ case WATER -> Material .WATER_BUCKET ;
784
+ case LAVA -> Material .LAVA_BUCKET ;
785
+ case TRIPWIRE -> Material .TRIPWIRE_HOOK ;
786
+ case PISTON_HEAD , MOVING_PISTON -> Material .PISTON ;
787
+ case TALL_SEAGRASS -> Material .SEAGRASS ;
788
+ case FIRE , SOUL_FIRE -> Material .FLINT_AND_STEEL ;
789
+ case REDSTONE_WIRE -> Material .REDSTONE ;
790
+ case WALL_TORCH , REDSTONE_WALL_TORCH , SOUL_WALL_TORCH -> Material .TORCH ;
791
+ case NETHER_PORTAL , END_PORTAL , END_GATEWAY -> Material .ENDER_PEARL ;
792
+ case ATTACHED_PUMPKIN_STEM , ATTACHED_MELON_STEM , PUMPKIN_STEM , MELON_STEM -> Material .PUMPKIN_SEEDS ;
793
+ case COCOA -> Material .COCOA_BEANS ;
794
+ case FROSTED_ICE -> Material .ICE ;
795
+ case WATER_CAULDRON , LAVA_CAULDRON , POWDER_SNOW_CAULDRON -> Material .CAULDRON ;
796
+ case SKELETON_WALL_SKULL , WITHER_SKELETON_WALL_SKULL , ZOMBIE_WALL_HEAD , PLAYER_WALL_HEAD , CREEPER_WALL_HEAD ,
797
+ DRAGON_WALL_HEAD , PIGLIN_WALL_HEAD ->
798
+ Material .SKELETON_SKULL ;
799
+ case SWEET_BERRY_BUSH -> Material .SWEET_BERRIES ;
800
+ case WEEPING_VINES_PLANT , TWISTING_VINES_PLANT -> Material .VINE ;
801
+ case CAVE_VINES , CAVE_VINES_PLANT -> Material .GLOW_BERRIES ;
802
+ case BIG_DRIPLEAF_STEM -> Material .BIG_DRIPLEAF ;
803
+ case BAMBOO_SAPLING , POTTED_BAMBOO -> Material .BAMBOO ;
804
+ case CARROTS -> Material .CARROT ;
805
+ case POTATOES -> Material .POTATO ;
806
+ case BEETROOTS -> Material .BEETROOT ;
807
+ case TORCHFLOWER_CROP -> Material .TORCHFLOWER_SEEDS ;
808
+ case PITCHER_CROP -> Material .PITCHER_PLANT ;
809
+ case VOID_AIR , CAVE_AIR , BUBBLE_COLUMN -> Material .GLASS_BOTTLE ;
810
+ case KELP_PLANT -> Material .KELP ;
811
+ case POWDER_SNOW -> Material .SNOWBALL ;
812
+ default -> Material .PAPER ;
813
+ };
814
+ }
815
+
738
816
/**
739
817
* This method is used to open UserPanel outside this class. It will be much
740
818
* easier to open panel with single method call then initializing new object.
0 commit comments