broken-arrow

Untitled

Dec 26th, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.15 KB | None | 0 0
  1.     private final class MenuEquipment extends MenuEditChances {
  2.  
  3.         private final StrictMap<Integer, BossEquipmentSlot> slots = new StrictMap<>();
  4.  
  5.         private final Button randomButton;
  6.  
  7.         private MenuEquipment(final Menu parent, final EditMode mode) {
  8.             super(parent, mode, 9 * 4);
  9.  
  10.             setTitle("Equipment");
  11.             fillSlots();
  12.  
  13.             randomButton = new Button() {
  14.  
  15.                 @Override
  16.                 public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) {
  17.                     final boolean has = boss.getEquipment().allowRandom();
  18.  
  19.                     boss.getEquipment().setAllowRandomNoSave(!has);
  20.                     ((SimpleSettings) boss.getSettings()).saveEquipment_();
  21.  
  22.                     restartMenu(has ? "&4Random equipment disallowed." : "&2Random equipment allowed.");
  23.                 }
  24.  
  25.                 @Override
  26.                 public ItemStack getItem() {
  27.                     final boolean has = boss.getEquipment().allowRandom();
  28.  
  29.                     return ItemCreator.of(
  30.                             has ? CompMaterial.BEACON : CompMaterial.GLASS,
  31.                             has ? "&aRandom Equipment Allowed" : "&fRandom Equipment Prevented",
  32.                             "",
  33.                             "Click to toggle.",
  34.                             "",
  35.                             "If random equipment is allowed",
  36.                             "mobs can wear vanilla equipment",
  37.                             "given randomly if you leave",
  38.                             "a slot empty.").build().make();
  39.                 }
  40.             };
  41.         }
  42.  
  43.         private void fillSlots() {
  44.             int offset = 0;
  45.  
  46.             for (final BossEquipmentSlot slot : BossEquipmentSlot.values()) {
  47.  
  48.                 if (slot == BossEquipmentSlot.OFF_HAND && MinecraftVersion.olderThan(V.v1_9)) {
  49.                     offset++;
  50.                     continue;
  51.                 }
  52.  
  53.                 slots.put(9 + (offset = slot == BossEquipmentSlot.HELMET ? offset + 2 : offset + 1), slot);
  54.             }
  55.         }
  56.  
  57.         @Override
  58.         public ItemStack getItemAt(final int slot) {
  59.  
  60.             if (mode == EditMode.ITEMS && slots.contains(slot + 9))
  61.                 return getHelpFor(slots.get(slot + 9));
  62.  
  63.             if (slots.contains(slot))
  64.                 return getEquipment(slots.get(slot));
  65.  
  66.             if (slot == getSize() - 3)
  67.                 return randomButton.getItem();
  68.  
  69.             return Common.getOrDefault(super.getItemAt(slot), ItemCreator.of(CompMaterial.BROWN_STAINED_GLASS_PANE).name(" ").build().make());
  70.         }
  71.  
  72.         private ItemStack getEquipment(final BossEquipmentSlot slot) {
  73.             return paintChanceItem(getBoss().getEquipment().get(slot));
  74.         }
  75.  
  76.         private ItemStack getHelpFor(final BossEquipmentSlot slot) {
  77.             return ItemCreator.of(
  78.                     CompMaterial.BLACK_STAINED_GLASS_PANE,
  79.                     "" + ItemUtil.bountifyCapitalized(slot) + " Slot",
  80.                     "",
  81.                     "Place &6" + ItemUtil.bountifyCapitalized(slot).toLowerCase() + (slot.toString().contains("HAND") ? " item" : "") + " &7below.")
  82.                     .color(CompColor.BLACK)
  83.                     .build().make();
  84.         }
  85.  
  86.         @Override
  87.         public void onMenuClose(final Player pl, final Inventory inv) {
  88.             if (mode == EditMode.ITEMS)
  89.                 for (final Entry<Integer, BossEquipmentSlot> e : slots.entrySet()) {
  90.                     final ItemStack item = pl.getOpenInventory().getTopInventory().getItem(e.getKey());
  91.  
  92.                     if (item != null && item.getType() == CompMaterial.PAPER.getMaterial() && item.getItemMeta().hasLore())
  93.                         continue;
  94.  
  95.                     final BossEquipmentSlot equipmentSlot = e.getValue();
  96.                     final BossDrop oldDrop = getBoss().getEquipment().get(equipmentSlot);
  97.  
  98.                     getBoss().getEquipment().setNoSave(equipmentSlot, item, item != null && oldDrop != null ? oldDrop.getDropChance() : 0F);
  99.                 }
  100.  
  101.             ((SimpleSettings) getBoss().getSettings()).saveEquipment_();
  102.  
  103.             BossUpdateUtil.updateAll();
  104.         }
  105.  
  106.         @Override
  107.         public void onMenuClick(final Player pl, final int slot, final InventoryAction action, final ClickType click, final ItemStack cursor, final ItemStack clicked, final boolean cancelled) {
  108.  
  109.             if (mode == EditMode.DROP_CHANCES && slots.contains(slot)) {
  110.                 final BossEquipment eq = getBoss().getEquipment();
  111.                 final BossEquipmentSlot equipSlot = slots.get(slot);
  112.  
  113.                 final int chance = (int) MathUtil.ceiling(eq.get(equipSlot).getDropChance() * 100);
  114.                 final int newChance = MathUtil.range(chance + getNextQuantity(click), 0, 100);
  115.  
  116.                 eq.setNoSave(equipSlot, eq.get(equipSlot).getItem(), newChance / 100F);
  117.  
  118.                 pl.getOpenInventory().getTopInventory().setItem(slot, getItemAt(slot));
  119.             }
  120.  
  121.             //((SimpleSettings) getBoss().getSettings()).saveEquipment();
  122.         }
  123.  
  124.         @Override
  125.         public boolean isActionAllowed(final MenuClickLocation location, final int slot, final ItemStack clicked, final ItemStack cursor) {
  126.             if (mode == EditMode.DROP_CHANCES)
  127.                 return false;
  128.  
  129.             if (location == MenuClickLocation.MENU && slots.contains(slot)) {
  130.                 final String type = cursor.getType().toString();
  131.                 final BossEquipmentSlot eq = slots.get(slot);
  132.  
  133.                 final boolean passed = type.equals("AIR") || eq == BossEquipmentSlot.HELMET ||
  134.                         eq == BossEquipmentSlot.CHESTPLATE && (type.contains("CHESTPLATE") || type.contains("ELYTRA")) ||
  135.                         eq == BossEquipmentSlot.LEGGINGS && type.contains("LEGGINGS") ||
  136.                         eq == BossEquipmentSlot.BOOTS && type.contains("BOOTS") ||
  137.                         eq == BossEquipmentSlot.HAND || eq == BossEquipmentSlot.OFF_HAND;
  138.  
  139.                 if (!passed) {
  140.                     if (clicked != null)
  141.                         clicked.setAmount(0);
  142.  
  143.                     animateTitle("&4Only insert " + ItemUtil.bountifyCapitalized(eq).toLowerCase() + " here!");
  144.                 }
  145.  
  146.                 return passed;
  147.             }
  148.  
  149.             return location == MenuClickLocation.PLAYER_INVENTORY;
  150.         }
  151.     }
Add Comment
Please, Sign In to add comment