@@ -63,95 +63,6 @@ public BDCCustomBlockService(CustomBlockStorage storage) {
6363 this .storage = storage ;
6464 }
6565
66- public static void applyDisplayTranslationRotation (@ NotNull GroupSummoner <Display > displaySummoner , Display display ) {
67- if (displaySummoner instanceof TranslationVectorAdjustable translationVectorAdjustable ) {
68- DirectedVector translation = translationVectorAdjustable .getTranslation ();
69- if (translation != null ) {
70- EntityRotation displayRotation = new EntityRotation (display );
71- displayRotation .addRotation (translation .getYaw (), translation .getPitch ());
72- displayRotation .applyToEntity (display );
73- }
74- }
75- }
76-
77- /**
78- * Creates a {@link CustomBlockData} from its location and stores all block data there
79- *
80- * @param customBlock the custom block to create data for
81- * @param displayVehicleUuids list of UUIDs of display vehicles associated with the custom block
82- * @return a {@link CustomBlockData} instance containing the custom block's data
83- */
84- public static CustomBlockData createCustomBlockData (CustomBlock customBlock , List <UUID > displayVehicleUuids ) {
85- CustomBlockData customBlockData = new CustomBlockData (customBlock .getLocation ().getBlock (), BlockDisplayCreator .getInstance ());
86- customBlockData .set (CustomBlockKey .NAME , PersistentDataType .STRING , customBlock .getName ());
87- customBlockData .set (CustomBlockKey .SERVICE_CLASS , PersistentDataType .STRING , BDCCustomBlockService .class .getName ());
88- customBlockData .set (CustomBlockKey .DISPLAY_UUID , PersistentDataTypes .UUID_ARRAY , displayVehicleUuids .toArray (UUID []::new ));
89- customBlockData .set (CustomBlockKey .INTERACTION_UUID , PersistentDataTypes .UUID_ARRAY , customBlock .getInteractions ().stream ().map (Entity ::getUniqueId ).toList ().toArray (UUID []::new ));
90- customBlockData .set (CustomBlockKey .COLLISION_UUID , PersistentDataTypes .UUID_ARRAY , customBlock .getCollisions ().stream ().map (Entity ::getUniqueId ).toList ().toArray (UUID []::new ));
91- customBlockData .set (CustomBlockKey .BLOCK_ROTATION , PersistentDataTypes .CUSTOM_BLOCK_ROTATION , customBlock .getRotation ());
92- customBlockData .set (CustomBlockKey .CUSTOM_BLOCK_UUID , PersistentDataTypes .UUID , customBlock .getUuid ());
93- if (customBlock .getSaveSystem ().equals ("item" )) {
94- GroupSummoner <Display > displaySummoner = customBlock .getDisplaySummoner ();
95- if (displaySummoner instanceof AutomaticCommandDisplaySummoner automaticCommandDisplaySummoner ) {
96- customBlockData .set (CustomBlockKey .DISPLAY_SPAWN_COMMAND , PersistentDataTypes .COMMAND_ARRAY , automaticCommandDisplaySummoner .getCommands ().toArray (CommandLine []::new ));
97- }
98- }
99- return customBlockData ;
100- }
101-
102- /**
103- * Triggers the {@link CustomBlockPlaceEvent} and handles cancellation
104- *
105- * @param customBlock the custom block that was placed
106- * @param player the player who placed the block (nullable)
107- * @param customBlockData the custom block data associated with the block's location
108- * @return true if the event was not cancelled, false if it was
109- */
110- private static boolean triggerCustomBlockPlaceEvent (CustomBlock customBlock , Player player , CustomBlockData customBlockData ) {
111- CustomBlockPlaceEvent customBlockPlaceEvent = new CustomBlockPlaceEvent (customBlock , player );
112- // If the event is canceled, remove all entities and clear the block data
113- if (!EventUtil .call (customBlockPlaceEvent )) {
114- customBlock .getDisplays ().forEach (Entity ::remove );
115- customBlock .getInteractions ().forEach (Entity ::remove );
116- customBlock .getCollisions ().forEach (Entity ::remove );
117- clearCustomBlockData (customBlockData );
118- customBlock .getLocation ().getBlock ().setType (Material .AIR );
119- return false ;
120- }
121- return true ;
122- }
123-
124- /**
125- * Triggers the {@link CustomBlockBreakEvent} and handles cancellation
126- *
127- * @param customBlock the custom block that is being broken
128- * @param player the player who is breaking the block (nullable)
129- * @return true if the event was not cancelled, false if it was
130- */
131- private static boolean triggerCustomBlockBreakEvent (CustomBlock customBlock , Player player ) {
132- CustomBlockBreakEvent customBlockBreakEvent = new CustomBlockBreakEvent (customBlock , player );
133- return EventUtil .call (customBlockBreakEvent );
134- }
135-
136- /**
137- * Clears all custom block data from the provided {@link CustomBlockData} instance
138- *
139- * @param customBlockData the custom block data to clear
140- */
141- public static void clearCustomBlockData (CustomBlockData customBlockData ) {
142- customBlockData .remove (CustomBlockKey .NAME );
143- customBlockData .remove (CustomBlockKey .SERVICE_CLASS );
144- customBlockData .remove (CustomBlockKey .DISPLAY_UUID );
145- customBlockData .remove (CustomBlockKey .INTERACTION_UUID );
146- customBlockData .remove (CustomBlockKey .COLLISION_UUID );
147- customBlockData .remove (CustomBlockKey .BLOCK_ROTATION );
148- customBlockData .remove (CustomBlockKey .CUSTOM_BLOCK_UUID );
149- customBlockData .remove (CustomBlockKey .DISPLAY_SPAWN_COMMAND );
150-
151- customBlockData .remove (CustomBlockKey .ITEM );
152- customBlockData .remove (CustomBlockKey .DISPLAY_SPAWN_COMMAND );
153- }
154-
15566 /**
15667 * {@inheritDoc}
15768 */
@@ -617,4 +528,93 @@ public boolean breakBlock(@NotNull CustomBlock customBlock, @Nullable Player pla
617528
618529 return true ;
619530 }
531+
532+ public static void applyDisplayTranslationRotation (@ NotNull GroupSummoner <Display > displaySummoner , Display display ) {
533+ if (displaySummoner instanceof TranslationVectorAdjustable translationVectorAdjustable ) {
534+ DirectedVector translation = translationVectorAdjustable .getTranslation ();
535+ if (translation != null ) {
536+ EntityRotation displayRotation = new EntityRotation (display );
537+ displayRotation .addRotation (translation .getYaw (), translation .getPitch ());
538+ displayRotation .applyToEntity (display );
539+ }
540+ }
541+ }
542+
543+ /**
544+ * Creates a {@link CustomBlockData} from its location and stores all block data there
545+ *
546+ * @param customBlock the custom block to create data for
547+ * @param displayVehicleUuids list of UUIDs of display vehicles associated with the custom block
548+ * @return a {@link CustomBlockData} instance containing the custom block's data
549+ */
550+ public static CustomBlockData createCustomBlockData (CustomBlock customBlock , List <UUID > displayVehicleUuids ) {
551+ CustomBlockData customBlockData = new CustomBlockData (customBlock .getLocation ().getBlock (), BlockDisplayCreator .getInstance ());
552+ customBlockData .set (CustomBlockKey .NAME , PersistentDataType .STRING , customBlock .getName ());
553+ customBlockData .set (CustomBlockKey .SERVICE_CLASS , PersistentDataType .STRING , BDCCustomBlockService .class .getName ());
554+ customBlockData .set (CustomBlockKey .DISPLAY_UUID , PersistentDataTypes .UUID_ARRAY , displayVehicleUuids .toArray (UUID []::new ));
555+ customBlockData .set (CustomBlockKey .INTERACTION_UUID , PersistentDataTypes .UUID_ARRAY , customBlock .getInteractions ().stream ().map (Entity ::getUniqueId ).toList ().toArray (UUID []::new ));
556+ customBlockData .set (CustomBlockKey .COLLISION_UUID , PersistentDataTypes .UUID_ARRAY , customBlock .getCollisions ().stream ().map (Entity ::getUniqueId ).toList ().toArray (UUID []::new ));
557+ customBlockData .set (CustomBlockKey .BLOCK_ROTATION , PersistentDataTypes .CUSTOM_BLOCK_ROTATION , customBlock .getRotation ());
558+ customBlockData .set (CustomBlockKey .CUSTOM_BLOCK_UUID , PersistentDataTypes .UUID , customBlock .getUuid ());
559+ if (customBlock .getSaveSystem ().equals ("item" )) {
560+ GroupSummoner <Display > displaySummoner = customBlock .getDisplaySummoner ();
561+ if (displaySummoner instanceof AutomaticCommandDisplaySummoner automaticCommandDisplaySummoner ) {
562+ customBlockData .set (CustomBlockKey .DISPLAY_SPAWN_COMMAND , PersistentDataTypes .COMMAND_ARRAY , automaticCommandDisplaySummoner .getCommands ().toArray (CommandLine []::new ));
563+ }
564+ }
565+ return customBlockData ;
566+ }
567+
568+ /**
569+ * Triggers the {@link CustomBlockPlaceEvent} and handles cancellation
570+ *
571+ * @param customBlock the custom block that was placed
572+ * @param player the player who placed the block (nullable)
573+ * @param customBlockData the custom block data associated with the block's location
574+ * @return true if the event was not cancelled, false if it was
575+ */
576+ private static boolean triggerCustomBlockPlaceEvent (CustomBlock customBlock , Player player , CustomBlockData customBlockData ) {
577+ CustomBlockPlaceEvent customBlockPlaceEvent = new CustomBlockPlaceEvent (customBlock , player );
578+ // If the event is canceled, remove all entities and clear the block data
579+ if (!EventUtil .call (customBlockPlaceEvent )) {
580+ customBlock .getDisplays ().forEach (Entity ::remove );
581+ customBlock .getInteractions ().forEach (Entity ::remove );
582+ customBlock .getCollisions ().forEach (Entity ::remove );
583+ clearCustomBlockData (customBlockData );
584+ customBlock .getLocation ().getBlock ().setType (Material .AIR );
585+ return false ;
586+ }
587+ return true ;
588+ }
589+
590+ /**
591+ * Triggers the {@link CustomBlockBreakEvent} and handles cancellation
592+ *
593+ * @param customBlock the custom block that is being broken
594+ * @param player the player who is breaking the block (nullable)
595+ * @return true if the event was not cancelled, false if it was
596+ */
597+ private static boolean triggerCustomBlockBreakEvent (CustomBlock customBlock , Player player ) {
598+ CustomBlockBreakEvent customBlockBreakEvent = new CustomBlockBreakEvent (customBlock , player );
599+ return EventUtil .call (customBlockBreakEvent );
600+ }
601+
602+ /**
603+ * Clears all custom block data from the provided {@link CustomBlockData} instance
604+ *
605+ * @param customBlockData the custom block data to clear
606+ */
607+ public static void clearCustomBlockData (CustomBlockData customBlockData ) {
608+ customBlockData .remove (CustomBlockKey .NAME );
609+ customBlockData .remove (CustomBlockKey .SERVICE_CLASS );
610+ customBlockData .remove (CustomBlockKey .DISPLAY_UUID );
611+ customBlockData .remove (CustomBlockKey .INTERACTION_UUID );
612+ customBlockData .remove (CustomBlockKey .COLLISION_UUID );
613+ customBlockData .remove (CustomBlockKey .BLOCK_ROTATION );
614+ customBlockData .remove (CustomBlockKey .CUSTOM_BLOCK_UUID );
615+ customBlockData .remove (CustomBlockKey .DISPLAY_SPAWN_COMMAND );
616+
617+ customBlockData .remove (CustomBlockKey .ITEM );
618+ customBlockData .remove (CustomBlockKey .DISPLAY_SPAWN_COMMAND );
619+ }
620620}
0 commit comments