2016-12-06 1 views
0

알림,이 플러그인 자체가 작동하며, 때리면 오류가 발생합니다.PlayerInteractEvent가 Spigot을 때릴 때 깨짐

나는 가슴이 미니 크래프트에서 어떻게 작동하는지 완전히 바꾸려고합니다. 내 플러그인에서, 당신이 그들을 열 때 그들은 일을하고 있지만 문제가있는 아이템을 사라지게합니다.

PlayerInteractEvent를 호출하고 if 문을 사용하여 블록 유형이 가슴인지 확인합니다. 그렇다면 이벤트가 취소되고 가슴을 사라지게하고 플레이어에게 항목을 제공합니다. 그러나 메인 클래스가 ChestRewards 클래스에 이벤트를 전달할 때 예상 한 PlayerInteractEvent에서 펀칭 액션 또는 타격 이벤트를 전달하는 것으로 보이지만 그 이유는 if 문을 사용하여 전달 된 이벤트 만 사용하기 때문입니다 유형은 가슴입니다. 하지만 이벤트를 통과 할 수없는 콘솔에서 오류가 발생하는 것 같습니다. 도와주세요!

@EventHandler 
    public void catchChestOpen(PlayerInteractEvent event) { 

    Entity p = event.getPlayer(); 
    Player player = (Player) p; 

    if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.PHYSICAL || event.getAction() == Action.LEFT_CLICK_BLOCK){ 
     // TODO: 2016-12-06 Nothing 
    } 

    if (event.getClickedBlock().getType() == Material.CHEST) { 


     event.getClickedBlock().setType(Material.AIR); 

     event.setCancelled(true); 

     int rando = (int) (Math.random() * 10); 


     //--------------------------------------------------------------------------------- 
     if (rando == 1) { 
      ItemStack Axe = new ItemStack(Material.DIAMOND_AXE, 1); 
      ItemMeta meta = Axe.getItemMeta(); 
      List<String> lores = new ArrayList<String>(); 
      lores.add(ChatColor.DARK_PURPLE + "The axe of a long lost survivor"); 

      meta.setDisplayName(ChatColor.DARK_RED + "Survivor Axe"); 
      meta.addEnchant(Enchantment.DAMAGE_ALL, 2, true); 
      meta.addEnchant(Enchantment.DURABILITY, 2, true); 
      meta.setLore(lores); 
      Axe.setItemMeta(meta); 
      Axe.setDurability((short) 800); 
      player.getInventory().addItem(Axe); 
      player.sendMessage(ChatColor.GOLD + "You opened a" + ChatColor.AQUA + " RARE " + ChatColor.GOLD + "loot chest!"); 
     } 
     //--------------------------------------------------------------------------------- 
     if (rando > 1) { 
      ItemStack IronSword = new ItemStack(Material.IRON_SWORD, 1); 
      ItemMeta meta2 = IronSword.getItemMeta(); 
      List<String> lores2 = new ArrayList<String>(); 
      lores2.add(ChatColor.DARK_PURPLE + "A reliable iron sword"); 

      meta2.setDisplayName(ChatColor.DARK_RED + "Reliable Iron Sword"); 
      meta2.addEnchant(Enchantment.DURABILITY, 3, true); 
      meta2.setLore(lores2); 
      IronSword.setItemMeta(meta2); 
      IronSword.setDurability((short) 800); 
      player.getInventory().addItem(IronSword); 
      player.sendMessage(ChatColor.GOLD + "You opened a loot chest!"); 
     } 
     //--------------------------------------------------------------------------------- 



    } 
} 

오류 자체

ActionRIGHT_CLICK_BLOCK 또는 LEFT_CLICK_BLOCK, 당신은에 block.getType()를 호출 할 때 다음 event.getClickedBlock()가 null이됩니다하지 않은 경우 당신이 코드의 실행을 중지하지 않기 때문에
[09:32:00 ERROR]: Could not pass event PlayerInteractEvent to Apocalypse v1.0 
+1

당신이 메시지 다음에 오는 스택 트레이스를 게시 할 수 : 왼쪽 또는 오른쪽 중 플레이어가 가슴을 클릭하면 아래의 조각은 확인합니다? – Pokechu22

답변

0

플레이어가 왼쪽 또는 오른쪽으로 클릭 한 경우 가슴과 비교할 수 있습니다.

조치가 블록과 관련이 있는지 확인하는 것이 좋습니다. "1.0 버전의 종말을 이벤트 PlayerInteractEvent을 통과 할 수 없습니다"

if ((event.getAction() == Action.RIGHT_CLICK_BLOCK || 
    event.getAction() == Action.LEFT_CLICK_BLOCK) && 
    event.getClickedBlock().getType() == Material.CHEST) { 
+0

정보, 감사합니다. –

+0

잘 했어! 정말 고마워! –