Event Half Triggered

Discussion in 'Plugin Development' started by xtreameprogram, Jun 19, 2014.

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

    xtreameprogram

    This is my code
    Code:
     Location r1;
    Location r2;
     
    @EventHandler
    public void onInteract(PlayerInteractEvent e) {
     
    if (Main.click2.contains(e.getPlayer())) {
    e.getPlayer().sendMessage("Test");
    if (e.getMaterial().equals(Material.DIRT)) {
    r1 = e.getClickedBlock().getLocation();
    Main.click2.remove(e.getPlayer());
    Main.click1.add(e.getPlayer());
    e.getPlayer().sendMessage(ChatColor.BLUE + "You need to right click 1 more piece of redstone.");
     
    }}}}
    For some reason when i put a a test message it triggers but it doesn't test or it returns false for the checking if its dirt. There are no errors and i have tried using different events.
     
  2. Offline

    THEREDBARON24

    could be the e.getMaterial method. I have never used that, however, you could use e.getClickedBlock().getType() instead.
     
  3. Offline

    zDylann

    Are you trying to check if they are clicking a dirt block that is placed? At the moment that code will only trigger if you interact with a dirt block in your hand. If you want to check what block they are clicking try something like this.

    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e){
    3.  
    4. if(e.getAction() != Action.RIGHT_CLICK_BLOCK){
    5. return;
    6. }
    7.  
    8. if(e.getClickedBlock().getType() == Material.DIRT){
    9. Bukkit.broadcastMessage("hooray!");
    10. }
    11.  
    12. }
     
    xtreameprogram likes this.
  4. Offline

    THEREDBARON24

    ahh, so its the material in the hand! 3rd way to get that block, how convenient.
     
Thread Status:
Not open for further replies.

Share This Page