@@ -625,12 +625,29 @@ public int getHighestFillSlot() {
625625 return this .highestFillSlot ;
626626 }
627627
628-
629- //========================================================
628+ public void cancelAnimateTitle () {
629+ Function <?> task = getAnimateTitle ();
630+ if (task == null ) return ;
631+ this .animateTitle = null ;
632+ this .animateTitleJson = null ;
633+ if (this .animateTitleTask != null && this .animateTitleTask .isRunning ()) {
634+ this .animateTitleTask .stopTask ();
635+ }
636+ updateTitle ();
637+ }
630638
631639 /**
632- * Do not try use methods below.
640+ * Get the amount of fill slots for each menu page.
641+ *
642+ * @return the number of items could be added on each page.
633643 */
644+ public int getNumberOfFillItems () {
645+ return numberOfFillItems ;
646+ }
647+
648+ //========================================================
649+ // Do not try use methods below if you don't know what you are doing.
650+
634651
635652 /**
636653 * Put data to menu cache.
@@ -642,6 +659,85 @@ public void putAddedButtonsCache(final Integer pageNumber, final MenuDataUtility
642659 this .pagesOfButtonsData .put (pageNumber , menuDataUtility );
643660 }
644661
662+ public Function <?> getAnimateTitle () {
663+ if (this .animateTitle != null )
664+ return this .animateTitle ;
665+ if (this .animateTitleJson != null )
666+ return this .animateTitleJson ;
667+ return null ;
668+ }
669+
670+ public void updateTitle (Object text ) {
671+ if (text instanceof String )
672+ UpdateTitle .update (player , (String ) text , useColorConversion );
673+ if (text instanceof JsonObject )
674+ UpdateTitle .update (player , (JsonObject ) text );
675+ }
676+
677+ /**
678+ * Remove the cached menu. if you use location.
679+ */
680+ public void removeMenuCache () {
681+ menuCache .removeMenuCached (this .menuCacheKey );
682+ }
683+
684+ /**
685+ * Set a unique key for the cached menu if you want to have multiple menus on the same location,
686+ * allowing many players to interact with different menus without limiting them to one menu or
687+ * risking the override of an old menu when a player opens a new one. You need to use this method
688+ * in your constructor,so your key gets added it to the cache.
689+ *
690+ * @param uniqueKey will used as part of the key in the cache.
691+ */
692+ public void setUniqueKeyMenuCache (final String uniqueKey ) {
693+ this .uniqueKey = uniqueKey ;
694+ }
695+
696+ /**
697+ * This gets triggered when a player clicks on a button inside the inventory.
698+ *
699+ * @param menuButton the MenuButton instance that the player is currently clicking on.
700+ * @param player the player who performs the action.
701+ * @param clickedPos the actual slot the player is clicking on, excluding the page calculation. You can look at {@link #getSlot(int)}.
702+ * @param clickType the type of click the player is performing, such as right-click, left-click, or shift-click.
703+ * @param clickedItem the item clicked on.
704+ */
705+ public void onClick (MenuButton menuButton , Player player , int clickedPos , ClickType clickType , ItemStack clickedItem ) {
706+ if (this .getMenu () != null )
707+ menuButton .onClickInsideMenu (player , this .getMenu (), clickType , clickedItem );
708+ }
709+
710+ public void updateTitle () {
711+ Object title = getTitle ();
712+ if (!menuAPI .isNotFoundUpdateTitleClazz ())
713+ this .updateTitle (title );
714+ }
715+
716+ @ Nullable
717+ public ItemStack getMenuItem (final MenuButton menuButton , final ButtonData <T > cachedButtons , final int slot , final boolean updateButton ) {
718+ if (menuButton == null ) return null ;
719+
720+ if (updateButton ) {
721+ ItemStack itemStack = menuButton .getItem ();
722+ if (itemStack != null ) return itemStack ;
723+ itemStack = menuButton .getItem (this .getSlot (slot ));
724+ return itemStack ;
725+ }
726+ return null ;
727+ }
728+
729+ public void setButton (final int pageNumber , final MenuDataUtility <T > menuDataUtility , final int slot , final int fillSlotIndex , final boolean isLastFillSlot ) {
730+ final MenuButton menuButton = getMenuButtonAtSlot (slot , fillSlotIndex );
731+ final ItemStack result = getItemAtSlot (menuButton , slot , fillSlotIndex );
732+
733+ if (menuButton != null ) {
734+ if (menuButton .shouldUpdateButtons ()) this .buttonsToUpdate .add (menuButton );
735+ final ButtonData <T > buttonData = new ButtonData <>(result , menuButton , null );
736+
737+ menuDataUtility .putButton (this .getSlot (slot ), buttonData , null );
738+ }
739+ }
740+
645741 protected void putTimeWhenUpdatesButtons (final MenuButton menuButton , final Long time ) {
646742 this .getTimeWhenUpdatesButtons ().put (menuButton .getId (), time );
647743 }
@@ -691,61 +787,6 @@ protected void updateTimeButtons() {
691787 }
692788 }
693789
694- public void updateTitle () {
695- Object title = getTitle ();
696- if (!menuAPI .isNotFoundUpdateTitleClazz ())
697- this .updateTitle (title );
698- }
699-
700- /**
701- * Get the amount of fill slots for each menu page.
702- *
703- * @return the number of items could be added on each page.
704- */
705- public int getNumberOfFillItems () {
706- return numberOfFillItems ;
707- }
708-
709- private void saveMenuCache (@ Nonnull final Location location ) {
710- menuCache .addToCache (location , this .uniqueKey , this );
711- }
712-
713- private MenuUtility <?> getMenuCache () {
714- return menuCache .getMenuInCache (this .menuCacheKey , this .getClass ());
715- }
716-
717- /**
718- * Remove the cached menu. if you use location.
719- */
720- public void removeMenuCache () {
721- menuCache .removeMenuCached (this .menuCacheKey );
722- }
723-
724- /**
725- * Set a unique key for the cached menu if you want to have multiple menus on the same location,
726- * allowing many players to interact with different menus without limiting them to one menu or
727- * risking the override of an old menu when a player opens a new one. You need to use this method
728- * in your constructor,so your key gets added it to the cache.
729- *
730- * @param uniqueKey will used as part of the key in the cache.
731- */
732- public void setUniqueKeyMenuCache (final String uniqueKey ) {
733- this .uniqueKey = uniqueKey ;
734- }
735-
736- /**
737- * This gets triggered when a player clicks on a button inside the inventory.
738- *
739- * @param menuButton the MenuButton instance that the player is currently clicking on.
740- * @param player the player who performs the action.
741- * @param clickedPos the actual slot the player is clicking on, excluding the page calculation. You can look at {@link #getSlot(int)}.
742- * @param clickType the type of click the player is performing, such as right-click, left-click, or shift-click.
743- * @param clickedItem the item clicked on.
744- */
745- public void onClick (MenuButton menuButton , Player player , int clickedPos , ClickType clickType , ItemStack clickedItem ) {
746- if (this .getMenu () != null )
747- menuButton .onClickInsideMenu (player , this .getMenu (), clickType , clickedItem );
748- }
749790
750791 protected void setLocationMetaOnPlayer (final Player player , final Location location ) {
751792 String key = this .uniqueKey ;
@@ -844,18 +885,6 @@ protected void putMenuItemsToCache(final int pageNumber) {
844885 retrieveMenuButtons (pageNumber , menuDataUtility );
845886 }
846887
847- public void setButton (final int pageNumber , final MenuDataUtility <T > menuDataUtility , final int slot , final int fillSlotIndex , final boolean isLastFillSlot ) {
848- final MenuButton menuButton = getMenuButtonAtSlot (slot , fillSlotIndex );
849- final ItemStack result = getItemAtSlot (menuButton , slot , fillSlotIndex );
850-
851- if (menuButton != null ) {
852- if (menuButton .shouldUpdateButtons ()) this .buttonsToUpdate .add (menuButton );
853- final ButtonData <T > buttonData = new ButtonData <>(result , menuButton , null );
854-
855- menuDataUtility .putButton (this .getSlot (slot ), buttonData , null );
856- }
857- }
858-
859888 protected MenuButton getMenuButtonAtSlot (final int slot , final int fillSlot ) {
860889 final MenuButton result ;
861890 if (!this .getFillSpace ().isEmpty () && this .getFillSpace ().contains (slot )) {
@@ -866,6 +895,20 @@ protected MenuButton getMenuButtonAtSlot(final int slot, final int fillSlot) {
866895 return result ;
867896 }
868897
898+ /**
899+ * Retrieves the {@link ItemStack} for the given menu button in the specified slot.
900+ * <p>
901+ * This method first tries to return the default item provided by {@link MenuButton#getItem()}.
902+ * If that returns {@code null}, it attempts to fetch an item using the slot index from the
903+ * {@link MenuButton#getItem(int)} method, using the {@code fillSlot} argument.
904+ * <p>
905+ * The {@code fillSlot} corresponds to the index from the {@link #fillSpace} range.
906+ *
907+ * @param menuButton the menu button to retrieve the item from.
908+ * @param slot the current inventory slot being rendered.
909+ * @param fillSlot the index within {@link #fillSpace} representing the inventory slot.
910+ * @return the corresponding {@link ItemStack}, or {@code null} if none is found.
911+ */
869912 protected ItemStack getItemAtSlot (final MenuButton menuButton , final int slot , final int fillSlot ) {
870913 if (menuButton == null ) return null ;
871914
@@ -880,20 +923,6 @@ protected void redrawInventory() {
880923 this .inventory = this .inventoryRender .redraw ();
881924 }
882925
883- @ Nullable
884- public ItemStack getMenuItem (final MenuButton menuButton , final ButtonData <T > cachedButtons , final int slot , final boolean updateButton ) {
885- if (menuButton == null ) return null ;
886-
887- if (updateButton ) {
888- ItemStack itemStack = menuButton .getItem ();
889- if (itemStack != null ) return itemStack ;
890- itemStack = menuButton .getItem (this .getSlot (slot ));
891- return itemStack ;
892- }
893- return null ;
894- }
895-
896-
897926 protected void updateButtonsInList () {
898927 if (this .buttonAnimation == null || !this .buttonAnimation .isRunning ()) {
899928 this .buttonAnimation = new ButtonAnimation <>(this );
@@ -908,35 +937,17 @@ protected void runAnimateTitle() {
908937
909938 if (this .animateTitleTask == null || !this .animateTitleTask .isRunning ()) {
910939 this .animateTitleTask = new AnimateTitleTask <T >(this );
911- this .animateTitleTask .runTask ( 20L + this .animateTitleTime );
940+ this .animateTitleTask .runTask (20L + this .animateTitleTime );
912941 }
913942
914943 }
915944
916- public void cancelAnimateTitle () {
917- Function <?> task = getAnimateTitle ();
918- if (task == null ) return ;
919- this .animateTitle = null ;
920- this .animateTitleJson = null ;
921- if (this .animateTitleTask != null && this .animateTitleTask .isRunning ()) {
922- this .animateTitleTask .stopTask ();
923- }
924- updateTitle ();
925- }
926-
927- public Function <?> getAnimateTitle () {
928- if (this .animateTitle != null )
929- return this .animateTitle ;
930- if (this .animateTitleJson != null )
931- return this .animateTitleJson ;
932- return null ;
945+ private void saveMenuCache (@ Nonnull final Location location ) {
946+ menuCache .addToCache (location , this .uniqueKey , this );
933947 }
934948
935- public void updateTitle (Object text ) {
936- if (text instanceof String )
937- UpdateTitle .update (player , (String ) text , useColorConversion );
938- if (text instanceof JsonObject )
939- UpdateTitle .update (player , (JsonObject ) text );
949+ private MenuUtility <?> getMenuCache () {
950+ return menuCache .getMenuInCache (this .menuCacheKey , this .getClass ());
940951 }
941952
942953 public Plugin getPlugin () {
0 commit comments