Bukkit
1.4.7-R1.0
Main Page
Related Pages
Classes
Files
File List
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
9
public
class
InactivityConversationCanceller
implements
ConversationCanceller
{
10
protected
Plugin
plugin
;
11
protected
int
timeoutSeconds
;
12
protected
Conversation
conversation
;
13
private
int
taskId = -1;
14
20
public
InactivityConversationCanceller
(
Plugin
plugin
,
int
timeoutSeconds
) {
21
this.plugin =
plugin
;
22
this.timeoutSeconds =
timeoutSeconds
;
23
}
24
25
public
void
setConversation
(
Conversation
conversation
) {
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
37
public
ConversationCanceller
clone
() {
38
return
new
InactivityConversationCanceller
(
plugin
,
timeoutSeconds
);
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
) {
50
cancelling
(
conversation
);
51
conversation
.
abandon
(
new
ConversationAbandonedEvent(
conversation
,
InactivityConversationCanceller
.this));
52
}
53
}
54
},
timeoutSeconds
* 20);
55
}
56
60
private
void
stopTimer() {
61
if
(taskId != -1) {
62
plugin
.
getServer
().
getScheduler
().
cancelTask
(taskId);
63
taskId = -1;
64
}
65
}
66
72
protected
void
cancelling
(
Conversation
conversation
) {
73
74
}
75
}
org
bukkit
conversations
InactivityConversationCanceller.java
Generated on Fri May 24 2013 17:16:40 for Bukkit by
1.8.2