broken-arrow

Untitled

Dec 26th, 2021
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.06 KB | None | 0 0
  1. private final class MenuDrops extends MenuEditChances {
  2.  
  3.         private final Button dropToInventoryButton;
  4.         private final Button vanillaDropsButton;
  5.         private final Button singleDropButton;
  6.  
  7.         private MenuDrops(final Menu parent, final EditMode mode) {
  8.             super(parent, mode, 9 * 6);
  9.  
  10.             setTitle("Drops");
  11.  
  12.             vanillaDropsButton = new Button() {
  13.  
  14.                 @Override
  15.                 public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) {
  16.                     final boolean has = getBoss().getSettings().hasNaturalDrops();
  17.  
  18.                     getBoss().getSettings().setNaturalDrops(!has);
  19.                     restartMenu(has ? "&4Vanilla drops disabled." : "&2Enabled vanilla drops.");
  20.                 }
  21.  
  22.                 @Override
  23.                 public ItemStack getItem() {
  24.                     final boolean has = getBoss().getSettings().hasNaturalDrops();
  25.  
  26.                     return ItemCreator.of(CompMaterial.FEATHER,
  27.                             "Vanilla Drops",
  28.                             "",
  29.                             has ? "&aBoss drops their vanilla drops" : "&7Boss only drops the items",
  30.                             has ? "&alike bones, food or picked items." : "&7specified in this menu.",
  31.                             "",
  32.                             "Click to toggle.")
  33.                             .glow(has)
  34.                             .build().make();
  35.                 }
  36.             };
  37.  
  38.             dropToInventoryButton = new ButtonMenu(new MenuInventoryDrop(this),
  39.                     ItemCreator.of(
  40.                             CompMaterial.DROPPER,
  41.                             "Inventory Drops",
  42.                             "",
  43.                             "Instead of dropping the loot on",
  44.                             "the floor, give it directly to",
  45.                             "the inventory of last players",
  46.                             "who damaged the Boss the most."));
  47.  
  48.             singleDropButton = new Button() {
  49.  
  50.                 @Override
  51.                 public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) {
  52.                     final boolean has = getBoss().getSettings().hasSingleDrops();
  53.  
  54.                     getBoss().getSettings().setSingleDrops(!has);
  55.                     restartMenu(has ? "&4Single drops disabled." : "&2Enabled single drops.");
  56.                 }
  57.  
  58.                 @Override
  59.                 public ItemStack getItem() {
  60.                     final boolean has = getBoss().getSettings().hasSingleDrops();
  61.  
  62.                     return ItemCreator.of(has ? CompMaterial.BLAZE_ROD : CompMaterial.STICK,
  63.                             "Single Drops",
  64.                             "",
  65.                             has ? "&aBoss only drops one item from" : "&7Boss drops all items above",
  66.                             has ? "&aall items you put above." : "&7that trigger their drop chance.",
  67.                             "",
  68.                             "Click to toggle.")
  69.                             .build().make();
  70.                 }
  71.             };
  72.         }
  73.  
  74.         @Override
  75.         public ItemStack getItemAt(final int slot) {
  76.  
  77.             if (slot == getSize() - 3)
  78.                 return vanillaDropsButton.getItem();
  79.  
  80.             if (slot == getSize() - 4)
  81.                 return singleDropButton.getItem();
  82.  
  83.             if (slot == getSize() - 7 && getMode() != EditMode.DROP_CHANCES)
  84.                 return dropToInventoryButton.getItem();
  85.  
  86.             if (slot < getSize() - 9) {
  87.                 final BossDrop drop = getBoss().getDrops().get(slot);
  88.  
  89.                 if (drop != null)
  90.                     return paintChanceItem(drop);
  91.             }
  92.  
  93.             return super.getItemAt(slot);
  94.         }
  95.  
  96.         @Override
  97.         public void onMenuClose(final Player pl, final Inventory inv) {
  98.             if (mode == EditMode.ITEMS)
  99.                 for (final Entry<Integer, ItemStack> e : getItemsExceptBottomBar(inv).entrySet()) {
  100.                     final AutoUpdateMap<Integer, BossDrop> drops = getBoss().getDrops();
  101.  
  102.                     final int slot = e.getKey();
  103.                     final ItemStack item = e.getValue();
  104.  
  105.                     if (item == null) {
  106.                         if (drops.contains(slot))
  107.                             drops.removeAndUpdate(slot);
  108.  
  109.                         continue;
  110.                     }
  111.  
  112.                     final float dropChance = drops.contains(slot) ? drops.get(slot).getDropChance() : 0.5F;
  113.                     final BossDrop drop = new BossDrop(item, dropChance);
  114.  
  115.                     drops.overrideAndUpdate(slot, drop);
  116.                 }
  117.         }
  118.  
  119.         private Map<Integer, ItemStack> getItemsExceptBottomBar(final Inventory inv) {
  120.             final Map<Integer, ItemStack> items = new HashMap<>();
  121.  
  122.             for (int i = 0; i < getSize() - 9; i++) {
  123.                 final ItemStack item = inv.getItem(i);
  124.  
  125.                 items.put(i, item != null && !CompMaterial.isAir(item.getType()) ? item : null);
  126.             }
  127.  
  128.             return items;
  129.         }
  130.  
  131.         @Override
  132.         public void onMenuClick(final Player pl, final int slot, final InventoryAction action, final ClickType click, final ItemStack cursor, final ItemStack clicked, final boolean cancelled) {
  133.  
  134.             if (mode == EditMode.DROP_CHANCES) {
  135.                 final BossDrop drop = getBoss().getDrops().get(slot);
  136.  
  137.                 if (drop == null)
  138.                     return;
  139.  
  140.                 final int chance = (int) MathUtil.ceiling(Math.round(drop.getDropChance() * 100));
  141.                 final int newChance = MathUtil.range(chance + getNextQuantity(click), 0, 100);
  142.  
  143.                 drop.setDropChance(newChance / 100F);
  144.                 pl.getOpenInventory().getTopInventory().setItem(slot, getItemAt(slot));
  145.             }
  146.         }
  147.  
  148.         @Override
  149.         public Menu newInstance() {
  150.             return new MenuDrops(getParent(), mode);
  151.         }
  152.     }
  153.  
  154.     private final class MenuInventoryDrop extends Menu {
  155.  
  156.         private final Button enabledButton;
  157.         private final Button playerLimitButton;
  158.         private final Button timeLimitButton;
  159.  
  160.         protected MenuInventoryDrop(final Menu parent) {
  161.             super(parent);
  162.  
  163.             setSize(9 * 4);
  164.             setTitle("Inventory Drops");
  165.  
  166.             enabledButton = new Button() {
  167.  
  168.                 @Override
  169.                 public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) {
  170.                     final boolean has = getBoss().getSettings().hasInventoryDrops();
  171.  
  172.                     getBoss().getSettings().setInventoryDrops(!has);
  173.                     restartMenu(has ? "&4Inventory drops disabled." : "&2Enabled direct inventory drops.");
  174.                 }
  175.  
  176.                 @Override
  177.                 public ItemStack getItem() {
  178.                     final boolean has = getBoss().getSettings().hasInventoryDrops();
  179.  
  180.                     return ItemCreator.of(CompMaterial.ENDER_EYE,
  181.                             "Inventory Drops",
  182.                             "",
  183.                             has ? "&aBoss drops go directly" : "&7Boss drops items normally",
  184.                             has ? "&ainto the player's inventory." : "&7on the floor (default Minecraft).",
  185.                             "",
  186.                             "Click to toggle.")
  187.                             .glow(has)
  188.                             .build().make();
  189.                 }
  190.             };
  191.  
  192.             playerLimitButton = new MenuButtonConvo(boss, this, BossConversation.PromptInvDropPlayerLimit.class, ItemCreator.of(
  193.                     CompMaterial.PLAYER_HEAD,
  194.                     "Player Limit",
  195.                     "",
  196.                     "Current: " + boss.getSettings().getInventoryDropsPlayerLimit(),
  197.                     "",
  198.                     "How many last players who",
  199.                     "damaged the Boss should",
  200.                     "get the drop reward?",
  201.                     "Default is 5 players."));
  202.  
  203.             timeLimitButton = new MenuButtonConvo(boss, this, BossConversation.PromptInvDropTimeLimit.class, ItemCreator.of(
  204.                     CompMaterial.CLOCK,
  205.                     "Time Limit",
  206.                     "",
  207.                     "Currently: " + Common.plural(boss.getSettings().getInventoryDropsTimeLimit(), "second"),
  208.                     "",
  209.                     "How many seconds should we",
  210.                     "keep the player who damaged",
  211.                     "the Boss in the reward list?",
  212.                     "Default is 10 seconds."));
  213.         }
  214.  
  215.         @Override
  216.         public ItemStack getItemAt(final int slot) {
  217.  
  218.             if (slot == 9 + 2)
  219.                 return enabledButton.getItem();
  220.  
  221.             if (slot == 9 + 4)
  222.                 return playerLimitButton.getItem();
  223.  
  224.             if (slot == 9 + 6)
  225.                 return timeLimitButton.getItem();
  226.  
  227.             return null;
  228.         }
  229.  
  230.         @Override
  231.         protected String[] getInfo() {
  232.             return new String[] {
  233.                     "Configure giving Boss drops",
  234.                     "directly to the inventories",
  235.                     "of last damaging players."
  236.             };
  237.         }
  238.  
  239.         @Override
  240.         public Menu newInstance() {
  241.             return new MenuInventoryDrop(getParent());
  242.         }
  243.     }
  244.  
Advertisement
Add Comment
Please, Sign In to add comment