Right Click Furnace

Discussion in 'Plugin Development' started by Profan, Jun 15, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Profan

    Im trying to make a merchant on a furnace, but ins't working, can anyone help me? here is my code:

    Code:java
    1. @EventHandler
    2. public void MerchantT1(PlayerInteractEvent e) {
    3. int gemt1 = 3 + (int)(Math.random() * 9.0D);
    4. Player p = (Player)e.getPlayer();
    5. if (e.getAction() == Action.RIGHT_CLICK_BLOCK)
    6. if (e.getClickedBlock().equals(Material.FURNACE))
    7. if (p.getItemInHand().getType() == Material.WOOD_SWORD)
    8. e.setCancelled(true);
    9. p.getItemInHand().setType(Material.AIR);
    10. amoney(p, gemt1);
    11. p.sendMessage(ChatColor.GREEN + "Voce trocou uma " + ChatColor.RED + "Espada de Madeira" + ChatColor.GREEN + "por gemas.");
    12.  
    13. }
     
  2. Offline

    LordVakar

    What exactly isn't working?
    The money part? The message?
    Player p = (Player)e.getPlayer();
    You don't have to cast to Player on this.
     
  3. Offline

    Profan

    Thanks, the error was in the (Player)

    But now everything i click on the furnace it give me the money, i just want to give the money if the player is holding a wood sword

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

    LordVakar

    Profan
    if (e.getClickedBlock().equals(Material.FURNACE))
    if (p.getItemInHand().getType() == Material.WOOD_SWORD)

    Why don't you have brackets on any of these o.o
    Switch those two above so wood sword comes before Furnace
     
  5. Offline

    Profan

    I maked it , and now nothing works...
     
  6. Offline

    xize

    Profan

    what exactly do you mean with a Merchant since an Merchant is a inventory type to so I'm sort of confused.
    also whats the real problem, do you want the item to be removed from the players hand?
     
  7. Offline

    amhokies

    Profan The problem is that you're trying to compare aBlock object to a Material enum, which will never return true.

    e.getClickedBlock().getType() returns the Material enum for any given Block object.
     
Thread Status:
Not open for further replies.

Share This Page