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


Java BlockPlaceEvent.canBuild方法代码示例

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


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

示例1: ignite

import org.bukkit.event.block.BlockPlaceEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public boolean ignite(Player igniter, Location loc, IgniteCause cause) {
    Random rand = new Random();

    loc.add(0.5, 0.5, 0.5);
    
    BlockIgniteEvent igniteEvent = new BlockIgniteEvent(loc.getBlock(), 
            cause, (org.bukkit.entity.Entity) igniter);
    Bukkit.getServer().getPluginManager().callEvent(igniteEvent);
    if (igniteEvent.isCancelled()) {
        return false;
    }
 
    BlockState blockState = loc.getBlock().getState();
 
    BlockPlaceEvent placeEvent = new BlockPlaceEvent(loc.getBlock(), 
            blockState, loc.getBlock(), igniter.getItemInHand(), igniter, true);
    Bukkit.getServer().getPluginManager().callEvent(placeEvent);
 
    if (placeEvent.isCancelled() || !placeEvent.canBuild()) {
        placeEvent.getBlockPlaced().setTypeIdAndData(0, (byte) 0, false);
        return false;
    }

    loc.getWorld().playSound(loc, Sound.ITEM_FLINTANDSTEEL_USE, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
    loc.getBlock().setType(Material.FIRE);
    
    return true;
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:30,代码来源:FirestrikerClick.java

示例2: ignite

import org.bukkit.event.block.BlockPlaceEvent; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public boolean ignite(Player igniter, Location loc, IgniteCause cause) {
    Random rand = new Random();

    loc.add(0.5, 0.5, 0.5);
    
    BlockIgniteEvent igniteEvent = new BlockIgniteEvent(loc.getBlock(), 
            cause, (org.bukkit.entity.Entity) igniter);
    Bukkit.getServer().getPluginManager().callEvent(igniteEvent);
    if (igniteEvent.isCancelled()) {
        return false;
    }
    
    List<Location> locations = new ArrayList<Location>();
    
    for(double x = loc.getX() - 2;x <= loc.getX() + 2;x++)
    {
    	for(double y = loc.getY() - 1;y <= loc.getY() + 1;y++)
    	{
    		for(double z = loc.getZ() - 2;z <= loc.getZ() + 2;z++)
    		{
    			locations.add(new Location(loc.getWorld(),x,y,z));
    		}
    	}
    }
    
    for(Location l : locations)
    {
	    BlockIgniteEvent igniteEvent2 = new BlockIgniteEvent(l.getBlock(), 
	            cause, (org.bukkit.entity.Entity) igniter);
	    Bukkit.getServer().getPluginManager().callEvent(igniteEvent2);
	    if (igniteEvent2.isCancelled()) {
	        continue;
	    }
	    
	    BlockState blockState = l.getBlock().getState();
	    
	    BlockPlaceEvent placeEvent = new BlockPlaceEvent(l.getBlock(), 
	            blockState, l.getBlock(), igniter.getItemInHand(), igniter, true);
	    Bukkit.getServer().getPluginManager().callEvent(placeEvent);
	    
	    if (placeEvent.isCancelled() || !placeEvent.canBuild()) {
	        continue;
	    }
    	
    	if(l.getBlock() == null || l.getBlock().getType() == Material.AIR)
    		l.getBlock().setType(Material.FIRE);
    }

   	loc.getWorld().playSound(loc, Sound.ITEM_FIRECHARGE_USE, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
    
    return true;
}
 
开发者ID:FattyMieo,项目名称:SurvivalPlus,代码行数:54,代码来源:BlazeSword.java

示例3: handle

import org.bukkit.event.block.BlockPlaceEvent; //导入方法依赖的package包/类
@Override
public void handle( ConnectionHandler connectionHandler, MessageC1FBlockPlacement message ) {
    FlexPlayer player = connectionHandler.getPlayer();
    synchronized ( player.getInventory() ) {
        int heldSlot = player.getHeldItemSlot();
        ItemStack stack = player.getInventory().getItem( heldSlot );
        if( stack != null ) {
            stack.setAmount( stack.getAmount() - 1 );
            if( stack.getAmount() <= 0 ) {
                stack = null;
            } else {
                ItemStack itemInHand = player.getItemInHand();
                Vector3i position = message.getPosition();
                switch ( message.getFace()  ) {
                    case 0:
                        position.modify( 0,-1,0 );
                        break;
                    case 1:
                        position.modify( 0, 1, 0 );
                        break;
                    case 2:
                        position.modify( 0, 0, -1 );
                        break;
                    case 3:
                        position.modify( 0, 0, 1 );
                        break;
                    case 4:
                        position.modify( -1, 0, 0 );
                        break;
                    case 5:
                        position.modify( 1, 0, 0 );
                        break;
                    default:
                        return;
                }
                BlockPlaceEvent event = new BlockPlaceEvent( player.getWorld().getBlock0( position.getX(), position.getY(), position.getZ(), true ), null, null, itemInHand, player, true, EquipmentSlot.HAND );
                BlockState pr = new BlockState( event.getBlock().getType(), event.getBlock().getData() );
                EventFactory.call( event );
                if( !event.isCancelled() && event.canBuild() ) {
                    player.getWorld().setBlock( position, new BlockState( stack.getType(), stack.getDurability() ) );
                } else {
                    player.getWorld().setBlock( position, pr );
                }
            }
        }
        player.getInventory().setItem( heldSlot, stack );
    }
}
 
开发者ID:lukas81298,项目名称:FlexMC,代码行数:49,代码来源:BlockPlaceListener.java


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