Solved player interact

Discussion in 'Plugin Development' started by NoLiver92, Jan 1, 2013.

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

    NoLiver92

    how do i detect when a player opens a door or pushes a button and not when its being placed or broken?

    I know its playerinteractevent

    thanks
     
  2. Offline

    Polaris29

    Get the event action with event.getAction() and if the action is equal to Action.RIGHT_CLICK_BLOCK, check if the Material type is wooden door, wooden button or stone button with event.getClickedBlock().getType() then do your stuff
     
  3. Offline

    NoLiver92

    ive tried that, this is my code: it doesnt work, only when it is placed it works

    Code:
    Location playerloc = player.getLocation();
            Action action = event.getAction();
            Material clicked = event.getMaterial();
            Material[] materials = {Material.WOOD_BUTTON, Material.STONE_BUTTON, Material.LEVER, Material.WOOD_DOOR, Material.TRAP_DOOR, Material.SIGN, Material.SIGN_POST};
           
            for(Material material : materials)
            {
                if(clicked == material && action == Action.RIGHT_CLICK_BLOCK)
                {
                    DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss");
                    Date date = new Date();
                    List<String> playerinteract = PlayerDataConfig.getStringList("Player Interact");
                    playerinteract.add("Time: " + dateFormat.format(date) + " ~ Block: " + material + " ~ Action:" + action + " ~ Location: " + player.getWorld().getName() + "    " + playerloc.getX() + "," + playerloc.getY() + "," + playerloc.getZ());
                    PlayerDataConfig.set("Player Interact", playerinteract);
                    try {PlayerDataConfig.save(PlayerDataFile);} catch (IOException e) {}
                }
            }
     
  4. Offline

    Jogy34

    clicked should be event.getClickedBlock().getType()
     
  5. Offline

    NoLiver92

    thanks that works for everything except doors
     
  6. Offline

    SgtStud

    Dunno if this is the problem, but in this line i would use .equals:
    if(clicked == material && action == Action.RIGHT_CLICK_BLOCK)
    So it should be:
    if(clicked.equals(material) && action.equals(Action.RIGHT_CLICK_BLOCK))
     
  7. Offline

    Polaris29

    Try WOODEN_DOOR for wood doors and IRON_DOOR_BLOCK for iron doors
     
  8. Offline

    NoLiver92

    Solved Thank You
     
Thread Status:
Not open for further replies.

Share This Page