Java 类org.bukkit.event.block.BlockCanBuildEvent 实例源码

项目:Skript    文件:EffCancelEvent.java   
@SuppressWarnings("null")
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
    if (isDelayed == Kleenean.TRUE) {
        Skript.error("Can't cancel an event anymore after is has already passed", ErrorQuality.SEMANTIC_ERROR);
        return false;
    }
    cancel = matchedPattern == 0;
    final Class<? extends Event>[] es = ScriptLoader.getCurrentEvents();
    if (es == null)
        return false;
    for (final Class<? extends Event> e : es) {
        if (Cancellable.class.isAssignableFrom(e) || BlockCanBuildEvent.class.isAssignableFrom(e))
            return true; // TODO warning if some event(s) cannot be cancelled even though some can (needs a way to be suppressed)
    }
    if (ScriptLoader.isCurrentEvent(PlayerLoginEvent.class))
        Skript.error("A connect event cannot be cancelled, but the player may be kicked ('kick player by reason of \"...\"')", ErrorQuality.SEMANTIC_ERROR);
    else
        Skript.error(Utils.A(ScriptLoader.getCurrentEventName()) + " event cannot be cancelled", ErrorQuality.SEMANTIC_ERROR);
    return false;
}
项目:SkyWarsReloaded    文件:SpectatorListener.java   
@EventHandler
protected void onBlockCanBuild(BlockCanBuildEvent e) {
    if (!e.isBuildable()) {
        Location blockL = e.getBlock().getLocation(); 

        boolean allowed = false; 

        for (Player target : SkyWarsReloaded.get().getServer().getOnlinePlayers()) {
            if (target.getWorld().equals(e.getBlock().getWorld()) && SkyWarsReloaded.getPC().getPlayer(target.getUniqueId()).isSpectating()) { 
                Location playerL = target.getLocation();

                if (playerL.getX() > blockL.getBlockX()-1 && playerL.getX() < blockL.getBlockX()+1) {
                    if (playerL.getZ() > blockL.getBlockZ()-1 && playerL.getZ() < blockL.getBlockZ()+1) { 
                        if (playerL.getY() > blockL.getBlockY()-2 && playerL.getY() < blockL.getBlockY()+1) {
                            if (SkyWarsReloaded.getPC().getPlayer(target.getUniqueId()).isSpectating()) {
                                allowed = true;
                                target.teleport(e.getBlock().getLocation().add(0, 5, 0), TeleportCause.PLUGIN);
                                target.sendMessage(new Messaging.MessageFormatter().withPrefix().format("spectate.teleport-from-block"));
                            } else {
                                allowed = false;
                                break;
                            }
                        }
                    }
                }

            }
        }
        e.setBuildable(allowed);
    }
}
项目:Skript    文件:EffCancelEvent.java   
@Override
public void execute(final Event e) {
    if (e instanceof Cancellable)
        ((Cancellable) e).setCancelled(cancel);
    if (e instanceof PlayerInteractEvent) {
        ((PlayerInteractEvent) e).setUseItemInHand(cancel ? Result.DENY : Result.DEFAULT);
        ((PlayerInteractEvent) e).setUseInteractedBlock(cancel ? Result.DENY : Result.DEFAULT);
    } else if (e instanceof BlockCanBuildEvent) {
        ((BlockCanBuildEvent) e).setBuildable(!cancel);
    } else if (e instanceof PlayerDropItemEvent) {
        PlayerUtils.updateInventory(((PlayerDropItemEvent) e).getPlayer());
    }
}
项目:CraftBukkit    文件:World.java   
public boolean mayPlace(Block block, int i, int j, int k, boolean flag, int l, Entity entity, ItemStack itemstack) {
    Block block1 = this.getType(i, j, k);
    AxisAlignedBB axisalignedbb = flag ? null : block.a(this, i, j, k);

    // CraftBukkit start - store default return
    boolean defaultReturn = axisalignedbb != null && !this.a(axisalignedbb, entity) ? false : (block1.getMaterial() == Material.ORIENTABLE && block == Blocks.ANVIL ? true : block1.getMaterial().isReplaceable() && block.canPlace(this, i, j, k, l, itemstack));

    // CraftBukkit start
    BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(i, j, k), CraftMagicNumbers.getId(block), defaultReturn);
    this.getServer().getPluginManager().callEvent(event);

    return event.isBuildable();
    // CraftBukkit end
}
项目:Almura-Server    文件:World.java   
public boolean mayPlace(int i, int j, int k, int l, boolean flag, int i1, Entity entity, ItemStack itemstack) {
    int j1 = this.getTypeId(j, k, l);
    Block block = Block.byId[j1];
    Block block1 = Block.byId[i];
    AxisAlignedBB axisalignedbb = block1.b(this, j, k, l);

    if (flag) {
        axisalignedbb = null;
    }

    boolean defaultReturn; // CraftBukkit - store the default action

    if (axisalignedbb != null && !this.a(axisalignedbb, entity)) {
        defaultReturn = false; // CraftBukkit
    } else {
        if (block != null && (block == Block.WATER || block == Block.STATIONARY_WATER || block == Block.LAVA || block == Block.STATIONARY_LAVA || block == Block.FIRE || block.material.isReplaceable())) {
            block = null;
        }

        // CraftBukkit
        defaultReturn = block != null && block.material == Material.ORIENTABLE && block1 == Block.ANVIL ? true : i > 0 && block == null && block1.canPlace(this, j, k, l, i1, itemstack);
    }

    // CraftBukkit start
    BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(j, k, l), i, defaultReturn);
    this.getServer().getPluginManager().callEvent(event);

    return event.isBuildable();
    // CraftBukkit end
}
项目:Tweakkit-Server    文件:World.java   
public boolean mayPlace(Block block, int i, int j, int k, boolean flag, int l, Entity entity, ItemStack itemstack) {
    Block block1 = this.getType(i, j, k);
    AxisAlignedBB axisalignedbb = flag ? null : block.a(this, i, j, k);

    // CraftBukkit start - store default return
    boolean defaultReturn = axisalignedbb != null && !this.a(axisalignedbb, entity) ? false : (block1.getMaterial() == Material.ORIENTABLE && block == Blocks.ANVIL ? true : block1.getMaterial().isReplaceable() && block.canPlace(this, i, j, k, l, itemstack));

    // CraftBukkit start
    BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(i, j, k), CraftMagicNumbers.getId(block), defaultReturn);
    this.getServer().getPluginManager().callEvent(event);

    return event.isBuildable();
    // CraftBukkit end
}
项目:Cauldron    文件:World.java   
public boolean canPlaceEntityOnSide(Block p_147472_1_, int p_147472_2_, int p_147472_3_, int p_147472_4_, boolean p_147472_5_, int p_147472_6_, Entity p_147472_7_, ItemStack p_147472_8_)
{
    Block block1 = this.getBlock(p_147472_2_, p_147472_3_, p_147472_4_);
    if (block1 == null) return false; // Cauldron
    AxisAlignedBB axisalignedbb = p_147472_5_ ? null : p_147472_1_.getCollisionBoundingBoxFromPool(this, p_147472_2_, p_147472_3_, p_147472_4_);
    // CraftBukkit start - store default return
    boolean defaultReturn = axisalignedbb != null && !this.checkNoEntityCollision(axisalignedbb, p_147472_7_) ? false : (block1.getMaterial() == Material.circuits && p_147472_1_ == Blocks.anvil ? true : block1.isReplaceable(this, p_147472_2_, p_147472_3_, p_147472_4_) && p_147472_1_.canReplace(this, p_147472_2_, p_147472_3_, p_147472_4_, p_147472_6_, p_147472_8_));
    BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(p_147472_2_, p_147472_3_, p_147472_4_), CraftMagicNumbers.getId(p_147472_1_), defaultReturn);
    this.getServer().getPluginManager().callEvent(event);
    return event.isBuildable();
    // CraftBukkit end
}
项目:SpigotSource    文件:World.java   
public boolean a(Block block, BlockPosition blockposition, boolean flag, EnumDirection enumdirection, @Nullable Entity entity, @Nullable ItemStack itemstack) {
    IBlockData iblockdata = this.getType(blockposition);
    AxisAlignedBB axisalignedbb = flag ? null : block.getBlockData().d(this, blockposition);

    // CraftBukkit start - store default return
    boolean defaultReturn = axisalignedbb != Block.k && !this.a(axisalignedbb.a(blockposition), entity) ? false : (iblockdata.getMaterial() == Material.ORIENTABLE && block == Blocks.ANVIL ? true : iblockdata.getMaterial().isReplaceable() && block.canPlace(this, blockposition, enumdirection, itemstack));
    BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(blockposition.getX(), blockposition.getY(), blockposition.getZ()), CraftMagicNumbers.getId(block), defaultReturn);
    this.getServer().getPluginManager().callEvent(event);

    return event.isBuildable();
    // CraftBukkit end
}
项目:Craft-city    文件:World.java   
public boolean mayPlace(int i, int j, int k, int l, boolean flag, int i1, Entity entity, ItemStack itemstack) {
    int j1 = this.getTypeId(j, k, l);
    Block block = Block.byId[j1];
    Block block1 = Block.byId[i];
    AxisAlignedBB axisalignedbb = block1.b(this, j, k, l);

    if (flag) {
        axisalignedbb = null;
    }

    boolean defaultReturn; // CraftBukkit - store the default action

    if (axisalignedbb != null && !this.a(axisalignedbb, entity)) {
        defaultReturn = false; // CraftBukkit
    } else {
        if (block != null && (block == Block.WATER || block == Block.STATIONARY_WATER || block == Block.LAVA || block == Block.STATIONARY_LAVA || block == Block.FIRE || block.material.isReplaceable())) {
            block = null;
        }

        // CraftBukkit
        defaultReturn = block != null && block.material == Material.ORIENTABLE && block1 == Block.ANVIL ? true : i > 0 && block == null && block1.canPlace(this, j, k, l, i1, itemstack);
    }

    // CraftBukkit start
    BlockCanBuildEvent event = new BlockCanBuildEvent(this.getWorld().getBlockAt(j, k, l), i, defaultReturn);
    this.getServer().getPluginManager().callEvent(event);

    return event.isBuildable();
    // CraftBukkit end
}
项目:HCFCore    文件:ModeratorMode.java   
@EventHandler
public void onPlayerPlacesBlock(BlockCanBuildEvent event) {
  event.setBuildable(true);
}
项目:Rixor    文件:PlayerEvents.java   
@EventHandler
public void onBlockAttempt(BlockCanBuildEvent event) {
    event.setBuildable(true);
}
项目:SpectatorPlus    文件:SpectatorsInteractionsListener.java   
/**
 * Used to prevent spectators from blocking players from placing blocks.
 */
@EventHandler (priority = EventPriority.HIGHEST)
public void onBlockCanBuild(final BlockCanBuildEvent ev)
{
    if (!ev.isBuildable())
    {
        // Get location of the block that is going to be placed
        Location blockLocation = ev.getBlock().getLocation(); // event.getBlock() returns the block to be placed -1 y

        boolean allowed = false; // If there are any actual players there, the event should not be over-wrote.

        for (Player target : p.getServer().getOnlinePlayers())
        {
            if (target.getWorld().equals(ev.getBlock().getWorld())) // Player in same world?
            {
                Location playerLocation = target.getLocation();

                // If the player is at this location
                if (playerLocation.getX() > blockLocation.getBlockX() - 1
                        && playerLocation.getX() < blockLocation.getBlockX() + 1
                        && playerLocation.getZ() > blockLocation.getBlockZ() - 1
                        && playerLocation.getZ() < blockLocation.getBlockZ() + 1
                        && playerLocation.getY() > blockLocation.getBlockY() - 2
                        && playerLocation.getY() < blockLocation.getBlockY() + 1)
                {
                    if (p.getPlayerData(target).isSpectating())
                    {
                        allowed = true;
                    }
                    else
                    {
                        allowed = false;
                        break;
                    }
                }

            }
        }

        ev.setBuildable(allowed);
    }
}