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

fix sound for the third time (on dev/feature this time) #7205

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions src/main/java/ch/njol/skript/expressions/ExprBlockSound.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ public Sound getSound(SoundGroup group) {
public abstract @Nullable Sound getSound(SoundGroup group);
}

private static final boolean SOUND_IS_INTERFACE;

static {
try {
Class<?> SOUND_CLASS = Class.forName("org.bukkit.Sound");
SOUND_IS_INTERFACE = SOUND_CLASS.isInterface();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
SimplePropertyExpression.register(ExprBlockSound.class, String.class, "(1:break|2:fall|3:hit|4:place|5:step) sound[s]", "blocks/blockdatas/itemtypes");
}

@SuppressWarnings("NotNullFieldNotInitialized")
private SoundType soundType;
@SuppressWarnings("NotNullFieldNotInitialized")
private Expression<?> objects;

@Override
Expand All @@ -92,11 +98,12 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

@Override
protected String @Nullable [] get(Event event) {
//noinspection rawtypes,deprecation
return objects.stream(event)
.map(this::convertAndGetSound)
.filter(Objects::nonNull)
.distinct()
.map(Sound::name)
.map(SOUND_IS_INTERFACE ? (sound -> sound.getKey().getKey()) : (sound -> ((Enum) sound).name()))
sovdeeth marked this conversation as resolved.
Show resolved Hide resolved
.toArray(String[]::new);
}

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprEntitySound.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,15 @@ public Sound getSound(LivingEntity entity, int height, ItemStack item, boolean b
{"[the] ambient sound[s] of %livingentities%", SoundType.AMBIENT},
{"%livingentities%'[s] ambient sound[s]", SoundType.AMBIENT}
});
private static final boolean SOUND_IS_INTERFACE;

static {
try {
Class<?> SOUND_CLASS = Class.forName("org.bukkit.Sound");
SOUND_IS_INTERFACE = SOUND_CLASS.isInterface();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
if (Skript.methodExists(LivingEntity.class, "getDeathSound"))
Skript.registerExpression(ExprEntitySound.class, String.class, ExpressionType.COMBINED, patterns.getPatterns());
}
Expand Down Expand Up @@ -146,11 +153,12 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
ItemStack defaultItem = new ItemStack(soundType == SoundType.EAT ? Material.COOKED_BEEF : Material.POTION);
ItemStack item = this.item == null ? defaultItem : this.item.getOptionalSingle(event).map(ItemType::getRandom).orElse(defaultItem);

//noinspection rawtypes,deprecation
return entities.stream(event)
.map(entity -> soundType.getSound(entity, height, item, bigOrSpeedy))
.filter(Objects::nonNull)
.distinct()
.map(Sound::name)
.map(SOUND_IS_INTERFACE ? (sound -> sound.getKey().getKey()) : (sound -> ((Enum) sound).name()))
.toArray(String[]::new);
}

Expand Down
Loading