Search in sources :

Example 66 with Inventory

use of org.bukkit.inventory.Inventory in project Village_Defense by Plajer.

the class SpectatorItemEvents method openSpectatorMenu.

private void openSpectatorMenu(World world, Player p) {
    Inventory inventory = plugin.getServer().createInventory(null, Util.serializeInt(ArenaRegistry.getArena(p).getPlayers().size()), ChatManager.colorMessage("In-Game.Spectator.Spectator-Menu-Name"));
    for (Player player : world.getPlayers()) {
        if (ArenaRegistry.getArena(player) != null && !UserManager.getUser(player.getUniqueId()).isFakeDead()) {
            ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1);
            SkullMeta meta = (SkullMeta) skull.getItemMeta();
            meta.setOwner(player.getName());
            meta.setDisplayName(player.getName());
            meta.setLore(Collections.singletonList(ChatManager.colorMessage("In-Game.Spectator.Target-Player-Health").replaceAll("%health%", String.valueOf(Util.round(player.getHealth(), 2)))));
            skull.setDurability((short) SkullType.PLAYER.ordinal());
            skull.setItemMeta(meta);
            inventory.addItem(skull);
        }
    }
    p.openInventory(inventory);
}
Also used : Player(org.bukkit.entity.Player) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory)

Example 67 with Inventory

use of org.bukkit.inventory.Inventory in project Village_Defense by Plajer.

the class InventoryManager method loadInventory.

public void loadInventory(Player player) {
    File file = new File(plugin.getDataFolder() + File.separator + "inventorys" + File.separator + player.getUniqueId().toString() + ".invsave");
    if (!file.exists() || file.isDirectory() || !file.getAbsolutePath().endsWith(".invsave"))
        return;
    try {
        FileConfiguration invConfig = YamlConfiguration.loadConfiguration(file);
        try {
            ItemStack[] armor = new ItemStack[player.getInventory().getArmorContents().length];
            for (int i = 0; i < player.getInventory().getArmorContents().length; i++) {
                if (invConfig.contains("Armor " + i))
                    armor[i] = invConfig.getItemStack("Armor " + i);
                else
                    armor[i] = new ItemStack(Material.AIR);
            }
            player.getInventory().setArmorContents(armor);
            player.setMaxHealth(invConfig.getDouble("Max health"));
            player.setHealth(invConfig.getDouble("Current health"));
            player.setFoodLevel(invConfig.getInt("Food"));
            player.setSaturation((float) invConfig.get("Saturation"));
            player.setFireTicks(invConfig.getInt("Fire ticks"));
            player.setGameMode(GameMode.valueOf(invConfig.getString("GameMode")));
            player.setAllowFlight(invConfig.getBoolean("Allow flight"));
            List<String> activePotions = invConfig.getStringList("Active potion effects");
            for (String potion : activePotions) {
                String[] splited = potion.split("#");
                player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(splited[0]), Integer.valueOf(splited[1]), Integer.valueOf(splited[2])));
            }
        } catch (Exception ignored) {
        }
    } catch (Exception ignored) {
    }
    Inventory inventory = this.getInventoryFromFile(player.getUniqueId().toString());
    for (Integer i = 0; i < inventory.getContents().length; i++) {
        if (inventory.getItem(i) != null)
            player.getInventory().setItem(i, inventory.getItem(i));
    }
    player.updateInventory();
    player.setLevel(Integer.valueOf(inventory.getTitle()));
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) PotionEffect(org.bukkit.potion.PotionEffect) ItemStack(org.bukkit.inventory.ItemStack) File(java.io.File) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory)

Example 68 with Inventory

use of org.bukkit.inventory.Inventory in project Village_Defense by Plajer.

the class InventoryManager method getInventoryFromFile.

private Inventory getInventoryFromFile(String UUID) {
    File file = new File(plugin.getDataFolder() + File.separator + "inventorys" + File.separator + UUID + ".invsave");
    if (!file.exists() || file.isDirectory() || !file.getAbsolutePath().endsWith(".invsave"))
        return null;
    try {
        FileConfiguration invConfig = YamlConfiguration.loadConfiguration(file);
        Inventory inventory;
        Integer invTitle = invConfig.getInt("Exp");
        int invSize = invConfig.getInt("Size", 36);
        int invMaxStackSize = invConfig.getInt("Max stack size", 64);
        InventoryHolder invHolder = null;
        if (invConfig.contains("Holder"))
            invHolder = Bukkit.getPlayer(invConfig.getString("Holder"));
        inventory = Bukkit.getServer().createInventory(invHolder, InventoryType.PLAYER, Integer.toString(invTitle));
        inventory.setMaxStackSize(invMaxStackSize);
        try {
            ItemStack[] invContents = new ItemStack[invSize];
            for (int i = 0; i < invSize; i++) {
                if (invConfig.contains("Slot " + i))
                    invContents[i] = invConfig.getItemStack("Slot " + i);
                else
                    invContents[i] = new ItemStack(Material.AIR);
            }
            inventory.setContents(invContents);
        } catch (Exception ex) {
            ex.printStackTrace();
            BigTextUtils.errorOccured();
            Bukkit.getConsoleSender().sendMessage("Cannot save inventory of player! Could not get armor!");
            Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
        }
        file.delete();
        return inventory;
    } catch (Exception ex) {
        ex.printStackTrace();
        BigTextUtils.errorOccured();
        Bukkit.getConsoleSender().sendMessage("Cannot save inventory of player!");
        Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
        return null;
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ItemStack(org.bukkit.inventory.ItemStack) File(java.io.File) InventoryHolder(org.bukkit.inventory.InventoryHolder) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory)

Example 69 with Inventory

use of org.bukkit.inventory.Inventory in project Village_Defense by Plajer.

the class TeleporterKit method openAndCreateTeleportationMenu.

private void openAndCreateTeleportationMenu(World world, Player p) {
    Arena arena = ArenaRegistry.getArena(p);
    Inventory inventory = plugin.getServer().createInventory(null, 18, ChatManager.colorMessage("Kits.Teleporter.Game-Item-Menu-Name"));
    for (Player player : world.getPlayers()) {
        if (ArenaRegistry.getArena(player) != null && !UserManager.getUser(player.getUniqueId()).isFakeDead()) {
            ItemStack skull = new ItemStack(397, 1, (short) 3);
            SkullMeta meta = (SkullMeta) skull.getItemMeta();
            meta.setOwner(player.getName());
            meta.setDisplayName(player.getName());
            meta.setLore(Collections.singletonList(""));
            skull.setItemMeta(meta);
            inventory.addItem(skull);
        }
    }
    for (Villager villager : arena.getVillagers()) {
        ItemStack villagerItem = new ItemStack(Material.EMERALD);
        this.setItemNameAndLore(villagerItem, villager.getCustomName(), new String[] { villager.getUniqueId().toString() });
        inventory.addItem(villagerItem);
    }
    p.openInventory(inventory);
}
Also used : Player(org.bukkit.entity.Player) Villager(org.bukkit.entity.Villager) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) Arena(pl.plajer.villagedefense3.arena.Arena) Inventory(org.bukkit.inventory.Inventory)

Example 70 with Inventory

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

the class InventoryTriggerManager method onClick.

@EventHandler(ignoreCancelled = true)
public void onClick(InventoryClickEvent e) {
    Inventory inventory = e.getInventory();
    if (!this.hasInventoryOpen(new BukkitInventory(inventory)))
        return;
    InventoryTrigger trigger = getTriggerForOpenInventory(new BukkitInventory(inventory));
    // just always cancel if it's GUI
    e.setCancelled(true);
    if (!(e.getWhoClicked() instanceof Player))
        return;
    if (e.getRawSlot() < 0)
        return;
    Map<String, Object> varMap = getSharedVarsForInventory(new BukkitInventory(inventory));
    if (e.getRawSlot() < trigger.getItems().length) {
        if (trigger.getItems()[e.getRawSlot()] == null)
            varMap.put("item", new ItemStack(Material.AIR));
        else {
            ItemStack item = trigger.getItems()[e.getRawSlot()].get();
            varMap.put("item", item.clone());
        }
    }
    varMap.put("slot", e.getRawSlot());
    varMap.put("click", e.getClick().name());
    varMap.put("hotbar", e.getHotbarButton());
    varMap.put("trigger", "click");
    trigger.activate(e, varMap);
}
Also used : Player(org.bukkit.entity.Player) BukkitPlayer(io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer) BukkitInventory(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitInventory) BukkitItemStack(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitItemStack) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) ItemStack(org.bukkit.inventory.ItemStack) 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)

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