Search in sources :

Example 81 with Inventory

use of org.bukkit.inventory.Inventory in project askyblock by tastybento.

the class AcidInventory method onInventoryOpen.

/**
 * This covers items in a chest, etc. inventory, then change the name then
 *
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent e) {
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());
    // plugin.getLogger().info("Inventory open event called");
    if (e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
        Inventory inventory = e.getInventory();
        if (Settings.acidDamage == 0D || !Settings.acidBottle) {
            return;
        }
        // If this is the minishop - forget it
        if (inventory.getName() != null && inventory.getName().equalsIgnoreCase(plugin.myLocale(e.getPlayer().getUniqueId()).islandMiniShopTitle)) {
            return;
        }
        if (inventory.contains(Material.WATER_BUCKET)) {
            if (DEBUG)
                plugin.getLogger().info("Inventory contains water bucket");
            ItemStack[] inv = inventory.getContents();
            for (ItemStack item : inv) {
                if (item != null) {
                    // plugin.getLogger().info(item.toString());
                    if (item.getType() == Material.WATER_BUCKET) {
                        if (DEBUG)
                            plugin.getLogger().info("Found it!");
                        ItemMeta meta = item.getItemMeta();
                        meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBucket);
                        lore = Arrays.asList(plugin.myLocale(e.getPlayer().getUniqueId()).acidLore.split("\n"));
                        meta.setLore(lore);
                        item.setItemMeta(meta);
                    }
                }
            }
        } else if (inventory.contains(Material.POTION)) {
            if (DEBUG)
                plugin.getLogger().info("Inventory contains water bottle");
            ItemStack[] inv = inventory.getContents();
            for (ItemStack item : inv) {
                if (item != null) {
                    // plugin.getLogger().info(item.toString());
                    if (item.getType() == Material.POTION) {
                        NMSAbstraction nms = null;
                        try {
                            nms = Util.checkVersion();
                        } catch (Exception ex) {
                            return;
                        }
                        if (!nms.isPotion(item)) {
                            if (DEBUG)
                                plugin.getLogger().info("Found it!");
                            ItemMeta meta = item.getItemMeta();
                            meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBottle);
                            lore = Arrays.asList(plugin.myLocale(e.getPlayer().getUniqueId()).acidLore.split("\n"));
                            meta.setLore(lore);
                            item.setItemMeta(meta);
                        }
                    }
                }
            }
        }
    }
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) NMSAbstraction(com.wasteofplastic.askyblock.nms.NMSAbstraction) BrewerInventory(org.bukkit.inventory.BrewerInventory) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemMeta(org.bukkit.inventory.meta.ItemMeta) EventHandler(org.bukkit.event.EventHandler)

Example 82 with Inventory

use of org.bukkit.inventory.Inventory in project askyblock by tastybento.

the class Challenges method challengePanel.

/**
 * Dynamically creates an inventory of challenges for the player showing the
 * level
 *
 * @param player
 * @param level
 * @return inventory
 */
public Inventory challengePanel(Player player, String level) {
    // plugin.getLogger().info("DEBUG: level requested = " + level);
    // Create the challenges control panel
    // New panel map
    List<CPItem> cp = new ArrayList<CPItem>();
    if (level.isEmpty() && !challengeList.containsKey("")) {
        if (!Settings.challengeLevels.isEmpty()) {
            level = Settings.challengeLevels.get(0);
        } else {
            // We have no challenges!
            plugin.getLogger().severe("There are no challenges to show!");
            Inventory error = Bukkit.createInventory(null, 9, plugin.myLocale(player.getUniqueId()).challengesguiTitle);
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
            return error;
        }
    }
    if (challengeList.get(level) != null) {
        // Only show a control panel for the level requested.
        for (String challengeName : challengeList.get(level)) {
            CPItem item = createItem(challengeName, player);
            if (item != null) {
                cp.add(item);
            }
        }
    }
    // Add the missing levels so player can navigate to them
    int levelDone = 0;
    for (; levelDone < Settings.challengeLevels.size(); levelDone++) {
        if (checkLevelCompletion(player, Settings.challengeLevels.get(levelDone)) > 0) {
            break;
        }
    }
    // plugin.getLogger().info("DEBUG: level done = " + levelDone);
    for (int i = 0; i < Settings.challengeLevels.size(); i++) {
        if (!level.equalsIgnoreCase(Settings.challengeLevels.get(i))) {
            // Add a navigation book
            List<String> lore = new ArrayList<String>();
            if (i <= levelDone) {
                CPItem item = new CPItem(Material.BOOK_AND_QUILL, ChatColor.GOLD + Settings.challengeLevels.get(i), null, null);
                lore = Util.chop(ChatColor.WHITE, plugin.myLocale(player.getUniqueId()).challengesNavigation.replace("[level]", Settings.challengeLevels.get(i)), 25);
                item.setNextSection(Settings.challengeLevels.get(i));
                item.setLore(lore);
                cp.add(item);
            } else {
                // Hint at what is to come
                CPItem item = new CPItem(Material.BOOK, ChatColor.GOLD + Settings.challengeLevels.get(i), null, null);
                // Add the level
                int toDo = checkLevelCompletion(player, Settings.challengeLevels.get(i - 1));
                lore = Util.chop(ChatColor.WHITE, plugin.myLocale(player.getUniqueId()).challengestoComplete.replace("[challengesToDo]", String.valueOf(toDo)).replace("[thisLevel]", Settings.challengeLevels.get(i - 1)), 25);
                item.setLore(lore);
                cp.add(item);
            }
        }
    }
    // Add the free challenges if not already shown (which can happen if all of the challenges are done!)
    if (!level.equals("") && challengeList.containsKey("")) {
        for (String freeChallenges : challengeList.get("")) {
            CPItem item = createItem(freeChallenges, player);
            if (item != null) {
                cp.add(item);
            }
        }
    }
    // Create the panel
    if (cp.size() > 0) {
        // Make sure size is a multiple of 9
        int size = cp.size() + 8;
        size -= (size % 9);
        Inventory newPanel = Bukkit.createInventory(null, size, plugin.myLocale(player.getUniqueId()).challengesguiTitle);
        // Store the panel details for retrieval later
        playerChallengeGUI.put(player.getUniqueId(), cp);
        // Fill the inventory and return
        int index = 0;
        for (CPItem i : cp) {
            newPanel.setItem(index++, i.getItem());
        }
        return newPanel;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) CPItem(com.wasteofplastic.askyblock.panels.CPItem) Inventory(org.bukkit.inventory.Inventory)

Example 83 with Inventory

use of org.bukkit.inventory.Inventory in project Towny by ElgarL.

the class ProtectionRegenTask method replaceProtections.

public void replaceProtections() {
    try {
        Block block = state.getBlock();
        if (state.getData() instanceof Door) {
            Door door = (Door) state.getData();
            Block topHalf;
            Block bottomHalf;
            if (door.isTopHalf()) {
                topHalf = block;
                bottomHalf = block.getRelative(BlockFace.DOWN);
            } else {
                bottomHalf = block;
                topHalf = block.getRelative(BlockFace.UP);
            }
            door.setTopHalf(true);
            topHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
            door.setTopHalf(false);
            bottomHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
        } else if (state instanceof Sign) {
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
            Sign sign = (Sign) block.getState();
            int i = 0;
            for (String line : ((Sign) state).getLines()) sign.setLine(i++, line);
            sign.update(true);
        } else if (state instanceof CreatureSpawner) {
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
            ((CreatureSpawner) block.getState()).setSpawnedType(((CreatureSpawner) state).getSpawnedType());
        } else if (state instanceof InventoryHolder) {
            block.setTypeId(state.getTypeId(), false);
            // Container to receive the inventory
            Inventory container = ((InventoryHolder) block.getState()).getInventory();
            container.setContents(contents.toArray(new ItemStack[0]));
            block.setData(state.getData().getData(), false);
        } else if (state.getData() instanceof PistonExtensionMaterial) {
            PistonExtensionMaterial extension = (PistonExtensionMaterial) state.getData();
            Block piston = block.getRelative(extension.getAttachedFace());
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
            if (altState != null) {
                piston.setTypeIdAndData(altState.getTypeId(), altState.getData().getData(), false);
            }
        } else if (state.getData() instanceof Attachable) {
            Block attachedBlock = block.getRelative(((Attachable) state.getData()).getAttachedFace());
            if (attachedBlock.getTypeId() == 0) {
                attachedBlock.setTypeId(placeholder.getId(), false);
                TownyRegenAPI.addPlaceholder(attachedBlock);
            }
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
        } else {
            if (NeedsPlaceholder.contains(state.getType())) {
                Block blockBelow = block.getRelative(BlockFace.DOWN);
                if (blockBelow.getTypeId() == 0) {
                    if (state.getType().equals(Material.CROPS)) {
                        blockBelow.setTypeId(Material.SOIL.getId(), true);
                    } else {
                        blockBelow.setTypeId(placeholder.getId(), true);
                    }
                    TownyRegenAPI.addPlaceholder(blockBelow);
                }
            }
            block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), !NeedsPlaceholder.contains(state.getType()));
        }
        TownyRegenAPI.removePlaceholder(block);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : PistonExtensionMaterial(org.bukkit.material.PistonExtensionMaterial) Block(org.bukkit.block.Block) Sign(org.bukkit.block.Sign) Attachable(org.bukkit.material.Attachable) InventoryHolder(org.bukkit.inventory.InventoryHolder) Door(org.bukkit.material.Door) Inventory(org.bukkit.inventory.Inventory) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 84 with Inventory

use of org.bukkit.inventory.Inventory in project Jobs by GamingMesh.

the class JobsPaymentListener method onInventoryRepair.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryRepair(InventoryClickEvent event) {
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    Inventory inv = event.getInventory();
    // If event is nothing or place, do nothing
    switch(event.getAction()) {
        case NOTHING:
        case PLACE_ONE:
        case PLACE_ALL:
        case PLACE_SOME:
            return;
        default:
            break;
    }
    // must be anvil inventory
    if (!(inv instanceof AnvilInventory))
        return;
    // Must be "container" slot 9
    if (!event.getSlotType().equals(SlotType.CONTAINER) || event.getSlot() != 2)
        return;
    if (!(event.getWhoClicked() instanceof Player))
        return;
    Player player = (Player) event.getWhoClicked();
    ItemStack resultStack = event.getCurrentItem();
    if (resultStack == null)
        return;
    if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
        return;
    // check if in creative
    if (player.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
        return;
    double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
    Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR), multiplier);
}
Also used : Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) ItemActionInfo(com.gamingmesh.jobs.actions.ItemActionInfo) AnvilInventory(org.bukkit.inventory.AnvilInventory) ItemStack(org.bukkit.inventory.ItemStack) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) CraftingInventory(org.bukkit.inventory.CraftingInventory) Inventory(org.bukkit.inventory.Inventory) EnchantingInventory(org.bukkit.inventory.EnchantingInventory) AnvilInventory(org.bukkit.inventory.AnvilInventory) EventHandler(org.bukkit.event.EventHandler)

Example 85 with Inventory

use of org.bukkit.inventory.Inventory in project Jobs by GamingMesh.

the class JobsPaymentListener method onEnchantItem.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchantItem(EnchantItemEvent event) {
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    Inventory inv = event.getInventory();
    if (!(inv instanceof EnchantingInventory))
        return;
    Player player = event.getEnchanter();
    ItemStack resultStack = ((EnchantingInventory) inv).getItem();
    if (resultStack == null)
        return;
    if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
        return;
    // check if in creative
    if (player.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
        return;
    double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
    Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.ENCHANT), multiplier);
}
Also used : Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) ItemActionInfo(com.gamingmesh.jobs.actions.ItemActionInfo) ItemStack(org.bukkit.inventory.ItemStack) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) CraftingInventory(org.bukkit.inventory.CraftingInventory) Inventory(org.bukkit.inventory.Inventory) EnchantingInventory(org.bukkit.inventory.EnchantingInventory) AnvilInventory(org.bukkit.inventory.AnvilInventory) EnchantingInventory(org.bukkit.inventory.EnchantingInventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Inventory (org.bukkit.inventory.Inventory)224 ItemStack (org.bukkit.inventory.ItemStack)132 Player (org.bukkit.entity.Player)80 EventHandler (org.bukkit.event.EventHandler)58 PlayerInventory (org.bukkit.inventory.PlayerInventory)40 ArrayList (java.util.ArrayList)37 ItemMeta (org.bukkit.inventory.meta.ItemMeta)34 InventoryHolder (org.bukkit.inventory.InventoryHolder)25 Block (org.bukkit.block.Block)18 Mage (com.elmakers.mine.bukkit.api.magic.Mage)16 Location (org.bukkit.Location)16 UUID (java.util.UUID)13 HashMap (java.util.HashMap)12 Entity (org.bukkit.entity.Entity)12 Material (org.bukkit.Material)11 HumanEntity (org.bukkit.entity.HumanEntity)10 Vector (org.bukkit.util.Vector)9 Sign (org.bukkit.block.Sign)8 InventoryType (org.bukkit.event.inventory.InventoryType)8 MageController (com.elmakers.mine.bukkit.api.magic.MageController)7