我想检查放置的块在短暂延迟后是否仍然存在并执行命令
我已经尝试过睡眠,但它只是给了块,在那里之前的延迟
public class BlockListener implements Listener {
@EventHandler
public void check(BlockPlaceEvent e)
{
Material blockType = e.getBlockPlaced().getType();
int locationX = e.getBlockPlaced().getLocation().getBlockX();
int locationY = e.getBlockPlaced().getLocation().getBlockY();
int locationZ = e.getBlockPlaced().getLocation().getBlockZ();
String locationXb = String.valueOf(locationX);
String locationYb = String.valueOf(locationY);
String locationZb = String.valueOf(locationZ);
World world = e.getPlayer().getWorld();
if ((blockType == Material.PLAYER_HEAD) || (blockType == Material.PLAYER_WALL_HEAD))
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException ex)
{
}
Material block = world.getBlockAt(locationX, locationY, locationZ).getType();
if((block == Material.PLAYER_WALL_HEAD) || (block == Material.PLAYER_HEAD)){
//empty
}
else {
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
}
}
}
1条答案
按热度按时间qltillow1#
你应该Never在spigot上使用
Thread.sleep
方法。它会停止所有服务器。您需要使用Scheduler(Tutorial- Javadoc:
BukkitScheduler
):其中:
MyPlugin.getInstance()
用于获取JavaPlugin的示例,也称为plugin
变量。() -> {}
是将运行的内容20
是服务器应该等待的时间(以滴答为单位)。20滴答= 1秒。