Search in sources :

Example 1 with EggIconService

use of de.Keyle.MyPet.api.util.service.types.EggIconService in project MyPet by xXKeyleXx.

the class ShopMyPet method getIcon.

public IconMenuItem getIcon() {
    IconMenuItem icon = this.icon.clone();
    Optional<EggIconService> egg = MyPetApi.getServiceManager().getService(EggIconService.class);
    egg.ifPresent(eggIconService -> eggIconService.updateIcon(petType, icon));
    icon.setTitle(ChatColor.AQUA + Colorizer.setColors(getPetName()));
    return icon;
}
Also used : EggIconService(de.Keyle.MyPet.api.util.service.types.EggIconService) IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem)

Example 2 with EggIconService

use of de.Keyle.MyPet.api.util.service.types.EggIconService in project MyPet by xXKeyleXx.

the class MyPetSelectionGui method open.

public void open(final List<StoredMyPet> pets, int page, final RepositoryCallback<StoredMyPet> callback) {
    if (pets.size() > 0) {
        if (page < 1 || Math.ceil(pets.size() / 45.) < page) {
            page = 1;
        }
        final Map<Integer, StoredMyPet> petSlotList = new HashMap<>();
        WorldGroup wg = WorldGroup.getGroupByWorld(player.getPlayer().getWorld().getName());
        Iterator<StoredMyPet> iterator = pets.iterator();
        while (iterator.hasNext()) {
            StoredMyPet mypet = iterator.next();
            if (mypet.getWorldGroup().equals("") || !mypet.getWorldGroup().equals(wg.getName())) {
                iterator.remove();
            }
            if (player.hasMyPet() && player.getMyPet().getUUID().equals(mypet.getUUID())) {
                iterator.remove();
            }
        }
        final int previousPage = page == 1 ? (int) Math.ceil(pets.size() / 45.) : page - 1;
        final int nextPage = page == Math.ceil(pets.size() / 45.) ? 1 : page + 1;
        IconMenu menu = new IconMenu(title, event -> {
            if (event.getPosition() == 45) {
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        open(pets, previousPage, callback);
                    }
                }.runTaskLater(MyPetApi.getPlugin(), 1L);
            } else if (event.getPosition() == 53) {
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        open(pets, nextPage, callback);
                    }
                }.runTaskLater(MyPetApi.getPlugin(), 1L);
            } else if (event.getPosition() > 45) {
                return;
            } else if (petSlotList.containsKey(event.getPosition())) {
                StoredMyPet storedMyPet = petSlotList.get(event.getPosition());
                if (storedMyPet != null && callback != null) {
                    callback.callback(storedMyPet);
                }
            }
            event.setWillClose(true);
            event.setWillDestroy(true);
        }, MyPetApi.getPlugin());
        int pagePets = pets.size() - (page - 1) * 45;
        for (int i = 0; i < pagePets && i <= 45; i++) {
            StoredMyPet mypet = pets.get(i + ((page - 1) * 45));
            List<String> lore = new ArrayList<>();
            lore.add(RESET + Translation.getString("Name.Hunger", player) + ": " + GOLD + Math.round(mypet.getSaturation()));
            if (mypet.getRespawnTime() > 0) {
                lore.add(RESET + Translation.getString("Name.Respawntime", player) + ": " + GOLD + mypet.getRespawnTime() + "sec");
            } else {
                lore.add(RESET + Translation.getString("Name.HP", player) + ": " + GOLD + String.format("%1.2f", mypet.getHealth()));
            }
            boolean levelFound = false;
            if (mypet.getInfo().containsKey("storage")) {
                TagCompound storage = mypet.getInfo().getAs("storage", TagCompound.class);
                if (storage.containsKey("level")) {
                    lore.add(RESET + Translation.getString("Name.Level", player) + ": " + GOLD + storage.getAs("level", TagInt.class).getIntData());
                    levelFound = true;
                }
            }
            if (!levelFound) {
                lore.add(RESET + Translation.getString("Name.Exp", player) + ": " + GOLD + String.format("%1.2f", mypet.getExp()));
            }
            lore.add(RESET + Translation.getString("Name.Type", player) + ": " + GOLD + Translation.getString("Name." + mypet.getPetType().name(), player));
            lore.add(RESET + Translation.getString("Name.Skilltree", player) + ": " + GOLD + Colorizer.setColors(mypet.getSkilltree() != null ? mypet.getSkilltree().getDisplayName() : "-"));
            IconMenuItem icon = new IconMenuItem();
            icon.setTitle(RESET + mypet.getPetName());
            icon.addLore(lore);
            Optional<EggIconService> egg = MyPetApi.getServiceManager().getService(EggIconService.class);
            egg.ifPresent(service -> service.updateIcon(mypet.getPetType(), icon));
            int pos = menu.addOption(icon);
            petSlotList.put(pos, mypet);
        }
        if (previousPage != page) {
            menu.setOption(45, new IconMenuItem().setMaterial(EnumSelector.find(Material.class, "SIGN", "OAK_SIGN")).setTitle("" + previousPage + " ≪≪"));
        }
        if (previousPage != page) {
            menu.setOption(53, new IconMenuItem().setMaterial(EnumSelector.find(Material.class, "SIGN", "OAK_SIGN")).setTitle(ChatColor.BOLD + "≫≫ " + ChatColor.RESET + nextPage));
        }
        menu.open(player.getPlayer());
    }
}
Also used : IconMenu(de.Keyle.MyPet.api.gui.IconMenu) WorldGroup(de.Keyle.MyPet.api.WorldGroup) TagInt(de.keyle.knbt.TagInt) EggIconService(de.Keyle.MyPet.api.util.service.types.EggIconService) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Material(org.bukkit.Material) TagCompound(de.keyle.knbt.TagCompound) IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Example 3 with EggIconService

use of de.Keyle.MyPet.api.util.service.types.EggIconService in project MyPet by xXKeyleXx.

the class MyPetAdminSelectionGui method open.

public void open(final List<StoredMyPet> pets, int page, final RepositoryCallback<StoredMyPet> callback) {
    if (pets.size() > 0) {
        if (page < 1 || Math.ceil(pets.size() / 45.) < page) {
            page = 1;
        }
        final Map<Integer, StoredMyPet> petSlotList = new HashMap<>();
        WorldGroup wg = WorldGroup.getGroupByWorld(petOwner.getPlayer().getWorld().getName());
        Iterator<StoredMyPet> iterator = pets.iterator();
        while (iterator.hasNext()) {
            StoredMyPet mypet = iterator.next();
            if (mypet.getWorldGroup().equals("") || !mypet.getWorldGroup().equals(wg.getName())) {
                iterator.remove();
            }
            if (petOwner.hasMyPet() && petOwner.getMyPet().getUUID().equals(mypet.getUUID())) {
                iterator.remove();
            }
        }
        final int previousPage = page == 1 ? (int) Math.ceil(pets.size() / 45.) : page - 1;
        final int nextPage = page == Math.ceil(pets.size() / 45.) ? 1 : page + 1;
        IconMenu menu = new IconMenu(title, event -> {
            if (event.getPosition() == 45) {
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        open(pets, previousPage, callback);
                    }
                }.runTaskLater(MyPetApi.getPlugin(), 1L);
            } else if (event.getPosition() == 53) {
                new BukkitRunnable() {

                    @Override
                    public void run() {
                        open(pets, nextPage, callback);
                    }
                }.runTaskLater(MyPetApi.getPlugin(), 1L);
            } else if (event.getPosition() > 45) {
                return;
            } else if (petSlotList.containsKey(event.getPosition())) {
                StoredMyPet storedMyPet = petSlotList.get(event.getPosition());
                if (storedMyPet != null && callback != null) {
                    callback.callback(storedMyPet);
                }
            }
            event.setWillClose(true);
            event.setWillDestroy(true);
        }, MyPetApi.getPlugin());
        int pagePets = pets.size() - (page - 1) * 45;
        for (int i = 0; i < pagePets && i <= 45; i++) {
            StoredMyPet mypet = pets.get(i + ((page - 1) * 45));
            List<String> lore = new ArrayList<>();
            lore.add(RESET + Translation.getString("Name.Hunger", admin) + ": " + GOLD + Math.round(mypet.getSaturation()));
            if (mypet.getRespawnTime() > 0) {
                lore.add(RESET + Translation.getString("Name.Respawntime", admin) + ": " + GOLD + mypet.getRespawnTime() + "sec");
            } else {
                lore.add(RESET + Translation.getString("Name.HP", admin) + ": " + GOLD + String.format("%1.2f", mypet.getHealth()));
            }
            boolean levelFound = false;
            if (mypet.getInfo().containsKey("storage")) {
                TagCompound storage = mypet.getInfo().getAs("storage", TagCompound.class);
                if (storage.containsKey("level")) {
                    lore.add(RESET + Translation.getString("Name.Level", admin) + ": " + GOLD + storage.getAs("level", TagInt.class).getIntData());
                    levelFound = true;
                }
            }
            if (!levelFound) {
                lore.add(RESET + Translation.getString("Name.Exp", admin) + ": " + GOLD + String.format("%1.2f", mypet.getExp()));
            }
            lore.add(RESET + Translation.getString("Name.Type", admin) + ": " + GOLD + Translation.getString("Name." + mypet.getPetType().name(), admin));
            lore.add(RESET + Translation.getString("Name.Skilltree", admin) + ": " + GOLD + Colorizer.setColors(mypet.getSkilltree() != null ? mypet.getSkilltree().getDisplayName() : "-"));
            IconMenuItem icon = new IconMenuItem();
            icon.setTitle(RESET + mypet.getPetName());
            icon.addLore(lore);
            Optional<EggIconService> egg = MyPetApi.getServiceManager().getService(EggIconService.class);
            egg.ifPresent(service -> service.updateIcon(mypet.getPetType(), icon));
            int pos = menu.addOption(icon);
            petSlotList.put(pos, mypet);
        }
        if (previousPage != page) {
            menu.setOption(45, new IconMenuItem().setMaterial(EnumSelector.find(Material.class, "SIGN", "OAK_SIGN")).setTitle("" + previousPage + " ≪≪"));
        }
        if (previousPage != page) {
            menu.setOption(53, new IconMenuItem().setMaterial(EnumSelector.find(Material.class, "SIGN", "OAK_SIGN")).setTitle(ChatColor.BOLD + "≫≫ " + ChatColor.RESET + nextPage));
        }
        menu.open(admin);
    }
}
Also used : IconMenu(de.Keyle.MyPet.api.gui.IconMenu) HashMap(java.util.HashMap) WorldGroup(de.Keyle.MyPet.api.WorldGroup) ArrayList(java.util.ArrayList) TagInt(de.keyle.knbt.TagInt) EggIconService(de.Keyle.MyPet.api.util.service.types.EggIconService) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Material(org.bukkit.Material) TagCompound(de.keyle.knbt.TagCompound) IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) StoredMyPet(de.Keyle.MyPet.api.entity.StoredMyPet)

Aggregations

IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)3 EggIconService (de.Keyle.MyPet.api.util.service.types.EggIconService)3 WorldGroup (de.Keyle.MyPet.api.WorldGroup)2 StoredMyPet (de.Keyle.MyPet.api.entity.StoredMyPet)2 IconMenu (de.Keyle.MyPet.api.gui.IconMenu)2 TagCompound (de.keyle.knbt.TagCompound)2 TagInt (de.keyle.knbt.TagInt)2 Material (org.bukkit.Material)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1