2014-03-27 2 views
0

서버 소유자가 서버용 간단한 플러그인을 작성하라고했습니다. 책자가있는 서가를 클릭하면 가슴이 열립니다. 그 사람이 가슴을 닫으면 그 안에있는 모든 책들이 파괴됩니다.간단한 Bukkit Plugin - 가슴을 여는 것

나는 bukkit 플러그인 개발의 기초를 이해하고 있지만, website의 지침은 상당히 복잡합니다. 그러나

Player player = event.getPlayer(); 
if (player.getItemInHand().getType() == Material.WRITTEN_BOOK) { 
// Do other stuff in here 
} 

플러그인을 누르면 버튼과 책에 일하기가 쉬울 것 경우 : 나는 손에 플레이어 항목이 실제로이 코드 책이다 내가 등록해야 이해 손이 멸망했다면, 저에게 알려 주시고 제가 그 단계에 대해 도움을 주시겠습니까?

답변

0

가 다음 책장을 마우스 오른쪽 단추로 클릭 한 가슴 GUI을 열 경우 당신은 이런 식으로 그것을 할 수 ... 확인 PlayerInteractEvent을들을 수 있습니다 :

@EventHandler //ALWAYS use this before events 
public void playerInteract(PlayerInteractEvent e){ //listen for PlayerInteractEvent 
    if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK){ //make sure the player right-clicked a block 
    if(e.getClickedBlock().getType().equals(Material.BOOKSHELF)){ //make sure the player right-clicked a bookshelf 
     Player p = e.getPlayer(); //get the player 
     if(p.getItemInHand() != null){ //make sure the player has something in their hand 
     if(p.getItemInHand().getType().equals(Material.WRITTEN_BOOK)){ //check if the player has a written book in their inventory 
      //Inventory inv = Bukkit.createInventory(null, <size (should be divisible by 9)>, "name"); //create the inventory 
      //An example of creating the inventory would be: 
      Inventory inv = Bukkit.createInventory(null, 36, "Disposal"); 
     } 
     } 
    } 
    } 
} 

해야한다고 당신이해야 할 모든 .

this.getServer().getPluginManager().registerEvents(new HandlerClassName(), this); 

을하고 있는지 그 핸들러 클래스 implements Listener합니다 그냥 당신이 사용하여 onEnable() 방법에서 이벤트를 등록하는 것이 있는지 확인하십시오.

거의 위하고있는 첫 번째 코드는 무엇인가 : PlayerInteractEvent

  • 가 상호 작용 이벤트 Right Clicked 블록
  • 과 관련된 플레이어가 바로이 있는지 확인 있는지 확인하기위한

    • 은 듣기 - 클릭 된 블록은 Book Shelf
    • 입니다. 플레이어의 손에있는 아이템이 null
    • Ma가 아닌지 확인하십시오 플레이어의 손에있는 아이템이 Written Book
    • 인 지 확인하십시오. Disposal이라는 새 인벤토리를 36 슬롯 또는 9 x 4 가슴으로 만듭니다.

    그런 다음 플레이어가 가슴에 물건을 넣고 닫으면 아이템이 파괴됩니다! 당신은 사용자가 가슴을 마우스 오른쪽 버튼으로 클릭하면 바로 책을 제거하기를 원하는 경우

    , 단순히 사용하는 대신이의

    p.setItemInHand(new ItemStack(Material.AIR)); 
    

    :

    Inventory inv = Bukkit.createInventory(null, 36, "Disposal"); 
    
  • 관련 문제