mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Fix /playsound command by stripping only the Minecraft namespace (#3956)
Fixes https://github.com/GeyserMC/Geyser/issues/3953
This commit is contained in:
parent
966270d3c8
commit
b17191b553
1 changed files with 13 additions and 13 deletions
|
@ -65,20 +65,20 @@ public final class SoundUtils {
|
|||
* @return a Bedrock sound
|
||||
*/
|
||||
public static String translatePlaySound(String javaIdentifier) {
|
||||
SoundMapping soundMapping = Registries.SOUNDS.get(trim(javaIdentifier));
|
||||
String soundIdentifier = removeMinecraftNamespace(javaIdentifier);
|
||||
SoundMapping soundMapping = Registries.SOUNDS.get(soundIdentifier);
|
||||
if (soundMapping == null || soundMapping.getPlaysound() == null) {
|
||||
// no mapping
|
||||
GeyserImpl.getInstance().getLogger().debug("[PlaySound] Defaulting to sound server gave us for " + javaIdentifier);
|
||||
return javaIdentifier;
|
||||
return soundIdentifier;
|
||||
}
|
||||
return soundMapping.getPlaysound();
|
||||
}
|
||||
|
||||
private static String trim(String identifier) {
|
||||
// Drop any namespace if applicable
|
||||
int i = identifier.indexOf(':');
|
||||
if (i >= 0) {
|
||||
return identifier.substring(i + 1);
|
||||
private static String removeMinecraftNamespace(String identifier) {
|
||||
// Drop any minecraft namespace if applicable
|
||||
if (identifier.startsWith("minecraft:")) {
|
||||
return identifier.substring("minecraft:".length());
|
||||
}
|
||||
return identifier;
|
||||
}
|
||||
|
@ -101,12 +101,12 @@ public final class SoundUtils {
|
|||
* @param pitch the pitch
|
||||
*/
|
||||
public static void playSound(GeyserSession session, Sound javaSound, Vector3f position, float volume, float pitch) {
|
||||
String packetSound = javaSound.getName();
|
||||
String soundIdentifier = removeMinecraftNamespace(javaSound.getName());
|
||||
|
||||
SoundMapping soundMapping = Registries.SOUNDS.get(packetSound);
|
||||
SoundMapping soundMapping = Registries.SOUNDS.get(soundIdentifier);
|
||||
if (soundMapping == null) {
|
||||
session.getGeyser().getLogger().debug("[Builtin] Sound mapping for " + packetSound + " not found; assuming custom.");
|
||||
playSound(session, packetSound, position, volume, pitch);
|
||||
session.getGeyser().getLogger().debug("[Builtin] Sound mapping for " + soundIdentifier + " not found; assuming custom.");
|
||||
playSound(session, soundIdentifier, position, volume, pitch);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -128,10 +128,10 @@ public final class SoundUtils {
|
|||
LevelSoundEventPacket soundPacket = new LevelSoundEventPacket();
|
||||
SoundEvent sound = SoundUtils.toSoundEvent(soundMapping.getBedrock());
|
||||
if (sound == null) {
|
||||
sound = SoundUtils.toSoundEvent(packetSound);
|
||||
sound = SoundUtils.toSoundEvent(soundIdentifier);
|
||||
}
|
||||
if (sound == null) {
|
||||
session.getGeyser().getLogger().debug("[Builtin] Sound for original '" + packetSound + "' to mappings '" + soundMapping.getBedrock()
|
||||
session.getGeyser().getLogger().debug("[Builtin] Sound for original '" + soundIdentifier + "' to mappings '" + soundMapping.getBedrock()
|
||||
+ "' was not a playable level sound, or has yet to be mapped to an enum in SoundEvent.");
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue