Java Code Examples for org.bukkit.inventory.ItemStack#getData()
The following examples show how to use
org.bukkit.inventory.ItemStack#getData() .
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: ExprColorOf.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("deprecated") @Nullable private Colorable getColorable(Object colorable) { if (colorable instanceof Item || colorable instanceof ItemType) { ItemStack item = colorable instanceof Item ? ((Item) colorable).getItemStack() : ((ItemType) colorable).getRandom(); if (item == null) return null; MaterialData data = item.getData(); if (data instanceof Colorable) return (Colorable) data; } else if (colorable instanceof Block) { BlockState state = ((Block) colorable).getState(); if (state instanceof Colorable) return (Colorable) state; } else if (colorable instanceof Colorable) { return (Colorable) colorable; } return null; }
Example 2
Source File: SpawnEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onSpawnEggEvent(PlayerInteractEvent event) { Player player = event != null ? event.getPlayer() : null; if (player == null || event.isCancelled() || !plugin.getWorldManager().isSkyWorld(player.getWorld())) { return; // Bail out, we don't care } if (player.hasPermission("usb.mod.bypassprotection") || player.isOp()) { return; } ItemStack item = event.getItem(); if (RIGHT_CLICKS.contains(event.getAction()) && item != null && isSpawnEgg(item)) { if (!plugin.playerIsOnIsland(player)) { event.setCancelled(true); plugin.notifyPlayer(player, tr("\u00a7eYou can only use spawn-eggs on your own island.")); return; } SpawnEgg spawnEgg = (SpawnEgg) item.getData(); checkLimits(event, spawnEgg.getSpawnedType(), player.getLocation()); if (event.isCancelled()) { plugin.notifyPlayer(player, tr("\u00a7cYou have reached your spawn-limit for your island.")); event.setUseItemInHand(Event.Result.DENY); event.setUseInteractedBlock(Event.Result.DENY); } } }
Example 3
Source File: Observing.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@Override public void onEvent(InventoryClickEvent event) { super.onEvent(event); if (!(event.getClickedInventory() instanceof PlayerInventory) || event.getCursor() == null) return; ItemStack item = event.getCursor(); if (BAD_TYPES.contains(item.getType()) || item.getData() instanceof Door) { event.setCancelled(true); } }
Example 4
Source File: StackLogic.java From StackMob-3 with GNU General Public License v3.0 | 5 votes |
@Override public boolean doSheepShearAll(Sheep sheared, ItemStack tool) { int stackSize = StackTools.getSize(sheared); if(sm.getCustomConfig().getBoolean("multiply.sheep-wool") && ItemTools.hasEnoughDurability(tool, stackSize)){ LootContext lootContext = new LootContext.Builder(sheared.getLocation()).lootedEntity(sheared).build(); Collection<ItemStack> loot = sheared.getLootTable().populateLoot(ThreadLocalRandom.current(), lootContext); for(ItemStack itemStack : loot){ if(itemStack.getData() instanceof Wool) { sm.getDropTools().dropDrops(itemStack, sm.getDropTools().calculateAmount(stackSize), sheared.getLocation()); } } return true; } return false; }
Example 5
Source File: PlayerListener.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
private void onLobbyInventoryClick(InventoryClickEvent ice, Player player, Game game) { Inventory inv = ice.getInventory(); ItemStack clickedStack = ice.getCurrentItem(); if (!inv.getTitle().equals(BedwarsRel._l(player, "lobby.chooseteam"))) { ice.setCancelled(true); return; } if (clickedStack == null) { ice.setCancelled(true); return; } if (clickedStack.getType() != Material.WOOL) { ice.setCancelled(true); return; } ice.setCancelled(true); Wool wool = (Wool) clickedStack.getData(); Team team = game.getTeamByDyeColor(wool.getColor()); if (team == null) { return; } game.playerJoinTeam(player, team); player.closeInventory(); }
Example 6
Source File: BukkitPlayer.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public BaseBlock getBlockInHand() throws WorldEditException { ItemStack itemStack = player.getItemInHand(); if (itemStack == null) { return EditSession.nullBlock; } final int typeId = itemStack.getTypeId(); switch (typeId) { case 0: return EditSession.nullBlock; case ItemID.INK_SACK: final Dye materialData = (Dye) itemStack.getData(); if (materialData.getColor() == DyeColor.BROWN) { return FaweCache.getBlock(BlockID.COCOA_PLANT, 0); } break; case ItemID.HEAD: return new SkullBlock(0, (byte) itemStack.getDurability()); default: final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability()); if (baseBlock != null) { return baseBlock; } break; } BaseBlock block = FaweCache.getBlock(typeId, itemStack.getType().getMaxDurability() != 0 ? 0 : Math.max(0, itemStack.getDurability())); if (Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES && Fawe.<FaweBukkit>imp().getItemUtil() != null) { return new BrushBoundBaseBlock(this, WorldEdit.getInstance().getSession(this), itemStack); } return block; }
Example 7
Source File: SpawnEggNBT.java From CratesPlus with GNU General Public License v3.0 | 5 votes |
public static SpawnEggNBT fromItemStack(ItemStack itemStack) { if (itemStack == null || itemStack.getType() != LegacyMaterial.MONSTER_EGG.getMaterial()) return null; try { Class craftItemStack = ReflectionUtil.getCBClass("inventory.CraftItemStack"); Method asNMSCopyMethod = craftItemStack.getDeclaredMethod("asNMSCopy", ItemStack.class); Object nmsItemStack = asNMSCopyMethod.invoke(null, itemStack); Class nmsItemStackClass = ReflectionUtil.getNMSClass("ItemStack"); Object nbtTagCompound = nmsItemStackClass.getDeclaredMethod("getTag").invoke(nmsItemStack); Class nbtTagCompoundClass = ReflectionUtil.getNMSClass("NBTTagCompound"); if (nbtTagCompound != null) { Method getCompoundMethod = nbtTagCompoundClass.getDeclaredMethod("getCompound", String.class); Object entityTagCompount = getCompoundMethod.invoke(nbtTagCompound, "EntityTag"); Method getStringMethod = nbtTagCompoundClass.getDeclaredMethod("getString", String.class); String type = (String) getStringMethod.invoke(entityTagCompount, "id"); type = type.replaceFirst("minecraft:", ""); switch (type) { case "CAVESPIDER": type = "CAVE_SPIDER"; break; } EntityType entityType = EntityType.fromName(type); if (entityType == null || !entityType.isAlive()) return null; return new SpawnEggNBT(entityType); } else if (itemStack.getData() instanceof SpawnEgg) { return new SpawnEggNBT(((SpawnEgg) itemStack.getData()).getSpawnedType()); } } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { e.printStackTrace(); } return null; }
Example 8
Source File: Version_Util.java From CratesPlus with GNU General Public License v3.0 | 4 votes |
public EntityType getEntityTypeFromItemStack(ItemStack itemStack) { SpawnEgg spawnEgg = (SpawnEgg) itemStack.getData(); return spawnEgg.getSpawnedType(); }
Example 9
Source File: SpawnEvents.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private boolean isSpawnEgg(ItemStack item) { return item.getType().name().endsWith("_SPAWN_EGG") && item.getData() instanceof MonsterEggs; }