Search in sources :

Example 1 with SpawnEggMeta

use of org.bukkit.inventory.meta.SpawnEggMeta in project Skills by StarTux.

the class BukkitSkillSacrifice method rewardsForItem.

List<Reward> rewardsForItem(ItemStack item) {
    List<Reward> result = new ArrayList<>();
    if (item == null)
        return result;
    addReward(result, rewardForItem(item));
    for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
        addReward(result, rewardForEnchantment(entry.getKey(), entry.getValue()));
    }
    if (item.hasItemMeta()) {
        ItemMeta meta = item.getItemMeta();
        if (meta instanceof EnchantmentStorageMeta) {
            for (Map.Entry<Enchantment, Integer> entry : ((EnchantmentStorageMeta) meta).getStoredEnchants().entrySet()) {
                addReward(result, rewardForEnchantment(entry.getKey(), entry.getValue()));
            }
        }
        if (meta instanceof SpawnEggMeta) {
            SpawnEggMeta spawnEggMeta = (SpawnEggMeta) meta;
            if (spawnEggMeta.getSpawnedType() != null) {
                addReward(result, rewardForEntityType(spawnEggMeta.getSpawnedType()));
            }
        }
    }
    return result;
}
Also used : EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) SpawnEggMeta(org.bukkit.inventory.meta.SpawnEggMeta) ArrayList(java.util.ArrayList) CustomReward(com.winthier.skills.CustomReward) Reward(com.winthier.skills.Reward) Enchantment(org.bukkit.enchantments.Enchantment) HashMap(java.util.HashMap) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 2 with SpawnEggMeta

use of org.bukkit.inventory.meta.SpawnEggMeta in project LandLord by SpatiumPrinceps.

the class AbstractManage method create.

@Override
protected void create() {
    List<String> regenerateDesc = lm.getStringList("Commands.Manage.Regenerate.description");
    List<String> greetDesc = lm.getStringList("Commands.Manage.SetGreet.description");
    List<String> farewellDesc = lm.getStringList("Commands.Manage.SetFarewell.description");
    int position = 0;
    if (regions.size() < 1)
        return;
    OwnedLand land = regions.get(0);
    for (LLFlag iFlag : land.getFlags()) {
        // For every IFlag of the land we wanna display an icon in the gui IF the flag is enabled for change
        String flagName = iFlag.getWGFlag().getName();
        String title = lm.getRawString("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".title");
        List<String> description = lm.getStringList("Commands.Manage.Allow" + flagName.substring(0, 1).toUpperCase() + flagName.substring(1) + ".description");
        if (plugin.getConfig().getBoolean("Manage." + flagName + ".enable")) {
            int finalPosition = position;
            this.setIcon(position, new Icon(createItem(iFlag.getMaterial(), 1, title, formatList(description, iFlag.getStatus()))).addClickAction((p, icon) -> {
                for (OwnedLand region : regions) {
                    for (LLFlag llFlag : region.getFlags()) {
                        if (llFlag.getWGFlag().equals(iFlag.getWGFlag())) {
                            llFlag.toggle();
                        }
                    }
                }
                updateLore(finalPosition, formatList(description, iFlag.getStatus()));
            }));
            position++;
        }
    }
    // Reminder: Regenerate is not implemented in Manageall, cos it might cos some trouble. Calculating costs might be a bit tedious
    if (plugin.getConfig().getBoolean("Manage.regenerate.enable") && regions.size() == 1) {
        double cost = plugin.getConfig().getDouble("ResetCost");
        this.setIcon(position, new Icon(createItem(Material.BARRIER, 1, lm.getRawString("Commands.Manage.Regenerate.title"), formatList(regenerateDesc, (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")))).addClickAction((p, ic) -> {
            if (land.isOwner(player.getUniqueId())) {
                ConfirmationGUI confi = new ConfirmationGUI(p, lm.getRawString("Commands.Manage.Regenerate.confirmation").replace("%cost%", (Options.isVaultEnabled() ? plugin.getVaultHandler().format(cost) : "-1")), (p1, ic1) -> {
                    boolean flag = false;
                    if (Options.isVaultEnabled())
                        if (plugin.getVaultHandler().hasBalance(player.getUniqueId(), cost)) {
                            plugin.getVaultHandler().take(player.getUniqueId(), cost);
                            flag = true;
                        } else
                            player.sendMessage(lm.getString("Commands.Manage.Regenerate.notEnoughMoney").replace("%cost%", plugin.getVaultHandler().format(cost)).replace("%name%", land.getName()));
                    else
                        flag = true;
                    if (flag) {
                        if (land.isOwner(player.getUniqueId())) {
                            player.getWorld().regenerateChunk(land.getChunk().getX(), land.getChunk().getZ());
                            player.sendMessage(lm.getString("Commands.Manage.Regenerate.success").replace("%land%", land.getName()));
                            display();
                        }
                    }
                }, (p2, ic2) -> {
                    player.sendMessage(lm.getString("Commands.Manage.Regenerate.abort").replace("%land%", land.getName()));
                    display();
                }, this);
                confi.setConfirm(lm.getRawString("Confirmation.accept"));
                confi.setDecline(lm.getRawString("Confirmation.decline"));
                confi.display();
            }
        }));
        position++;
    }
    // Set greet icon
    if (plugin.getConfig().getBoolean("Manage.setgreet.enable")) {
        String currentGreet = land.getWGLand().getFlag(DefaultFlag.GREET_MESSAGE);
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setgreet.item")), 1, lm.getRawString("Commands.Manage.SetGreet.title"), formatList(greetDesc, currentGreet))).addClickAction(((p, ic) -> {
            p.closeInventory();
            ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetGreet.clickMsg"));
            if (regions.size() > 1)
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreetall "));
            else
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setgreet "));
            p.spigot().sendMessage(builder.create());
        })));
        position++;
    }
    // TODO add functionality for manageall
    if (plugin.getConfig().getBoolean("Manage.mob-spawning.enable")) {
        String title = lm.getRawString("Commands.Manage.AllowMob-spawning.title");
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.mob-spawning.item")), 1, title, lm.getStringList("Commands.Manage.AllowMob-spawning.description"))).addClickAction((p, icon) -> {
            // Open a new gui with spawneggs where you can manage the spawns by clicking on them
            List<Icon> icons = new ArrayList<>();
            EntityType[] types = EntityType.values();
            List<String> lore = lm.getStringList("Commands.Manage.AllowMob-spawning.toggleItem.description");
            MultiPagedGUI gui = new MultiPagedGUI(p, 4, title, icons, this) {
            };
            for (EntityType t : types) {
                if (t.isAlive() && t.isSpawnable()) {
                    if (!toggleMobs.contains(t.name()))
                        continue;
                    ItemStack spawnEgg = new ItemStack(Material.MONSTER_EGG);
                    SpawnEggMeta meta = (SpawnEggMeta) spawnEgg.getItemMeta();
                    meta.setSpawnedType(t);
                    meta.setDisplayName(lm.getRawString("Commands.Manage.AllowMob-spawning.toggleItem.title").replace("%mob%", t.name()));
                    Set<EntityType> flag = land.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
                    String state;
                    if (flag != null)
                        state = (flag.contains(t) ? "DENY" : "ALLOW");
                    else
                        state = "ALLOW";
                    List<String> formattedLore = new ArrayList<>();
                    for (String s : lore) {
                        formattedLore.add(s.replace("%mob%", t.name()).replace("%value%", state));
                    }
                    meta.setLore(formattedLore);
                    spawnEgg.setItemMeta(meta);
                    Icon ic = new Icon(spawnEgg).addClickAction((clickingPlayer, ic3) -> {
                        for (OwnedLand region : regions) {
                            Set<EntityType> localFlag = region.getWGLand().getFlag(DefaultFlag.DENY_SPAWN);
                            // Toggle spawning of specific mob
                            if (localFlag != null) {
                                if (localFlag.contains(t))
                                    localFlag.remove(t);
                                else
                                    localFlag.add(t);
                            } else {
                                Set<EntityType> set = new HashSet<>();
                                set.add(t);
                                region.getWGLand().setFlag(DefaultFlag.DENY_SPAWN, set);
                            }
                        }
                        // update icon text
                        String iconState;
                        if (flag != null)
                            iconState = (flag.contains(t) ? "DENY" : "ALLOW");
                        else
                            iconState = "ALLOW";
                        List<String> newLore = new ArrayList<>();
                        for (String s : lore) {
                            newLore.add(s.replace("%mob%", t.name()).replace("%value%", iconState));
                        }
                        // System.out.println(newLore + " :" + finalIconPos);
                        ic3.setLore(newLore);
                        gui.refresh();
                    });
                    icons.add(ic);
                }
            }
            gui.display();
        }));
        position++;
    }
    // set farewell icon
    if (plugin.getConfig().getBoolean("Manage.setfarewell.enable")) {
        String currentFarewell = land.getWGLand().getFlag(DefaultFlag.FAREWELL_MESSAGE);
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.setfarewell.item")), 1, lm.getRawString("Commands.Manage.SetFarewell.title"), formatList(farewellDesc, currentFarewell))).addClickAction(((p, icon) -> {
            p.closeInventory();
            ComponentBuilder builder = new ComponentBuilder(lm.getString("Commands.Manage.SetFarewell.clickMsg"));
            if (regions.size() > 1)
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewellall "));
            else
                builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/land manage setfarewell "));
            p.spigot().sendMessage(builder.create());
        })));
        position++;
    }
    // set friends icon
    if (plugin.getConfig().getBoolean("Manage.friends.enable")) {
        ItemStack skull = createSkull(player.getName(), lm.getRawString("Commands.Manage.ManageFriends.title"), lm.getStringList("Commands.Manage.ManageFriends.description"));
        Set<UUID> friends = land.getWGLand().getMembers().getUniqueIds();
        MultiPagedGUI friendsGui = new MultiPagedGUI(player, (int) Math.ceil((double) friends.size() / 9.0), lm.getRawString("Commands.Manage.ManageFriends.title"), new ArrayList<>(), this) {
        };
        friends.forEach(id -> friendsGui.addIcon(new Icon(createSkull(Bukkit.getOfflinePlayer(id).getName(), Bukkit.getOfflinePlayer(id).getName(), formatFriendsSegment(id))).addClickAction((player, icon) -> {
            ConfirmationGUI confirmationGUI = new ConfirmationGUI(player, lm.getRawString("Commands.Manage.ManageFriends.unfriend").replace("%player%", Bukkit.getOfflinePlayer(id).getName()), (p, ic1) -> {
                friendsGui.removeIcon(friendsGui.filter(Bukkit.getOfflinePlayer(id).getName()).get(0));
                if (regions.size() > 1)
                    Bukkit.dispatchCommand(player, "land unfriendall " + Bukkit.getOfflinePlayer(id).getName());
                else
                    Bukkit.dispatchCommand(player, "land unfriend " + Bukkit.getOfflinePlayer(id).getName());
                player.closeInventory();
                friendsGui.display();
            }, (p, ic2) -> {
                player.closeInventory();
                friendsGui.display();
            }, friendsGui);
            confirmationGUI.setConfirm(lm.getRawString("Confirmation.accept"));
            confirmationGUI.setDecline(lm.getRawString("Confirmation.decline"));
            confirmationGUI.display();
        })));
        this.setIcon(position, new Icon(skull).setName(lm.getRawString("Commands.Manage.ManageFriends.title")).addClickAction((p, ic) -> friendsGui.display()));
        position++;
    }
    if (plugin.getConfig().getBoolean("Manage.unclaim.enable")) {
        this.setIcon(position, new Icon(createItem(Material.valueOf(plugin.getConfig().getString("Manage.unclaim.item")), 1, lm.getRawString("Commands.Manage.Unclaim.title"), lm.getStringList("Commands.Manage.Unclaim.description"))).addClickAction(((player1, icon) -> {
            ConfirmationGUI gui = new ConfirmationGUI(player1, lm.getRawString("Commands.Manage.Unclaim.confirmationTitle").replace("%land%", land.getName()), (p, ic2) -> {
                if (regions.size() > 1)
                    Bukkit.dispatchCommand(p, "ll unclaimall");
                else
                    Bukkit.dispatchCommand(p, "ll unclaim " + land.getName());
                p.closeInventory();
            }, (p, ic) -> {
                p.closeInventory();
                display();
            }, this);
            gui.setConfirm(lm.getRawString("Confirmation.accept"));
            gui.setDecline(lm.getRawString("Confirmation.decline"));
            gui.display();
        })));
        position++;
    }
}
Also used : MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) java.util(java.util) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) LLFlag(biz.princeps.landlord.flags.LLFlag) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Landlord(biz.princeps.landlord.Landlord) OwnedLand(biz.princeps.landlord.util.OwnedLand) CompletableFuture(java.util.concurrent.CompletableFuture) Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) DefaultFlag(com.sk89q.worldguard.protection.flags.DefaultFlag) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) Conditions(biz.princeps.lib.storage.requests.Conditions) SpawnEggMeta(org.bukkit.inventory.meta.SpawnEggMeta) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) ConfirmationGUI(biz.princeps.lib.gui.ConfirmationGUI) LPlayer(biz.princeps.landlord.persistent.LPlayer) Options(biz.princeps.landlord.api.Options) EntityType(org.bukkit.entity.EntityType) OfflinePlayer(org.bukkit.OfflinePlayer) ItemStack(org.bukkit.inventory.ItemStack) ExecutionException(java.util.concurrent.ExecutionException) AbstractGUI(biz.princeps.lib.gui.simple.AbstractGUI) LangManager(biz.princeps.landlord.manager.LangManager) Icon(biz.princeps.lib.gui.simple.Icon) SpawnEggMeta(org.bukkit.inventory.meta.SpawnEggMeta) OwnedLand(biz.princeps.landlord.util.OwnedLand) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) LLFlag(biz.princeps.landlord.flags.LLFlag) EntityType(org.bukkit.entity.EntityType) MultiPagedGUI(biz.princeps.lib.gui.MultiPagedGUI) ConfirmationGUI(biz.princeps.lib.gui.ConfirmationGUI) Icon(biz.princeps.lib.gui.simple.Icon) ItemStack(org.bukkit.inventory.ItemStack) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Aggregations

ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 SpawnEggMeta (org.bukkit.inventory.meta.SpawnEggMeta)2 Landlord (biz.princeps.landlord.Landlord)1 Options (biz.princeps.landlord.api.Options)1 LLFlag (biz.princeps.landlord.flags.LLFlag)1 LangManager (biz.princeps.landlord.manager.LangManager)1 LPlayer (biz.princeps.landlord.persistent.LPlayer)1 OwnedLand (biz.princeps.landlord.util.OwnedLand)1 ConfirmationGUI (biz.princeps.lib.gui.ConfirmationGUI)1 MultiPagedGUI (biz.princeps.lib.gui.MultiPagedGUI)1 AbstractGUI (biz.princeps.lib.gui.simple.AbstractGUI)1 Icon (biz.princeps.lib.gui.simple.Icon)1 Conditions (biz.princeps.lib.storage.requests.Conditions)1 DefaultFlag (com.sk89q.worldguard.protection.flags.DefaultFlag)1 CustomReward (com.winthier.skills.CustomReward)1 Reward (com.winthier.skills.Reward)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1