Skip to content

Commit e8c6ba5

Browse files
authored
Expose JukeboxSong variables (#13214)
1 parent 5fd3c95 commit e8c6ba5

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

paper-api/src/main/java/org/bukkit/JukeboxSong.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.papermc.paper.registry.RegistryAccess;
44
import io.papermc.paper.registry.RegistryKey;
5+
import net.kyori.adventure.text.Component;
56
import org.jspecify.annotations.NullMarked;
67

78
/**
@@ -65,4 +66,32 @@ private static JukeboxSong get(String key) {
6566
@Override
6667
@Deprecated(forRemoval = true)
6768
String getTranslationKey();
69+
70+
/**
71+
* Gets the sound for this song.
72+
*
73+
* @return the sound
74+
*/
75+
Sound getSound();
76+
77+
/**
78+
* Gets the description for this song.
79+
*
80+
* @return the description
81+
*/
82+
Component getDescription();
83+
84+
/**
85+
* Gets the length in seconds for this song.
86+
*
87+
* @return the length in seconds
88+
*/
89+
float getLengthInSeconds();
90+
91+
/**
92+
* Gets the comparator output for this song.
93+
*
94+
* @return the comparator output
95+
*/
96+
int getComparatorOutput();
6897
}

paper-server/src/main/java/org/bukkit/craftbukkit/CraftJukeboxSong.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package org.bukkit.craftbukkit;
22

3+
import io.papermc.paper.adventure.PaperAdventure;
34
import io.papermc.paper.registry.HolderableBase;
5+
import net.kyori.adventure.text.Component;
46
import net.minecraft.core.Holder;
57
import net.minecraft.core.registries.Registries;
68
import net.minecraft.network.chat.contents.TranslatableContents;
79
import org.bukkit.JukeboxSong;
10+
import org.bukkit.Sound;
11+
import org.jspecify.annotations.NullMarked;
812

13+
@NullMarked
914
public class CraftJukeboxSong extends HolderableBase<net.minecraft.world.item.JukeboxSong> implements JukeboxSong {
1015

1116
public static JukeboxSong minecraftToBukkit(net.minecraft.world.item.JukeboxSong minecraft) {
@@ -33,4 +38,24 @@ public String getTranslationKey() {
3338
if (!(this.getHandle().description().getContents() instanceof TranslatableContents)) throw new UnsupportedOperationException("Description isn't translatable!"); // Paper
3439
return ((TranslatableContents) this.getHandle().description().getContents()).getKey();
3540
}
41+
42+
@Override
43+
public Sound getSound() {
44+
return CraftSound.minecraftHolderToBukkit(this.getHandle().soundEvent());
45+
}
46+
47+
@Override
48+
public Component getDescription() {
49+
return PaperAdventure.asAdventure(this.getHandle().description());
50+
}
51+
52+
@Override
53+
public float getLengthInSeconds() {
54+
return this.getHandle().lengthInSeconds();
55+
}
56+
57+
@Override
58+
public int getComparatorOutput() {
59+
return this.getHandle().comparatorOutput();
60+
}
3661
}

0 commit comments

Comments
 (0)