Skip to content

Commit

Permalink
Added #playSound methods for MCPlayers
Browse files Browse the repository at this point in the history
  • Loading branch information
xDec0de committed Oct 11, 2024
1 parent 1f3ade5 commit 8c249da
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package net.codersky.mcutils.spigot.player;

import net.codersky.mcutils.crossplatform.player.MCPlayer;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -57,6 +60,12 @@ public boolean sendActionBar(@NotNull Component message) {
return true;
}

@Override
public boolean playSound(@NotNull Sound sound) {
handle.playSound(handle.getLocation(), sound.name().asString(), sound.volume(), sound.pitch());
return true;
}

/*
* MessageReceiver implementation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.velocitypowered.api.proxy.Player;
import net.codersky.mcutils.crossplatform.player.MCPlayer;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,6 +54,14 @@ public boolean sendActionBar(@NotNull Component message) {
return true;
}

// Sound //

@Override
public boolean playSound(@NotNull Sound sound) {
handle.playSound(sound);
return true;
}

/*
* MessageReceiver implementation
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import net.codersky.mcutils.crossplatform.MessageReceiver;
import net.codersky.mcutils.java.strings.Replacement;
import net.codersky.mcutils.java.strings.Replacer;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -170,6 +173,28 @@ default boolean sendActionBar(@NotNull Component message, @NotNull Object... rep
return sendActionBar(message, new Replacer(replacements));
}

/*
* Sound
*/

boolean playSound(@NotNull Sound sound);

default boolean playSound(@KeyPattern @NotNull String key, @NotNull Sound.Source source, float volume, float pitch) {
return playSound(Sound.sound(Key.key(key), source, volume, pitch));
}

default boolean playSound(@KeyPattern @NotNull String key, float volume, float pitch) {
return playSound(key, Sound.Source.AMBIENT, volume, pitch);
}

default boolean playSound(@KeyPattern @NotNull String key, float volume) {
return playSound(key, volume, 1.0f);
}

default boolean playSound(@KeyPattern @NotNull String key) {
return playSound(key, 1.0f);
}

/*
* Replacement
*/
Expand Down

0 comments on commit 8c249da

Please sign in to comment.