org.spongepowered.api.entity.Item Java Examples
The following examples show how to use
org.spongepowered.api.entity.Item.
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: HuskyUI.java From HuskyUI-Plugin with GNU General Public License v3.0 | 6 votes |
/** * Handle item drops * @param event dispense event */ @Listener public void onItemDrop(DropItemEvent.Dispense event){ for(Entity e :event.getEntities()){ if(e instanceof Item){ ItemStack affectedStack = ((Item) e).getItemData().item().get().createStack(); Optional<Integer> potentialID = registry.getElementIDFromItemStack(affectedStack); if(potentialID.isPresent()){ if(registry.elementExists(potentialID.get())){ event.setCancelled(true); //NOTHING should drop a registered item. >:( //TODO: handle https://github.com/SpongePowered/SpongeCommon/issues/1678 properly w/ workaround } } } } }
Example #2
Source File: ItemListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onDrop(DropItemEvent.Dispense event) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); for (Entity en : event.getEntities()) { if (!(en instanceof Item)) continue; Item item = (Item) en; CommentedConfigurationNode node = hnode.getNode("items", item.getItemType().getId()); if (!node.isVirtual()) { if (node.getNode("deny-drop").getBoolean()) { event.setCancelled(true); } } } }
Example #3
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onItemPickup(CollideEntityEvent event, @Root Player p) { for (Entity ent : event.getEntities()) { if (!(ent instanceof Item)) { continue; } Region r = RedProtect.get().rm.getTopRegion(ent.getLocation(), this.getClass().getName()); if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_canpickup && !p.hasPermission("redprotect.world.bypass")) { event.setCancelled(true); } } }
Example #4
Source File: InventoryListener.java From Prism with MIT License | 5 votes |
/** * Saves event records when a player drops an item on to the ground. * * @param event DropItemEvent.Dispense * @param player Player */ @Listener(order = Order.POST) public void onDropItemDispense(DropItemEvent.Dispense event, @Root Player player) { if (event.getEntities().isEmpty() || !Prism.getInstance().getConfig().getEventCategory().isItemDrop()) { return; } for (Entity entity : event.getEntities()) { if (!(entity instanceof Item)) { continue; } Item item = (Item) entity; if (!item.item().exists()) { continue; } ItemStackSnapshot itemStack = item.item().get(); Prism.getInstance().getLogger().debug("Inventory dropped - {} x{}", itemStack.getType().getId(), itemStack.getQuantity()); PrismRecord.create() .source(event.getCause()) .event(PrismEvents.ITEM_DROP) .itemStack(itemStack) .location(player.getLocation()) .buildAndSave(); } }