Search in sources :

Example 71 with Inventory

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

the class InventoryTriggerManager method onDrag.

@EventHandler(ignoreCancelled = true)
public void onDrag(InventoryDragEvent e) {
    Inventory inventory = e.getInventory();
    if (!this.hasInventoryOpen(new BukkitInventory(inventory)))
        return;
    e.setCancelled(true);
}
Also used : BukkitInventory(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitInventory) BukkitInventory(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitInventory) Inventory(org.bukkit.inventory.Inventory) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) EventHandler(org.bukkit.event.EventHandler)

Example 72 with Inventory

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

the class SchematicsPanel method onInventoryClick.

/**
 * Handles when the schematics panel is actually clicked
 * @param event
 */
@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent event) {
    // The player that
    Player player = (Player) event.getWhoClicked();
    // clicked the item
    // The inventory that was clicked in
    Inventory inventory = event.getInventory();
    if (inventory.getName() == null) {
        return;
    }
    int slot = event.getRawSlot();
    // Check this is the right panel
    if (!inventory.getName().equals(plugin.myLocale(player.getUniqueId()).schematicsTitle)) {
        return;
    }
    if (slot == -999) {
        player.closeInventory();
        inventory.clear();
        schematicItems.remove(player.getUniqueId());
        event.setCancelled(true);
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        event.setCancelled(true);
        player.closeInventory();
        inventory.clear();
        schematicItems.remove(player.getUniqueId());
        player.updateInventory();
        return;
    }
    // Get the list of items for this player
    List<SPItem> thisPanel = schematicItems.get(player.getUniqueId());
    if (thisPanel == null) {
        player.closeInventory();
        inventory.clear();
        schematicItems.remove(player.getUniqueId());
        event.setCancelled(true);
        return;
    }
    if (slot >= 0 && slot < thisPanel.size()) {
        event.setCancelled(true);
        // plugin.getLogger().info("DEBUG: slot is " + slot);
        // Closes the inventory
        player.closeInventory();
        inventory.clear();
        // Get the item clicked
        SPItem item = thisPanel.get(slot);
        // Check cost
        if (item.getCost() > 0) {
            if (Settings.useEconomy && VaultHelper.setupEconomy() && !VaultHelper.econ.has(player, item.getCost())) {
                // Too expensive
                Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).minishopYouCannotAfford.replace("[description]", item.getName()));
            } else {
                // Do something
                if (Settings.useEconomy && VaultHelper.setupEconomy()) {
                    VaultHelper.econ.withdrawPlayer(player, item.getCost());
                }
                Util.runCommand(player, Settings.ISLANDCOMMAND + " make " + item.getHeading());
            }
        } else {
            Util.runCommand(player, Settings.ISLANDCOMMAND + " make " + item.getHeading());
        }
        schematicItems.remove(player.getUniqueId());
        thisPanel.clear();
    }
    return;
}
Also used : Player(org.bukkit.entity.Player) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 73 with Inventory

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

the class SettingsPanel method onInventoryClick.

/**
 * Handle clicks to the Settings panel
 * @param event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
    // The player that clicked the item
    Player player = (Player) event.getWhoClicked();
    // The inventory that was clicked in
    Inventory inventory = event.getInventory();
    if (inventory.getName() == null) {
        return;
    }
    int slot = event.getRawSlot();
    // Check this is the right panel
    if (!inventory.getName().equals(plugin.myLocale(player.getUniqueId()).igsTitle)) {
        return;
    }
    // Stop removal of items
    event.setCancelled(true);
    if (event.getSlotType() == SlotType.OUTSIDE) {
        player.closeInventory();
        inventory.clear();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        inventory.clear();
        player.updateInventory();
        return;
    }
    // Check world
    if (!player.getLocation().getWorld().equals(ASkyBlock.getIslandWorld()) && !player.getLocation().getWorld().equals(ASkyBlock.getNetherWorld())) {
        return;
    }
    // 1.7.x server
    if (!hasArmorStand && slot > lookup.size()) {
        return;
    }
    // 1.8.x server
    if (slot > (lookup.size() + 1)) {
        return;
    }
    // Get the flag
    SettingsFlag flag = null;
    if (lookup.containsKey(event.getCurrentItem().getType())) {
        // All other items
        flag = lookup.get(event.getCurrentItem().getType());
    } else if (hasArmorStand && event.getCurrentItem().getType() == Material.ARMOR_STAND) {
        // Special handling to avoid errors on 1.7.x servers
        flag = SettingsFlag.ARMOR_STAND;
    }
    // If flag is null, do nothing
    if (flag == null) {
        return;
    }
    // Players can only do something if they own the island or are op
    Island island = plugin.getGrid().getIslandAt(player.getLocation());
    if (island != null && (player.isOp() || (island.getOwner() != null && island.getOwner().equals(player.getUniqueId())))) {
        // Check perms
        if (player.isOp() || player.hasPermission(Settings.PERMPREFIX + "settings." + flag.toString())) {
            // plugin.getLogger().info("DEBUG: Player has perm " + flag.toString());
            if (flag.equals(SettingsFlag.PVP) || flag.equals(SettingsFlag.NETHER_PVP)) {
                // PVP always results in an inventory closure
                player.closeInventory();
                inventory.clear();
                // PVP activation
                if (!island.getIgsFlag(flag)) {
                    // plugin.getLogger().info("DEBUG: attempt to activate PVP");
                    if (pvpCoolDown.containsKey(player.getUniqueId())) {
                        // plugin.getLogger().info("DEBUG: player is in the cooldown list");
                        long setTime = pvpCoolDown.get(player.getUniqueId());
                        // plugin.getLogger().info("DEBUG: set time is " + setTime);
                        long secondsLeft = Settings.pvpRestartCooldown - (System.currentTimeMillis() - setTime) / 1000;
                        // plugin.getLogger().info("DEBUG: seconds left = " + secondsLeft);
                        if (secondsLeft > 0) {
                            Util.sendMessage(player, ChatColor.RED + "You must wait " + secondsLeft + " seconds until you can do that again!");
                            return;
                        }
                        // Tidy up
                        pvpCoolDown.remove(player.getUniqueId());
                    }
                    // Warn players on the island
                    for (Player p : plugin.getServer().getOnlinePlayers()) {
                        if (island.onIsland(p.getLocation())) {
                            if (flag.equals(SettingsFlag.NETHER_PVP)) {
                                Util.sendMessage(p, ChatColor.RED + "" + ChatColor.BOLD + plugin.myLocale(p.getUniqueId()).igs.get(SettingsFlag.NETHER_PVP) + " " + plugin.myLocale(p.getUniqueId()).igsAllowed);
                            } else {
                                Util.sendMessage(p, ChatColor.RED + "" + ChatColor.BOLD + plugin.myLocale(p.getUniqueId()).igs.get(SettingsFlag.PVP) + " " + plugin.myLocale(p.getUniqueId()).igsAllowed);
                            }
                            if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
                                player.getWorld().playSound(player.getLocation(), Sound.valueOf("ARROW_HIT"), 1F, 1F);
                            } else {
                                player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
                            }
                        }
                    }
                    // Toggle the flag
                    island.toggleIgs(flag);
                    // Update warp signs
                    final List<UUID> members = island.getMembers();
                    // Run one tick later because text gets updated at the end of tick
                    plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            for (UUID playerUUID : members) {
                                plugin.getWarpPanel().updateWarp(playerUUID);
                            }
                        }
                    });
                    return;
                } else {
                    // PVP deactivation
                    // Store this deactivation time
                    pvpCoolDown.put(player.getUniqueId(), System.currentTimeMillis());
                    // Immediately toggle the setting
                    island.toggleIgs(flag);
                    // Update warp signs
                    final List<UUID> members = island.getMembers();
                    // Run one tick later because text gets updated at the end of tick
                    plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

                        @Override
                        public void run() {
                            for (UUID playerUUID : members) {
                                plugin.getWarpPanel().updateWarp(playerUUID);
                            }
                        }
                    });
                    // Warn players of change
                    for (Player p : plugin.getServer().getOnlinePlayers()) {
                        if (island.onIsland(p.getLocation())) {
                            // Deactivate PVP
                            if (flag.equals(SettingsFlag.NETHER_PVP)) {
                                Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).igs.get(SettingsFlag.NETHER_PVP) + " " + plugin.myLocale(p.getUniqueId()).igsDisallowed);
                            } else {
                                Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).igs.get(SettingsFlag.PVP) + " " + plugin.myLocale(p.getUniqueId()).igsDisallowed);
                            }
                            if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
                                p.getWorld().playSound(p.getLocation(), Sound.valueOf("FIREWORK_TWINKLE"), 1F, 1F);
                            } else {
                                p.getWorld().playSound(p.getLocation(), Sound.ENTITY_FIREWORK_TWINKLE, 1F, 1F);
                            }
                        }
                    }
                }
            } else {
                island.toggleIgs(flag);
            }
        }
        // player.closeInventory();
        inventory.clear();
        player.openInventory(islandGuardPanel(player));
    }
}
Also used : SettingsFlag(com.wasteofplastic.askyblock.Island.SettingsFlag) Player(org.bukkit.entity.Player) UUID(java.util.UUID) Island(com.wasteofplastic.askyblock.Island) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 74 with Inventory

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

the class SettingsPanel method islandGuardPanel.

/**
 * Presents a GUI for toggling or viewing settings
 * @param player
 * @return
 */
public Inventory islandGuardPanel(Player player) {
    UUID uuid = player.getUniqueId();
    // Get the island settings for this player's location
    Island island = plugin.getGrid().getProtectedIslandAt(player.getLocation());
    List<IPItem> ip = new ArrayList<IPItem>();
    Inventory newPanel = null;
    if (island == null) {
        // plugin.getLogger().info("DEBUG: default world settings");
        ip.add(new IPItem(Material.MAP, plugin.myLocale(uuid).igsSettingsGeneralTitle, plugin.myLocale(uuid).igsSettingsGeneralDesc));
        // General settings all enum
        for (SettingsFlag flag : SettingsFlag.values()) {
            // plugin.getLogger().info("DEBUG: default setting = " + Settings.defaultWorldSettings.get(flag));
            if (flag.equals(SettingsFlag.ACID_DAMAGE) && Settings.acidDamage == 0)
                continue;
            if (Settings.defaultWorldSettings.containsKey(flag) && lookup.inverse().containsKey(flag) && plugin.myLocale(uuid).igs.containsKey(flag)) {
                ip.add(new IPItem(Settings.defaultWorldSettings.get(flag), lookup.inverse().get(flag), plugin.myLocale(uuid).igs.get(flag), uuid));
            }
        }
        // System settings that are visible to users
        ip.add(new IPItem(Settings.allowChestDamage, Material.CHEST, plugin.myLocale(uuid).igsChestDamage, uuid));
        ip.add(new IPItem(Settings.allowCreeperDamage, Material.SKULL_ITEM, 4, plugin.myLocale(uuid).igsCreeperDamage, uuid));
        ip.add(new IPItem(Settings.allowCreeperGriefing, Material.SKULL_ITEM, 4, plugin.myLocale(uuid).igsCreeperGriefing, uuid));
        ip.add(new IPItem(!Settings.restrictWither, Material.SKULL_ITEM, 1, plugin.myLocale(uuid).igsWitherDamage, uuid));
        ip.add(new IPItem(Settings.allowTNTDamage, Material.TNT, plugin.myLocale(uuid).igsTNT, uuid));
        ip.add(new IPItem(Settings.allowVisitorKeepInvOnDeath, Material.IRON_CHESTPLATE, plugin.myLocale(uuid).igsVisitorKeep, uuid));
    } else if (island.isSpawn()) {
        ip.add(new IPItem(Material.MAP, plugin.myLocale(uuid).igsSettingsSpawnTitle, plugin.myLocale(uuid).igsSettingsSpawnDesc));
        // Spawn settings
        for (SettingsFlag flag : Settings.defaultSpawnSettings.keySet()) {
            // plugin.getLogger().info("DEBUG: " + flag.toString());
            if (flag.equals(SettingsFlag.ACID_DAMAGE) && Settings.acidDamage == 0)
                continue;
            if (lookup.inverse().containsKey(flag) && plugin.myLocale(uuid).igs.containsKey(flag)) {
                ip.add(new IPItem(island.getIgsFlag(flag), lookup.inverse().get(flag), plugin.myLocale(uuid).igs.get(flag), uuid));
            }
        }
    } else {
        // Standard island
        // plugin.getLogger().info("DEBUG: Standard island");
        ip.add(new IPItem(Material.MAP, plugin.myLocale(uuid).igsSettingsIslandTitle, plugin.myLocale(uuid).igsSettingsIslandDesc));
        for (SettingsFlag flag : Settings.visitorSettings.keySet()) {
            if (DEBUG) {
                plugin.getLogger().info("DEBUG: visitor flag = " + flag);
                plugin.getLogger().info("DEBUG: setting for island = " + island.getIgsFlag(flag));
            }
            if (flag.equals(SettingsFlag.ACID_DAMAGE) && Settings.acidDamage == 0)
                continue;
            if (lookup.inverse().get(flag) != null) {
                if (plugin.myLocale(uuid).igs.containsKey(flag)) {
                    // plugin.getLogger().info("DEBUG: Adding flag");
                    ip.add(new IPItem(island.getIgsFlag(flag), lookup.inverse().get(flag), plugin.myLocale(uuid).igs.get(flag), uuid));
                }
            } else if (DEBUG) {
                plugin.getLogger().severe("DEBUG: " + flag + " is missing an icon");
            }
        }
    }
    if (ip.size() > 0) {
        // Make sure size is a multiple of 9
        int size = ip.size() + 8;
        size -= (size % 9);
        String title = plugin.myLocale(uuid).igsTitle;
        if (title.length() > 32) {
            title = title.substring(0, 31);
        }
        newPanel = Bukkit.createInventory(null, size, title);
        // Fill the inventory and return
        int slot = 0;
        for (IPItem i : ip) {
            i.setSlot(slot);
            newPanel.addItem(i.getItem());
        }
    }
    return newPanel;
}
Also used : SettingsFlag(com.wasteofplastic.askyblock.Island.SettingsFlag) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Island(com.wasteofplastic.askyblock.Island) Inventory(org.bukkit.inventory.Inventory)

Example 75 with Inventory

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

the class BiomesPanel method onInventoryClick.

@EventHandler(priority = EventPriority.LOWEST)
public void onInventoryClick(InventoryClickEvent event) {
    // The player that
    Player player = (Player) event.getWhoClicked();
    // clicked the item
    UUID playerUUID = player.getUniqueId();
    // The inventory that was
    Inventory inventory = event.getInventory();
    // clicked in
    int slot = event.getRawSlot();
    // Check this is the right panel
    if (inventory.getName() == null || !inventory.getName().equals(plugin.myLocale().biomePanelTitle)) {
        return;
    }
    if (slot == -999) {
        inventory.clear();
        player.closeInventory();
        event.setCancelled(true);
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        event.setCancelled(true);
        inventory.clear();
        player.closeInventory();
        player.updateInventory();
        return;
    }
    // Get the list of items for this player
    List<BiomeItem> thisPanel = biomeItems.get(player.getUniqueId());
    if (thisPanel == null) {
        inventory.clear();
        player.closeInventory();
        event.setCancelled(true);
        return;
    }
    if (slot >= 0 && slot < thisPanel.size()) {
        event.setCancelled(true);
        // plugin.getLogger().info("DEBUG: slot is " + slot);
        // Do something
        // Check this player has an island
        Island island = plugin.getGrid().getIsland(playerUUID);
        if (island == null) {
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
            return;
        }
        // Check ownership
        if (!island.getOwner().equals(playerUUID)) {
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).levelerrornotYourIsland);
            return;
        }
        if (!plugin.getGrid().playerIsOnIsland(player)) {
            Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorNotOnIsland);
            return;
        }
        Biome biome = thisPanel.get(slot).getBiome();
        if (biome != null) {
            event.setCancelled(true);
            if (Settings.useEconomy) {
                // Check cost
                double cost = thisPanel.get(slot).getPrice();
                if (cost > 0D) {
                    if (!VaultHelper.econ.has(player, Settings.worldName, cost)) {
                        Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).minishopYouCannotAfford.replace("[description]", VaultHelper.econ.format(cost)));
                        return;
                    } else {
                        VaultHelper.econ.withdrawPlayer(player, Settings.worldName, cost);
                        Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).biomeYouBought.replace("[cost]", VaultHelper.econ.format(cost)));
                    }
                }
            }
        }
        inventory.clear();
        // Closes the inventory
        player.closeInventory();
        // Actually set the biome
        Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).biomePleaseWait);
        new SetBiome(plugin, island, biome, player);
    }
    return;
}
Also used : Player(org.bukkit.entity.Player) Biome(org.bukkit.block.Biome) UUID(java.util.UUID) Island(com.wasteofplastic.askyblock.Island) 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