已解决 - 命令中的定时器 - Minecraft Plugins

问题描述 投票:-3回答:1

我正试图在我的插件中添加一个定时器降温功能,我希望像他们运行一个命令时说请不要移动3s,然后如果他们不移动,就会传送他们,但如果他们移动,就会取消并重置定时器。我想成为像当他们运行的命令是说,请不要移动3s,然后如果他们不动,它会传送他们,但如果他们做移动,它会取消和重置定时器。谢谢你的帮助

plugins minecraft bukkit
1个回答
0
投票

有多种方法来检查这个。例如,你可以从 Bukkit 的内置调度器中启动一个延迟任务,并在那里验证位置。或者你可以在某个地方为用户设置一个标志,然后在 playerMove 事件中进行检查。

如果你决定使用第一个选项,你会希望使用Bukkit的内部调度器。https:/bukkit.gamepedia.comScheduler_Programming.

// proudly stolen from here:
// https://bukkit.org/threads/making-a-countdown-timer.97071/#post-1312737

this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
  public void run() {
      // Your check if the player actually has moved
      // Your teleport logic
  }
}, 60L); // 60 L == 3 sec, 20 ticks == 1 sec
© www.soinside.com 2019 - 2024. All rights reserved.