当前位置: 首页>>代码示例>>Java>>正文


Java DropItemEvent.Pre方法代码示例

本文整理汇总了Java中org.spongepowered.api.event.item.inventory.DropItemEvent.Pre方法的典型用法代码示例。如果您正苦于以下问题:Java DropItemEvent.Pre方法的具体用法?Java DropItemEvent.Pre怎么用?Java DropItemEvent.Pre使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.event.item.inventory.DropItemEvent的用法示例。


在下文中一共展示了DropItemEvent.Pre方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: finalizeHarvestEvent

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
/**
 * Finalize the {@link HarvestEntityEvent}. This will spawn all
 * the dropped {@link Item}s and {@link ExperienceOrb}s. But only
 * if the event isn't cancelled.
 *
 * @param causeStack The cause stack
 * @param event The harvest event
 */
protected void finalizeHarvestEvent(CauseStack causeStack, HarvestEntityEvent event, List<ItemStackSnapshot> itemStackSnapshots) {
    if (event.isCancelled()) {
        return;
    }
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        frame.pushCause(event);

        final int exp = event.getExperience();
        // No experience, don't spawn any entity
        if (exp > 0) {
            frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.EXPERIENCE);
            // Spawn a experience orb with the experience value
            LanternWorld.handleEntitySpawning(EntityTypes.EXPERIENCE_ORB, getTransform(),
                    entity -> entity.offer(Keys.CONTAINED_EXPERIENCE, exp));
        }

        frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
        // Collect entity drops
        collectDrops(causeStack, itemStackSnapshots);
        if (!itemStackSnapshots.isEmpty()) {
            final DropItemEvent.Pre preDropEvent = SpongeEventFactory.createDropItemEventPre(
                    frame.getCurrentCause(), ImmutableList.copyOf(itemStackSnapshots), Lists2.nonNullOf(itemStackSnapshots));
            Sponge.getEventManager().post(preDropEvent);
            if (!preDropEvent.isCancelled()) {
                final Transform<World> transform = getTransform().setPosition(
                        getBoundingBox().map(AABB::getCenter).orElse(Vector3d.ZERO));
                final List<EntitySpawningEntry> entries = itemStackSnapshots.stream()
                        .filter(snapshot -> !snapshot.isEmpty())
                        .map(snapshot -> new EntitySpawningEntry(EntityTypes.ITEM, transform, entity -> {
                            entity.offer(Keys.REPRESENTED_ITEM, snapshot);
                            entity.offer(Keys.PICKUP_DELAY, 15);
                        }))
                        .collect(Collectors.toList());
                LanternWorld.handleEntitySpawning(entries, SpongeEventFactory::createDropItemEventDestruct);
            }
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:47,代码来源:LanternLiving.java

示例2: PlayerDropItemGui

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void PlayerDropItemGui(DropItemEvent.Pre e, @Root Player p){
	e.getDroppedItems().forEach(item -> {
		if (RPUtil.isGuiItem(item.createStack())){
			RPUtil.removeGuiItem(p);
			e.setCancelled(true);
		}
	});
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:10,代码来源:RPPlayerListener.java

示例3: handle

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Override
public void handle(@Nonnull DropItemEvent.Pre e) throws Exception {
    List<ItemStackSnapshot> itemStackSnapshots = new ArrayList<>();
    Iterator<ItemStackSnapshot> itr = e.getDroppedItems().iterator();
    while (itr.hasNext()) {
        ItemStackSnapshot snapshot = itr.next();
        if (snapshot.getType() == ItemTypes.GHAST_TEAR) {
            itr.remove();
            ItemStack stack = ItemStack.of(ItemTypes.GOLD_INGOT, snapshot.getCount());
            itemStackSnapshots.add(stack.createSnapshot());
        }
    }
    e.getDroppedItems().addAll(itemStackSnapshots);
}
 
开发者ID:liachmodded,项目名称:UHC-Reloaded,代码行数:15,代码来源:GhastTearToGoldListener.java

示例4: spawnEntity

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener(order = Order.POST)
@Exclude({ConstructEntityEvent.class, DropItemEvent.Pre.class})
public void spawnEntity(Event event, @Root Cause cause)
        throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (!(cause.root() instanceof Player)) {
        return;
    }

    Player player = (Player) cause.root();

    if (event instanceof SpawnEntityEvent) {
        if (((SpawnEntityEvent) event).getEntities().isEmpty()) {
            return;
        }

        Entity entity = ((SpawnEntityEvent) event).getEntities().get(0);

        if (entity.getType().equals(EntityTypes.FISHING_HOOK)) {
            // Ignore fishing hooks - handled by FishingEvent
            return;
        }

        if (event instanceof DropItemEvent.Dispense) {
            int quantityDropped = 0;
            try {
                quantityDropped = ((Item) entity).item().get().getQuantity();
            } catch (IndexOutOfBoundsException err) {
                // suppress IndexOutOfBoundsException error and bail
                // this fixes an "impossible" issue #27
            }

            if (quantityDropped == 0) {
                return;
            }

            processEvent(event, player, quantityDropped);
        }
    } else {
        processEvent(event, player);
    }
}
 
开发者ID:BadgeUp,项目名称:badgeup-sponge-client,代码行数:42,代码来源:GeneralEventListener.java

示例5: onQPress

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener(order = Order.EARLY)
public void onQPress(DropItemEvent.Pre e, @Root Player player) {
	IActiveCharacter character = characterService.getCharacter(player);
	e.setCancelled(characterService.processUserAction(character, UserActionType.Q));
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:6,代码来源:ComboListener.java

示例6: onDropTool

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onDropTool(DropItemEvent.Pre event)
{
    event.getDroppedItems().removeIf(item -> item.get(ImmutableLookupData.class).isPresent());
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:6,代码来源:ToolListener.java


注:本文中的org.spongepowered.api.event.item.inventory.DropItemEvent.Pre方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。