gpt4 book ai didi

java暂停脚本的替代方法

转载 作者:行者123 更新时间:2023-12-01 18:44:28 27 4
gpt4 key购买 nike

好的,我正在制作一个 Minecraft Java 插件,它使用触发的预设声音向播放器播放歌曲:
player.playSound(player.getLocation(), Sound.NOTE_BASS, 2, 10);

我希望它能够唱出歌词,例如锤子时间,所以它看起来像这样:

Bukkit.broadcastMessage(ChatColor.DARK_PURPLE +"[Server]" +ChatColor.AQUA + "Na Na Na Na, Na Na");
player.playSound(player.getLocation(), Sound.NOTE_BASS, 1, 10);
player.playSound(player.getLocation(), Sound.NOTE_BASS, 2, 10);
player.playSound(player.getLocation(), Sound.NOTE_BASS, 3, 10);
player.playSound(player.getLocation(), Sound.NOTE_BASS, 4, 10);
player.playSound(player.getLocation(), Sound.NOTE_BASS, 1, 10);
//a sleep statement here

等等......所以我不想使用 Thread.sleep(100)wait() 因为它们需要我使用 try, catch 语句女巫不起作用,因为我需要它作为一个大脚本,我在脚本中没有一堆 try catch 。所以我想我问还有其他方法可以做到这一点吗?

最佳答案

您可以妥协并使用一个try-catch:

try {
player.playSound(...);
Thread.sleep(100);
player.playSound(...);
Thread.sleep(100);
/* etc */
} catch (InterruptedException e) {
e.printStackTrace();
// handle exception
}

关于java暂停脚本的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18424548/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com