I'm trying to use a Bukkit conversation, which already works, yet, when I use TimeUnit.SECONDS.sleep(integer-value)
, it works once, and then it fails with this error in console: java.lang.InterruptedException: sleep interrupted
When a prompt has been shown and the next is going to be shown the method acceptInput is called. In the first prompt it works all fine, in the other prompts, which are called out of this prompt (the prompt calls a new instance of itself). All works fine except the sleep part. Any ideas to fix this?
Here is my code:
package dbx12.Test1.Tutorial.Prompts;
import java.util.concurrent.TimeUnit;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
public class Text implements Prompt {
@Override
public Prompt acceptInput(ConversationContext context, String input) {
int thisPrompt = (int) context.getSessionData("step");
context.setSessionData("step", thisPrompt+1);
Player p = (Player) context.getForWhom();
boolean type;
try {
TimeUnit.SECONDS.sleep(dbx12.Test1.Utils.Prompt_List.delay.get(thisPrompt));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace(); //DEBUG
}
try {
type = dbx12.Test1.Utils.Prompt_List.promptType.get(thisPrompt+1);
} catch (Exception e) {
return new Finish();
}
if(dbx12.Test1.Utils.Prompt_List.hasLocation.get(thisPrompt+1) == true)
p.teleport(dbx12.Test1.Utils.Prompt_List.location.get(thisPrompt+1));
if(type==true)
{
System.out.println("return a text");
return new Text();
}
else
{
System.out.println("return a interaction");
return new Interaction();
}
}
@Override
public boolean blocksForInput(ConversationContext context) {
return false;
}
@Override
public String getPromptText(ConversationContext context) {
return dbx12.Test1.Utils.Prompt_List.promptText.get(context.getSessionData("step"));
}
}