Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final class MenuDrops extends MenuEditChances {
- private final Button dropToInventoryButton;
- private final Button vanillaDropsButton;
- private final Button singleDropButton;
- private MenuDrops(final Menu parent, final EditMode mode) {
- super(parent, mode, 9 * 6);
- setTitle("Drops");
- vanillaDropsButton = new Button() {
- @Override
- public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) {
- final boolean has = getBoss().getSettings().hasNaturalDrops();
- getBoss().getSettings().setNaturalDrops(!has);
- restartMenu(has ? "&4Vanilla drops disabled." : "&2Enabled vanilla drops.");
- }
- @Override
- public ItemStack getItem() {
- final boolean has = getBoss().getSettings().hasNaturalDrops();
- return ItemCreator.of(CompMaterial.FEATHER,
- "Vanilla Drops",
- "",
- has ? "&aBoss drops their vanilla drops" : "&7Boss only drops the items",
- has ? "&alike bones, food or picked items." : "&7specified in this menu.",
- "",
- "Click to toggle.")
- .glow(has)
- .build().make();
- }
- };
- dropToInventoryButton = new ButtonMenu(new MenuInventoryDrop(this),
- ItemCreator.of(
- CompMaterial.DROPPER,
- "Inventory Drops",
- "",
- "Instead of dropping the loot on",
- "the floor, give it directly to",
- "the inventory of last players",
- "who damaged the Boss the most."));
- singleDropButton = new Button() {
- @Override
- public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) {
- final boolean has = getBoss().getSettings().hasSingleDrops();
- getBoss().getSettings().setSingleDrops(!has);
- restartMenu(has ? "&4Single drops disabled." : "&2Enabled single drops.");
- }
- @Override
- public ItemStack getItem() {
- final boolean has = getBoss().getSettings().hasSingleDrops();
- return ItemCreator.of(has ? CompMaterial.BLAZE_ROD : CompMaterial.STICK,
- "Single Drops",
- "",
- has ? "&aBoss only drops one item from" : "&7Boss drops all items above",
- has ? "&aall items you put above." : "&7that trigger their drop chance.",
- "",
- "Click to toggle.")
- .build().make();
- }
- };
- }
- @Override
- public ItemStack getItemAt(final int slot) {
- if (slot == getSize() - 3)
- return vanillaDropsButton.getItem();
- if (slot == getSize() - 4)
- return singleDropButton.getItem();
- if (slot == getSize() - 7 && getMode() != EditMode.DROP_CHANCES)
- return dropToInventoryButton.getItem();
- if (slot < getSize() - 9) {
- final BossDrop drop = getBoss().getDrops().get(slot);
- if (drop != null)
- return paintChanceItem(drop);
- }
- return super.getItemAt(slot);
- }
- @Override
- public void onMenuClose(final Player pl, final Inventory inv) {
- if (mode == EditMode.ITEMS)
- for (final Entry<Integer, ItemStack> e : getItemsExceptBottomBar(inv).entrySet()) {
- final AutoUpdateMap<Integer, BossDrop> drops = getBoss().getDrops();
- final int slot = e.getKey();
- final ItemStack item = e.getValue();
- if (item == null) {
- if (drops.contains(slot))
- drops.removeAndUpdate(slot);
- continue;
- }
- final float dropChance = drops.contains(slot) ? drops.get(slot).getDropChance() : 0.5F;
- final BossDrop drop = new BossDrop(item, dropChance);
- drops.overrideAndUpdate(slot, drop);
- }
- }
- private Map<Integer, ItemStack> getItemsExceptBottomBar(final Inventory inv) {
- final Map<Integer, ItemStack> items = new HashMap<>();
- for (int i = 0; i < getSize() - 9; i++) {
- final ItemStack item = inv.getItem(i);
- items.put(i, item != null && !CompMaterial.isAir(item.getType()) ? item : null);
- }
- return items;
- }
- @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) {
- final BossDrop drop = getBoss().getDrops().get(slot);
- if (drop == null)
- return;
- final int chance = (int) MathUtil.ceiling(Math.round(drop.getDropChance() * 100));
- final int newChance = MathUtil.range(chance + getNextQuantity(click), 0, 100);
- drop.setDropChance(newChance / 100F);
- pl.getOpenInventory().getTopInventory().setItem(slot, getItemAt(slot));
- }
- }
- @Override
- public Menu newInstance() {
- return new MenuDrops(getParent(), mode);
- }
- }
- private final class MenuInventoryDrop extends Menu {
- private final Button enabledButton;
- private final Button playerLimitButton;
- private final Button timeLimitButton;
- protected MenuInventoryDrop(final Menu parent) {
- super(parent);
- setSize(9 * 4);
- setTitle("Inventory Drops");
- enabledButton = new Button() {
- @Override
- public void onClickedInMenu(final Player pl, final Menu menu, final ClickType click) {
- final boolean has = getBoss().getSettings().hasInventoryDrops();
- getBoss().getSettings().setInventoryDrops(!has);
- restartMenu(has ? "&4Inventory drops disabled." : "&2Enabled direct inventory drops.");
- }
- @Override
- public ItemStack getItem() {
- final boolean has = getBoss().getSettings().hasInventoryDrops();
- return ItemCreator.of(CompMaterial.ENDER_EYE,
- "Inventory Drops",
- "",
- has ? "&aBoss drops go directly" : "&7Boss drops items normally",
- has ? "&ainto the player's inventory." : "&7on the floor (default Minecraft).",
- "",
- "Click to toggle.")
- .glow(has)
- .build().make();
- }
- };
- playerLimitButton = new MenuButtonConvo(boss, this, BossConversation.PromptInvDropPlayerLimit.class, ItemCreator.of(
- CompMaterial.PLAYER_HEAD,
- "Player Limit",
- "",
- "Current: " + boss.getSettings().getInventoryDropsPlayerLimit(),
- "",
- "How many last players who",
- "damaged the Boss should",
- "get the drop reward?",
- "Default is 5 players."));
- timeLimitButton = new MenuButtonConvo(boss, this, BossConversation.PromptInvDropTimeLimit.class, ItemCreator.of(
- CompMaterial.CLOCK,
- "Time Limit",
- "",
- "Currently: " + Common.plural(boss.getSettings().getInventoryDropsTimeLimit(), "second"),
- "",
- "How many seconds should we",
- "keep the player who damaged",
- "the Boss in the reward list?",
- "Default is 10 seconds."));
- }
- @Override
- public ItemStack getItemAt(final int slot) {
- if (slot == 9 + 2)
- return enabledButton.getItem();
- if (slot == 9 + 4)
- return playerLimitButton.getItem();
- if (slot == 9 + 6)
- return timeLimitButton.getItem();
- return null;
- }
- @Override
- protected String[] getInfo() {
- return new String[] {
- "Configure giving Boss drops",
- "directly to the inventories",
- "of last damaging players."
- };
- }
- @Override
- public Menu newInstance() {
- return new MenuInventoryDrop(getParent());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment