Java Code Examples for org.spongepowered.api.item.inventory.ItemStack#getType()
The following examples show how to use
org.spongepowered.api.item.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: ElementRegistry.java From HuskyUI-Plugin with GNU General Public License v3.0 | 5 votes |
/** * Convert an ItemStack into an ElementID * * @param stack ItemStack to pull ElementID from * @return ElementID, if it exists. This ID may not actually be associated with an Element, so please verify that before use with {@link #elementExists(int)}. */ public Optional<Integer> getElementIDFromItemStack(ItemStack stack){ if(stack.getType() == ItemTypes.AIR || stack.getType() == ItemTypes.NONE) return Optional.empty(); Optional<Object> optRegID = stack.toContainer().get(DataQuery.of("UnsafeData", "regid")); if(optRegID.isPresent()){ return Optional.of((int)optRegID.get()); } return Optional.empty(); }
Example 2
Source File: HuskyUI.java From HuskyUI-Plugin with GNU General Public License v3.0 | 5 votes |
/** * Handle inventory clicks * @param event clickinvevent */ @Listener(order = Order.PRE) public void onItemClick(ClickInventoryEvent event){ try { if (event instanceof ClickInventoryEvent.Primary || event instanceof ClickInventoryEvent.Secondary || event instanceof ClickInventoryEvent.Shift || event instanceof ClickInventoryEvent.Creative) { ItemStack affected; affected = event.getTransactions().get(0).getOriginal().createStack(); if (event instanceof ClickInventoryEvent.Shift && (affected.getType() == ItemTypes.AIR || affected.getType() == ItemTypes.NONE)) { affected = event.getTransactions().get(0).getDefault().createStack(); } Optional<Integer> potentialID = registry.getElementIDFromItemStack(affected); if (potentialID.isPresent()) { if (registry.elementExists(potentialID.get())) { if (registry.isElementAuto(potentialID.get())) { if (event.getTransactions().get(0).getSlot().parent().getArchetype().equals(InventoryArchetypes.PLAYER)) { if (registry.isElementFixedAuto(potentialID.get())) { event.setCancelled(true); } } else { event.setCancelled(true); } } } } } }catch(Exception ignored){} }
Example 3
Source File: SpongeDeathListener.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
private Runnable handlePlayerKill(long time, UUID victimUUID, Player killer) { Optional<ItemStack> inMainHand = killer.getItemInHand(HandTypes.MAIN_HAND); ItemStack inHand = inMainHand.orElse(killer.getItemInHand(HandTypes.OFF_HAND).orElse(ItemStack.empty())); ItemType type = inHand.isEmpty() ? ItemTypes.AIR : inHand.getType(); return victimUUID != null ? new PlayerKillProcessor(killer.getUniqueId(), time, victimUUID, new ItemNameFormatter().apply(type.getName())) : new MobKillProcessor(killer.getUniqueId()); }
Example 4
Source File: ClaimFlagBase.java From GriefPrevention with MIT License | 5 votes |
protected String filterMeta(ItemStack stack, String id) { if (stack != null && stack.getType() != null) { final int meta = ((net.minecraft.item.ItemStack)(Object) stack).getItemDamage(); if (meta == 0) { return GPPermissionHandler.getIdentifierWithoutMeta(id); } } return id; }
Example 5
Source File: UCVHelper8.java From UltimateChat with GNU General Public License v3.0 | 4 votes |
@Override public ItemType getItemName(ItemStack itemStack) { return itemStack.getType(); }
Example 6
Source File: UCVHelper7.java From UltimateChat with GNU General Public License v3.0 | 4 votes |
@Override public ItemType getItemName(ItemStack itemStack) { return itemStack.getType(); }
Example 7
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 4 votes |
public InteractEvent handleItemInteract(InteractEvent event, Player player, World world, ItemStack itemInHand) { if (lastInteractItemSecondaryTick == Sponge.getServer().getRunningTimeTicks() || lastInteractItemPrimaryTick == Sponge.getServer().getRunningTimeTicks()) { // ignore return event; } if (event instanceof InteractItemEvent.Primary) { lastInteractItemPrimaryTick = Sponge.getServer().getRunningTimeTicks(); } else { lastInteractItemSecondaryTick = Sponge.getServer().getRunningTimeTicks(); } final ItemType itemType = itemInHand.getType(); if (itemInHand.isEmpty() || itemType instanceof ItemFood) { return event; } final boolean primaryEvent = event instanceof InteractItemEvent.Primary || event instanceof InteractBlockEvent.Primary; if (!GPFlags.INTERACT_ITEM_PRIMARY && primaryEvent || !GPFlags.INTERACT_ITEM_SECONDARY && !primaryEvent || !GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) { return event; } if (primaryEvent && GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ITEM_PRIMARY.toString(), itemInHand.getType(), world.getProperties())) { return event; } if (!primaryEvent && GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ITEM_SECONDARY.toString(), itemInHand.getType(), world.getProperties())) { return event; } final Cause cause = event.getCause(); final EventContext context = cause.getContext(); final BlockSnapshot blockSnapshot = context.get(EventContextKeys.BLOCK_HIT).orElse(BlockSnapshot.NONE); final Vector3d interactPoint = event.getInteractionPoint().orElse(null); final Entity entity = context.get(EventContextKeys.ENTITY_HIT).orElse(null); final Location<World> location = entity != null ? entity.getLocation() : blockSnapshot != BlockSnapshot.NONE ? blockSnapshot.getLocation().get() : interactPoint != null ? new Location<World>(world, interactPoint) : player.getLocation(); final String ITEM_PERMISSION = primaryEvent ? GPPermissions.INTERACT_ITEM_PRIMARY : GPPermissions.INTERACT_ITEM_SECONDARY; final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); if (!itemInHand.isEmpty() && (itemInHand.getType().equals(GriefPreventionPlugin.instance.modificationTool) || itemInHand.getType().equals(GriefPreventionPlugin.instance.investigationTool))) { GPPermissionHandler.addEventLogEntry(event, location, itemInHand, blockSnapshot == null ? entity : blockSnapshot, player, ITEM_PERMISSION, null, Tristate.TRUE); if (investigateClaim(event, player, blockSnapshot, itemInHand)) { return event; } onPlayerHandleShovelAction(event, blockSnapshot, player, ((HandInteractEvent) event).getHandType(), playerData); return event; } final GPClaim claim = this.dataStore.getClaimAtPlayer(location, playerData, true); if (GPPermissionHandler.getClaimPermission(event, location, claim, ITEM_PERMISSION, player, itemType, player, TrustType.ACCESSOR, true) == Tristate.FALSE) { Text message = GriefPreventionPlugin.instance.messageData.permissionInteractItem .apply(ImmutableMap.of( "owner", claim.getOwnerName(), "item", itemInHand.getType().getId())).build(); GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message); if (event instanceof InteractItemEvent) { if (!SpongeImplHooks.isFakePlayer(((EntityPlayerMP) player)) && itemType == ItemTypes.WRITABLE_BOOK) { ((EntityPlayerMP) player).closeScreen(); } } event.setCancelled(true); } return event; }
Example 8
Source File: VersionHelper7.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@Override public ItemType getItemType(ItemStack itemStack) { return itemStack.getType(); }
Example 9
Source File: VersionHelper8.java From RedProtect with GNU General Public License v3.0 | 4 votes |
@Override public ItemType getItemType(ItemStack itemStack) { return itemStack.getType(); }