fix: more SongPlayer fixes

This commit is contained in:
Chayapak Supasakul 2025-10-19 14:29:17 +07:00
parent 7675aae619
commit d579f8bff8
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA

View file

@ -14,6 +14,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import java.io.File; import java.io.File;
@ -50,6 +51,7 @@ public class SongPlayer {
} }
// TODO: Less duplicate code // TODO: Less duplicate code
// TODO: Reduce the mess
public void loadSong (final Path location) { public void loadSong (final Path location) {
final ClientPlayerEntity player = client.player; final ClientPlayerEntity player = client.player;
@ -108,10 +110,12 @@ public class SongPlayer {
if (loaderThread != null && !loaderThread.isAlive() && client.player != null) { if (loaderThread != null && !loaderThread.isAlive() && client.player != null) {
if (loaderThread.exception != null) { if (loaderThread.exception != null) {
client.execute(() -> client.player.sendMessage(Component.translatable("Failed to load song: %s", Component.text(loaderThread.exception.message.getString())).color(NamedTextColor.RED))); final Text exceptionMessage = loaderThread.exception.message;
client.execute(() -> client.player.sendMessage(Component.translatable("Failed to load song: %s", Component.text(exceptionMessage.getString())).color(NamedTextColor.RED)));
} else { } else {
songQueue.add(loaderThread.song); songQueue.add(loaderThread.song);
client.execute(() -> client.player.sendMessage(Component.translatable("Added %s to the song queue", Component.empty().append(loaderThread.song.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN))); final Component name = loaderThread.song.name;
client.execute(() -> client.player.sendMessage(Component.translatable("Added %s to the song queue", Component.empty().append(name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)));
} }
loaderThread = null; loaderThread = null;
} }