Java Code Examples for org.bukkit.inventory.Inventory#setItem()

The following examples show how to use org.bukkit.inventory.Inventory#setItem() . 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: MessageGui.java    From WildernessTp with MIT License 8 votes vote down vote up
public static void openMessGui(Player p) {
    ItemStack close = new ItemStack(Material.REDSTONE_BLOCK, 1);
    ItemMeta meta = close.getItemMeta();
    meta.setDisplayName("Close");
    ArrayList<String> lore = new ArrayList<>();
    lore.add("Click to close the inventory and return to normal gameplay");
    meta.setLore(lore);
    close.setItemMeta(meta);
    Inventory messages = Bukkit.createInventory(p, 27, "WildTp");
    p.openInventory(messages);
    messages.setItem(0, makeItem("Teleport" , "Click to set the message to be said on teleport"));
    messages.setItem(2, makeItem("NoSuit", "Click to set the no suitable location message"));
    messages.setItem(4, makeItem("CostMsg", "Click to set the cost message"));
    messages.setItem(6, makeItem("No-Break", "Click to set the no perm for sign break message"));
    messages.setItem(8, makeItem("No-Perm", "Click to set the No permission to make a sign message"));
    messages.setItem(10, makeItem( "Cooldown Message", "Click to set the cool down message"));
    messages.setItem(12, makeItem( "Wait/Warmup Message", "Click to set the warmp/delay/wait message"));
    messages.setItem(14, makeItem("Used command Message", "Click to set the command used message"));
    messages.setItem(17, makeItem("Refund Message", "Click to set the RefundMessage"));
    messages.setItem(19, makeItem("Blocked Command Message", "Click me to set the Blocked Command Message"));
    messages.setItem(21, makeItem("World Message","Click me to set the message for when command is used \nin a non configured world"));
    messages.setItem(23, makeItem("Cancel Message", "Click me to set the message for when a player \ncauses teleportation to be canceld"));
    messages.setItem(24, MainGui.backItem());
    messages.setItem(26, close);
}
 
Example 2
Source File: AdminShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected boolean openWindow(Player player) {
	final AdminShopkeeper shopkeeper = this.getShopkeeper();
	Inventory inventory = Bukkit.createInventory(player, 27, Settings.editorTitle);

	// add the shopkeeper's trade offers:
	List<ItemStack[]> recipes = shopkeeper.getRecipes();
	for (int column = 0; column < recipes.size() && column < 8; column++) {
		ItemStack[] recipe = recipes.get(column);
		inventory.setItem(column, recipe[0]);
		inventory.setItem(column + 9, recipe[1]);
		inventory.setItem(column + 18, recipe[2]);
	}
	// add the special buttons:
	this.setActionButtons(inventory);
	// show editing inventory:
	player.openInventory(inventory);
	return true;
}
 
Example 3
Source File: ScenarioManager.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
public Inventory getScenarioEditInventory(){

        Inventory inv = Bukkit.createInventory(null,6*ROW, Lang.SCENARIO_GLOBAL_INVENTORY_EDIT);

        // add edit item
        ItemStack back = new ItemStack(Material.ARROW);
        ItemMeta itemMeta = back.getItemMeta();
        itemMeta.setDisplayName(Lang.SCENARIO_GLOBAL_ITEM_BACK);
        back.setItemMeta(itemMeta);
        inv.setItem(5*ROW+8,back);

        for (Scenario scenario : Scenario.values()){
            if (!scenario.isCompatibleWithVersion()){
                continue;
            }

            ItemStack scenarioItem = scenario.getScenarioItem();
            if (isActivated(scenario)){
                scenarioItem.addUnsafeEnchantment(Enchantment.DURABILITY, 1);
                scenarioItem.setAmount(2);
            }
            inv.addItem(scenarioItem);
        }

        return inv;
    }
 
Example 4
Source File: CraftsManager.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public static void openCraftInventory(Player player, Craft craft) {
	int maxSlots = 6*9;
	Inventory inv = Bukkit.createInventory(null, maxSlots, Lang.ITEMS_CRAFT_BOOK_INVENTORY);

	for(int i = 0 ; i < maxSlots-9 ; i++){
		inv.setItem(i, UniversalMaterial.BLACK_STAINED_GLASS_PANE.getStack());
	}
	
	for(int i = maxSlots-9 ; i < maxSlots ; i++){
		inv.setItem(i, UniversalMaterial.WHITE_STAINED_GLASS_PANE.getStack());
	}
	
	// Recipe
	inv.setItem(11, craft.getRecipe().get(0));
	inv.setItem(12, craft.getRecipe().get(1));
	inv.setItem(13, craft.getRecipe().get(2));
	inv.setItem(20, craft.getRecipe().get(3));
	inv.setItem(21, craft.getRecipe().get(4));
	inv.setItem(22, craft.getRecipe().get(5));
	inv.setItem(29, craft.getRecipe().get(6));
	inv.setItem(30, craft.getRecipe().get(7));
	inv.setItem(31, craft.getRecipe().get(8));
	
	// Craft
	inv.setItem(24, craft.getCraft());		

	// Back
	ItemStack back = UniversalMaterial.PUFFERFISH.getStack();
	ItemMeta im = back.getItemMeta();
	im.setDisplayName(ChatColor.GRAY+Lang.ITEMS_CRAFT_BOOK_BACK);
	back.setItemMeta(im);
	inv.setItem(49, back);
	
	player.openInventory(inv);
	
}
 
Example 5
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void updateRestartMenu(Inventory menu, Player player, List<String> schemeNames) {
    ItemStack menuItem;
    ItemMeta meta;
    List<String> lores;
    int index = 1;
    for (String schemeName : schemeNames) {
        IslandPerk islandPerk = plugin.getPerkLogic().getIslandPerk(schemeName);
        boolean enabled = plugin.getConfig().getBoolean("island-schemes." + islandPerk.getSchemeName() + ".enabled", true);
        if (!enabled) {
            continue; // Skip
        }
        index = plugin.getConfig().getInt("island-schemes." + islandPerk.getSchemeName() + ".index", index);
        menuItem = islandPerk.getDisplayItem();
        meta = menuItem.getItemMeta();
        lores = meta.getLore();
        if (lores == null) {
            lores = new ArrayList<>();
        }
        if (player.hasPermission(islandPerk.getPermission())) {
            long millisLeft = plugin.getConfirmHandler().millisLeft(player, "/is restart");
            if (millisLeft > 0) {
                addLore(lores, tr("\u00a7cClick within \u00a79{0}\u00a7c to restart!", TimeUtil.millisAsString(millisLeft)));
            } else {
                addLore(lores, tr("\u00a7aClick to restart!"));
            }
        } else {
            addLore(lores, tr("\u00a7cNo access!\n\u00a77({0})", islandPerk.getPermission()));
        }
        meta.setLore(lores);
        menuItem.setItemMeta(meta);
        menu.setItem(index++, menuItem);
    }
    player.updateInventory();
}
 
Example 6
Source File: ObserverModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
public Inventory getFakeInventory(Player player, String locale) {
    Inventory inventory = Bukkit.createInventory(null, 45, player.getDisplayName().length() > 32 ? Teams.getTeamColorByPlayer(player) + player.getName() : player.getDisplayName());
    inventory.setItem(0, player.getInventory().getHelmet());
    inventory.setItem(1, player.getInventory().getChestplate());
    inventory.setItem(2, player.getInventory().getLeggings());
    inventory.setItem(3, player.getInventory().getBoots());
    inventory.setItem(4, player.getInventory().getItemInOffHand());

    ItemStack potion;
    if (player.getActivePotionEffects().size() > 0){
        ArrayList<String> effects = new ArrayList<>();
        for (PotionEffect effect : player.getActivePotionEffects()) {
            String effectName = WordUtils.capitalizeFully(effect.getType().getName().toLowerCase().replaceAll("_", " "));
            effects.add(ChatColor.YELLOW + effectName + " " + (effect.getAmplifier() + 1));
        }
        potion = Items.createItem(Material.POTION, 1, (short) 0, ChatColor.AQUA + "" + ChatColor.ITALIC + new LocalizedChatMessage(ChatConstant.UI_POTION_EFFECTS).getMessage(locale), effects);
    } else {
        potion = Items.createItem(Material.GLASS_BOTTLE, 1, (short) 0, ChatColor.AQUA + "" + ChatColor.ITALIC + new LocalizedChatMessage(ChatConstant.UI_POTION_EFFECTS).getMessage(locale), new ArrayList<>(Collections.singletonList(ChatColor.YELLOW + new LocalizedChatMessage(ChatConstant.UI_NO_POTION_EFFECTS).getMessage(locale))));
    }
    inventory.setItem(6, potion);
    ItemStack food = Items.createItem(Material.COOKED_BEEF, player.getFoodLevel(), (short) 0, ChatColor.AQUA + "" + ChatColor.ITALIC + new LocalizedChatMessage(ChatConstant.UI_HUNGER_LEVEL).getMessage(locale));
    inventory.setItem(7, food);
    ItemStack health = Items.createItem(Material.REDSTONE, (int) Math.ceil(player.getHealth()), (short) 0, ChatColor.AQUA + "" + ChatColor.ITALIC + new LocalizedChatMessage(ChatConstant.UI_HEALTH_LEVEL).getMessage(locale));
    inventory.setItem(8, health);
    for (int i = 36; i <= 44; i++) {
        inventory.setItem(i, player.getInventory().getItem(i - 36));
    }
    for (int i = 9; i <= 35; i++) {
        inventory.setItem(i, player.getInventory().getItem(i));
    }
    return inventory;
}
 
Example 7
Source File: ShowRecipe.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public void buildInfoBar(LoreCraftableMaterial craftMat, Inventory recInv, Player player) {
	int offset = 0;
	ItemStack stack = null;
	
	if (craftMat.getConfigMaterial().required_tech != null) {
		Resident resident = CivGlobal.getResident(player);
		ConfigTech tech = CivSettings.techs.get(craftMat.getConfigMaterial().required_tech);
		if (tech != null) {
		
			if (resident.hasTown() && resident.getCiv().hasTechnology(craftMat.getConfigMaterial().required_tech)) {
				stack = LoreGuiItem.build("Required Technology", ItemManager.getId(Material.EMERALD_BLOCK), 0, tech.name);
			} else {
				stack = LoreGuiItem.build("Required Technology", ItemManager.getId(Material.REDSTONE_BLOCK), 0, tech.name);
			}
		}
		
		if (stack != null) {
			recInv.setItem(offset+0, stack);
		}
	}
	
	if (craftMat.isShaped()) {
		stack = LoreGuiItem.build("Shaped", ItemManager.getId(Material.HOPPER), 0, "");
	} else {
		stack = LoreGuiItem.build("Unshaped", ItemManager.getId(Material.COAL), 0, "");
	}
	offset += LoreGuiItem.INV_ROW_COUNT;
	recInv.setItem(offset+0, stack);
	

}
 
Example 8
Source File: InvUtils.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
public static Inventory getSpectatorInventory(Player player1, Player player2) {
  String title =
      ChatColor.translateAlternateColorCodes(
          '&', pl.getConfig().getString("gui.spectator-title"));
  if (Sounds.version > 1.8)
    title = title.replace("%PLAYER1%", player1.getName()).replace("%PLAYER2%", player2.getName());
  Inventory inv = Bukkit.createInventory(player1.getInventory().getHolder(), 54, title);
  for (int i = 4; i <= 49; i += 9) inv.setItem(i, placeHolder);
  for (int i = 45; i <= 53; i++) inv.setItem(i, placeHolder);
  inv.setItem(0, ItemFactory.getPlayerSkull(player1, "&f" + player1.getName()));
  inv.setItem(8, ItemFactory.getPlayerSkull(player2, "&f" + player2.getName()));
  inv.setItem(4, theyCancelled);
  return inv;
}
 
Example 9
Source File: GizmoUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void openMenu(Player player) {
    Inventory inventory = Bukkit.createInventory(player, 18, ChatColor.RED + LobbyTranslations.get().t("gizmos", player));
    inventory.setItem(4, Utils.getGhastTear(player, RaindropsListener.raindrops.get(player)));

    int i = 9;
    for(Gizmo gizmo : Gizmos.gizmos) {
        inventory.setItem(i++, gizmo.getItemStack(player));
    }

    player.openInventory(inventory);
}
 
Example 10
Source File: KitsManager.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public static void openKitSelectionInventory(Player player){
	int maxSlots = 6*9;
	Inventory inv = Bukkit.createInventory(null, maxSlots, Lang.ITEMS_KIT_INVENTORY);
	int slot = 0;
	for(Kit kit : kits){
		if(slot < maxSlots){
			inv.setItem(slot, kit.getSymbol());
			slot++;
		}
	}
	
	player.openInventory(inv);
}
 
Example 11
Source File: Roulette.java    From Crazy-Crates with MIT License 5 votes vote down vote up
public static void openRoulette(Player player, Crate crate, KeyType keyType, boolean checkHand) {
    Inventory inv = Bukkit.createInventory(null, 27, Methods.sanitizeColor(crate.getFile().getString("Crate.CrateName")));
    setGlass(inv);
    inv.setItem(13, crate.pickPrize(player).getDisplayItem());
    player.openInventory(inv);
    if (!cc.takeKeys(1, player, crate, keyType, checkHand)) {
        Methods.failedToTakeKey(player, crate);
        cc.removePlayerFromOpeningList(player);
        return;
    }
    startRoulette(player, inv, crate);
}
 
Example 12
Source File: SpectatorTools.java    From CardinalPGM with MIT License 5 votes vote down vote up
public Inventory getTeleportMenu(Player player, TeamModule team) {
    int size = ((team.size() + 9) / 9) * 9;
    Inventory inventory = Bukkit.createInventory(null, size, getTeleportMenuTitle(player.getLocale()));
    int item = 0;
    for (Player view : (List<Player>) team) {
        ItemStack skull = Items.createItem(Material.SKULL_ITEM, 1, (short) 3, view.getDisplayName(), Collections.singletonList("Click to teleport"));
        SkullMeta meta = ((SkullMeta) skull.getItemMeta());
        meta.setOwner(view.getName(), view.getUniqueId(), view.getSkin());
        skull.setItemMeta(meta);
        inventory.setItem(item, skull);
        item++;
    }
    inventory.setItem(size - 1, getGoBackItem(player.getLocale()));
    return inventory;
}
 
Example 13
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void updateLeaveMenuItem(Inventory inventory, ItemStack currentItem, long millisLeft) {
    if (currentItem == null || currentItem.getItemMeta() == null ||currentItem.getItemMeta().getLore() == null) {
        return;
    }
    ItemMeta meta = currentItem.getItemMeta();
    List<String> lore = meta.getLore();
    if (millisLeft >= 0) {
        lore.set(lore.size()-1, tr("\u00a7cClick within \u00a79{0}\u00a7c to leave!", TimeUtil.millisAsString(millisLeft)));
    } else {
        lore.set(lore.size()-1, tr("\u00a7cClick to leave"));
    }
    meta.setLore(lore);
    currentItem.setItemMeta(meta);
    inventory.setItem(17, currentItem);
}
 
Example 14
Source File: BasicElement.java    From black with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void displayOn(final Inventory inventory, final int locX, final int locY) {
    inventory.setItem(locX + locY * 9, icon.clone());
}
 
Example 15
Source File: CargoUtils.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
static ItemStack insertIntoVanillaInventory(ItemStack stack, Inventory inv) {
    ItemStack[] contents = inv.getContents();
    int minSlot = 0;
    int maxSlot = contents.length;

    // Check if it is a normal furnace
    if (inv instanceof FurnaceInventory) {
        // Check if it is fuel or not
        if (stack.getType().isFuel()) {
            maxSlot = 2;

            // Any non-smeltable items should not land in the upper slot
            if (!isSmeltable(stack, true)) {
                minSlot = 1;
            }
        }
        else {
            maxSlot = 1;
        }
    }
    else if (inv instanceof BrewerInventory) {
        if (stack.getType() == Material.POTION || stack.getType() == Material.LINGERING_POTION || stack.getType() == Material.SPLASH_POTION) {
            // Potions slot
            maxSlot = 3;
        }
        else if (stack.getType() == Material.BLAZE_POWDER) {
            // Blaze Powder slot
            minSlot = 4;
            maxSlot = 5;
        }
        else {
            // Input slot
            minSlot = 3;
            maxSlot = 4;
        }
    }

    ItemStackWrapper wrapper = new ItemStackWrapper(stack);

    for (int slot = minSlot; slot < maxSlot; slot++) {
        // Changes to this ItemStack are synchronized with the Item in the Inventory
        ItemStack itemInSlot = contents[slot];

        if (itemInSlot == null) {
            inv.setItem(slot, stack);
            return null;
        }
        else {
            int maxStackSize = itemInSlot.getType().getMaxStackSize();

            if (SlimefunUtils.isItemSimilar(itemInSlot, wrapper, true, false) && itemInSlot.getAmount() < maxStackSize) {
                int amount = itemInSlot.getAmount() + stack.getAmount();

                if (amount > maxStackSize) {
                    stack.setAmount(amount - maxStackSize);
                }
                else {
                    stack = null;
                }

                itemInSlot.setAmount(Math.min(amount, maxStackSize));
                // Setting item in inventory will clone the ItemStack
                inv.setItem(slot, itemInSlot);

                return stack;
            }
        }
    }

    return stack;
}
 
Example 16
Source File: SkyBlockMenu.java    From uSkyBlock with GNU General Public License v3.0 4 votes vote down vote up
private void addExtraMenus(Player player, Inventory menu) {
    ConfigurationSection extras = plugin.getConfig().getConfigurationSection("options.extra-menus");
    if (extras == null) {
        return;
    }
    for (String sIndex : extras.getKeys(false)) {
        ConfigurationSection menuSection = extras.getConfigurationSection(sIndex);
        if (menuSection == null) {
            continue;
        }
        try {
            int index = Integer.parseInt(sIndex, 10);
            String title = menuSection.getString("title", "\u00a9Unknown");
            String icon = menuSection.getString("displayItem", "CHEST");
            List<String> lores = new ArrayList<>();
            for (String l : menuSection.getStringList("lore")) {
                Matcher matcher = PERM_VALUE_PATTERN.matcher(l);
                if (matcher.matches()) {
                    String perm = matcher.group("perm");
                    String lore = matcher.group("value");
                    boolean not = matcher.group("not") != null;
                    if (perm != null) {
                        boolean hasPerm = player.hasPermission(perm);
                        if ((hasPerm && !not) || (!hasPerm && not)) {
                            lores.add(lore);
                        }
                    } else {
                        lores.add(lore);
                    }
                }
            }
            // Only SIMPLE icons supported...
            ItemStack item = new ItemStack(Material.matchMaterial(icon), 1);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName(title);
            meta.setLore(lores);
            item.setItemMeta(meta);
            menu.setItem(index, item);
        } catch (Exception e) {
            log(Level.INFO, "\u00a79[uSkyBlock]\u00a7r Unable to add extra-menu " + sIndex + ": " + e);
        }
    }
}
 
Example 17
Source File: SkinsGUI.java    From SkinsRestorerX with GNU General Public License v3.0 4 votes vote down vote up
public Inventory getGUI(Player p, int page, Map<String, Object> skinsList) {
    Inventory inventory = Bukkit.createInventory(p, 54, Locale.SKINSMENU_TITLE.replace("&", "ยง") + page);

    inventory.setItem(36, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(37, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(38, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(39, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(40, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(41, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(42, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(43, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(44, new GuiGlass(GlassType.NONE).getItemStack());

    //Middle button //remove skin
    inventory.setItem(48, new GuiGlass(GlassType.DELETE).getItemStack());
    inventory.setItem(49, new GuiGlass(GlassType.DELETE).getItemStack());
    inventory.setItem(50, new GuiGlass(GlassType.DELETE).getItemStack());
    //button place next
    inventory.setItem(45, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(46, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(47, new GuiGlass(GlassType.NONE).getItemStack());

    //button place next
    inventory.setItem(53, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(52, new GuiGlass(GlassType.NONE).getItemStack());
    inventory.setItem(51, new GuiGlass(GlassType.NONE).getItemStack());

    skinsList.forEach((name, property) -> {
        //if page is not 0, adding Previous Page button.
        if (page != 0) {
            inventory.setItem(45, new GuiGlass(GlassType.PREV).getItemStack());
            inventory.setItem(46, new GuiGlass(GlassType.PREV).getItemStack());
            inventory.setItem(47, new GuiGlass(GlassType.PREV).getItemStack());
        }

        inventory.addItem(createSkull(name, property));

        //if the page is full, adding Next Page button.
        if (inventory.firstEmpty() == -1 || inventory.getItem(26) != null) {
            inventory.setItem(53, new GuiGlass(GlassType.NEXT).getItemStack());
            inventory.setItem(52, new GuiGlass(GlassType.NEXT).getItemStack());
            inventory.setItem(51, new GuiGlass(GlassType.NEXT).getItemStack());
            return;
        }
    });

    return inventory;
}
 
Example 18
Source File: UhcItems.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
private static void fillInventory(Inventory inv){
	for (int i = 0; i < inv.getSize(); i++) {
		inv.setItem(i, GameItem.TEAM_FILL_BLACK.getItem());
	}
}
 
Example 19
Source File: Recipes.java    From ProRecipes with GNU General Public License v2.0 3 votes vote down vote up
public void clearIngredients(Inventory it){
	

			for(int i = 8; i< 45; i++){
				if((i-1) % 9 == 0 || (i-2) % 9 == 0 || (i-3) % 9 == 0 || (i-4) % 9 == 0){
					it.setItem(i, null);
				}
			}
		
	
}
 
Example 20
Source File: Config.java    From CS-CoreLib with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Gets the Contents of an Inventory at the specified Path
 *
 * @param  path The path in the Config File
 * @param  size The Size of the Inventory
 * @param  title The Title of the Inventory
 * @return      The generated Inventory
 */ 
public Inventory getInventory(String path, int size, String title) {
	Inventory inventory = Bukkit.createInventory(null, size, title);
	for (int i = 0; i < size; i++) {
		inventory.setItem(i, getItem(path + "." + i));
	}
	return inventory;
}