2016-12-06 4 views
0

注意、このプラグイン自体は動作します、ちょうど打撃時にエラーを与えます。PlayerInteractEventスピゴットを打つときに壊れる

私は胸部がミニクラフトでどのように機能するかを完全に変更しようとしています。私のプラグインでは、あなたがそれらを開いたときにアイテムが消えてしまい、それが機能していますが、問題があります。

私は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_BLOCKLEFT_CLICK_BLOCKでない場合、これはあなたがコードの実行をエラー自体

[09:32:00 ERROR]: Could not pass event PlayerInteractEvent to Apocalypse v1.0 
+1

あなたがメッセージの後に来るスタックトレースを投稿することができます:左または右のいずれかのプレイヤーが胸をクリックした場合は、以下のスニペットは、チェックしますか? – Pokechu22

答えて

0

停止されていないされているので、あなたが上block.getType()を呼び出すとき、そしてevent.getClickedBlock()はnullになりますプレーヤーが左または右の空気をクリックした場合、それを胸と比較すること。

アクションがブロックと何か関係があるかどうかをチェックすることをおすすめします。 「v1.0のを黙示録するイベントPlayerInteractEventを渡すことができませんでした」

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

申し訳ありませんが、情報のおかげで! –

+0

うまくいった!本当にありがとう! –

関連する問題