Search in sources :

Example 6 with IconMenuItem

use of de.Keyle.MyPet.api.gui.IconMenuItem in project MyPet by xXKeyleXx.

the class IconMenuInventory method open.

@Override
public void open(IconMenu menu, HumanEntity player) {
    size = menu.getSize();
    minecraftInventory = new CustomInventory(size, menu.getTitle());
    for (int slot = 0; slot < size; slot++) {
        IconMenuItem menuItem = menu.getOption(slot);
        if (menuItem != null) {
            ItemStack item = createItemStack(menuItem);
            minecraftInventory.setItem(slot, item);
        }
    }
    player.openInventory(minecraftInventory.getBukkitInventory());
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_11_R1.ItemStack) CustomInventory(de.Keyle.MyPet.compat.v1_11_R1.util.inventory.CustomInventory)

Example 7 with IconMenuItem

use of de.Keyle.MyPet.api.gui.IconMenuItem in project MyPet by xXKeyleXx.

the class IconMenuInventory method open.

@Override
public void open(IconMenu menu, HumanEntity player) {
    size = menu.getSize();
    minecraftInventory = new CustomInventory(size, menu.getTitle());
    for (int slot = 0; slot < size; slot++) {
        IconMenuItem menuItem = menu.getOption(slot);
        if (menuItem != null) {
            ItemStack item = createItemStack(menuItem);
            minecraftInventory.setItem(slot, item);
        }
    }
    player.openInventory(minecraftInventory.getBukkitInventory());
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) CustomInventory(de.Keyle.MyPet.compat.v1_8_R3.util.inventory.CustomInventory)

Example 8 with IconMenuItem

use of de.Keyle.MyPet.api.gui.IconMenuItem in project MyPet by xXKeyleXx.

the class IconMenuInventory method update.

@Override
public void update(IconMenu menu) {
    for (int slot = 0; slot < size; slot++) {
        IconMenuItem menuItem = menu.getOption(slot);
        if (menuItem != null) {
            ItemStack item = createItemStack(menuItem);
            minecraftInventory.setItem(slot, item);
        } else {
            minecraftInventory.setItem(slot, null);
        }
    }
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) ItemStack(net.minecraft.server.v1_9_R1.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)

Example 9 with IconMenuItem

use of de.Keyle.MyPet.api.gui.IconMenuItem in project MyPet by xXKeyleXx.

the class IconMenuInventory method open.

@Override
public void open(IconMenu menu, HumanEntity player) {
    size = menu.getSize();
    minecraftInventory = new CustomInventory(size, menu.getTitle());
    for (int slot = 0; slot < size; slot++) {
        IconMenuItem menuItem = menu.getOption(slot);
        if (menuItem != null) {
            ItemStack item = createItemStack(menuItem);
            minecraftInventory.setItem(slot, item);
        }
    }
    player.openInventory(minecraftInventory.getBukkitInventory());
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) ItemStack(net.minecraft.server.v1_9_R2.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack) CustomInventory(de.Keyle.MyPet.compat.v1_9_R2.util.inventory.CustomInventory)

Example 10 with IconMenuItem

use of de.Keyle.MyPet.api.gui.IconMenuItem in project MyPet by xXKeyleXx.

the class Beacon method activate.

public boolean activate() {
    final Player owner = myPet.getOwner().getPlayer();
    final Beacon beacon = this;
    String title = RESET + Translation.getString("Name.Skill.Beacon", myPet.getOwner());
    IconMenu menu = new IconMenu(title, new IconMenu.OptionClickEventHandler() {

        List<Integer> selectedBuffs = new ArrayList<>(beacon.selectedBuffs);

        boolean active = beacon.active;

        private BeaconReceiver receiver = beacon.receiver;

        @Override
        public void onOptionClick(IconMenu.OptionClickEvent event) {
            event.setWillClose(false);
            event.setWillDestroy(false);
            if (getMyPet().getStatus() != MyPet.PetState.Here) {
                return;
            }
            IconMenu menu = event.getMenu();
            switch(event.getPosition()) {
                case 5:
                    event.setWillClose(true);
                    event.setWillDestroy(true);
                    return;
                case 4:
                    if (active) {
                        menu.getOption(4).setMaterial(REDSTONE_BLOCK).setTitle(Util.formatText(Translation.getString("Message.Skill.Beacon.Effect", myPet.getOwner().getLanguage()), RED + Translation.getString("Name.Off", myPet.getOwner().getLanguage()))).setLore(RESET + Translation.getString("Message.Skill.Beacon.ClickOn", myPet.getOwner().getLanguage()));
                        active = false;
                    } else {
                        menu.getOption(4).setMaterial(EMERALD_BLOCK).setTitle(Util.formatText(Translation.getString("Message.Skill.Beacon.Effect", myPet.getOwner().getLanguage()), GREEN + Translation.getString("Name.On", myPet.getOwner().getLanguage()))).setLore(RESET + Translation.getString("Message.Skill.Beacon.ClickOff", myPet.getOwner().getLanguage()));
                        active = true;
                    }
                    menu.update();
                    break;
                case 3:
                    beacon.active = active;
                    beacon.selectedBuffs.clear();
                    beacon.selectedBuffs.addAll(selectedBuffs);
                    beacon.receiver = receiver;
                    event.setWillClose(true);
                    event.setWillDestroy(true);
                    break;
                case 21:
                    if (receiver != BeaconReceiver.Owner) {
                        menu.getOption(21).setMeta(ownerMeta, false, false);
                        if (menu.getOption(22) != null) {
                            menu.getOption(22).setMeta(partyMeta);
                        }
                        menu.getOption(23).setMeta(disabledMeta);
                        receiver = BeaconReceiver.Owner;
                        menu.update();
                    }
                    break;
                case 22:
                    if (receiver != BeaconReceiver.Party) {
                        menu.getOption(21).setMeta(disabledMeta);
                        menu.getOption(22).setMeta(partyMeta);
                        menu.getOption(23).setMeta(disabledMeta);
                        receiver = BeaconReceiver.Party;
                        menu.update();
                    }
                    break;
                case 23:
                    if (receiver != BeaconReceiver.Everyone) {
                        menu.getOption(21).setMeta(disabledMeta);
                        if (menu.getOption(22) != null) {
                            menu.getOption(22).setMeta(disabledMeta);
                        }
                        menu.getOption(23).setMeta(everyoneMeta);
                        receiver = BeaconReceiver.Everyone;
                        menu.update();
                    }
                    break;
                default:
                    if (buffPositionItems.containsKey(event.getPosition())) {
                        int selectedBuff = buffPositionItems.get(event.getPosition());
                        if (selectableBuffs > 1) {
                            if (selectedBuffs.indexOf(selectedBuff) != -1) {
                                selectedBuffs.remove(selectedBuffs.indexOf(selectedBuff));
                                menu.getOption(buffItemPositions.get(selectedBuff)).setGlowing(false);
                                if (selectableBuffs > selectedBuffs.size()) {
                                    menu.setOption(13, new IconMenuItem().setMaterial(POTION).setTitle(BLUE + Util.formatText(Translation.getString("Message.Skill.Beacon.RemainingBuffs", myPet.getOwner().getLanguage()), selectableBuffs - selectedBuffs.size())).setAmount(selectableBuffs - selectedBuffs.size()));
                                } else {
                                    menu.setOption(13, new IconMenuItem().setMaterial(GLASS_BOTTLE).setTitle(GRAY + Util.formatText(Translation.getString("Message.Skill.Beacon.RemainingBuffs", myPet.getOwner().getLanguage()), 0)));
                                }
                                menu.update();
                            } else if (selectableBuffs > selectedBuffs.size()) {
                                selectedBuffs.add(selectedBuff);
                                menu.getOption(buffItemPositions.get(selectedBuff)).setGlowing(true);
                                if (selectableBuffs > selectedBuffs.size()) {
                                    menu.setOption(13, new IconMenuItem().setMaterial(POTION).setTitle(BLUE + Util.formatText(Translation.getString("Message.Skill.Beacon.RemainingBuffs", myPet.getOwner().getLanguage()), selectableBuffs - selectedBuffs.size())).setAmount(selectableBuffs - selectedBuffs.size()));
                                } else {
                                    menu.setOption(13, new IconMenuItem().setMaterial(GLASS_BOTTLE).setTitle(GRAY + Util.formatText(Translation.getString("Message.Skill.Beacon.RemainingBuffs", myPet.getOwner().getLanguage()), 0)));
                                }
                                menu.update();
                            } else {
                                break;
                            }
                            if (selectableBuffs > selectedBuffs.size()) {
                                menu.setOption(13, new IconMenuItem().setMaterial(POTION).setTitle(BLUE + Util.formatText(Translation.getString("Message.Skill.Beacon.RemainingBuffs", myPet.getOwner().getLanguage()), selectableBuffs - selectedBuffs.size())).setAmount(selectableBuffs - selectedBuffs.size()));
                            } else {
                                menu.setOption(13, new IconMenuItem().setMaterial(GLASS_BOTTLE).setTitle(GRAY + Util.formatText(Translation.getString("Message.Skill.Beacon.RemainingBuffs", myPet.getOwner().getLanguage()), 0)));
                            }
                        } else {
                            if (!selectedBuffs.contains(selectedBuff)) {
                                if (selectedBuffs.size() != 0 && menu.getOption(buffItemPositions.get(selectedBuff)) != null) {
                                    menu.getOption(buffItemPositions.get(selectedBuffs.get(0))).setGlowing(false);
                                    selectedBuffs.clear();
                                }
                                selectedBuffs.add(selectedBuff);
                                menu.getOption(buffItemPositions.get(selectedBuff)).setGlowing(true);
                                menu.update();
                            }
                        }
                    }
            }
        }
    }, MyPetApi.getPlugin());
    if (beacon.active) {
        menu.setOption(4, new IconMenuItem().setMaterial(EMERALD_BLOCK).setTitle(Util.formatText(Translation.getString("Message.Skill.Beacon.Effect", myPet.getOwner().getLanguage()), GREEN + Translation.getString("Name.On", myPet.getOwner().getLanguage()))).addLoreLine(RESET + Translation.getString("Message.Skill.Beacon.ClickOff", myPet.getOwner().getLanguage())));
    } else {
        menu.setOption(4, new IconMenuItem().setMaterial(REDSTONE_BLOCK).setTitle(Util.formatText(Translation.getString("Message.Skill.Beacon.Effect", myPet.getOwner().getLanguage()), RED + Translation.getString("Name.Off", myPet.getOwner().getLanguage()))).addLoreLine(RESET + Translation.getString("Message.Skill.Beacon.ClickOn", myPet.getOwner().getLanguage())));
    }
    menu.setOption(3, new IconMenuItem().setMaterial(STAINED_GLASS_PANE).setData(5).setTitle(GREEN + Translation.getString("Name.Done", myPet.getOwner().getLanguage())));
    menu.setOption(5, new IconMenuItem().setMaterial(STAINED_GLASS_PANE).setData(14).setTitle(RED + Translation.getString("Name.Cancel", myPet.getOwner().getLanguage())));
    if (receiver == BeaconReceiver.Owner) {
        menu.setOption(21, new IconMenuItem().setMaterial(SKULL_ITEM).setData(3).setTitle(GOLD + Translation.getString("Name.Owner", myPet.getOwner().getLanguage())).setMeta(ownerMeta, false, false));
    } else {
        menu.setOption(21, new IconMenuItem().setMaterial(SKULL_ITEM).setData(3).setTitle(GOLD + Translation.getString("Name.Owner", myPet.getOwner().getLanguage())).setMeta(disabledMeta));
    }
    if (Configuration.Skilltree.Skill.Beacon.PARTY_SUPPORT && MyPetApi.getHookHelper().isInParty(getMyPet().getOwner().getPlayer())) {
        if (receiver != BeaconReceiver.Party) {
            menu.setOption(22, new IconMenuItem().setMaterial(SKULL_ITEM).setData(3).setTitle(GOLD + Translation.getString("Name.Party", myPet.getOwner().getLanguage())).setMeta(partyMeta));
        } else {
            menu.setOption(22, new IconMenuItem().setMaterial(SKULL_ITEM).setData(3).setTitle(GOLD + Translation.getString("Name.Party", myPet.getOwner().getLanguage())).setMeta(disabledMeta));
        }
    }
    if (receiver == BeaconReceiver.Everyone) {
        menu.setOption(23, new IconMenuItem().setMaterial(SKULL_ITEM).setData(3).setTitle(GOLD + Translation.getString("Name.Everyone", myPet.getOwner().getLanguage())).setMeta(everyoneMeta));
    } else {
        menu.setOption(23, new IconMenuItem().setMaterial(SKULL_ITEM).setData(3).setTitle(GOLD + Translation.getString("Name.Everyone", myPet.getOwner().getLanguage())).setMeta(disabledMeta));
    }
    if (buffLevel.get(1) > 0) {
        menu.setOption(0, new IconMenuItem().setMaterial(LEATHER_BOOTS).setAmount(buffLevel.get(1)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(1), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(1))));
    }
    if (buffLevel.get(3) > 0) {
        menu.setOption(9, new IconMenuItem().setMaterial(GOLD_PICKAXE).setAmount(buffLevel.get(3)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(3), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(3))));
    }
    if (buffLevel.get(5) > 0) {
        menu.setOption(18, new IconMenuItem().setMaterial(DIAMOND_SWORD).setAmount(buffLevel.get(5)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(5), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(5))));
    }
    if (buffLevel.get(8) > 0) {
        menu.setOption(1, new IconMenuItem().setMaterial(FIREWORK).setAmount(buffLevel.get(8)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(8), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(8))));
    }
    if (buffLevel.get(10) > 0) {
        menu.setOption(10, new IconMenuItem().setMaterial(APPLE).setAmount(buffLevel.get(10)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(10), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(10))));
    }
    if (buffLevel.get(11) > 0) {
        menu.setOption(19, new IconMenuItem().setMaterial(DIAMOND_CHESTPLATE).setAmount(buffLevel.get(11)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(11), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(11))));
    }
    if (buffLevel.get(12) > 0) {
        menu.setOption(7, new IconMenuItem().setMaterial(LAVA_BUCKET).setAmount(buffLevel.get(12)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(12), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(12))));
    }
    if (buffLevel.get(13) > 0) {
        menu.setOption(16, new IconMenuItem().setMaterial(RAW_FISH).setAmount(buffLevel.get(13)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(13), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(13))));
    }
    if (buffLevel.get(14) > 0) {
        menu.setOption(25, new IconMenuItem().setMaterial(EYE_OF_ENDER).setAmount(buffLevel.get(14)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(14), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(14))));
    }
    if (buffLevel.get(16) > 0) {
        menu.setOption(8, new IconMenuItem().setMaterial(TORCH).setAmount(buffLevel.get(16)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(16), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(16))));
    }
    if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
        if (buffLevel.get(26) > 0) {
            menu.setOption(17, new IconMenuItem().setMaterial(DIAMOND).setAmount(buffLevel.get(26)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(26), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(26))));
        }
    }
    /*
        if (buffLevel.get(21) > 0) {
            menu.setOption(17, new IconMenuItem().setMaterial(GOLDEN_APPLE).setAmount(buffLevel.get(21)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(21), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(21))));
        }
        */
    if (buffLevel.get(22) > 0) {
        menu.setOption(26, new IconMenuItem().setMaterial(SPONGE).setAmount(buffLevel.get(22)).setTitle(GOLD + Translation.getString("Name." + buffNames.get(22), myPet.getOwner().getLanguage()) + GRAY + " " + Util.decimal2roman(buffLevel.get(22))));
    }
    Iterator<Integer> iterator = selectedBuffs.iterator();
    while (iterator.hasNext()) {
        int buff = iterator.next();
        if (buffLevel.containsKey(buff) && buffLevel.get(buff) > 0) {
            menu.getOption(buffItemPositions.get(buff)).setGlowing(true);
        } else {
            iterator.remove();
        }
    }
    if (selectableBuffs > 1) {
        if (selectableBuffs > selectedBuffs.size()) {
            menu.setOption(13, new IconMenuItem().setMaterial(POTION).setTitle(BLUE + Util.formatText(Translation.getString("Message.Skill.Beacon.RemainingBuffs", myPet.getOwner().getLanguage()), selectableBuffs - selectedBuffs.size())).setAmount(selectableBuffs - selectedBuffs.size()));
        } else {
            menu.setOption(13, new IconMenuItem().setMaterial(GLASS_BOTTLE).setTitle(GRAY + Util.formatText(Translation.getString("Message.Skill.Beacon.RemainingBuffs", myPet.getOwner().getLanguage()), 0)));
        }
    }
    menu.open(owner);
    return true;
}
Also used : Player(org.bukkit.entity.Player) IconMenu(de.Keyle.MyPet.api.gui.IconMenu) IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem)

Aggregations

IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)21 IconMenu (de.Keyle.MyPet.api.gui.IconMenu)3 TagCompound (de.keyle.knbt.TagCompound)2 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)2 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)2 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)2 ItemStack (net.minecraft.server.v1_7_R4.ItemStack)2 ItemStack (net.minecraft.server.v1_8_R1.ItemStack)2 ItemStack (net.minecraft.server.v1_8_R2.ItemStack)2 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)2 ItemStack (net.minecraft.server.v1_9_R1.ItemStack)2 ItemStack (net.minecraft.server.v1_9_R2.ItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)2