gpt4 book ai didi

java - 我的世界 Bukkit 插件 : My minigame teleporter not working

转载 作者:太空宇宙 更新时间:2023-11-04 12:37:51 24 4
gpt4 key购买 nike

我正在尝试制作一个迷你游戏,所以当我希望玩家在倒计时后自动传送,但没有人传送时,我发出了一个命令来启动游戏并传送(有效),所以这是我的代码(这是冰岛服务器,所以变量名称是冰岛语和一些东西):

主类中的onEnable:

    public void onEnable() {
stada.setjaStodu(stada.Lobby);
nidurtalning.keyra = true;
new Thread(new nidurtalning()).start();
registerEvt();
getCmd();
for (Player p : Bukkit.getOnlinePlayers()) {
p.teleport(playerJoin.wait);
p.setGameMode(GameMode.ADVENTURE);
}

}

当倒计时变量为 0(klukka)时:

if(klukka == 0){
try{
Thread.sleep(500);
}catch(InterruptedException e){
e.printStackTrace();
Bukkit.shutdown();
}
for(Player p : Bukkit.getOnlinePlayers()){

p.playSound(p.getLocation(), "random.levelup", 100.0F, 1F);
byrja.teleportToGame(p);
}

stada.setjaStodu(stada.Leikur);
chat.tilkynna("Og þið megið byrja!", false);

keyra = false;
}

以及传送类:

public class byrja {


public static void teleportToGame(Player p){
World war = Bukkit.getWorld("Empty");
Location leikur = new Location(war, -416, 253, 175);
p.teleport(leikur);
}
}

最佳答案

使用从不

Thread.sleep();

因为它会暂停整个线程!即使您使用 asnc 调度程序,它仍然不好! (这会花费不必要的资源)

而是使用RunTaskLater调度程序

但是...你确定世界存在吗?`

总而言之,该功能应该可以工作!

类似这样的事情:

protected void endCountdown(int klukka) {
if (klukka == 0) {
Bukkit.getScheduler().runTaskLater(pl, new Runnable() {
@Override
public void run() {
Bukkit.getOnlinePlayers().stream().forEach(all -> {
all.playSound(all.getLocation(), Sound.LEVEL_UP, 100, 1);
teleportToGame(all);
});
// DO MORE STUFF IF NEEDED
}
}, 10);
}
}

private void teleportToGame(Player p) {
World war = Bukkit.getWorld("Empty");
Location loc = new Location(war, -416, 253, 175);
p.teleport(loc);
}

关于java - 我的世界 Bukkit 插件 : My minigame teleporter not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37125269/

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