所以,我很难想出如何在发送用户消息之间做出延迟,如果我可以继续调用任务将是不同的字符串,那会很酷,并且它将这些字符串添加到字符串列表中当它到达时播放(在播放所有消息之后,以及之前的所有30tick中断)。
我无法使用Thread.sleep();
,这将停止整个插件:/
这是我正在使用的方法,但是我很难做到,并且无法想出让它正常工作的方法,非常感谢所有帮助:)
public static void speakBegin(final Player p){
final int messageNumber = 0;
String string1 = "Hey, user! this is message 1!";
//30 tick break
String string2 = "msg 2";
//30 tick break
String string3 = "msg 3";
//30 tick break
String string4 = "msg 4";
//30 tick break
String string5 = "msg 5";
//30 tick break
String string6 = "msg 6";
//30 tick break
String string7 = "msg 7";
//30 tick break
String string8 = "msg 8";
//30 tick break
String string9 = "msg 9";
//30 tick break
String string10 = "this is the final message, user!";
//30 tick break
final int id = plugin.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
public void run() {
//Send user string1, then wait 60 ticks and send string2, ect. ect.
/*
* eg:
* p.sendMessage(string + messageNumber);
*
* <-----I dont know how to do this bit so it plays string1,
* then wait, add int to messageNumber,
* then play string2 because 'string' + messageNumber would equal 'string2'
*
*/
//messageNumber++; ?
//after string10 is played call "plugin.getScheduler().cancelTasks(plugin);"
}
//this just waits 20ticks in beginning, then waits 60 tick between messages
}, 20L, 60L).getTaskId();
}
答案 0 :(得分:0)
Thread.sleep可能就是你想要的 http://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html