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


Java Transaction.setValid方法代码示例

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


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

示例1: onBreak

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBreak(ChangeBlockEvent.Break event) {
    ModuleConfig config = Modules.BLOCKPROTECTION.get().getConfig().get();
    if (!config.get().getNode("protections", "allow-interact-primary").getBoolean()) return;
    Player p = event.getCause().first(Player.class).orElse(null);

    boolean modified = false;
    for (Protection prot : GlobalData.get(BlockprotectionKeys.PROTECTIONS).get()) {
        //Ignore protection if the player is allowed to modify it
        if (p != null && prot.getPlayers().contains(p.getUniqueId())) continue;
        //For each location of the protection,
        for (Transaction trans : event.getTransactions().stream().filter(trans -> trans.getFinal().getLocation().isPresent() && prot.getLocations().contains(trans.getFinal().getLocation().get())).collect(Collectors.toList())) {
            modified = true;
            trans.setValid(false);
        }

        //If anything has been cancelled & caused by player, send message
        if (p != null && modified) {
            p.sendMessage(prot.getLocktype().getErrorMessage(p, prot));
        }
    }
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:23,代码来源:BlockprotectionListener.java

示例2: onExplosion

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onExplosion(final ExplosionEvent.Detonate event) {
    Optional<Entity> optional = event.getCause().first(Entity.class);
    if (optional.isPresent()) {
        for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
            if (SafeGuard.getZoneManager().zoneExists(transaction.getOriginal().getLocation().get())) {
                transaction.setValid(false);
            }
        }
    }
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:12,代码来源:ExplosionListener.java

示例3: onPlaceBlock

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onPlaceBlock(final ChangeBlockEvent.Place event) {
    Optional<Player> player = event.getCause().first(Player.class);

    // Allow if they have mod permission
    if (player.isPresent() && player.get().hasPermission("safeguard.mod")) {
        return;
    }

    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        List<Zone> zones = SafeGuard.getZoneManager().getZones(transaction.getOriginal().getLocation().get());

        // Allow change if no zone exists
        if (zones.isEmpty()) {
            continue;
        }

        for (Zone zone : zones) {
            // Reject if zone doesn't permit
            if (!zone.allows(player, flag)) {
                transaction.setValid(false);

                // Should we message the player?
                if (player.isPresent() && !BlockUtil.ignore(event, transaction)) {
                    String block = transaction.getOriginal().getState().getType().getName();

                    player.get().sendMessage(Format.error(String.format("Zone does not allow you to place %s.",
                        block.replace("minecraft:", ""))));
                }

                break;
            }
        }
    }
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:36,代码来源:ChangeBlockListener.java

示例4: handleBreak

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
private boolean handleBreak(Player player, Transaction<BlockSnapshot> transaction, BlockSnapshot block, boolean autoUnlock) {
    if (Keys.getLockableBlocks().contains(block.getState().getType())) {
        try {
            // Is user allowed here?
            if (player.hasPermission("keys.mod") || Keys.getStorageAdapter().ownsLock(player, block.getLocation().get())) {
                // Remove locks
                if (autoUnlock && Keys.getStorageAdapter().removeLocks(block.getLocation().get())) {
                    // Build message
                    String blockName = block.getState().getType().getName().replace("minecraft:", "").replace("_", " ");
                    Vector3i position = block.getLocation().get().getPosition().toInt();
                    String message = String.format("Removed %s locks and keys at %d %d %d", blockName, position.getX(), position.getY(), position.getZ());

                    player.sendMessage(Format.heading(message));
                }
            } else {
                transaction.setValid(false);
                player.sendMessage(Format.error("You may not destroy this locked location."));
            }

            return true;
        } catch (SQLException e) {
            player.sendMessage(Format.error("Storage error. Details have been logged."));
            e.printStackTrace();
        }
    }

    return false;
}
 
开发者ID:prism,项目名称:Keys,代码行数:29,代码来源:ChangeBlockListener.java

示例5: 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

示例6: 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

示例7: 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

示例8: onExplosion

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onExplosion(ExplosionEvent.Post event) {
    final World world = event.getExplosion().getWorld();
    if (!GPFlags.EXPLOSION || !GriefPreventionPlugin.instance.claimsEnabledForWorld(world.getProperties())) {
        return;
    }

    GPTimings.EXPLOSION_EVENT.startTimingIfSync();
    Object source = event.getCause().root();
    final User user = CauseContextHelper.getEventUser(event);
    GPClaim targetClaim = null;
    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        BlockSnapshot blockSnapshot = transaction.getOriginal();
        Location<World> location = blockSnapshot.getLocation().orElse(null);
        if (location == null) {
            continue;
        }

        targetClaim =  GriefPreventionPlugin.instance.dataStore.getClaimAt(blockSnapshot.getLocation().get(), targetClaim);
        if (GPFlags.EXPLOSION_SURFACE && location.getPosition().getY() > ((net.minecraft.world.World) world).getSeaLevel() && GPPermissionHandler.getClaimPermission(event, location, targetClaim, GPPermissions.EXPLOSION_SURFACE, source, blockSnapshot, user, true) == Tristate.FALSE) {
            event.setCancelled(true);
            GPTimings.EXPLOSION_EVENT.stopTimingIfSync();
            return;
        }

        if (GPPermissionHandler.getClaimPermission(event, location, targetClaim, GPPermissions.EXPLOSION, source, blockSnapshot, user, true) == Tristate.FALSE) {
            // Avoid lagging server from large explosions.
            if (event.getTransactions().size() > 100) {
                event.setCancelled(true);
                GPTimings.EXPLOSION_EVENT.stopTimingIfSync();
                return;
            }
            transaction.setValid(false);
            GPTimings.EXPLOSION_EVENT.stopTimingIfSync();
            return;
        }
    }
    GPTimings.EXPLOSION_EVENT.stopTimingIfSync();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:40,代码来源:BlockEventHandler.java

示例9: 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

示例10: onBlockBurn

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBlockBurn(ChangeBlockEvent.Break event)
{
    Optional<BlockSnapshot> blockCause = event.getCause().first(BlockSnapshot.class);
    if (!blockCause.isPresent() || blockCause.get().getState().getType().equals(FIRE))
    {
        return;
    }
    if (!this.module.getConfig().protectBlockFromFire) return;
    for (Transaction<BlockSnapshot> trans : event.getTransactions())
    {
        Location<World> location = trans.getOriginal().getLocation().get();
        Lock lock = manager.getLock(location);
        if (lock != null)
        {
            trans.setValid(false);
            continue;
        }
        for (Location<World> block : BlockUtil.getDetachableBlocks(location))
        {
            lock = this.manager.getLock(block);
            if (lock != null)
            {
                trans.setValid(false);
                break;
            }
        }
    }
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:30,代码来源:LockerBlockListener.java

示例11: 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

示例12: 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

示例13: onBreakBlock

import org.spongepowered.api.data.Transaction; //导入方法依赖的package包/类
@Listener
public void onBreakBlock(final ChangeBlockEvent.Break event) {
    Optional<Player> player = event.getCause().first(Player.class);

    // Allow if they have mod permission
    if (player.isPresent() && player.get().hasPermission("safeguard.mod")) {
        return;
    }

    for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
        List<Zone> zones = SafeGuard.getZoneManager().getZones(transaction.getOriginal().getLocation().get());

        // Allow change if no zone exists
        if (zones.isEmpty()) {
            continue;
        }

        // Allow self or reject non-players
        Optional<UUID> creator = transaction.getOriginal().getCreator();
        if (creator.isPresent()) {
            // Deny non-players changing player-owned blocks
            if (!player.isPresent()) {
                transaction.setValid(false);
                continue;
            }

            // Allow if player is block owner
            if (creator.get().equals(player.get().getUniqueId())) {
                continue;
            }
        }

        for (Zone zone : zones) {
            // Reject if zone doesn't allow
            if (!zone.allows(player, flag)) {
                transaction.setValid(false);

                // Should we message the player?
                if (player.isPresent() && !BlockUtil.ignore(event, transaction)) {
                    String block = transaction.getOriginal().getState().getType().getName();

                    player.get().sendMessage(Format.error(String.format("Zone does not allow you to break %s.",
                        block.replace("minecraft:", ""))));
                }

                break;
            }
        }
    }
}
 
开发者ID:prism,项目名称:SafeGuard,代码行数:51,代码来源:ChangeBlockListener.java

示例14: 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

示例15: 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


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