Пример #1
0
 protected boolean unregisterTask(@Nonnull CommonTask commonTask) {
   boolean removed = this.tasks.remove(commonTask);
   if (removed && this.state.equals(State.ACTIVE)) {
     commonTask.stop();
   }
   return removed;
 }
Пример #2
0
 protected boolean registerTask(@Nonnull CommonTask commonTask) {
   boolean added = this.tasks.add(commonTask);
   if (added && this.state.equals(State.ACTIVE)) {
     commonTask.start();
   }
   return added;
 }
Пример #3
0
 @Override
 public boolean setState(@Nonnull State state) throws UnsupportedOperationException {
   Preconditions.checkNotNull(state, "state cannot be null.");
   boolean change = this.state.isIdle() != state.isIdle();
   this.state = state;
   if (change) {
     for (CommonTask task : this.tasks) {
       task.setState(state);
     }
     if (state.equals(State.ACTIVE)) {
       for (Listener listener : this.listeners) {
         this.plugin.registerEvents(listener);
       }
     } else if (state.equals(State.STOPPED)) {
       for (Listener listener : this.listeners) {
         this.plugin.unregisterEvents(listener);
       }
     }
   }
   return change;
 }