Advertisement
JackOUT

Untitled

Apr 6th, 2022
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 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. /**
  14.  * An example slider iterating through items and highlighting one.
  15.  */
  16. @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
  17. public final class ItemFrameBounceSlider implements Slider<Map<Integer, ItemStack>> {
  18.  
  19.     /**
  20.      * The filler items
  21.      */
  22.     private final ItemStack fillerItem;
  23.  
  24.     /**
  25.      * The selected item
  26.      */
  27.     private final ItemStack highlightItem;
  28.  
  29.     /**
  30.      * The items that are on each side of the frame
  31.      */
  32.     private final ItemStack sideItem;
  33.  
  34.     /**
  35.      * The items that are on each corner of the frame
  36.      */
  37.     private final ItemStack cornerItem;
  38.  
  39.     /**
  40.      * The size of the frame for the animation (allowed values - 18, 27, 36, 45, 54), make sure the menu's size is big enough
  41.      */
  42.     private int frameSize = 27;
  43.  
  44.     /*
  45.      * The first head in the slider.
  46.      */
  47.     private int topPointer = 0;
  48.  
  49.     /*
  50.      * The second head in the slider.
  51.      */
  52.     private int bottomPointer = 44;
  53.  
  54.     /*
  55.      * Check if the top pointer is decreasing
  56.      */
  57.     boolean topDecreasing = false;
  58.  
  59.     /*
  60.      * Check if the bottom pointer is decreasing
  61.      */
  62.     boolean bottomDecreasing = true;
  63.  
  64.     /**
  65.      * Set the frame's size
  66.      *
  67.      * @param frameSize
  68.      * @return
  69.      */
  70.     public ItemFrameBounceSlider frameSize(final int frameSize) {
  71.         this.frameSize = frameSize;
  72.  
  73.         return this;
  74.     }
  75.  
  76.     /**
  77.      * @see org.mineacademy.fo.slider.Slider#next()
  78.      */
  79.     @Override
  80.     public Map<Integer, ItemStack> next() {
  81.         final Map<Integer, ItemStack> items = new HashMap<>();
  82.         final int rowCount = this.frameSize / 9;
  83.  
  84.         for (int index = 0; index < this.frameSize; index++) {
  85.             final int row = index / 9;
  86.             final int column = (index % 9) + 1;
  87.  
  88.             if (row == 0 || row == rowCount - 1 /*|| column == 1 || column == 9*/)
  89.                 items.put(index, this.fillerItem);
  90.  
  91.             if (column == 1 || column == 9)
  92.                 items.put(index, sideItem);
  93.         }
  94.  
  95.         if (topDecreasing)
  96.             this.topPointer--;
  97.         else this.topPointer++;
  98.         if (this.topPointer == 0)
  99.             this.topDecreasing = false;
  100.         else if (this.topPointer == 8)
  101.             this.topDecreasing = true;
  102.  
  103.         if (bottomDecreasing)
  104.             this.bottomPointer--;
  105.         else this.bottomPointer++;
  106.         if (this.bottomPointer == this.frameSize - 9)
  107.             this.bottomDecreasing = false;
  108.         else if (this.bottomPointer == this.frameSize - 1)
  109.             this.bottomDecreasing = true;
  110.  
  111.         items.replace(this.topPointer, this.highlightItem);
  112.         items.replace(this.bottomPointer, this.highlightItem);
  113.  
  114.         if (this.topPointer == 0 || this.topPointer == 8)
  115.             items.replace(this.topPointer, this.cornerItem);
  116.  
  117.         if (this.bottomPointer == this.frameSize - 9 || this.bottomPointer == this.frameSize - 1)
  118.             items.replace(this.bottomPointer, this.cornerItem);
  119.  
  120.         return items;
  121.     }
  122.  
  123.     /**
  124.      * Create a new slider for the given items.
  125.      *
  126.      * @param filler
  127.      * @param highlighted
  128.      * @return
  129.      */
  130.     public static ItemFrameBounceSlider from(final CompMaterial filler, final CompMaterial highlighted, final CompMaterial side, final CompMaterial corner) {
  131.         return from(ItemCreator.of(filler), ItemCreator.of(highlighted), ItemCreator.of(side), ItemCreator.of(corner));
  132.     }
  133.  
  134.     /**
  135.      * Create a new slider for the given items.
  136.      *
  137.      * @param filler
  138.      * @param highlighted
  139.      * @return
  140.      */
  141.     public static ItemFrameBounceSlider from(final ItemCreator.ItemCreatorBuilder filler, final ItemCreator.ItemCreatorBuilder highlighted, final ItemCreator.ItemCreatorBuilder side, final ItemCreator.ItemCreatorBuilder corner) {
  142.         return from(filler.build().make(), highlighted.build().make(), side.build().make(), corner.build().make());
  143.     }
  144.  
  145.     /**
  146.      * Create a new slider for the given items.
  147.      *
  148.      * @param filler
  149.      * @param highlighted
  150.      * @return
  151.      */
  152.     public static ItemFrameBounceSlider from(final ItemStack filler, final ItemStack highlighted, final ItemStack side, final ItemStack corner) {
  153.         return new ItemFrameBounceSlider(filler, highlighted, side, corner);
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement