Bukkit  1.4.7-R1.0
 All Classes Namespaces Files Functions Variables Enumerator Pages
InactivityConversationCanceller.java
Go to the documentation of this file.
1 package org.bukkit.conversations;
2 
3 import org.bukkit.Server;
4 import org.bukkit.plugin.Plugin;
5 
10  protected Plugin plugin;
11  protected int timeoutSeconds;
13  private int taskId = -1;
14 
21  this.plugin = plugin;
22  this.timeoutSeconds = timeoutSeconds;
23  }
24 
26  this.conversation = conversation;
27  startTimer();
28  }
29 
30  public boolean cancelBasedOnInput(ConversationContext context, String input) {
31  // Reset the inactivity timer
32  stopTimer();
33  startTimer();
34  return false;
35  }
36 
39  }
40 
44  private void startTimer() {
45  taskId = plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
46  public void run() {
47  if (conversation.getState() == Conversation.ConversationState.UNSTARTED) {
48  startTimer();
49  } else if (conversation.getState() == Conversation.ConversationState.STARTED) {
51  conversation.abandon(new ConversationAbandonedEvent(conversation, InactivityConversationCanceller.this));
52  }
53  }
54  }, timeoutSeconds * 20);
55  }
56 
60  private void stopTimer() {
61  if (taskId != -1) {
63  taskId = -1;
64  }
65  }
66 
73 
74  }
75 }