2014-12-22 4 views
1

내가 명령을 입력 할 때 "/ customblock"속보 사용자 정의 블록

@EventHandler 
public void onBlockBreak(BlockBreakEvent broke){ 




    Player player = broke.getPlayer(); 
    PlayerInventory inventory = broke.getPlayer().getInventory(); 
    World world = player.getWorld(); 
    Material block = broke.getBlock().getType(); 


    if(block.equals(CustomBlock)){ 

     player.sendMessage("Test"); 

    } 

세계와 PlayerInventory

겠어요 - 같은 추가 변수를 무시를 내가받을 사용자 지정 블록을 파괴하기 위해 노력하고있어 .. 내가 원하는 블록을 받고 있지만, 내가 그것을 깰 때 ... 그냥 아무 것도하지 말아라.

+0

"CustomBlock"은 평등을 비교할 수있는 개체가 아닙니다. – Constant

답변

3

CustomBlock는 무엇인가? 그것은 변수 또는 클래스입니까? 2 일 :

  1. Block 단지 위치입니다, 당신은 그것을 직렬화, 또는 다른 블록에 동일한 경우는 확인할 수 없습니다.
  2. block.equals()은 native Object's 메서드이며, bukkit으로 덮어 쓰지 않습니다. 한 객체가 다른 객체와 동일한 지 여부를 단순히 확인합니다.

블록을 확인하는 가장 좋은 방법은 "사용자 정의 블록"입니다. 모든 사용자 정의 블록의 위치를 ​​기록하고 해당 블록이 해당 위치에 있는지 확인하는 것입니다. 예 :

public List<Location> customBlocks = new ArrayList<Location>(); 

//... in the block place event add the block's location to the list 

@EventHandler 
public void onBlockBreak(BlockBreakEvent broke){ 

    Player player = broke.getPlayer(); 
    PlayerInventory inventory = broke.getPlayer().getInventory(); 
    World world = player.getWorld(); 
    Material block = broke.getBlock().getType(); 


    if(customBlocks.contains(block.getLocation())){ 
     //custom block 
     block.setType(Material.AIR); //destroy the block 
    } 

} 
관련 문제