-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
api/src/main/java/de/oliver/fancynpcs/api/actions/types/PlaySoundAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters