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

    systemUnderTest.onVehicleDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
Exemplo n.º 2
0
  @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
  void onVehicleDamage(VehicleDamageEvent event) {
    Player attacker = getAttackingPlayer(event.getAttacker());
    ChunkData chunk = dataStore.getChunkAt(event.getVehicle().getLocation());

    revokeIfNotPermitted(attacker, chunk, event, "break vehicles");
  }
 @EventHandler
 public void VehicleDamage(final VehicleDamageEvent event) {
   if (!(event.getAttacker() instanceof Player)) return;
   final Player player = (Player) event.getAttacker();
   if (plugin.isLoggedIn(player)) return;
   event.setCancelled(true);
   plugin.sendAuthReminderMessage(player);
 }
  @Test
  public void testTrustedPlayerCanDamageVehiclesWhenInChunk() {
    playerIsTrusted();

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

    systemUnderTest.onVehicleDamage(event);
    Assert.assertFalse(event.isCancelled());
  }
  // when a vehicle is damaged
  @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
  public void onVehicleDamage(VehicleDamageEvent event) {
    // all of this is anti theft code
    if (!GriefPrevention.instance.config_claims_preventTheft) return;

    // determine which player is attacking, if any
    Player attacker = null;
    Entity damageSource = event.getAttacker();
    if (damageSource instanceof Player) {
      attacker = (Player) damageSource;
    } else if (damageSource instanceof Arrow) {
      Arrow arrow = (Arrow) damageSource;
      if (arrow.getShooter() instanceof Player) {
        attacker = (Player) arrow.getShooter();
      }
    } else if (damageSource instanceof ThrownPotion) {
      ThrownPotion potion = (ThrownPotion) damageSource;
      if (potion.getShooter() instanceof Player) {
        attacker = (Player) potion.getShooter();
      }
    }

    // NOTE: vehicles can be pushed around.
    // so unless precautions are taken by the owner, a resourceful thief might find ways to steal
    // anyway
    Claim cachedClaim = null;
    PlayerData playerData = null;
    if (attacker != null) {
      playerData = this.dataStore.getPlayerData(attacker.getName());
      cachedClaim = playerData.lastClaim;
    }

    Claim claim = this.dataStore.getClaimAt(event.getVehicle().getLocation(), false, cachedClaim);

    // if it's claimed
    if (claim != null) {
      // if damaged by anything other than a player, cancel the event
      if (attacker == null) {
        event.setCancelled(true);
      }

      // otherwise the player damaging the entity must have permission
      else {
        String noContainersReason = claim.allowContainers(attacker);
        if (noContainersReason != null) {
          event.setCancelled(true);
          GriefPrevention.sendMessage(
              attacker, TextMode.Err, Messages.NoDamageClaimedEntity, claim.getOwnerName());
        }

        // cache claim for later
        if (playerData != null) {
          playerData.lastClaim = claim;
        }
      }
    }
  }
  @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());
    }
  }