Example #1
0
  /**
   * Clears mobs which count towards the players limit
   *
   * @param player
   */
  public void removeMobs(Player player) {
    PlayerMobCounter limiter = playerMobs.remove(player.getName());

    if (limiter != null && cfg.removePlayersMobOnDisconnect) limiter.killAll();

    groupedPlayerMobs.remove(player.getName());
  }
Example #2
0
  /**
   * Adds the placeholder to spawn limits to prepare for spawning a mob
   *
   * @param player The player involved
   * @param mob The mob config used to create the entity
   * @param mobRef The entity to add
   * @return True if the mob is allowed to spawn
   */
  public boolean addSpawnedMob(Player player, Mob mob, MobReference mobRef) {
    if (!mobRef.isValid()) return false;

    // Fetch the players mob list
    PlayerMobCounter limiter = playerMobs.get(player.getName());

    // If the limiter doesn't exist create it
    if (limiter == null) playerMobs.put(player.getName(), limiter = new PlayerMobCounter(player));

    // Track the entity
    if (!limiter.add(mobRef)) return false;

    // Check for grouped limiters
    if (mob.playerLimitGroup.length() > 0) {
      HashMap<String, PlayerMobCounter> playerLimiters = groupedPlayerMobs.get(player.getName());

      if (playerLimiters == null)
        groupedPlayerMobs.put(
            player.getName(), playerLimiters = new HashMap<String, PlayerMobCounter>());

      synchronized (playerLimiters) {
        PlayerMobCounter groupedLimiter = playerLimiters.get(mob.playerLimitGroup);

        if (groupedLimiter == null)
          playerLimiters.put(mob.playerLimitGroup, groupedLimiter = new PlayerMobCounter(player));

        if (!groupedLimiter.add(mobRef)) return false;
      }
    }
    return true;
  }
Example #3
0
  public boolean withinGroupedLimit(Player player, Region region, Mob mob) {
    if (mob.playerLimitGroup.length() <= 0) return true;

    int limit = region.getPlayerGroupMobLimit(mob.playerLimitGroup);

    if (limit <= 0) return true;

    HashMap<String, PlayerMobCounter> playerLimiters = groupedPlayerMobs.get(player.getName());

    if (playerLimiters == null) return true;

    synchronized (playerLimiters) {
      PlayerMobCounter limiter = playerLimiters.get(mob.playerLimitGroup);
      return limiter != null ? limiter.withinLimit(limit, region.playerMobCooldown) : true;
    }
  }
Example #4
0
  /**
   * Fetches the number of mobs which the player has spawned
   *
   * @param player The player involved
   * @param mobLimitTimeout The timeout for when a mob is removed
   * @return The number of mobs which the player has spawned
   */
  public int getMobCount(Player player, int mobLimitTimeout) {
    PlayerMobCounter limiter = playerMobs.get(player.getName());

    return limiter != null ? limiter.getMobCount() : 0;
  }