Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final class MenuEquipment extends MenuEditChances {
- private final StrictMap<Integer, BossEquipmentSlot> slots = new StrictMap<>();
- private final Button randomButton;
- private MenuEquipment(final Menu parent, final EditMode mode) {
- super(parent, mode, 9 * 4);
- setTitle("Equipment");
- fillSlots();
- randomButton = new Button() {
- @Override
- public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) {
- final boolean has = boss.getEquipment().allowRandom();
- boss.getEquipment().setAllowRandomNoSave(!has);
- ((SimpleSettings) boss.getSettings()).saveEquipment_();
- restartMenu(has ? "&4Random equipment disallowed." : "&2Random equipment allowed.");
- }
- @Override
- public ItemStack getItem() {
- final boolean has = boss.getEquipment().allowRandom();
- return ItemCreator.of(
- has ? CompMaterial.BEACON : CompMaterial.GLASS,
- has ? "&aRandom Equipment Allowed" : "&fRandom Equipment Prevented",
- "",
- "Click to toggle.",
- "",
- "If random equipment is allowed",
- "mobs can wear vanilla equipment",
- "given randomly if you leave",
- "a slot empty.").build().make();
- }
- };
- }
- private void fillSlots() {
- int offset = 0;
- for (final BossEquipmentSlot slot : BossEquipmentSlot.values()) {
- if (slot == BossEquipmentSlot.OFF_HAND && MinecraftVersion.olderThan(V.v1_9)) {
- offset++;
- continue;
- }
- slots.put(9 + (offset = slot == BossEquipmentSlot.HELMET ? offset + 2 : offset + 1), slot);
- }
- }
- @Override
- public ItemStack getItemAt(final int slot) {
- if (mode == EditMode.ITEMS && slots.contains(slot + 9))
- return getHelpFor(slots.get(slot + 9));
- if (slots.contains(slot))
- return getEquipment(slots.get(slot));
- if (slot == getSize() - 3)
- return randomButton.getItem();
- return Common.getOrDefault(super.getItemAt(slot), ItemCreator.of(CompMaterial.BROWN_STAINED_GLASS_PANE).name(" ").build().make());
- }
- private ItemStack getEquipment(final BossEquipmentSlot slot) {
- return paintChanceItem(getBoss().getEquipment().get(slot));
- }
- private ItemStack getHelpFor(final BossEquipmentSlot slot) {
- return ItemCreator.of(
- CompMaterial.BLACK_STAINED_GLASS_PANE,
- "" + ItemUtil.bountifyCapitalized(slot) + " Slot",
- "",
- "Place &6" + ItemUtil.bountifyCapitalized(slot).toLowerCase() + (slot.toString().contains("HAND") ? " item" : "") + " &7below.")
- .color(CompColor.BLACK)
- .build().make();
- }
- @Override
- public void onMenuClose(final Player pl, final Inventory inv) {
- if (mode == EditMode.ITEMS)
- for (final Entry<Integer, BossEquipmentSlot> e : slots.entrySet()) {
- final ItemStack item = pl.getOpenInventory().getTopInventory().getItem(e.getKey());
- if (item != null && item.getType() == CompMaterial.PAPER.getMaterial() && item.getItemMeta().hasLore())
- continue;
- final BossEquipmentSlot equipmentSlot = e.getValue();
- final BossDrop oldDrop = getBoss().getEquipment().get(equipmentSlot);
- getBoss().getEquipment().setNoSave(equipmentSlot, item, item != null && oldDrop != null ? oldDrop.getDropChance() : 0F);
- }
- ((SimpleSettings) getBoss().getSettings()).saveEquipment_();
- BossUpdateUtil.updateAll();
- }
- @Override
- public void onMenuClick(final Player pl, final int slot, final InventoryAction action, final ClickType click, final ItemStack cursor, final ItemStack clicked, final boolean cancelled) {
- if (mode == EditMode.DROP_CHANCES && slots.contains(slot)) {
- final BossEquipment eq = getBoss().getEquipment();
- final BossEquipmentSlot equipSlot = slots.get(slot);
- final int chance = (int) MathUtil.ceiling(eq.get(equipSlot).getDropChance() * 100);
- final int newChance = MathUtil.range(chance + getNextQuantity(click), 0, 100);
- eq.setNoSave(equipSlot, eq.get(equipSlot).getItem(), newChance / 100F);
- pl.getOpenInventory().getTopInventory().setItem(slot, getItemAt(slot));
- }
- //((SimpleSettings) getBoss().getSettings()).saveEquipment();
- }
- @Override
- public boolean isActionAllowed(final MenuClickLocation location, final int slot, final ItemStack clicked, final ItemStack cursor) {
- if (mode == EditMode.DROP_CHANCES)
- return false;
- if (location == MenuClickLocation.MENU && slots.contains(slot)) {
- final String type = cursor.getType().toString();
- final BossEquipmentSlot eq = slots.get(slot);
- final boolean passed = type.equals("AIR") || eq == BossEquipmentSlot.HELMET ||
- eq == BossEquipmentSlot.CHESTPLATE && (type.contains("CHESTPLATE") || type.contains("ELYTRA")) ||
- eq == BossEquipmentSlot.LEGGINGS && type.contains("LEGGINGS") ||
- eq == BossEquipmentSlot.BOOTS && type.contains("BOOTS") ||
- eq == BossEquipmentSlot.HAND || eq == BossEquipmentSlot.OFF_HAND;
- if (!passed) {
- if (clicked != null)
- clicked.setAmount(0);
- animateTitle("&4Only insert " + ItemUtil.bountifyCapitalized(eq).toLowerCase() + " here!");
- }
- return passed;
- }
- return location == MenuClickLocation.PLAYER_INVENTORY;
- }
- }
Add Comment
Please, Sign In to add comment