Advertisement
JackOUT

Untitled

Apr 6th, 2022
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.54 KB | None | 0 0
  1. package games.coob.animations.menu;
  2.  
  3. import lombok.AccessLevel;
  4. import lombok.RequiredArgsConstructor;
  5. import org.bukkit.inventory.ItemStack;
  6. import org.mineacademy.fo.menu.model.ItemCreator;
  7. import org.mineacademy.fo.remain.CompMaterial;
  8. import org.mineacademy.fo.slider.Slider;
  9.  
  10. import java.util.HashMap;
  11. import java.util.Map;
  12.  
  13. @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
  14. public class ItemFrameClockwiseSlider implements Slider<Map<Integer, ItemStack>> {
  15.  
  16.     /**
  17.      * The filler items
  18.      */
  19.     private final ItemStack fillerItem;
  20.  
  21.     /**
  22.      * The selected item
  23.      */
  24.     private final ItemStack highlightItem;
  25.  
  26.     /**
  27.      * The size of the frame for the animation (allowed values - 18, 27, 36, 45, 54), make sure the menu's size is big enough
  28.      */
  29.     private int frameSize = 27;
  30.  
  31.     /*
  32.      * The current head in the slider.
  33.      */
  34.     private int currentPointer = 0;
  35.  
  36.     /**
  37.      * Set the frame's size
  38.      *
  39.      * @param frameSize
  40.      * @return
  41.      */
  42.     public ItemFrameClockwiseSlider frameSize(final int frameSize) {
  43.         this.frameSize = frameSize;
  44.  
  45.         return this;
  46.     }
  47.  
  48.     /**
  49.      * @see org.mineacademy.fo.slider.Slider#next()
  50.      */
  51.     @Override
  52.     public Map<Integer, ItemStack> next() {
  53.  
  54.         final Map<Integer, ItemStack> items = new HashMap<>();
  55.         final int rowCount = this.frameSize / 9;
  56.  
  57.         for (int index = 0; index < this.frameSize; index++) {
  58.             final int row = index / 9;
  59.             final int column = (index % 9) + 1;
  60.  
  61.             if (row == 0 || row == rowCount - 1 || column == 1 || column == 9)
  62.                 items.put(index, this.fillerItem);
  63.         }
  64.  
  65.         if (this.currentPointer < 8)
  66.             this.currentPointer++;
  67.         else if (this.currentPointer == 8)
  68.             this.currentPointer = 17;
  69.  
  70.         else if (this.currentPointer <= this.frameSize - 1 && this.currentPointer > this.frameSize - 9)
  71.             this.currentPointer--;
  72.  
  73.         else if (this.currentPointer == 9)
  74.             this.currentPointer = 0;
  75.  
  76.         else if (rowCount >= 3) {
  77.             if (this.currentPointer == 17)
  78.                 this.currentPointer = 26;
  79.             else if (this.currentPointer == 18)
  80.                 this.currentPointer = 9;
  81.             else if (rowCount >= 4) {
  82.                 if (this.currentPointer == 26)
  83.                     this.currentPointer = 35;
  84.                 else if (this.currentPointer == 27)
  85.                     this.currentPointer = 18;
  86.                 else if (rowCount >= 5) {
  87.                     if (this.currentPointer == 35)
  88.                         this.currentPointer = 44;
  89.                     else if (this.currentPointer == 36)
  90.                         this.currentPointer = 27;
  91.                     else if (rowCount == 6) {
  92.                         if (this.currentPointer == 44)
  93.                             this.currentPointer = 53;
  94.                         else if (this.currentPointer == 45)
  95.                             this.currentPointer = 36;
  96.                     }
  97.                 }
  98.             }
  99.         }
  100.  
  101.         items.replace(this.currentPointer, this.highlightItem);
  102.  
  103.         return items;
  104.     }
  105.  
  106.     /**
  107.      * Create a new slider for the given items.
  108.      *
  109.      * @param filler
  110.      * @param highlighted
  111.      * @return
  112.      */
  113.     public static ItemFrameClockwiseSlider from(final CompMaterial filler, final CompMaterial highlighted) {
  114.         return from(ItemCreator.of(filler), ItemCreator.of(highlighted));
  115.     }
  116.  
  117.     /**
  118.      * Create a new slider for the given items.
  119.      *
  120.      * @param filler
  121.      * @param highlighted
  122.      * @return
  123.      */
  124.     public static ItemFrameClockwiseSlider from(final ItemCreator.ItemCreatorBuilder filler,
  125.                                                 final ItemCreator.ItemCreatorBuilder highlighted) {
  126.         return from(filler.build().make(), highlighted.build().make());
  127.     }
  128.  
  129.     /**
  130.      * Create a new slider for the given items.
  131.      *
  132.      * @param filler
  133.      * @param highlighted
  134.      * @return
  135.      */
  136.     public static ItemFrameClockwiseSlider from(final ItemStack filler, final ItemStack highlighted) {
  137.         return new ItemFrameClockwiseSlider(filler, highlighted);
  138.     }
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement