Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve ResourceKeyInvalidException #2413

Merged
merged 9 commits into from
Sep 29, 2019
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions src/main/java/ch/njol/skript/effects/EffPlaySound.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
public class EffPlaySound extends Effect {

private static final boolean SOUND_CATEGORIES_EXIST = Skript.classExists("org.bukkit.SoundCategory");

private static final String SOUND_VALID_CHARACTERS = "[a-z0-9\\/._-]+"; // Minecraft only accepts these characters
Wealthyturtle marked this conversation as resolved.
Show resolved Hide resolved

static {
if (SOUND_CATEGORIES_EXIST) {
Skript.registerEffect(EffPlaySound.class,
Expand Down Expand Up @@ -157,41 +158,55 @@ protected void execute(Event e) {

private static void playSound(Player p, Location location, String[] sounds, SoundCategory category, float volume, float pitch) {
for (String sound : sounds) {
sound = sound.toLowerCase();
Sound soundEnum = null;
try {
soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException ignored) {}
if (SOUND_CATEGORIES_EXIST) {
if (soundEnum == null)
if (soundEnum == null) {
if (!sound.matches(SOUND_VALID_CHARACTERS))
continue;
p.playSound(location, sound, category, volume, pitch);
else
} else {
p.playSound(location, soundEnum, category, volume, pitch);
}
} else {
if (soundEnum == null)
if (soundEnum == null) {
if (!sound.matches(SOUND_VALID_CHARACTERS))
continue;
p.playSound(location, sound, volume, pitch);
else
} else {
p.playSound(location, soundEnum, volume, pitch);
}
}
}
}

private static void playSound(Location location, String[] sounds, SoundCategory category, float volume, float pitch) {
World w = location.getWorld();
for (String sound : sounds) {
sound = sound.toLowerCase();
Sound soundEnum = null;
try {
soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException ignored) {}
if (SOUND_CATEGORIES_EXIST) {
if (soundEnum == null)
if (soundEnum == null) {
if (!sound.matches(SOUND_VALID_CHARACTERS))
continue;
w.playSound(location, sound, category, volume, pitch);
else
} else {
w.playSound(location, soundEnum, category, volume, pitch);
}
} else {
if (soundEnum == null)
if (soundEnum == null) {
if (!sound.matches(SOUND_VALID_CHARACTERS))
continue;
w.playSound(location, sound, volume, pitch);
else
} else {
w.playSound(location, soundEnum, volume, pitch);
}
}
}
}
Expand Down