コード例 #1
0
  @Before
  public void setupTestCase() {
    mockVehicle = mock(Vehicle.class);
    mockCreature = mock(Creature.class);
    DataManager mockDataManager = mock(DataManager.class);
    Location mockLocation = mock(Location.class);
    mockChunk = mock(ChunkData.class);
    systemUnderTest = new EntityEventHandler(mockDataManager);

    when(mockVehicle.getLocation()).thenReturn(mockLocation);
    when(mockCreature.getLocation()).thenReturn(mockLocation);
    when(mockDataManager.getChunkAt(mockLocation)).thenReturn(mockChunk);
    when(mockChunk.getOwnerName()).thenReturn("APlayer");
  }
コード例 #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");
  }
コード例 #3
0
  @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
  void onEntityDamage(EntityDamageEvent event) {
    Entity damagedEntity = event.getEntity();
    if (!(event instanceof EntityDamageByEntityEvent) || (damagedEntity instanceof Monster)) {
      return;
    }

    Player attacker = getAttackingPlayer(((EntityDamageByEntityEvent) event).getDamager());
    ChunkData chunk = dataStore.getChunkAt(event.getEntity().getLocation());

    revokeIfNotPermitted(attacker, chunk, event, "hurt creatures");
  }