Esempio n. 1
0
  public UHBorderManager(UHPlugin plugin) {
    this.p = plugin;
    this.i = p.getI18n();

    this.warningTimerName = i.t("borders.warning.nameTimer");

    this.currentBorderDiameter = p.getConfig().getInt("map.size");
    this.isCircularBorder = p.getConfig().getBoolean("map.circular");
  }
Esempio n. 2
0
  /**
   * Returns a list of the players outside a border with the given diameter. The check is performed
   * for a circular or squared border, following the configuration.
   *
   * @param diameter
   * @return
   */
  public HashSet<Player> getPlayersOutside(int diameter) {
    HashSet<Player> playersOutside = new HashSet<Player>();

    for (final Player player : p.getGameManager().getOnlineAlivePlayers()) {
      if (!isInsideBorder(player.getLocation(), diameter)) {
        playersOutside.add(player);
      }
    }

    return playersOutside;
  }
Esempio n. 3
0
  /**
   * Sets the size of the future border, used in the warning messages sent to the players out of
   * this future border.
   *
   * <p>This also starts the display of the warning messages, every 90 seconds by default
   * (configurable, see config.yml, map.border.warningInterval).
   *
   * <p>If timeLeft is not null, the time available for the players to go inside the future border
   * is displayed in the warning message.
   *
   * @param diameter
   * @param timeLeft The time available for the players to go inside the future border (minutes).
   */
  public void setWarningSize(int diameter, int timeLeft, CommandSender sender) {
    cancelWarning();

    this.warningSize = diameter;

    if (timeLeft != 0) {
      UHTimer timer = new UHTimer(this.warningTimerName);
      timer.setDuration(timeLeft * 60);

      p.getTimerManager().registerTimer(timer);

      timer.start();
    }

    if (sender != null) {
      this.warningSender = sender;
    }

    warningTask = new BorderWarningTask(p);
    warningTask.runTaskTimer(p, 20L, 20L * p.getConfig().getInt("map.border.warningInterval", 90));
  }
Esempio n. 4
0
  /** Stops the display of the warning messages. */
  public void cancelWarning() {
    if (warningTask != null) {
      try {
        warningTask.cancel();
      } catch (IllegalStateException e) {

      }
    }

    UHTimer timer = getWarningTimer();
    if (timer != null) {
      timer.stop();
      p.getTimerManager().unregisterTimer(timer);
    }
  }
Esempio n. 5
0
  /**
   * Changes the shape of the border.
   *
   * @param circular If true the border is circular. Else, squared.
   */
  public void setCircular(boolean circular) {
    this.isCircularBorder = circular;

    p.getWorldBorderIntegration().setupBorders(); // Updates the WB border if needed
  }
Esempio n. 6
0
  /**
   * Changes the current border diameter. This also reconfigures WorldBorder (if present).
   *
   * <p>If WorldBorder is installed, all players out of this new border will be teleported inside
   * the new one. Else, nothing will happens.
   *
   * @param diameter
   */
  public void setCurrentBorderDiameter(int diameter) {
    cancelWarning();
    this.currentBorderDiameter = diameter;

    p.getWorldBorderIntegration().setupBorders(); // Updates the WB border if needed
  }
Esempio n. 7
0
 /**
  * Returns the UHTimer object representing the countdown before the next border reduction.
  *
  * <p>Returns null if there isn't any countdown running currently.
  *
  * @return The timer.
  */
 public UHTimer getWarningTimer() {
   return p.getTimerManager().getTimer(this.warningTimerName);
 }