Solved PlayerInteractEvent

Discussion in 'Plugin Development' started by 808sFinest, Jan 5, 2017.

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

    808sFinest

    When there's no block behind the player i'm hitting, or hitting air and a player at the same time; it counts as left_click_air in PlayerInteractEvent(I don't want this to happen). Does anybody know a solution to this?
     
  2. Offline

    OTF Catastrophe

    In 1.9+ PlayerInteractEvent is affected by a new variable OFF_HAND equipment slot. Try adding

    Code:
    if (e.getHand() != EquipmentSlot.OFF_HAND) {
        //CODE...
    }
    Since a player has "two hands" in minecraft 1.9 it checks both instances on the interact event. Lemme know if that helps you. :)
     
  3. Offline

    808sFinest

    I'm using 1.8 :(
     
  4. Offline

    Zombie_Striker

    @808sFinest
    This seems like the bug with the old versions of spigot. This was fixed somewhere around 1.10. I highly recommend you upgrade to versions 1.10 or higher. In case you are still using 1.8 due to combat or the fact that there are two hands, there are tons of plugins out there that fix this for the newer updates.
     
  5. Offline

    808sFinest

    Is there a solution to this while staying at 1.8? If not ill convert to 1.10 i guess
     
  6. Offline

    Zombie_Striker

    @808sFinest
    Not really. Most of the other ways are hacky (canceling the event if the there is any players near the main player, but that can lead to false positives in some cases or not detect them in others)
     
  7. Offline

    808sFinest

    I converted to 1.11 but the same thing happens, playerInteractEvent and entityDamageEvent bot run if you hit a player and left click air.
     
  8. Offline

    Zombie_Striker

    @808sFinest
    Okay, you may have to check in the playerinteractevent if the is a player in the other player's line of sight. Use this to check
    Code:
    //P is the others players, player is your player
    
    for(Player p: Bukkit.getOnlinePlayers()){
    //This gets all the players online
    if(p.getLocation().distance(player.getLocation) <= 5){
    //Get if the player is even close to the player.
    Vector direction = player.getLocation().getDirection.normalize();
    Player eyes = player.getLocation().add(0,player.getEyeHeight(),0);
    //Getting the player's eyes location and where they are looking.
    for(int i = 0; i < 5; i++){
     eyes.add(direction);
     for(int k = -1; k < 2;k++){
    //Make sure the player is not above/below the player's eyesight
     if(eyes.add(0,k,0).distance(eyes) < 0.6){
        //THE PLAYER IS LOOKING AT ANOTHER PLAYER. CANCEL THE EVENT.
     }
    eyes.subtract(0,k,0);
    }
    }
     
  9. Offline

    808sFinest

    @Zombie_Striker I found a solution using booleans and delays but thank you for taking your time to help me :)
     
Thread Status:
Not open for further replies.

Share This Page