Skip to content

Commit

Permalink
Fix reading custom jukebox songs (GeyserMC#4757)
Browse files Browse the repository at this point in the history
* Read sound event objects properly in jukebox song

* Add debug log for unexpected sound event type
  • Loading branch information
eclipseisoffline authored Jun 16, 2024
1 parent 1efb633 commit 63a3da7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/java/org/geysermc/geyser/level/JukeboxSong.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@
package org.geysermc.geyser.level;

import org.cloudburstmc.nbt.NbtMap;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.mcprotocollib.protocol.data.game.RegistryEntry;

public record JukeboxSong(String soundEvent, String description) {

public static JukeboxSong read(RegistryEntry entry) {
NbtMap data = entry.getData();
String soundEvent = data.getString("sound_event");
Object soundEventObject = data.get("sound_event");
String soundEvent;
if (soundEventObject instanceof NbtMap map) {
soundEvent = map.getString("sound_id");
} else if (soundEventObject instanceof String string) {
soundEvent = string;
} else {
soundEvent = "";
GeyserImpl.getInstance().getLogger().debug("Sound event for " + entry.getId() + " was of an unexpected type! Expected string or NBT map, got " + soundEventObject);
}
String description = MessageTranslator.deserializeDescription(data);
return new JukeboxSong(soundEvent, description);
}
Expand Down

0 comments on commit 63a3da7

Please sign in to comment.