@Test
  public void testWhenVehicleIsAttackedByNonPlayerEventIsPassed() {
    VehicleDamageEvent event = new VehicleDamageEvent(mockVehicle, mock(Creeper.class), 10.0);

    systemUnderTest.onVehicleDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
  @Test
  public void testTrustedPlayerCanDamageVehiclesWhenInChunk() {
    playerIsTrusted();

    VehicleDamageEvent event = new VehicleDamageEvent(mockVehicle, mockPlayer, 10.0);

    systemUnderTest.onVehicleDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
  @Test
  public void testAdminCanDamageVehiclesWithProjectilesWhenInChunk() {
    playerIsAdmin();
    playerThrewProjectile();

    VehicleDamageEvent event = new VehicleDamageEvent(mockVehicle, mockProjectile, 10.0);

    systemUnderTest.onVehicleDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
  @Test
  public void testUntrustedPlayerCannotDamageVehiclesWhenInChunk() {
    playerIsUntrusted();

    VehicleDamageEvent event = new VehicleDamageEvent(mockVehicle, mockPlayer, 10.0);

    systemUnderTest.onVehicleDamage(event);
    Assert.assertTrue(event.isCancelled());
    verify(mockPlayer)
        .sendMessage("§eYou do not have APlayer's permission to break vehicles here.");
  }
  @Test
  public void testWhenVehicleIsAttackedByNonPlayerWithProjectileEventIsPassed() {
    Skeleton mockSkeleton = mock(Skeleton.class);
    Projectile mockAttacker = mock(Projectile.class);
    when(mockAttacker.getShooter()).thenReturn(mockSkeleton);

    VehicleDamageEvent event = new VehicleDamageEvent(mockVehicle, mockAttacker, 10.0);

    systemUnderTest.onVehicleDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onVehicleDamage(VehicleDamageEvent event) {
    if (event.isCancelled()) return;

    if (event.getAttacker() instanceof Player) {
      final Player player = (Player) event.getAttacker();
      final Vehicle vehicle = event.getVehicle();

      if (player.getWorld() != plugin.getIslandWorld()) return;
      if (player.isOp()) return;
      if (player.hasPermission("islandworld.bypass.island")) return;

      if (vehicle != null
          && !(plugin.getConfig().getBoolean("flags.use-vehicle", false)
              || plugin.canBuildOnLocation(player, vehicle.getLocation())))
        event.setCancelled(true);

      plugin.debug("Event :" + event.getEventName() + ", cancelled:" + event.isCancelled());
    }
  }