Skip to content

Commit

Permalink
Remove code duplication in jukebox song reading
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipseisoffline committed Oct 25, 2024
1 parent 221f15e commit cc6f77c
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions core/src/main/java/org/geysermc/geyser/level/JukeboxSong.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,13 @@
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.session.cache.registry.RegistryEntryContext;
import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.geyser.util.SoundUtils;

public record JukeboxSong(String soundEvent, String description) {

public static JukeboxSong read(RegistryEntryContext context) {
NbtMap data = context.data();
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 " + context.id() + " was of an unexpected type! Expected string or NBT map, got " + soundEventObject);
}
String soundEvent = SoundUtils.readSoundEvent(data, "jukebox song " + context.id());;
String description = MessageTranslator.deserializeDescription(context.session(), data);
return new JukeboxSong(soundEvent, description);
}
Expand Down

0 comments on commit cc6f77c

Please sign in to comment.