Search in sources :

Example 76 with Inventory

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

the class BiomesPanel method getBiomePanel.

/**
 * Returns a customized panel of available Biomes for the player
 *
 * @param player
 * @return custom Inventory object
 */
public Inventory getBiomePanel(Player player) {
    // Go through the available biomes and check permission
    int slot = 0;
    List<BiomeItem> items = new ArrayList<BiomeItem>();
    for (String biomeName : plugin.getConfig().getConfigurationSection("biomes").getKeys(false)) {
        // Check the biome is actually real
        try {
            Biome biome = Biome.valueOf(biomeName);
            // Check permission
            String permission = plugin.getConfig().getString("biomes." + biomeName + ".permission", "");
            if (permission.isEmpty() || VaultHelper.permission.has(player, permission)) {
                // Build inventory item
                // Get icon
                String icon = plugin.getConfig().getString("biomes." + biomeName + ".icon", "SAPLING");
                Material material = null;
                try {
                    if (StringUtils.isNumeric(icon)) {
                        material = Material.getMaterial(Integer.parseInt(icon));
                    } else {
                        material = Material.valueOf(icon.toUpperCase());
                    }
                } catch (Exception e) {
                    plugin.getLogger().warning("Error parsing biome icon value " + icon + ". Using default SAPLING.");
                    material = Material.SAPLING;
                }
                // Get cost
                double cost = plugin.getConfig().getDouble("biomes." + biomeName + ".cost", Settings.biomeCost);
                // Get friendly name
                String name = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("biomes." + biomeName + ".friendlyname", Util.prettifyText(biomeName)));
                // Get description
                String description = ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("biomes." + biomeName + ".description", ""));
                // Get confirmation or not
                boolean confirm = plugin.getConfig().getBoolean("biomes." + biomeName + ".confirm", false);
                // Add item to list
                // plugin.getLogger().info("DEBUG: " + description + name +
                // confirm);
                BiomeItem item = new BiomeItem(material, slot++, cost, description, name, confirm, biome);
                // Add to item list
                items.add(item);
            }
        } catch (Exception e) {
            e.printStackTrace();
            plugin.getLogger().severe("Could not recognize " + biomeName + " as valid Biome! Skipping...");
            plugin.getLogger().severe("For V1.9, some biome names do not exist anymore. Change config.yml to the latest.");
        }
    }
    // Now create the inventory panel
    if (items.size() > 0) {
        // Save the items for later retrieval when the player clicks on them
        biomeItems.put(player.getUniqueId(), items);
        // Make sure size is a multiple of 9
        int size = items.size() + 8;
        size -= (size % 9);
        Inventory newPanel = Bukkit.createInventory(null, size, plugin.myLocale().biomePanelTitle);
        // Fill the inventory and return
        for (BiomeItem i : items) {
            newPanel.addItem(i.getItem());
        }
        return newPanel;
    } else {
        Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
        plugin.getLogger().warning("There are no biomes in config.yml so /island biomes will not work!");
    }
    return null;
}
Also used : Biome(org.bukkit.block.Biome) ArrayList(java.util.ArrayList) Material(org.bukkit.Material) Inventory(org.bukkit.inventory.Inventory)

Example 77 with Inventory

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

the class WarpPanel method onInventoryClick.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    // The inventory that was clicked in
    Inventory inventory = event.getInventory();
    if (inventory.getName() == null) {
        return;
    }
    // The player that clicked the item
    final Player player = (Player) event.getWhoClicked();
    String title = inventory.getTitle();
    if (!inventory.getTitle().startsWith(plugin.myLocale().warpsTitle + " #")) {
        return;
    }
    event.setCancelled(true);
    if (event.getSlotType().equals(SlotType.OUTSIDE)) {
        player.closeInventory();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        player.updateInventory();
        return;
    }
    // The item that was clicked
    ItemStack clicked = event.getCurrentItem();
    if (DEBUG)
        plugin.getLogger().info("DEBUG: inventory size = " + inventory.getSize());
    if (DEBUG)
        plugin.getLogger().info("DEBUG: clicked = " + clicked);
    if (DEBUG)
        plugin.getLogger().info("DEBUG: rawslot = " + event.getRawSlot());
    if (event.getRawSlot() >= event.getInventory().getSize() || clicked.getType() == Material.AIR) {
        return;
    }
    int panelNumber = 0;
    try {
        panelNumber = Integer.valueOf(title.substring(title.indexOf('#') + 1));
    } catch (Exception e) {
        panelNumber = 0;
    }
    if (clicked.getItemMeta().hasDisplayName()) {
        String command = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
        if (DEBUG)
            plugin.getLogger().info("DEBUG: command = " + command);
        if (command != null) {
            if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsNext))) {
                player.closeInventory();
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber + 1));
            } else if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsPrevious))) {
                player.closeInventory();
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber - 1));
            } else {
                player.closeInventory();
                Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpswarpToPlayersSign.replace("<player>", command));
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warp " + command);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 78 with Inventory

use of org.bukkit.inventory.Inventory in project TriggerReactor by wysohn.

the class JavaPluginBridge method createInterrupterForInv.

@Override
public ProcessInterrupter createInterrupterForInv(Object e, Interpreter interpreter, Map<UUID, Long> cooldowns, Map<IInventory, InventoryTrigger> inventoryMap) {
    return new ProcessInterrupter() {

        @Override
        public boolean onNodeProcess(Node node) {
            if (interpreter.isCooldown()) {
                if (e instanceof InventoryInteractEvent) {
                    HumanEntity he = ((InventoryInteractEvent) e).getWhoClicked();
                    if (he instanceof Player) {
                        Player player = (Player) he;
                        UUID uuid = player.getUniqueId();
                        cooldowns.put(uuid, interpreter.getCooldownEnd());
                    }
                }
                return false;
            }
            // is still running after the inventory is closed.
            if (e instanceof InventoryOpenEvent || e instanceof InventoryClickEvent) {
                Inventory inv = ((InventoryEvent) e).getInventory();
                // it's not GUI so stop execution
                if (!inventoryMap.containsKey(new BukkitInventory(inv)))
                    return true;
            }
            return false;
        }

        @Override
        public boolean onCommand(Object context, String command, Object[] args) {
            if ("CALL".equals(command)) {
                if (args.length < 1)
                    throw new RuntimeException("Need parameter [String] or [String, boolean]");
                if (args[0] instanceof String) {
                    Trigger trigger = getNamedTriggerManager().getTriggerForName((String) args[0]);
                    if (trigger == null)
                        throw new RuntimeException("No trigger found for Named Trigger " + args[0]);
                    if (args.length > 1 && args[1] instanceof Boolean) {
                        trigger.setSync((boolean) args[1]);
                    } else {
                        trigger.setSync(true);
                    }
                    if (trigger.isSync()) {
                        trigger.activate(e, interpreter.getVars());
                    } else {
                        // use snapshot to avoid concurrent modification
                        trigger.activate(e, new HashMap<>(interpreter.getVars()));
                    }
                    return true;
                } else {
                    throw new RuntimeException("Parameter type not match; it should be a String." + " Make sure to put double quotes, if you provided String literal.");
                }
            } else if ("CANCELEVENT".equals(command)) {
                if (!interpreter.isSync())
                    throw new RuntimeException("CANCELEVENT is illegal in async mode!");
                if (context instanceof Cancellable) {
                    ((Cancellable) context).setCancelled(true);
                    return true;
                } else {
                    throw new RuntimeException(context + " is not a Cancellable event!");
                }
            }
            return false;
        }
    };
}
Also used : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) InventoryEvent(org.bukkit.event.inventory.InventoryEvent) DelegatedPlayer(io.github.wysohn.triggerreactor.bukkit.tools.DelegatedPlayer) IPlayer(io.github.wysohn.triggerreactor.core.bridge.player.IPlayer) Player(org.bukkit.entity.Player) BukkitPlayer(io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer) Cancellable(org.bukkit.event.Cancellable) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) ProcessInterrupter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.Trigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractInventoryTriggerManager.InventoryTrigger) BukkitInventory(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitInventory) HumanEntity(org.bukkit.entity.HumanEntity) InventoryInteractEvent(org.bukkit.event.inventory.InventoryInteractEvent) UUID(java.util.UUID) BukkitInventory(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitInventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) Inventory(org.bukkit.inventory.Inventory)

Example 79 with Inventory

use of org.bukkit.inventory.Inventory in project TriggerReactor by wysohn.

the class BukkitPlayer method openInventory.

@Override
public void openInventory(IInventory inventory) {
    Inventory inv = inventory.get();
    player.openInventory(inv);
}
Also used : IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) BukkitInventory(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitInventory) Inventory(org.bukkit.inventory.Inventory)

Example 80 with Inventory

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

the class TopTen method onInventoryClick.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    // The inventory that was clicked in
    Inventory inventory = event.getInventory();
    if (inventory.getName() == null) {
        return;
    }
    // The player that clicked the item
    Player player = (Player) event.getWhoClicked();
    if (!inventory.getTitle().equals(plugin.myLocale(player.getUniqueId()).topTenGuiTitle)) {
        return;
    }
    event.setCancelled(true);
    player.updateInventory();
    if (event.getCurrentItem() != null && event.getCurrentItem().getType().equals(Material.SKULL_ITEM) && event.getCurrentItem().hasItemMeta()) {
        if (((SkullMeta) event.getCurrentItem().getItemMeta()).hasOwner()) {
            Util.runCommand(player, "is warp " + ((SkullMeta) event.getCurrentItem().getItemMeta()).getOwner());
            player.closeInventory();
        }
        return;
    }
    if (event.getSlotType().equals(SlotType.OUTSIDE)) {
        player.closeInventory();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        return;
    }
}
Also used : Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Inventory(org.bukkit.inventory.Inventory) 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