示例#1
0
  /**
   * Method openMe.
   *
   * @param opener Player
   * @param autoClose boolean
   * @return boolean
   */
  public boolean openMe(Player opener, boolean autoClose) {
    _openLock.lock();

    try {
      if (!setOpen(true)) {
        return false;
      }

      setGeoOpen(true);
    } finally {
      _openLock.unlock();
    }
    broadcastStatusUpdate();

    if (autoClose && (getTemplate().getCloseTime() > 0)) {
      scheduleAutoAction(false, getTemplate().getCloseTime() * 1000L);
    }

    getAI().onEvtOpen(opener);

    for (Listener<Creature> l : getListeners().getListeners()) {
      if (l instanceof OnOpenCloseListener) {
        ((OnOpenCloseListener) l).onOpen(this);
      }
    }

    return true;
  }
示例#2
0
  /**
   * Method closeMe.
   *
   * @param closer Player
   * @param autoOpen boolean
   * @return boolean
   */
  public boolean closeMe(Player closer, boolean autoOpen) {
    if (isDead()) {
      return false;
    }

    _openLock.lock();

    try {
      if (!setOpen(false)) {
        return false;
      }

      setGeoOpen(false);
    } finally {
      _openLock.unlock();
    }
    broadcastStatusUpdate();

    if (autoOpen && (getTemplate().getOpenTime() > 0)) {
      long openDelay = getTemplate().getOpenTime() * 1000L;

      if (getTemplate().getRandomTime() > 0) {
        openDelay += Rnd.get(0, getTemplate().getRandomTime()) * 1000L;
      }

      scheduleAutoAction(true, openDelay);
    }

    getAI().onEvtClose(closer);

    for (Listener<Creature> l : getListeners().getListeners()) {
      if (l instanceof OnOpenCloseListener) {
        ((OnOpenCloseListener) l).onClose(this);
      }
    }

    return true;
  }