Skip to content

Commit

Permalink
Resolve ResourceKeyInvalidException (#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wealthyturtle authored and FranKusmiruk committed Sep 29, 2019
1 parent 9914e43 commit 177681c
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/main/java/ch/njol/skript/effects/EffPlaySound.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package ch.njol.skript.effects;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.bukkit.Location;
import org.bukkit.Sound;
Expand Down Expand Up @@ -55,7 +57,8 @@
public class EffPlaySound extends Effect {

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

private static final Pattern SOUND_VALID_PATTERN = Pattern.compile("[a-z0-9\\/._-]+"); // Minecraft only accepts these characters

static {
if (SOUND_CATEGORIES_EXIST) {
Skript.registerEffect(EffPlaySound.class,
Expand Down Expand Up @@ -162,15 +165,23 @@ private static void playSound(Player p, Location location, String[] sounds, Soun
soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException ignored) {}
if (SOUND_CATEGORIES_EXIST) {
if (soundEnum == null)
if (soundEnum == null) {
sound = sound.toLowerCase(Locale.ENGLISH);
if (!SOUND_VALID_PATTERN.matcher(sound).matches())
continue;
p.playSound(location, sound, category, volume, pitch);
else
} else {
p.playSound(location, soundEnum, category, volume, pitch);
}
} else {
if (soundEnum == null)
if (soundEnum == null) {
sound = sound.toLowerCase(Locale.ENGLISH);
if (!SOUND_VALID_PATTERN.matcher(sound).matches())
continue;
p.playSound(location, sound, volume, pitch);
else
} else {
p.playSound(location, soundEnum, volume, pitch);
}
}
}
}
Expand All @@ -183,15 +194,23 @@ private static void playSound(Location location, String[] sounds, SoundCategory
soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException ignored) {}
if (SOUND_CATEGORIES_EXIST) {
if (soundEnum == null)
if (soundEnum == null) {
sound = sound.toLowerCase(Locale.ENGLISH);
if (!SOUND_VALID_PATTERN.matcher(sound).matches())
continue;
w.playSound(location, sound, category, volume, pitch);
else
} else {
w.playSound(location, soundEnum, category, volume, pitch);
}
} else {
if (soundEnum == null)
if (soundEnum == null) {
sound = sound.toLowerCase(Locale.ENGLISH);
if (!SOUND_VALID_PATTERN.matcher(sound).matches())
continue;
w.playSound(location, sound, volume, pitch);
else
} else {
w.playSound(location, soundEnum, volume, pitch);
}
}
}
}
Expand Down

0 comments on commit 177681c

Please sign in to comment.