Search in sources :

Example 6 with CrateOpeningException

use of gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException in project Nexus by ProjectEdenGG.

the class Crate method takeKey.

public void takeKey() {
    try {
        boolean took = false;
        ItemStack key = getCrateType().getKey();
        for (ItemStack item : player.getInventory().getContents()) {
            if (isNullOrAir(item))
                continue;
            if (ItemUtils.isFuzzyMatch(key, item)) {
                item.setAmount(item.getAmount() - 1);
                took = true;
                break;
            }
        }
        if (!took)
            throw new CrateOpeningException("no key present");
    } catch (Exception ex) {
        throw new CrateOpeningException("You must have a key in your inventory");
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) CrateOpeningException(gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException) CrateOpeningException(gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException)

Aggregations

CrateOpeningException (gg.projecteden.nexus.framework.exceptions.postconfigured.CrateOpeningException)6 CrateSpawnItemEvent (gg.projecteden.nexus.features.crates.models.events.CrateSpawnItemEvent)3 Item (org.bukkit.entity.Item)3 Vector (org.bukkit.util.Vector)3 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)2 MuteMenuItem (gg.projecteden.nexus.features.commands.MuteMenuCommand.MuteMenuProvider.MuteMenuItem)2 HashMap (java.util.HashMap)2 Location (org.bukkit.Location)2 ParticleBuilder (com.destroystokyo.paper.ParticleBuilder)1 Hologram (com.gmail.filoghost.holographicdisplays.api.Hologram)1 HologramsAPI (com.gmail.filoghost.holographicdisplays.api.HologramsAPI)1 Nexus (gg.projecteden.nexus.Nexus)1 Chat (gg.projecteden.nexus.features.chat.Chat)1 Crates (gg.projecteden.nexus.features.crates.Crates)1 CratePreviewProvider (gg.projecteden.nexus.features.crates.menus.CratePreviewProvider)1 CrateLoot (gg.projecteden.nexus.features.crates.models.CrateLoot)1 CrateType (gg.projecteden.nexus.features.crates.models.CrateType)1 MenuUtils (gg.projecteden.nexus.features.menus.MenuUtils)1 NexusException (gg.projecteden.nexus.framework.exceptions.NexusException)1 Nickname (gg.projecteden.nexus.models.nickname.Nickname)1