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


Java BlockSnapshot.getLocation方法代码示例

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


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

示例1: onChangeBlockEvent

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的package包/类
@Listener
public void onChangeBlockEvent(ChangeBlockEvent.Break e, @First Player player) {
    if (plugin.getMainConfig().isUseSigns()) {
        if (player.hasPermission("minecraftmarket.signs")) {
            if (e.getTransactions().size() > 0) {
                BlockSnapshot blockSnapshot = e.getTransactions().get(0).getOriginal();
                Optional<Location<World>> optionalLocation = blockSnapshot.getLocation();
                if (optionalLocation.isPresent()) {
                    if (plugin.getSignsConfig().getDonorSignFor(optionalLocation.get()) != null) {
                        if (plugin.getSignsConfig().removeDonorSign(optionalLocation.get())) {
                            player.sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("sign_removed")));
                            plugin.getSignsTask().updateSigns();
                        }
                    }
                }
            }
        }
    }
}
 
开发者ID:MinecraftMarket,项目名称:MinecraftMarket-Plugin,代码行数:20,代码来源:SignsListener.java

示例2: checkBlockChange

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的package包/类
public static void checkBlockChange(BlockSnapshot block) {
    Optional<Location<World>> loc = block.getLocation();
    if (!loc.isPresent()) {
        return;
    }

    List<Arena> arenas = checkChangeAtLocation(WorldLocationConverter.of(loc.get()));
    for (Arena arena : arenas) {
        try {
            ((InfernoRollbackAgent) ((InfernoArena) arena).getRollbackAgent()).logBlockChange(block);
        } catch (IOException | SQLException ex) {
            throw new RuntimeException("Failed to log block mutation event for rollback in arena "
                    + arena.getDisplayName(), ex);
        }
    }
}
 
开发者ID:caseif,项目名称:Inferno,代码行数:17,代码来源:InfernoRollbackAgent.java

示例3: onBlockNotify

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的package包/类
@Listener
public void onBlockNotify(NotifyNeighborBlockEvent event, @First BlockSnapshot notifySource) {
    Optional<Location<World>> loc = notifySource.getLocation();
    if (!loc.isPresent()) {
        return;
    }
    Vector3i origin = loc.get().getBlockPosition();
    CustomWorld world = WorldManager.toCustomWorld(loc.get().getExtent());
    for (Iterator<Entry<Direction, BlockState>> iterator = event.getNeighbors().entrySet().iterator(); iterator
            .hasNext();) {
        Direction side = iterator.next().getKey();
        Vector3i notifyPos = origin.add(side.asBlockOffset());
        BlockNature block = world.getBlock(notifyPos);
        if (block != null) {
            boolean allow =
                    block.onNeighborNotify(world, notifyPos, notifySource.getPosition(), side.getOpposite());
            if (!allow) {
                iterator.remove();
            }
        }
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:23,代码来源:CustomBlockEventListeners.java

示例4: onItemDrop

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的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

示例5: onItemDrop

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的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

示例6: onBlockInteract

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的package包/类
@Listener
public void onBlockInteract(InteractBlockEvent.Primary event, @Root Player player) {
  BlockSnapshot targetBlock = event.getTargetBlock();
  if (targetBlock.getState().getType() != this) {
    return;
  }

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

  Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
  if (!optService.isPresent()) {
    return;
  }

  RegionService service = optService.get();
  Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
  if (optRef.isPresent()) {
    Region ref = optRef.get();
    service.setSelectedRegion(player, ref);
    player.sendMessage(Text.of(TextColors.YELLOW, "Region selected!"));
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:26,代码来源:RegionMaster.java

示例7: onSleepingEvent

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的package包/类
@Listener
@IsCancelled(Tristate.FALSE)
public void onSleepingEvent(SleepingEvent.Pre event) {
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getTargetEntity();
    PlayerEntity playerEntity = PlayerCache.instance.get(player);
    BlockSnapshot blockSnapshot = event.getBed();
    Optional<Location<World>> optional = blockSnapshot.getLocation();
    if (!optional.isPresent()) {
        return;
    }

    Location<World> location = optional.get();
    for (BedEntity bed : playerEntity.getBeds()) {
        if (bed.getLocation().getWorld().getIdentifier().equals(player.getWorld().getUniqueId().toString())) {
            Location<World> bedLocation = bed.getLocation().getLocation();
            if (location.getBlockPosition().equals(bedLocation.getBlockPosition())) {
                bed.setLastUse(new Timestamp(new Date().getTime()));
                playerEntity = PlayerRepository.instance.save(playerEntity);
                PlayerCache.instance.set(player, playerEntity);
                return;
            }
        }
    }

    playerEntity.getBeds().add(new BedEntity(new LocationEntity(location)));
    playerEntity = PlayerRepository.instance.save(playerEntity);
    PlayerCache.instance.set(player, playerEntity);
}
 
开发者ID:mmonkey,项目名称:Destinations,代码行数:33,代码来源:PlayerListeners.java

示例8: onItemDrop

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的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

示例9: onBlockBreak

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Entity srcEnt) {
  if (!isApplicable(srcEnt)) {
    return;
  }

  List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
  for (Transaction<BlockSnapshot> block : transactions) {
    BlockSnapshot original = block.getOriginal();
    if (original.getCreator().isPresent()) {
      continue;
    }

    Optional<Location<World>> optLoc = original.getLocation();

    if (!optLoc.isPresent()) {
      continue;
    }

    Location<World> loc = optLoc.get();

    BlockState state = original.getState();

    // Prevent item dupe glitch by removing the position before subsequent breaks
    markedOrePoints.remove(loc);
    if (config.getDropModification().blocks(state)) {
      markedOrePoints.add(loc);
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:31,代码来源:BuildWorldWrapper.java

示例10: onOreDrop

import org.spongepowered.api.block.BlockSnapshot; //导入方法依赖的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.block.BlockSnapshot.getLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。