Player spectate Entity Event

Discussion in 'Spigot Plugin Development' started by ItsChristian, May 26, 2017.

  1. How to check if a player clicks an entity to spectate that entity
     
  2. PlayerInteractEvent, check if the action is a left click on a Player and check if the clicker is in spectate mode?
     
  3. How do I test if it is a click on a player?
     
  4. Use a PlayerInteractAtEntityEvent and check if the entity is a player.
     
  5. Code (Text):
    @EventHandler
        public void onPlayerInteract(PlayerInteractAtEntityEvent event) {
            if (!(event.getPlayer() instanceof Player) || !(event.getRightClicked() instanceof Player))
                return;
           
            Player player = event.getPlayer();
            Player clicked = (Player) event.getRightClicked();
    }
    I have this but it doesn't seem to work. If I right click it works but not w/ left click
     
  6. Use PlayerTeleportEvent, then check if the reason is caused by SPECTATE
     
  7. Thanks I'll try it when I come home.
     
  8. The correct events for this are:
    Code (Java):
    PlayerStopSpectatingEntityEvent
    // and
    PlayerStartSpectatingEntityEvent
    Apologies for the bump.