當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。