Java Code Examples for org.bukkit.inventory.ItemStack#getType()
The following examples show how to use
org.bukkit.inventory.ItemStack#getType() .
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: TutorialPlayerFacet.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
@Repeatable(interval = @Time(seconds = 1), scope = MatchScope.LOADED) public void refreshNavigation() { if(!tutorial.hasStages()) return; final ItemStack holding = inventory.getItemInHand(); if(holding == null || holding.getType() != TUTORIAL_ITEM) return; if(currentStage != null) { if(navigation == null) { navigation = tutorial.renderNavigation(currentStage); } player.sendHotbarMessage(navigation); } else { if(navigation != null) { navigation = null; player.sendHotbarMessage(Components.blank()); } } }
Example 2
Source File: AntiGriefListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void checkDefuse(final PlayerInteractEvent event) { ItemStack hand = event.getPlayer().getItemInHand(); if (hand == null || hand.getType() != DEFUSE_ITEM) return; MatchPlayer clicker = this.mm.getPlayer(event.getPlayer()); if (clicker != null && clicker.isObserving() && clicker.getBukkit().hasPermission(Permissions.DEFUSE)) { if (event.getAction() == Action.RIGHT_CLICK_AIR) { this.obsTntDefuse(clicker, event.getPlayer().getLocation()); } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { this.obsTntDefuse(clicker, event.getClickedBlock().getLocation()); } } }
Example 3
Source File: QualityArmory.java From QualityArmory with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecation") public static boolean isCustomItemNextId(ItemStack is) { if (is == null) return false; try{ if(CustomItemManager.isUsingCustomData()) return false; }catch (Error|Exception e4){} List<MaterialStorage> ms = new ArrayList<MaterialStorage>(); ms.addAll(QAMain.expansionPacks); ms.addAll(QAMain.gunRegister.keySet()); ms.addAll(QAMain.armorRegister.keySet()); ms.addAll(QAMain.ammoRegister.keySet()); ms.addAll(QAMain.miscRegister.keySet()); for (MaterialStorage mat : ms) { if (mat.getMat() == is.getType()) if (mat.getData() == (is.getDurability() + 1)) if (!mat.hasVariant()) return true; } return false; }
Example 4
Source File: InventoryCompressor.java From Minepacks with GNU General Public License v3.0 | 6 votes |
public List<ItemStack> fast() { for(ItemStack stack : inputStacks) { if(stack == null || stack.getType() == Material.AIR || stack.getAmount() < 1) continue; if(filled == targetStacks.length) { toMuch.add(stack); } else { targetStacks[filled++] = stack; } } return toMuch; }
Example 5
Source File: InventoryCompressor.java From Minepacks with GNU General Public License v3.0 | 6 votes |
public List<ItemStack> compress() { for(ItemStack stack : inputStacks) { if(stack == null || stack.getType() == Material.AIR || stack.getAmount() < 1) continue; tryToStack(stack); if(stack.getAmount() == 0) continue; if(filled == targetStacks.length) { toMuch.add(stack); } else { targetStacks[filled++] = stack; } } return toMuch; }
Example 6
Source File: NbtFactory.java From AdditionsAPI with MIT License | 5 votes |
/** * Ensure that the given stack can store arbitrary NBT information. * @param stack - the stack to check. */ private static void checkItemStack(ItemStack stack) { if (stack == null) throw new IllegalArgumentException("Stack cannot be NULL."); if (!get().CRAFT_STACK.isAssignableFrom(stack.getClass())) throw new IllegalArgumentException("Stack must be a CraftItemStack."); if (stack.getType() == Material.AIR) throw new IllegalArgumentException("ItemStacks representing air cannot store NMS information."); }
Example 7
Source File: PacketDataSerializer.java From PlayerSQL with GNU General Public License v2.0 | 5 votes |
@SneakyThrows public void write(ItemStack input) { if (input == null || input.getType() == Material.AIR) { return; } CraftItemStack item = input instanceof CraftItemStack ? ((CraftItemStack) input) : CraftItemStack.asCraftCopy(input); net.minecraft.server.v1_8_R3.ItemStack nms = (net.minecraft.server.v1_8_R3.ItemStack) handle.get(item); NBTTagCompound compound = new NBTTagCompound(); nms.save(compound); ByteArrayDataOutput output = ByteStreams.newDataOutput(); save.invoke(compound, output); buf.writeBytes(output.toByteArray()); }
Example 8
Source File: SentinelItemHelper.java From Sentinel with MIT License | 5 votes |
/** * Returns whether the NPC is holding a shield in its offhand. */ public boolean hasShield() { if (SentinelVersionCompat.v1_9) { ItemStack item = SentinelUtilities.getOffhandItem(sentinel.getLivingEntity()); return item != null && item.getType() == Material.SHIELD; } return false; }
Example 9
Source File: MapPoll.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public void sendBook(MatchPlayer viewer, boolean forceOpen) { String title = ChatColor.GOLD + "" + ChatColor.BOLD; title += TextTranslations.translate("vote.title.map", viewer.getBukkit()); ItemStack is = new ItemStack(Material.WRITTEN_BOOK); BookMeta meta = (BookMeta) is.getItemMeta(); meta.setAuthor("PGM"); meta.setTitle(title); TextComponent.Builder content = TextComponent.builder(); content.append(TranslatableComponent.of("vote.header.map", TextColor.DARK_PURPLE)); content.append(TextComponent.of("\n\n")); for (MapInfo pgmMap : votes.keySet()) content.append(getMapBookComponent(viewer, pgmMap)); NMSHacks.setBookPages( meta, TextTranslations.toBaseComponent(content.build(), viewer.getBukkit())); is.setItemMeta(meta); ItemStack held = viewer.getInventory().getItemInHand(); if (held.getType() != Material.WRITTEN_BOOK || !title.equals(((BookMeta) is.getItemMeta()).getTitle())) { viewer.getInventory().setHeldItemSlot(2); } viewer.getInventory().setItemInHand(is); if (forceOpen || viewer.getSettings().getValue(SettingKey.VOTE) == SettingValue.VOTE_ON) NMSHacks.openBook(is, viewer.getBukkit()); }
Example 10
Source File: UhcItems.java From UhcCore with GNU General Public License v3.0 | 5 votes |
public static boolean isRegenHeadItem(ItemStack item) { return ( item != null && item.getType() == UniversalMaterial.PLAYER_HEAD.getType() && item.hasItemMeta() && item.getItemMeta().hasLore() && item.getItemMeta().getLore().contains(Lang.ITEMS_REGEN_HEAD) ); }
Example 11
Source File: BukkitImageViewer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
private int getMapSlot(Player player) { PlayerInventory inventory = player.getInventory(); for (int i = 0; i < 9; i++) { ItemStack item = inventory.getItem(i); if (item != null && item.getType() == Material.MAP) { return i; } } return -1; }
Example 12
Source File: UtilTests.java From Civs with GNU General Public License v3.0 | 5 votes |
@Test public void addItemsShouldAddProperItems() { TestUtil.world.setChunkLoaded(false); List<ItemStack> inventoryContents = new ArrayList<>(); inventoryContents.add(new ItemStack(Material.COBBLESTONE, 6)); inventoryContents.add(new ItemStack(Material.WOODEN_AXE)); inventoryContents.add(new ItemStack(Material.STONE_SWORD)); inventoryContents.add(null); inventoryContents.add(null); inventoryContents.add(null); inventoryContents.add(null); inventoryContents.add(null); inventoryContents.add(null); List<CVItem> tempList = new ArrayList<>(); tempList.add(CVItem.createCVItemFromString("GRASS")); List<List<CVItem>> returnList = new ArrayList<>(); returnList.add(tempList); CVInventory cvInventory = UnloadedInventoryHandler.getInstance().getChestInventory(new Location(TestUtil.world, 0, 0, 0)); Util.addItems(returnList, cvInventory); for (ItemStack itemStack : cvInventory.getContents()) { System.out.println(itemStack.getType().name()); if (itemStack.getType() == Material.GRASS) { return; } } fail("No Grass found in inventory"); }
Example 13
Source File: ItemMatcher.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean test(@Nullable ItemStack query) { if(query == null) return false; if(query.getType() != item.getType()) return false; query = normalize(query.clone()); // Match if items stack, and query stack is at least big as the base stack return item.isSimilar(query) && query.getAmount() >= item.getAmount(); }
Example 14
Source File: BrewingStandContainer.java From Transport-Pipes with MIT License | 5 votes |
@Override public ItemStack insertItem(TPDirection insertDirection, ItemStack insertion) { if (!isInLoadedChunk()) { return insertion; } if (isInvLocked(cachedBrewingStand)) { return insertion; } if (insertion.getType() == Material.POTION || insertion.getType() == Material.SPLASH_POTION || insertion.getType() == Material.LINGERING_POTION) { if (cachedInv.getItem(0) == null) { cachedInv.setItem(0, insertion); return null; } else if (cachedInv.getItem(1) == null) { cachedInv.setItem(1, insertion); return null; } else if (cachedInv.getItem(2) == null) { cachedInv.setItem(2, insertion); return null; } } else if (insertDirection.isSide() && insertion.getType() == Material.BLAZE_POWDER) { ItemStack oldFuel = cachedInv.getFuel(); cachedInv.setFuel(accumulateItems(oldFuel, insertion)); if (insertion == null || insertion.getAmount() == 0) { insertion = null; } } else if (isBrewingIngredient(insertion.getType())) { ItemStack oldIngredient = cachedInv.getIngredient(); cachedInv.setIngredient(accumulateItems(oldIngredient, insertion)); if (insertion == null || insertion.getAmount() == 0) { insertion = null; } } return insertion; }
Example 15
Source File: GlobalItemParser.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public ItemStack parseItem(Element el, Material type, short damage) throws InvalidXMLException { int amount = XMLUtils.parseNumber(el.getAttribute("amount"), Integer.class, 1); // If the item is a potion with non-zero damage, and there is // no modern potion ID, decode the legacy damage value. final Potion legacyPotion; if(type == Material.POTION && damage > 0 && el.getAttribute("potion") == null) { try { legacyPotion = Potion.fromDamage(damage); } catch(IllegalArgumentException e) { throw new InvalidXMLException("Invalid legacy potion damage value " + damage + ": " + e.getMessage(), el, e); } // If the legacy splash bit is set, convert to a splash potion if(legacyPotion.isSplash()) { type = Material.SPLASH_POTION; legacyPotion.setSplash(false); } // Potions always have damage 0 damage = 0; } else { legacyPotion = null; } ItemStack itemStack = new ItemStack(type, amount, damage); if(itemStack.getType() != type) { throw new InvalidXMLException("Invalid item/block", el); } final ItemMeta meta = itemStack.getItemMeta(); if(meta != null) { // This happens if the item is "air" parseItemMeta(el, meta); // If we decoded a legacy potion, apply it now, but only if there are no custom effects. // This emulates the old behavior of custom effects overriding default effects. if(legacyPotion != null) { final PotionMeta potionMeta = (PotionMeta) meta; if(!potionMeta.hasCustomEffects()) { potionMeta.setBasePotionData(new PotionData(legacyPotion.getType(), legacyPotion.hasExtendedDuration(), legacyPotion.getLevel() == 2)); } } itemStack.setItemMeta(meta); } return itemStack; }
Example 16
Source File: PlantTreeEventHandler.java From GiantTrees with GNU General Public License v3.0 | 4 votes |
private boolean stackIsCorrect(final ItemStack inHand) { return (inHand != null) && (inHand.getType() == Material.BONE_MEAL); }
Example 17
Source File: LWC.java From Modern-LWC with MIT License | 4 votes |
/** * Deposit items into an inventory chest Works with double chests. * * @param block * @param itemStack * @return remaining items (if any) */ @SuppressWarnings("deprecation") public Map<Integer, ItemStack> depositItems(Block block, ItemStack itemStack) { BlockState blockState; if ((blockState = block.getState()) != null && (blockState instanceof InventoryHolder)) { Block doubleChestBlock = null; InventoryHolder holder = (InventoryHolder) blockState; if (DoubleChestMatcher.PROTECTABLES_CHESTS.contains(block.getType())) { doubleChestBlock = findAdjacentDoubleChest(block); } else if (block.getType() == Material.FURNACE) { Inventory inventory = holder.getInventory(); if (inventory.getItem(0) != null && inventory.getItem(1) != null) { if (inventory.getItem(0).getType() == itemStack.getType() && inventory.getItem(0).getData().getData() == itemStack.getData().getData() && inventory.getItem(0) .getMaxStackSize() >= (inventory.getItem(0).getAmount() + itemStack.getAmount())) { // ItemStack fits on Slot 0 } else if (inventory.getItem(1).getType() == itemStack.getType() && inventory.getItem(1).getData().getData() == itemStack.getData().getData() && inventory.getItem(1) .getMaxStackSize() >= (inventory.getItem(1).getAmount() + itemStack.getAmount())) { // ItemStack fits on Slot 1 } else { return null; } } } if (itemStack.getAmount() <= 0) { return new HashMap<Integer, ItemStack>(); } Map<Integer, ItemStack> remaining = holder.getInventory().addItem(itemStack); // we have remainders, deal with it if (remaining.size() > 0) { int key = remaining.keySet().iterator().next(); ItemStack remainingItemStack = remaining.get(key); // is it a double chest ????? if (doubleChestBlock != null) { InventoryHolder holder2 = (InventoryHolder) doubleChestBlock.getState(); remaining = holder2.getInventory().addItem(remainingItemStack); } // recheck remaining in the event of double chest being used if (remaining.size() > 0) { return remaining; } } } return new HashMap<Integer, ItemStack>(); }
Example 18
Source File: DurabilityBar.java From AdditionsAPI with MIT License | 4 votes |
public static void sendDurabilityBossBar(Player player, ItemStack item, EquipmentSlot slot) { BossBarConfig config = ConfigFile.getInstance().getBossBarConfig(); if (!config.show()) return; UUID uuid = player.getUniqueId(); BossBar bar; HashMap<UUID, BossBar> playersBars; String title; if (slot.equals(EquipmentSlot.HAND)) { title = LangFileUtils.get("item_durability_main_hand"); playersBars = playersBarsMain; } else if (slot.equals(EquipmentSlot.OFF_HAND)) { title = LangFileUtils.get("item_durability_off_hand"); playersBars = playersBarsOff; } else { return; } if (!playersBars.containsKey(uuid)) { bar = Bukkit.createBossBar(title, BarColor.GREEN, BarStyle.SOLID); bar.addPlayer(player); playersBars.put(uuid, bar); } else { bar = playersBars.get(uuid); } if (item == null || item.getType() == Material.AIR) { bar.setVisible(false); bar.setProgress(1.0D); return; } int durability = 0; int durabilityMax = 0; if (AdditionsAPI.isCustomItem(item)) { if (!config.showCustomItems() || item.getType().getMaxDurability() == 0) { bar.setVisible(false); bar.setProgress(1.0D); return; } CustomItemStack cStack = new CustomItemStack(item); CustomItem cItem = cStack.getCustomItem(); if (cItem.hasFakeDurability()) { durability = cStack.getFakeDurability(); durabilityMax = cItem.getFakeDurability(); } else if (cStack.getCustomItem().isUnbreakable()) { bar.setVisible(false); bar.setProgress(1.0D); return; } else { durabilityMax = item.getType().getMaxDurability(); durability = durabilityMax - item.getDurability(); } } else if (item.getType().getMaxDurability() != 0) { if (!config.showVanillaItems()) { bar.setVisible(false); bar.setProgress(1.0D); return; } durabilityMax = item.getType().getMaxDurability(); durability = durabilityMax - item.getDurability(); } else { bar.setVisible(false); bar.setProgress(1.0D); return; } double progress = (double) durability / (double) durabilityMax; if (progress > 1) { progress = 1; } else if (progress < 0) { progress = 0; } bar.setVisible(true); if (progress < 0) progress = 0; else if (progress > 1) progress = 1; try { bar.setProgress(progress); } catch (IllegalArgumentException event) {} if (progress >= 0.5) { bar.setColor(BarColor.GREEN); bar.setTitle(title + ChatColor.GREEN + durability + " / " + durabilityMax); } else if (progress >= 0.25) { bar.setColor(BarColor.YELLOW); bar.setTitle(title + ChatColor.YELLOW + durability + " / " + durabilityMax); } else { bar.setColor(BarColor.RED); bar.setTitle(title + ChatColor.RED + durability + " / " + durabilityMax); } }
Example 19
Source File: UHPluginListener.java From KTP with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("deprecation") @EventHandler public void onPlayerInteract(PlayerInteractEvent ev) { if ((ev.getAction() == Action.RIGHT_CLICK_AIR || ev.getAction() == Action.RIGHT_CLICK_BLOCK) && ev.getPlayer().getItemInHand().getType() == Material.COMPASS && p.getConfig().getBoolean("compass")) { Player pl = ev.getPlayer(); Boolean foundRottenFlesh = false; for (ItemStack is : pl.getInventory().getContents()) { if (is != null && is.getType() == Material.ROTTEN_FLESH) { p.getLogger().info(""+is.getAmount()); if (is.getAmount() != 1) is.setAmount(is.getAmount()-1); else { p.getLogger().info("lol"); pl.getInventory().removeItem(is); } pl.updateInventory(); foundRottenFlesh = true; break; } } if (!foundRottenFlesh) { pl.sendMessage(ChatColor.GRAY+""+ChatColor.ITALIC+"Vous n'avez pas de chair de zombie."); pl.playSound(pl.getLocation(), Sound.BLOCK_WOOD_STEP, 1F, 1F); return; } pl.playSound(pl.getLocation(), Sound.ENTITY_PLAYER_BURP, 1F, 1F); Player nearest = null; Double distance = 99999D; for (Player pl2 : p.getServer().getOnlinePlayers()) { try { Double calc = pl.getLocation().distance(pl2.getLocation()); if (calc > 1 && calc < distance) { distance = calc; if (pl2 != pl && !this.p.inSameTeam(pl, pl2)) nearest = pl2.getPlayer(); } } catch (Exception e) {} } if (nearest == null) { pl.sendMessage(ChatColor.GRAY+""+ChatColor.ITALIC+"Seul le silence comble votre requĂȘte."); return; } pl.sendMessage(ChatColor.GRAY+"La boussole pointe sur le joueur le plus proche."); pl.setCompassTarget(nearest.getLocation()); } }
Example 20
Source File: SlimefunBackpack.java From Slimefun4 with GNU General Public License v3.0 | 3 votes |
/** * This method returns whether a given {@link ItemStack} is allowed to be stored * in this {@link SlimefunBackpack}. * * @param item * The {@link ItemStack} to check for * * @param itemAsSlimefunItem * The same {@link ItemStack} as a {@link SlimefunItem}, might be null * * @return Whether the given {@link ItemStack} is allowed to be put into this {@link SlimefunBackpack} */ public boolean isItemAllowed(ItemStack item, SlimefunItem itemAsSlimefunItem) { // Shulker Boxes are not allowed! if (item.getType() == Material.SHULKER_BOX || item.getType().toString().endsWith("_SHULKER_BOX")) { return false; } return !(itemAsSlimefunItem instanceof SlimefunBackpack); }