本文整理汇总了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);
}
}
}
}
示例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);
}
});
}
示例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);
}
示例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);
}
}
示例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));
}
示例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());
}