Skip to content

Commit

Permalink
支持播放音效提醒玩家
Browse files Browse the repository at this point in the history
  • Loading branch information
stevei5mc committed Jun 15, 2024
1 parent dc5f890 commit 2656c48
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/main/java/cn/stevei5mc/autorestart/AutoRestartPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import cn.nukkit.scheduler.Task;
import cn.nukkit.utils.Config;
import cn.nukkit.Player;
import cn.nukkit.level.Sound;
import cn.nukkit.network.protocol.PlaySoundPacket;

import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -45,6 +47,9 @@ public void onRun(int currentTick) {
if (config.getBoolean("show_tip")) {
player.sendTip(subtitle.replace("{seconds}",String.valueOf(timeLeft)));
}
if (config.getBoolean("play_sound")) {
playSound(player, Sound.RANDOM_TOAST, 1.0F);
}
}
}
// 如果时间到了,重启服务器
Expand All @@ -63,4 +68,20 @@ public void onRun(int currentTick) {
}
}, 20, true); // 每20tick运行一次 20tick=1s
}

/**
* 播放音效
* @author LYEmerald
* https://github.com/LYEmerald/Festival/blob/ae6ade65253859ac8cb03f85d5b8e6be4a09fc16/src/main/java/net/endlight/festival/utils/Utils.java#L42
*/
public static void playSound(Player player, Sound sound,Float pitch) {
PlaySoundPacket packet = new PlaySoundPacket();
packet.name = sound.getSound();
packet.volume = 1.0F;
packet.pitch = pitch;
packet.x = player.getFloorX();
packet.y = player.getFloorY();
packet.z = player.getFloorZ();
player.dataPacket(packet);
}
}
6 changes: 5 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ kick_player: true
#调试模式(开启后到时间只会给出相对应的提示并不会执行对应的操作)
debug: false
#一些显示的设置
#显示title(包括subtitle)
show_title: true
show_tip: true
#底部显示(在物品栏上方)
show_tip: true
#是否播放音效
play_sound: true

0 comments on commit 2656c48

Please sign in to comment.