Skip to content

Commit

Permalink
Add play_sound action (#209)
Browse files Browse the repository at this point in the history
* Add play_sound action

* fix
  • Loading branch information
OliverSchlueter authored Dec 16, 2024
1 parent 1fc12a4 commit 4ccd3ed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.oliver.fancynpcs.api.actions.types;

import de.oliver.fancynpcs.api.FancyNpcsPlugin;
import de.oliver.fancynpcs.api.actions.NpcAction;
import de.oliver.fancynpcs.api.actions.executor.ActionExecutionContext;
import org.jetbrains.annotations.NotNull;
import org.lushplugins.chatcolorhandler.ChatColorHandler;
import org.lushplugins.chatcolorhandler.parsers.ParserTypes;

public class PlaySoundAction extends NpcAction {

public PlaySoundAction() {
super("play_sound", true);
}

@Override
public void execute(@NotNull ActionExecutionContext context, String value) {
if (value == null || value.isEmpty()) {
return;
}

if (context.getPlayer() == null) {
return;
}

String sound = ChatColorHandler.translate(value, context.getPlayer(), ParserTypes.placeholder());

FancyNpcsPlugin.get().getScheduler().runTask(
context.getPlayer().getLocation(),
() -> {
try {
context.getPlayer().playSound(context.getPlayer().getLocation(), value, 1.0F, 1.0F);
} catch (Exception e) {
FancyNpcsPlugin.get().getFancyLogger().warn("Failed to play sound: " + sound);
}
});
}
}
1 change: 1 addition & 0 deletions src/main/java/de/oliver/fancynpcs/FancyNpcs.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public void onEnable() {
actionManager.registerAction(new ExecuteRandomActionAction());
actionManager.registerAction(new BlockUntilDoneAction());
actionManager.registerAction(new NeedPermissionAction());
actionManager.registerAction(new PlaySoundAction());

skinCache = new SkinCacheYaml();
skinCache.loadAndInsertToSkinFetcher();
Expand Down

0 comments on commit 4ccd3ed

Please sign in to comment.