PlayerInteractEvent don't throwing with specific items

Discussion in 'Plugin Development' started by TheBigSuperCraft, Mar 29, 2014.

Thread Status:
Not open for further replies.
  1. Hello,
    I'm trying to fix my plugin but I can't. I hope that you'll help me fixing it.
    I'm using PlayerInteractEvent for getting if player is right clicking with magma cream.
    I'm doing the same with slime ball, and it works. It doesn't with magma cream.
    I have no stack-trace.
    I've registered the events.
    My code is (Only posting the method):
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract5(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4.  
    5. if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    6.  
    7. if (!(p.getInventory().getItemInHand().getType() == Material.SLIME_BALL)) return;
    8. hubGames.remove(p);
    9. ItemStack hub = new ItemStack(Material.MAGMA_CREAM);
    10. ItemMeta hubM = hub.getItemMeta();
    11. hubM.setDisplayName(ChatColor.YELLOW + "" + ChatColor.BOLD + "Hub Games: " + ChatColor.RED + "OFF");
    12. hub.setItemMeta(hubM);
    13.  
    14. p.getInventory().setItem(7, hub);
    15. }


    I'm doing onPlayerInteract5 because I have more PlayerInteractEvent methods.

    And I need to fix it fast.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    fearleas

    Do you got a nullpointerexception or another exception or doesnt it work else do this.

    Place this in a class in your main or just somewhere else like the listner class.

    Code:java
    1. public ItemStack setMeta(ItemStack material, String name) {
    2. if (material == null || material.getType() == Material.AIR
    3. || name == null)
    4. return null;
    5.  
    6. ItemMeta im = material.getItemMeta();
    7. if (name != null) {
    8. im.setDisplayName(name);
    9. }
    10. material.setItemMeta(im);
    11.  
    12. return material;
    13. }


    And than just us it like this.

    Code:java
    1. setMeta(Matrial.MAGMA_CREAM, ChatColor.YELLOW + "" + ChatColor.BOLD + "Hub Games: " + ChatColor.RED + "OFF")


    This will give you the item and set the name.
     
  3. Like I said, I don't have any stack trace.
    And what you're doing will not fix my problem. My problem is that the event will not be thrown.

    fearleas

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    fearleas

    can you sow your main class where you registered your events if you did that
     
  5. Offline

    Wolfey

    Debug your event and see where your code is failing.
     
  6. Wolfey
    When I'm right clicking with magma cream. But it doesn't says anything. Even if I'm debug messages.
     
  7. Ummm... Someone?
     
Thread Status:
Not open for further replies.

Share This Page