Esempio n. 1
0
  /**
   * On entity damage by entity.
   *
   * @param event the events
   */
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {

    ApiPlayerConfEntry entry;
    ApiPlayerConfEntry entryVictim;

    // Check if a player break a ItemFrame
    Player player = getSourcePlayer(event.getDamager());

    if (player != null) {
      ApiDummyLand land =
          Secuboid.getThisPlugin().getLands().getLandOrOutsideArea(event.getEntity().getLocation());
      Entity entity = event.getEntity();

      // For PVP
      if (entity instanceof Player
          && (entry = playerConf.get(player)) != null
          && (entryVictim = playerConf.get((Player) entity)) != null
          && !isPvpValid(land, entry.getPlayerContainer(), entryVictim.getPlayerContainer())) {
        event.setCancelled(true);
      }
    }
  }
Esempio n. 2
0
  /**
   * Check when a player deposits fire and add it to list
   *
   * @param event the events
   * @param player the player
   */
  private void checkForPvpFire(BlockEvent event, Player player) {

    ApiPlayerConfEntry entry;

    if (player != null && (entry = playerConf.get(player)) != null) {

      Location loc = event.getBlock().getLocation();
      ApiDummyLand land = Secuboid.getThisPlugin().getLands().getLandOrOutsideArea(loc);

      if (land.getFlagAndInherit(FlagList.FULL_PVP.getFlagType()).getValueBoolean() == false
          || land.getFlagAndInherit(FlagList.FULL_PVP.getFlagType()).getValueBoolean() == false) {

        // Add fire for pvp listen
        playerFireLocation.put(loc, entry.getPlayerContainer());
      }
    }
  }
Esempio n. 3
0
  /**
   * On entity damage.
   *
   * @param event the events
   */
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onEntityDamage(EntityDamageEvent event) {

    // Check for fire cancel
    if (event.getEntity() instanceof Player
        && (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK)) {

      Player player = (Player) event.getEntity();
      ApiPlayerConfEntry entry = playerConf.get(player);

      if (entry != null) {
        Location loc = player.getLocation();
        ApiDummyLand land = Secuboid.getThisPlugin().getLands().getLandOrOutsideArea(loc);

        // Check for fire near the player
        for (Map.Entry<Location, ApiPlayerContainerPlayer> fireEntry :
            playerFireLocation.entrySet()) {

          if (loc.getWorld() == fireEntry.getKey().getWorld()
              && loc.distanceSquared(fireEntry.getKey()) < 5) {
            Block block = loc.getBlock();
            if ((block.getType() == Material.FIRE || block.getType() == Material.AIR)
                && !isPvpValid(land, fireEntry.getValue(), entry.getPlayerContainer())) {

              // remove fire
              Secuboid.getThisPlugin()
                  .getLog()
                  .write(
                      "Anti-pvp from "
                          + entry.getPlayerContainer().getPlayer().getName()
                          + " to "
                          + player.getName());
              block.setType(Material.AIR);
              player.setFireTicks(0);
              event.setDamage(0);
              event.setCancelled(true);
            }
          }
        }
      }
    }
  }