Java Code Examples for org.bukkit.inventory.Inventory#addItem()
The following examples show how to use
org.bukkit.inventory.Inventory#addItem() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
public Inventory createRestartGUI(Player player) { List<String> schemeNames = plugin.getIslandGenerator().getSchemeNames(); int menuSize = (int) Math.ceil(getMaxSchemeIndex(schemeNames) / 9d)*9; String title = "\u00a79" + tr("Island Restart Menu"); Inventory menu = Bukkit.createInventory(new UltimateHolder(player, title, MenuType.DEFAULT), menuSize, title); List<String> lores = new ArrayList<>(); ItemStack menuItem = new ItemStack(SIGN_MATERIAL, 1); ItemMeta meta = menuItem.getItemMeta(); meta.setDisplayName(tr("\u00a7a\u00a7lReturn to the main menu")); meta.setLore(lores); menuItem.setItemMeta(meta); menu.addItem(menuItem); lores.clear(); updateRestartMenu(menu, player, schemeNames); if (plugin.getConfirmHandler().millisLeft(player, "/is restart") > 0) { updateRestartMenuTimer(player, menu); } return menu; }
Example 2
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
public Inventory displayLogGUI(final Player player) { List<String> lores = new ArrayList<>(); String title = "\u00a79" + tr("Island Log"); Inventory menu = Bukkit.createInventory(new UltimateHolder(player, title, MenuType.DEFAULT), 9, title); ItemMeta meta4 = sign.getItemMeta(); meta4.setDisplayName("\u00a79\u00a7l" + tr("Island Log")); addLore(lores, tr("\u00a7eClick here to return to\n\u00a7ethe main island screen.")); meta4.setLore(lores); sign.setItemMeta(meta4); menu.addItem(new ItemStack[]{sign}); lores.clear(); ItemStack menuItem = new ItemStack(Material.WRITABLE_BOOK, 1); meta4 = menuItem.getItemMeta(); meta4.setDisplayName(tr("\u00a7e\u00a7lIsland Log")); for (String log : plugin.getIslandInfo(player).getLog()) { lores.add(log); } meta4.setLore(lores); menuItem.setItemMeta(meta4); menu.setItem(8, menuItem); lores.clear(); return menu; }
Example 3
Source File: ScenarioManager.java From UhcCore with GNU General Public License v3.0 | 6 votes |
public Inventory getScenarioMainInventory(boolean editItem){ Inventory inv = Bukkit.createInventory(null,3*ROW, Lang.SCENARIO_GLOBAL_INVENTORY); for (Scenario scenario : getActiveScenarios()) { if (scenario.isCompatibleWithVersion()) { inv.addItem(scenario.getScenarioItem()); } } if (editItem){ // add edit item ItemStack edit = new ItemStack(Material.BARRIER); ItemMeta itemMeta = edit.getItemMeta(); itemMeta.setDisplayName(Lang.SCENARIO_GLOBAL_ITEM_EDIT); edit.setItemMeta(itemMeta); inv.setItem(26,edit); } return inv; }
Example 4
Source File: TownCommand.java From civcraft with GNU General Public License v2.0 | 6 votes |
public void templates_cmd() throws CivException { Player player = getPlayer(); Town town = getSelectedTown(); Inventory inv = Bukkit.getServer().createInventory(player, CivTutorial.MAX_CHEST_SIZE*9, town.getName()+" Perks"); for (ConfigBuildableInfo info : CivSettings.structures.values()) { for (Perk p : CustomTemplate.getTemplatePerksForBuildable(town, info.template_base_name)) { ItemStack stack = LoreGuiItem.build(p.configPerk.display_name, p.configPerk.type_id, p.configPerk.data, CivColor.Gray+"Provided by: "+CivColor.LightBlue+p.provider); inv.addItem(stack); } } player.openInventory(inv); }
Example 5
Source File: LoreMaterial.java From civcraft with GNU General Public License v2.0 | 6 votes |
public void moveDropSet(Player player, Inventory inv, int slot, ItemStack newItem) { ItemStack stack = inv.getItem(slot); inv.setItem(slot, newItem); if (stack != null) { if (stack.equals(newItem)) { return; } HashMap<Integer, ItemStack> leftovers = inv.addItem(stack); for (ItemStack s : leftovers.values()) { player.getWorld().dropItem(player.getLocation(), s); } } }
Example 6
Source File: TableSaw.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@Override public void onInteract(Player p, Block b) { ItemStack log = p.getInventory().getItemInMainHand(); Optional<Material> planks = MaterialConverter.getPlanksFromLog(log.getType()); if (planks.isPresent()) { if (p.getGameMode() != GameMode.CREATIVE) { ItemUtils.consumeItem(log, true); } ItemStack output = new ItemStack(planks.get(), 8); Inventory outputChest = findOutputChest(b, output); if (outputChest != null) { outputChest.addItem(output); } else { b.getWorld().dropItemNaturally(b.getLocation(), output); } b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, log.getType()); } }
Example 7
Source File: OreWasher.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
private void removeItem(Player p, Block b, Inventory inputInv, Inventory outputInv, ItemStack input, ItemStack output, int amount) { if (outputInv != null) { ItemStack removing = input.clone(); removing.setAmount(amount); inputInv.removeItem(removing); outputInv.addItem(output.clone()); b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.WATER); b.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1, 1); } else { SlimefunPlugin.getLocalization().sendMessage(p, "machines.full-inventory", true); } }
Example 8
Source File: FlagShears.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@Subscribe public void onGameStart(GameStartEvent event) { Game game = event.getGame(); for (SpleefPlayer player : game.getPlayers()) { Player bukkitPlayer = player.getBukkitPlayer(); Inventory inv = bukkitPlayer.getInventory(); ItemStack stack = createShears(); inv.addItem(stack); bukkitPlayer.updateInventory(); } }
Example 9
Source File: FlagShovels.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@Subscribe public void onGameStart(GameStartEvent event) { Game game = event.getGame(); for (SpleefPlayer player : game.getPlayers()) { Player bukkitPlayer = player.getBukkitPlayer(); Inventory inv = bukkitPlayer.getInventory(); ItemStack stack = createShovel(); inv.addItem(stack); bukkitPlayer.updateInventory(); } }
Example 10
Source File: Arena.java From civcraft with GNU General Public License v2.0 | 5 votes |
private void addCivCraftItemToInventory(String id, Inventory inv) { LoreCraftableMaterial craftMat = LoreCraftableMaterial.getCraftMaterialFromId(id); ItemStack stack = LoreCraftableMaterial.spawn(craftMat); stack = LoreCraftableMaterial.addEnhancement(stack, LoreEnhancement.enhancements.get("LoreEnhancementSoulBound")); stack = LoreCraftableMaterial.addEnhancement(stack, LoreEnhancement.enhancements.get("LoreEnhancementArenaItem")); inv.addItem(stack); }
Example 11
Source File: NewItemShop.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private void addCategoriesToInventory(Inventory inventory, Player player, Game game) { for (MerchantCategory category : this.categories) { if (category.getMaterial() == null) { BedwarsRel.getInstance().getServer().getConsoleSender() .sendMessage(ChatWriter.pluginMessage(ChatColor.RED + "Careful: Not supported material in shop category '" + category.getName() + "'")); continue; } if (player != null && !player.hasPermission(category.getPermission())) { continue; } ItemStack is = new ItemStack(category.getMaterial(), 1); ItemMeta im = is.getItemMeta(); if (Utils.isColorable(is)) { is.setDurability(game.getPlayerTeam(player).getColor().getDyeColor().getWoolData()); } if (this.currentCategory != null && this.currentCategory.equals(category)) { im.addEnchant(Enchantment.DAMAGE_ALL, 1, true); im.addItemFlags(ItemFlag.HIDE_ENCHANTS); } im.setDisplayName(category.getName()); im.setLore(category.getLores()); im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_POTION_EFFECTS); is.setItemMeta(im); inventory.addItem(is); } }
Example 12
Source File: VaultManager.java From PlayerVaults with GNU General Public License v3.0 | 5 votes |
/** * Get an inventory from file. Returns null if the inventory doesn't exist. SHOULD ONLY BE USED INTERNALLY * * @param playerFile the YamlConfiguration file. * @param size the size of the vault. * @param number the vault number. * @return inventory if exists, otherwise null. */ private Inventory getInventory(InventoryHolder owner, String ownerName, YamlConfiguration playerFile, int size, int number, String title) { Inventory inventory = Bukkit.createInventory(owner, size, title); String data = playerFile.getString(String.format(VAULTKEY, number)); Inventory deserialized = Base64Serialization.fromBase64(data, ownerName); if (deserialized == null) { PlayerVaults.debug("Loaded vault as null"); return inventory; } // Check if deserialized has more used slots than the limit here. // Happens on change of permission or if people used the broken version. // In this case, players will lose items. if (deserialized.getContents().length > size) { for (ItemStack stack : deserialized.getContents()) { if (stack != null) { inventory.addItem(stack); } } } else { inventory.setContents(deserialized.getContents()); } PlayerVaults.debug("Loaded vault"); return inventory; }
Example 13
Source File: CrazyCrates.java From Crazy-Crates with MIT License | 5 votes |
/** * Load the crate preview of a crate. * @param crate The crate you wish to load the preview of. * @return An Inventory object of the preview. */ public Inventory loadPreview(Crate crate) { FileConfiguration file = crate.getFile(); int slots = 9; for (int size = file.getConfigurationSection("Crate.Prizes").getKeys(false).size(); size > 9 && slots < crate.getMaxSlots(); size -= 9) { slots += 9; } Inventory inv = Bukkit.createInventory(null, slots, Methods.sanitizeColor(file.getString("Crate.Name"))); for (String reward : file.getConfigurationSection("Crate.Prizes").getKeys(false)) { String id = file.getString("Crate.Prizes." + reward + ".DisplayItem", "Stone"); String name = file.getString("Crate.Prizes." + reward + ".DisplayName", ""); List<String> lore = file.getStringList("Crate.Prizes." + reward + ".Lore"); HashMap<Enchantment, Integer> enchantments = new HashMap<>(); String player = file.getString("Crate.Prizes." + reward + ".Player", ""); boolean glowing = file.getBoolean("Crate.Prizes." + reward + ".Glowing"); int amount = file.getInt("Crate.Prizes." + reward + ".DisplayAmount", 1); for (String enchantmentName : file.getStringList("Crate.Prizes." + reward + ".DisplayEnchantments")) { Enchantment enchantment = Methods.getEnchantment(enchantmentName.split(":")[0]); if (enchantment != null) { enchantments.put(enchantment, Integer.parseInt(enchantmentName.split(":")[1])); } } try { inv.setItem(inv.firstEmpty(), new ItemBuilder().setMaterial(id).setAmount(amount).setName(name).setLore(lore).setEnchantments(enchantments).setGlowing(glowing).setPlayer(player).build()); } catch (Exception e) { inv.addItem(new ItemBuilder().setMaterial("RED_TERRACOTTA", "STAINED_CLAY:14").setName("&c&lERROR").setLore(Arrays.asList("&cThere is an error", "&cFor the reward: &c" + reward)).build()); } } return inv; }
Example 14
Source File: UhcItems.java From UhcCore with GNU General Public License v3.0 | 5 votes |
public static void openTeamReplyInviteInventory(Player player, UhcTeam team){ Inventory inv = Bukkit.createInventory(null, InventoryType.HOPPER, Lang.TEAM_INVENTORY_REPLY_INVITE); inv.addItem(createTeamSkullItem(team, false)); inv.addItem(GameItem.TEAM_INVITE_ACCEPT.getItem(ChatColor.DARK_GRAY + team.getTeamName())); inv.addItem(GameItem.TEAM_INVITE_DENY.getItem(ChatColor.DARK_GRAY + team.getTeamName())); player.openInventory(inv); }
Example 15
Source File: AbstractSmeltery.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
protected void craft(Player p, Block b, Inventory inv, ItemStack[] recipe, ItemStack output, Inventory outputInv) { for (ItemStack removing : recipe) { if (removing != null) { InvUtils.removeItem(inv, removing.getAmount(), true, stack -> SlimefunUtils.isItemSimilar(stack, removing, true)); } } outputInv.addItem(output); p.getWorld().playSound(p.getLocation(), Sound.BLOCK_LAVA_POP, 1, 1); p.getWorld().playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1); }
Example 16
Source File: Resident.java From civcraft with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") public int giveItem(int itemId, short damage, int amount) throws CivException { Player player = CivGlobal.getPlayer(this); Inventory inv = player.getInventory(); ItemStack stack = new ItemStack(itemId, amount, damage); HashMap <Integer, ItemStack> leftovers = null; leftovers = inv.addItem(stack); int leftoverAmount = 0; for (ItemStack i : leftovers.values()) { leftoverAmount += i.getAmount(); } player.updateInventory(); return amount - leftoverAmount; }
Example 17
Source File: TimebombListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
private void spawnChest(){ spawned = true; block1 = loc.getBlock(); loc.add(-1, 0, 0); block2 = loc.getBlock(); block1.setType(Material.CHEST); block2.setType(Material.CHEST); Chest chest1 = (Chest) block1.getState(); Chest chest2 = (Chest) block2.getState(); String chestName = Lang.SCENARIO_TIMEBOMB_CHEST.replace("%player%", name); VersionUtils.getVersionUtils().setChestName(chest1, chestName); VersionUtils.getVersionUtils().setChestName(chest2, chestName); // Make double chest for 1.13 and up VersionUtils.getVersionUtils().setChestSide(chest1, false); VersionUtils.getVersionUtils().setChestSide(chest2, true); Inventory inv = chest1.getInventory(); for (ItemStack drop : drops){ inv.addItem(drop); } loc.add(1,-1,.5); armorStand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND); armorStand.setCustomNameVisible(true); armorStand.setGravity(false); armorStand.setVisible(false); armorStand.setCustomName(""); }
Example 18
Source File: AdminCommand.java From civcraft with GNU General Public License v2.0 | 5 votes |
public void items_cmd() throws CivException { Player player = getPlayer(); if (spawnInventory == null) { spawnInventory = Bukkit.createInventory(player, LoreGuiItem.MAX_INV_SIZE, "Admin Item Spawn"); /* Build the Category Inventory. */ for (ConfigMaterialCategory cat : ConfigMaterialCategory.getCategories()) { ItemStack infoRec = LoreGuiItem.build(cat.name, ItemManager.getId(Material.WRITTEN_BOOK), 0, CivColor.LightBlue+cat.materials.size()+" Items", CivColor.Gold+"<Click To Open>"); infoRec = LoreGuiItem.setAction(infoRec, "OpenInventory"); infoRec = LoreGuiItem.setActionData(infoRec, "invType", "showGuiInv"); infoRec = LoreGuiItem.setActionData(infoRec, "invName", cat.name+" Spawn"); spawnInventory.addItem(infoRec); /* Build a new GUI Inventory. */ Inventory inv = Bukkit.createInventory(player, LoreGuiItem.MAX_INV_SIZE, cat.name+" Spawn"); for (ConfigMaterial mat : cat.materials.values()) { LoreCraftableMaterial craftMat = LoreCraftableMaterial.getCraftMaterialFromId(mat.id); ItemStack stack = LoreMaterial.spawn(craftMat); stack = LoreGuiItem.asGuiItem(stack); stack = LoreGuiItem.setAction(stack, "SpawnItem"); inv.addItem(stack); LoreGuiItemListener.guiInventories.put(inv.getName(), inv); } } } player.openInventory(spawnInventory); }
Example 19
Source File: TradeInventoryListener.java From civcraft with GNU General Public License v2.0 | 4 votes |
public void handleShiftClick(InventoryClickEvent event, Player player, TradeInventoryPair pair) { /* First determine if we're shifting into our inv or into the trade window. */ if (event.getRawSlot() > SLOTS_END) { /* We're clicking in our inventory, trying to bring in an item. * lets cheat by creating a new temp inventory which contains the * current contents of our slots, add this item to it, then replace * the slots with that inv's contents. */ Inventory tempInv = Bukkit.createInventory(event.getWhoClicked(), 9); /* Copy contents from current slots. */ int k = 0; for (int i = MY_SLOTS_START; i < MY_SLOTS_END; i++) { tempInv.setItem(k, event.getInventory().getItem(i));; k++; } /* Add this item to our tempInv. */ HashMap<Integer, ItemStack> leftovers = tempInv.addItem(event.getCurrentItem()); /* Copy contents of the temp inventory on top of our slots. */ k = 0; for (int i = MY_SLOTS_START; i < MY_SLOTS_END; i++) { event.getInventory().setItem(i, tempInv.getItem(k)); k++; } /* Now, remove the item from the player's inventory. */ player.getInventory().setItem(event.getSlot(), null); /* Re-add any leftovers we might have. */ for (ItemStack stack : leftovers.values()) { player.getInventory().addItem(stack); } /* Cancel normal event processing. */ TaskMaster.syncTask(new SyncInventoryChangeAll(pair.inv, pair.otherResident, pair.otherInv)); event.setCancelled(true); return; } else { /* We're clicking in the trade inventory, tryign to take out an item. */ if (event.getRawSlot() < OTHERS_SLOTS_END) { /* We tried to shift click on the other player's side. Cancel. */ event.setCancelled(true); return; } else { /* We're clicking on our side, allow it as normal. */ TaskMaster.syncTask(new SyncInventoryChangeAll(pair.inv, pair.otherResident, pair.otherInv)); return; } } }
Example 20
Source File: SkyBlockMenu.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
public Inventory displayBiomeGUI(final Player player) { List<String> lores = new ArrayList<>(); String title = "\u00a79" + tr("Island Biome"); Inventory menu = Bukkit.createInventory(new UltimateHolder(player, title, MenuType.DEFAULT), 27, title); ItemMeta meta4 = sign.getItemMeta(); meta4.setDisplayName("\u00a7h" + tr("Island Biome")); addLore(lores, tr("\u00a7eClick here to return to\n\u00a7ethe main island screen.")); meta4.setLore(lores); sign.setItemMeta(meta4); menu.addItem(new ItemStack[]{sign}); lores.clear(); String currentBiome = plugin.getIslandInfo(player).getBiome(); for (BiomeMenuItem biomeMenu : biomeMenus) { if (!BiomeCommand.biomeExists(biomeMenu.getId())) { continue; // Skip it } ItemStack menuItem = biomeMenu.getIcon(); meta4 = menuItem.getItemMeta(); if (player.hasPermission("usb.biome." + biomeMenu.getId())) { meta4.setDisplayName("\u00a7a" + tr("Biome: {0}", biomeMenu.getTitle())); addLore(lores, "\u00a7f", biomeMenu.getDescription()); if (biomeMenu.getId().equalsIgnoreCase(currentBiome)) { addLore(lores, tr("\u00a72\u00a7lThis is your current biome.")); } else { addLore(lores, tr("\u00a7e\u00a7lClick to change to this biome.")); } } else { meta4.setDisplayName("\u00a78" + tr("Biome: {0}", biomeMenu.getTitle())); lores.add("\u00a7c" + tr("You cannot use this biome.")); addLore(lores, "\u00a77", biomeMenu.getDescription()); } meta4.setLore(lores); menuItem.setItemMeta(meta4); menu.addItem(menuItem); lores.clear(); } updateBiomeRadius(player, menu); return menu; }