[英]Clear dropped items every 5 minutes
I am coding a Spigot 1.8.9 plugin and am trying to clear drops every 5 minutes but before the items are cleared I want to give a 60, 30, 15, 10, 5, 3, 2, 1 second warning then have them cleared. 我正在编写Spigot 1.8.9插件,并尝试每5分钟清除一次删除,但是在清除项目之前,我想给出60、30、15、10、5、3、2、1秒的警告,然后将其清除。
I tried using the following but it doesn't have the countdown warning. 我尝试使用以下内容,但没有倒数警告。
public static void startDropTimer() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(MyPlugin.getPlugin(), new Runnable() {
@Override
public void run() {
clearAllDrops();
}
}, 6000, 6000);
}
How can I implement the warning countdown before clearing the drops? 如何在清除滴剂之前实施警告倒计时?
You can create a timer
variable to store passed time 您可以创建一个timer
变量来存储经过的时间
long remainingTimeInSeconds = 300; //5 minutes
Then update your task to reduce this timer every 20 ticks (20 ticks = 1 second in Bukkit). 然后更新您的任务,以减少每20滴答声的计时器(在Bukkit中20滴答声= 1秒)。 With the update task, make checks on your timer variable to verify if a message should be sent or if the drops should be cleared: 使用update任务,检查您的timer变量,以验证是否应该发送消息或是否应该清除丢弃:
Bukkit.getScheduler().scheduleSyncRepeatingTask(MyPlugin.getPlugin(), new Runnable() {
@Override
public void run() {
currentTimeInSeconds--;
switch(remainingTimeInSeconds) {
case 60:
case 30:
case 15:
case 10:
case 5:
case 3:
case 2:
case 1:
//Send message remainingTimeInSeconds seconds left until drops are cleared!
break;
case 0:
clearAllDrops();
remainingTimeInSeconds = 300; //Reset your timer
break;
}
}
}, 20L, 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.