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


Java DropItemEvent.Destruct方法代码示例

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


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

示例1: fireDropItemEvent

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
private void fireDropItemEvent(World world, Vector3i pos) {
    List<ItemStack> stacks = getDroppedItems();
    if (stacks.isEmpty()) {
        return;
    }
    List<Entity> entities = Lists.newArrayList();
    for (ItemStack stack : stacks) {
        Entity drop = createItemDrop(world, pos, stack);
        entities.add(drop);
    }
    Cause cause = Cause.source(BlockSpawnCause.builder()
            .type(SpawnTypes.DROPPED_ITEM)
            .block(world.createSnapshot(pos))
            .build())
            .build();
    DropItemEvent.Destruct harvestEvent = SpongeEventFactory.createDropItemEventDestruct(cause, entities);
    if (Sponge.getEventManager().post(harvestEvent)) {
        return;
    }
    for (Entity entity : harvestEvent.getEntities()) {
        world.spawnEntity(entity, cause);
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:24,代码来源:PipeBlock.java

示例2: onEntityDropItemDeath

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityDropItemDeath(DropItemEvent.Destruct event, @Root Living livingEntity) {
    if (!GPFlags.ITEM_DROP || event.getEntities().isEmpty()) {
        return;
    }

    final World world = event.getEntities().get(0).getWorld();
    if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) {
        return;
    }

    GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.startTimingIfSync();
    // special rule for creative worlds: killed entities don't drop items or experience orbs
    if (GriefPreventionPlugin.instance.claimModeIsActive(livingEntity.getLocation().getExtent().getProperties(), ClaimsMode.Creative)) {
        event.setCancelled(true);
        GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.stopTimingIfSync();
        return;
    }

    GPTimings.ENTITY_DROP_ITEM_DEATH_EVENT.stopTimingIfSync();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:22,代码来源:EntityEventHandler.java

示例3: onItemDrop

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
  BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();

  Optional<Location<World>> optLocation = blockSnapshot.getLocation();
  if (!optLocation.isPresent()) {
    return;
  }

  Location<World> loc = optLocation.get();
  if (!markedOrePoints.remove(loc)) {
    return;
  }

  event.getEntities().clear();
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:17,代码来源:BuildWorldWrapper.java

示例4: onItemDrop

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
  if (event.getCause().containsType(Player.class)) {
    return;
  }

  BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();

  Optional<Location<World>> optLocation = blockSnapshot.getLocation();
  if (!optLocation.isPresent()) {
    return;
  }

  Location<World> location = optLocation.get();
  while (true) {
    location = location.add(0, -1, 0);
    if (location.getBlockType() != BlockTypes.CACTUS) {
      break;
    }
    location.setBlockType(BlockTypes.AIR, Cause.source(SkreePlugin.container()).build());
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:23,代码来源:AntiCactusFarmListener.java

示例5: onEntityDrop

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onEntityDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) EntitySpawnCause spawnCause) {
  Entity entity = spawnCause.getEntity();
  if (!(entity instanceof Animal)) {
    return;
  }

  Optional<TheButcherShopInstance> optInst = manager.getApplicableZone(entity);
  if (!optInst.isPresent()) {
    return;
  }

  event.getEntities().clear();

  Item item = (Item) entity.getLocation().createEntity(EntityTypes.ITEM);
  item.offer(Keys.REPRESENTED_ITEM, newItemStack("skree:unpackaged_meat").createSnapshot());

  event.getEntities().add(item);
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:20,代码来源:TheButcherShopListener.java

示例6: onDropItem

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onDropItem(DropItemEvent.Destruct event) {
    java.util.Optional<Player> player = event.getCause().first(Player.class);
    if (player.isPresent() && event.getCause().root() instanceof BlockSpawnCause) {
        Optional<Challenger> challenger = Main.getMinigame().getChallenger(player.get().getUniqueId());
        if (challenger.isPresent()) {
            event.setCancelled(true);
        }
    }
}
 
开发者ID:caseif,项目名称:InfernoSpleef,代码行数:11,代码来源:BlockListener.java

示例7: onItemDropDeath

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onItemDropDeath(DropItemEvent.Destruct event, @Root Player player) {

    PermHandler ph = PermHandler.getInstance();
        
        event.filterEntities(entity -> {
            if (entity.getType().equals(EntityTypes.ITEM)) {
                Item item = (Item) entity;
                String itemId = item.getItemType().getId();
                return ph.checkPerm(player, "protectionperms.item.drop." + itemId + ".death");
            }
            return true;
        });
}
 
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:15,代码来源:DropItemDeathListener.java

示例8: onBlockDropItems

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onBlockDropItems(DropItemEvent.Destruct event, @Root BlockSpawnCause blockCause) {
    if (blockCause.getType() != SpawnTypes.DROPPED_ITEM) {
        return;
    }
    BlockSnapshot blockSnapshot = blockCause.getBlockSnapshot();
    CustomWorld world = WorldManager.toCustomWorld(blockSnapshot.getLocation().get().getExtent());
    Vector3i pos = blockSnapshot.getPosition();
    BlockNature block = world.getBlock(pos);
    if (block == null) {
        return;
    }
    boolean allowDrop = block.onBlockHarvest(world, pos, event.getEntities());
    event.setCancelled(!allowDrop);
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:16,代码来源:CustomBlockEventListeners.java

示例9: onItemDrop

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
  BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();

  Optional<Location<World>> optLocation = blockSnapshot.getLocation();
  if (!optLocation.isPresent()) {
    return;
  }

  Location<World> loc = optLocation.get();
  if (!markedOrePoints.remove(loc)) {
    return;
  }

  Optional<Integer> optLevel = getLevel(loc);
  if (!optLevel.isPresent()) {
    return;
  }

  List<ItemStackSnapshot> itemStacks = new ArrayList<>();
  event.getEntities().forEach((entity -> {
    if (entity instanceof Item) {
      ItemStackSnapshot snapshot = ((Item) entity).item().get();
      itemStacks.add(getPoolItemDrop(snapshot));
    }
  }));

  addPool(loc, () -> itemStacks);
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:30,代码来源:WildernessWorldWrapper.java

示例10: onEntityDrop

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onEntityDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) EntitySpawnCause spawnCause) {
  Entity entity = spawnCause.getEntity();
  if (!Creature.class.isAssignableFrom(entity.getType().getEntityClass())) {
    return;
  }

  if (isApplicable(entity.getLocation())) {
    event.setCancelled(true);
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:12,代码来源:ZoneCreatureDropBlocker.java

示例11: onOreDrop

import org.spongepowered.api.event.item.inventory.DropItemEvent; //导入方法依赖的package包/类
@Listener
public void onOreDrop(
    DropItemEvent.Destruct event,
    @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause,
    @Named(NamedCause.NOTIFIER) Player player
) {
  if (!Probability.getChance(4)) {
    return;
  }

  BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();

  Optional<Location<World>> optLocation = blockSnapshot.getLocation();
  if (!optLocation.isPresent()) {
    return;
  }

  Location<World> loc = optLocation.get();
  Optional<CursedMineInstance> optInst = manager.getApplicableZone(loc);

  if (!optInst.isPresent()) {
    return;
  }

  CursedMineInstance inst = optInst.get();
  if (!inst.hasrecordForPlayerAt(player, loc)) {
    return;
  }

  List<ItemStackSnapshot> itemStacks = new ArrayList<>();
  Iterator<Entity> entityIterator = event.getEntities().iterator();
  while (entityIterator.hasNext()) {
    Entity entity = entityIterator.next();
    if (entity instanceof Item) {
      ItemStackSnapshot snapshot = ((Item) entity).item().get();
      itemStacks.add(snapshot);
      entityIterator.remove();
    }
  }

  int times = 1;

  Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
  if (optService.isPresent()) {
    ModifierService service = optService.get();
    if (service.isActive(Modifiers.DOUBLE_CURSED_ORES)) {
      times *= 2;
    }
  }

  for (ItemStackSnapshot stackSnapshot : itemStacks) {
    int quantity = Math.min(
        stackSnapshot.getCount() * Probability.getRangedRandom(4, 8),
        stackSnapshot.getType().getMaxStackQuantity()
    );

    for (int i = 0; i < times; ++i) {
      ItemStack stack = stackSnapshot.createStack();
      stack.setQuantity(quantity);
      player.getInventory().offer(stack);
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:64,代码来源:CursedMineListener.java


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