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


Java Transaction.isValid方法代码示例

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


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

示例1: finishInventoryEvent

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
private void finishInventoryEvent(ChangeInventoryEvent event) {
    final List<SlotTransaction> slotTransactions = event.getTransactions();
    Sponge.getEventManager().post(event);
    if (!event.isCancelled()) {
        if (!(event instanceof ClickInventoryEvent.Creative) && event instanceof ClickInventoryEvent) {
            final Transaction<ItemStackSnapshot> cursorTransaction = ((ClickInventoryEvent) event).getCursorTransaction();
            if (cursorTransaction.isValid()) {
                setCursorItem(cursorTransaction.getFinal().createStack());
            }
        }
        slotTransactions.stream().filter(Transaction::isValid).forEach(
                transaction -> transaction.getSlot().set(transaction.getFinal().createStack()));
        if (event instanceof SpawnEntityEvent) {
            LanternWorld.finishSpawnEntityEvent((SpawnEntityEvent) event);
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:VanillaContainerInteractionBehavior.java

示例2: onBlockBreak

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event) {
    Optional<Player> playerOptional = event.getCause().first(Player.class);
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        if (transaction.isValid()) {
            if (transaction.getOriginal().get(LiteKeys.JOB_NAME).isPresent()) {
                if (!playerOptional.isPresent()) {
                    event.setCancelled(true);
                    return;
                }
                Player player = playerOptional.get();
                if (!player.hasPermission("jobs.admin.sign.delete")) {
                    player.sendMessage(messageStorage.getMessage("sign.nopermission"));
                    event.setCancelled(true);
                }
            }
        }
    }
}
 
开发者ID:Flibio,项目名称:JobsLite,代码行数:20,代码来源:SignListeners.java

示例3: onBlockBreak

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBreak(ChangeBlockEvent.Break event) {
	for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
		if (transaction.isValid()) {
			Optional<Location<World>> loc = transaction.getOriginal().getLocation();
			if (loc.isPresent()) {
				Optional<List<Shop>> shops = ShopsData.getShops(loc.get());
				if (shops.isPresent()) {
					Optional<Player> cause = event.getCause().first(Player.class);
					if (!cause.isPresent()) {
						event.setCancelled(true);
					}
					List<Shop> toDelete = new ArrayList<>();
					shops.get().forEach((shop) -> {
						toDelete.add(shop);
					});
					toDelete.forEach((shop) -> {
						if (!shop.destroy(cause.get()))
							event.setCancelled(true);
					});
				} else if (isSignAndShop(loc.get(), Direction.UP, false) ||
						isSignAndShop(loc.get(), Direction.NORTH, true) ||
						isSignAndShop(loc.get(), Direction.SOUTH, true) ||
						isSignAndShop(loc.get(), Direction.EAST, true) ||
						isSignAndShop(loc.get(), Direction.WEST, true)) {
					event.setCancelled(true);
				}
			}
		}
	}
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:32,代码来源:BlockBreakListener.java

示例4: onBlockBrokenByExplosion

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockBrokenByExplosion(final ExplosionEvent.Post event) {
    if (Latch.getConfig().getNode("protect_from_explosives").getBoolean(true)) {
        //If we're supposed to protect from explosions, invalidate the transaction
        final LockManager lockManager = Latch.getLockManager();
        for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
            if (transaction.isValid() && transaction.getOriginal().getLocation().isPresent()) {
                final Location<World> location = transaction.getOriginal().getLocation().get();
                if (lockManager.getLock(location).isPresent()) {
                    transaction.setValid(false);
                }
                final Optional<Lock> aboveLock = lockManager.getLock(location.getBlockRelative(Direction.UP));
                if (aboveLock.isPresent() && lockManager.isProtectBelowBlocks(location.getBlockRelative(Direction.UP).getBlockType())) {
                    transaction.setValid(false);
                }
            }
        }
    } else {
        //Otherwise we should delete the locks destroyed by the explosion
        for (Transaction<BlockSnapshot> bs : event.getTransactions()) {
            if (bs.isValid() && bs.getOriginal().getLocation().isPresent()) {
                if (Latch.getLockManager().getLock(bs.getOriginal().getLocation().get()).isPresent()) {
                    Latch.getLockManager().deleteLock(bs.getOriginal().getLocation().get(), false);
                }
            }
        }
    }
}
 
开发者ID:ichorpowered,项目名称:latch,代码行数:29,代码来源:ChangeBlockListener.java

示例5: onBlockPlaceAfterPiston

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockPlaceAfterPiston(ChangeBlockEvent.Place event, @First Piston piston) {
    World world = piston.getWorld();
    CustomWorld blockAccess = WorldManager.toCustomWorld(world);
    Vector3i pistonPos = piston.getLocation().getBlockPosition();
    if (!WorldManager.getPistonTracker(world).isTracked(pistonPos)) {
        return;
    }
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        if (!transaction.isValid()) {
            continue;
        }
        BlockSnapshot orig = transaction.getOriginal();
        if (orig.getState().getType() == BlockTypes.PISTON_EXTENSION) {
            Vector3i newPos = orig.getPosition();
            Tuple<Vector3i, ImmutablePair<EnhancedCustomBlock, BlockData>> oldData =
                    WorldManager.getPistonTracker(world).restore(newPos);
            if (oldData == null) {
                continue;
            }
            Vector3i oldPos = oldData.getFirst();
            EnhancedCustomBlock block = oldData.getSecond().getLeft();
            BlockData data = oldData.getSecond().getRight();
            BlockSnapshot finalBlock = transaction.getFinal();
            BlockSnapshot newBlock = block.onMovedByPiston(blockAccess, newPos, finalBlock, data, oldPos);
            transaction.setValid(newBlock != null);
            if (newBlock != null) {
                if (finalBlock != newBlock) {
                    finalBlock = newBlock;
                    transaction.setCustom(finalBlock);
                }
                if (data != null) {
                    data.setPos(newPos);
                }
                blockAccess.setBlockWithData(newPos, block, data);
            }
        }
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:40,代码来源:CustomBlockEventListeners.java

示例6: onBlockBreak

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event) {
    Player player = event.getCause().first(Player.class).orElse(null);
    BlockSnapshot pistonCause = getPistonCause(event.getCause());
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        if (!transaction.isValid()) {
            continue;
        }
        CustomWorld world = WorldManager.toCustomWorld(transaction.getFinal().getLocation().get().getExtent());
        BlockSnapshot finalBlock = transaction.getFinal();
        Vector3i pos = finalBlock.getPosition();
        BlockNature block = world.getBlock(pos);
        if (block == null) {
            continue;
        }
        BlockSnapshot newBlock = finalBlock;
        if (pistonCause != null && block instanceof EnhancedCustomBlock) {
            WorldManager.getPistonTracker(world.getWorld()).addTarget(pistonCause, (EnhancedCustomBlock) block,
                    world.getBlockData(pos), pos);
            newBlock = finalBlock;
        } else {
            if (block instanceof EnhancedCustomBlock) {
                newBlock = ((EnhancedCustomBlock) block).onBlockBreak(world, pos, finalBlock, player);
            } else {
                newBlock = block.onBlockBreak(world, pos, player) ? newBlock : null;
            }
        }
        transaction.setValid(newBlock != null);
        if (newBlock != null) {
            if (newBlock != finalBlock) {
                transaction.setCustom(newBlock);
            }
            world.removeBlock(pos);
        }

    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:38,代码来源:CustomBlockEventListeners.java

示例7: onBlockBreak

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
  Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
  if (!optService.isPresent()) {
    return;
  }

  RegionService service = optService.get();

  for (Transaction<BlockSnapshot> block : event.getTransactions()) {
    if (!block.isValid()) {
      continue;
    }

    if (block.getOriginal().getState().getType() != this) {
      continue;
    }

    Optional<Location<World>> optLoc = block.getOriginal().getLocation();
    if (!optLoc.isPresent()) {
      continue;
    }

    Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
    if (!optRef.isPresent()) {
      continue;
    }

    Region ref = optRef.get();
    if (!ref.getFullPoints().isEmpty()) {
      block.setValid(false);
      player.sendMessage(Text.of(TextColors.RED, "You must first delete all markers!"));
    } else {
      service.rem(optLoc.get());
      player.sendMessage(Text.of(TextColors.YELLOW, "Region deleted!"));
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:39,代码来源:RegionMaster.java

示例8: onBlockBreak

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
  Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
  if (!optService.isPresent()) {
    return;
  }

  RegionService service = optService.get();

  for (Transaction<BlockSnapshot> block : event.getTransactions()) {
    if (!block.isValid()) {
      continue;
    }

    if (block.getOriginal().getState().getType() != this) {
      continue;
    }

    Optional<Location<World>> optLoc = block.getOriginal().getLocation();
    if (optLoc.isPresent()) {
      Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
      if (optRef.isPresent()) {
        Region ref = optRef.get();
        if (ref.isMember(player)) {
          ref.remPoint(new RegionPoint(optLoc.get().getPosition()));
          player.sendMessage(Text.of(TextColors.YELLOW, "Region marker deleted!"));
        }
      }
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:32,代码来源:RegionMarker.java

示例9: onChangeBlock

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
/**
 * Listens to the base change block event.
 *
 * @param event
 */
@Listener
public void onChangeBlock(final ChangeBlockEvent event) {
    Optional<Player> playerCause = event.getCause().first(Player.class);
    if (playerCause.isPresent() && Prism.getActiveWands().contains(playerCause.get().getUniqueId())) {
        // Cancel and exit event here, not supposed to place/track a block with an active wand.
        event.setCancelled(true);
        return;
    }
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        if (!transaction.isValid()) {
            continue;
        }

        PrismRecordEventBuilder record = PrismRecord.create().source(event.getCause());

        BlockType original = transaction.getOriginal().getState().getType();
        BlockType finalBlock = transaction.getFinal().getState().getType();

        if (event instanceof ChangeBlockEvent.Break) {
            if (Prism.listening.BREAK &&
                    !BlockUtil.rejectBreakCombination(original, finalBlock) &&
                    !EventUtil.rejectBreakEventIdentity(original, finalBlock, event.getCause())) {
                record.brokeBlock(transaction).save();
            }
        }
        else if (event instanceof ChangeBlockEvent.Place) {
            if (Prism.listening.PLACE &&
                    !BlockUtil.rejectPlaceCombination(original, finalBlock) &&
                    !EventUtil.rejectPlaceEventIdentity(original, finalBlock, event.getCause())) {
                record.placedBlock(transaction).save();
            }
        }
        else if (event instanceof ChangeBlockEvent.Decay) {
            if (Prism.listening.DECAY) {
                record.decayedBlock(transaction).save();
            }
        }
    }
}
 
开发者ID:prism,项目名称:Prism,代码行数:45,代码来源:ChangeBlockListener.java

示例10: onBreak

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBreak(ChangeBlockEvent.Break event) {
    ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
    CommentedConfigurationNode hnode = config.get();
    for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
        if (!trans.isValid()) continue;
        CommentedConfigurationNode node = hnode.getNode("blocks", trans.getOriginal().getState().getType().getId());
        if (!node.isVirtual()) {
            if (node.getNode("deny-break").getBoolean()) {
                trans.setValid(false);
            }
        }
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:15,代码来源:BlockListener.java

示例11: onPlace

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onPlace(ChangeBlockEvent.Place event) {
    ModuleConfig config = Modules.BLACKLIST.get().getConfig().get();
    CommentedConfigurationNode hnode = config.get();
    for (Transaction<BlockSnapshot> trans : event.getTransactions()) {
        if (!trans.isValid()) continue;
        CommentedConfigurationNode node = hnode.getNode("blocks", trans.getFinal().getState().getType().getId());
        if (!node.isVirtual() && node.getNode("deny-place").getBoolean()) {
            trans.setValid(false);
        }
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:13,代码来源:BlockListener.java

示例12: onBreakBlockByPlayer

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBreakBlockByPlayer(final ChangeBlockEvent.Break event, @Root Player player) {
    //Track the names of the locks broken - only display message once per lock
    final HashSet<String> locksDeleted = new HashSet<>();

    //Only allow the owner to break a lock
    for (Transaction<BlockSnapshot> bs : event.getTransactions()) {
        if (bs.isValid() && bs.getOriginal().getLocation().isPresent()) {
            final Location location = bs.getOriginal().getLocation().get();
            final LockManager lockManager = Latch.getLockManager();

            final Optional<Lock> optionalLock = lockManager.getLock(location);

            //If the block is below a block we need to protect the below blocks of...
            //Potentially Sponge issue - should be able to detect these blocks
            final Optional<Lock> aboveLock = lockManager.getLock(location.getBlockRelative(Direction.UP));

            if (aboveLock.isPresent() && lockManager.isProtectBelowBlocks(location.getBlockRelative(Direction.UP).getBlockType()) && !aboveLock
                .get().isOwnerOrBypassing(player.getUniqueId())) {
                player.sendMessage(Text.of(TextColors.RED, "You cannot destroy a block which is depended on by a lock that's not yours."));
                bs.setValid(false);
                continue;
            }

            if (optionalLock.isPresent()) {
                final Lock lock = optionalLock.get();

                //Check to make sure they're the owner
                if (!lock.isOwnerOrBypassing(player.getUniqueId())) {
                    bs.setValid(false);
                    player.sendMessage(Text.of(TextColors.RED, "You cannot destroy a lock you are not the owner of."));
                    return;
                }

                if (!locksDeleted.contains(lock.getName())) {
                    player.sendMessage(
                        Text.of(TextColors.DARK_GREEN, "You have destroyed this ", TextColors.GRAY, lock.getLockedObject(), TextColors.DARK_GREEN, " lock."));
                    locksDeleted.add(lock.getName());
                }

                lockManager.deleteLock(bs.getOriginal().getLocation().get(), false);
            }
        }
    }
}
 
开发者ID:ichorpowered,项目名称:latch,代码行数:46,代码来源:ChangeBlockListener.java

示例13: onBlockPlaceAfterItemUse

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockPlaceAfterItemUse(ChangeBlockEvent.Place event, @First Player player) {
    if (!event.getCause().get(NamedCause.SOURCE, Player.class).isPresent()) {
        clearTempVars();
        return; // Player must be source of event (i.e. not Notifier)
    }
    if (player != playerWhoClicked) {
        return;
    }
    ItemStack itemStack = clickedItemStack;
    clearTempVars();
    // Can safely cast as the itemstack was set from an ItemBlockWrapper instance
    ItemBlockWrapper item = (ItemBlockWrapper) CustomItem.fromItemStack(itemStack);
    BlockNature block = item.getBlock();
    CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        if (!transaction.isValid()) {
            continue;
        }
        BlockSnapshot finalBlock = transaction.getFinal();
        Vector3i pos = finalBlock.getPosition();
        BlockSnapshot newSnapshot;
        if (block instanceof EnhancedCustomBlock) {
            newSnapshot = ((EnhancedCustomBlock) block).onBlockPlacedByPlayer(world, pos, finalBlock, player, item,
                    itemStack);
        } else {
            newSnapshot = block.onBlockPlacedByPlayer(world, pos, player, item, itemStack) ? finalBlock : null;
        }
        transaction.setValid(newSnapshot != null);
        if (newSnapshot != null) {
            if (finalBlock != newSnapshot) {
                transaction.setCustom(newSnapshot);
                finalBlock = newSnapshot;
            }
            BlockData data = block.createData(world, pos);
            if (data != null) {
                item.transferToBlock(itemStack, data);
            }
            world.setBlockWithData(pos, block, data);
        }
    }
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:43,代码来源:CustomBlockEventListeners.java

示例14: onBlockPlace

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player) {
  Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
  if (!optService.isPresent()) {
    return;
  }

  RegionService service = optService.get();

  for (Transaction<BlockSnapshot> block : event.getTransactions()) {
    if (!block.isValid()) {
      continue;
    }

    if (block.getFinal().getState().getType() != this) {
      continue;
    }

    Optional<Location<World>> optLoc = block.getFinal().getLocation();
    if (optLoc.isPresent()) {
      Optional<Region> optOriginRef = service.getSelectedRegion(player);
      Optional<Region> optRef = service.getOrCreate(optLoc.get(), player);
      if (optRef.isPresent()) {
        Region ref = optRef.get();

        Vector3d masterBlock = ref.getMasterBlock();
        Vector3d blockPos = optLoc.get().getPosition();
        // Determine if this is a new region or not
        if (!masterBlock.equals(blockPos)) {
          if (blockPos.equals(recentlyClicked.get(player))) {
            // Update the master block
            ref.setMasterBlock(new RegionPoint(blockPos));

            // Delete the existing master block
            optLoc.get().getExtent().setBlockType(
                masterBlock.toInt(),
                BlockTypes.AIR,
                BlockChangeFlag.NONE,
                Cause.source(SkreePlugin.container()).build()
            );

            player.sendMessage(
                Text.of(
                    TextColors.YELLOW,
                    "Master block moved."
                )
            );
          } else {
            recentlyClicked.put(player, blockPos);
            block.setValid(false);
            player.sendMessage(
                Text.of(
                    TextColors.YELLOW,
                    "Place the master block again to move this region's master block."
                )
            );
          }
        }

        service.setSelectedRegion(player, ref);

        if (!ref.equals(optOriginRef.orElse(null))) {
          player.sendMessage(Text.of(TextColors.YELLOW, "Active region set!"));
        }
      }
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:69,代码来源:RegionMaster.java

示例15: onBlockPlace

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @First Player player) {
  Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
  if (!optService.isPresent()) {
    return;
  }

  RegionService service = optService.get();

  for (Transaction<BlockSnapshot> block : event.getTransactions()) {
    if (!block.isValid()) {
      continue;
    }

    if (block.getFinal().getState().getType() != this) {
      continue;
    }

    Optional<Location<World>> optLoc = block.getFinal().getLocation();
    if (optLoc.isPresent()) {
      Optional<Region> optRef = service.getSelectedRegion(player);
      if (optRef.isPresent()) {
        Location<World> loc = optLoc.get();
        Region ref = optRef.get();
        if (ref.getWorldName().equals(loc.getExtent().getName())) {
          if (ref.isMember(player)) {
            RegionErrorStatus status = ref.addPoint(new RegionPoint(loc.getPosition()));
            if (status == RegionErrorStatus.NONE) {
              player.sendMessage(Text.of(TextColors.YELLOW, "Region marker added!"));
              continue;
            } else if (status == RegionErrorStatus.INTERSECT) {
              player.sendMessage(Text.of(TextColors.RED, "No two regions can occupy the same space!"));
            } else if (status == RegionErrorStatus.REGION_TOO_LARGE) {
              player.sendMessage(Text.of(TextColors.RED, "You do not have enough power to expand your region!"));
            }
          }
        }
      }
    }
    block.setValid(false);
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:43,代码来源:RegionMarker.java


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