diff --git a/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java b/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java index 333fd786..436743f5 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java +++ b/bukkit/src/main/java/net/william278/huskhomes/player/BukkitPlayer.java @@ -110,6 +110,11 @@ public class BukkitPlayer extends OnlineUser { player.spigot().sendMessage(new TranslatableComponent(translationKey)); } + @Override + public void playSound(@NotNull String soundEffect) { + player.playSound(player.getLocation(), soundEffect, 1, 1); + } + @Override public CompletableFuture teleport(@NotNull Location location, boolean asynchronous) { return CompletableFuture.supplyAsync(() -> { diff --git a/common/src/main/java/net/william278/huskhomes/config/Settings.java b/common/src/main/java/net/william278/huskhomes/config/Settings.java index 97e6a57c..0f929bb2 100644 --- a/common/src/main/java/net/william278/huskhomes/config/Settings.java +++ b/common/src/main/java/net/william278/huskhomes/config/Settings.java @@ -129,6 +129,9 @@ public class Settings { ); public Optional getSoundEffect(@NotNull SoundEffectAction action) { + if (!playSoundEffects) { + return Optional.empty(); + } return Optional.ofNullable(soundEffects.get(action.name().toLowerCase())); } @@ -271,9 +274,9 @@ public class Settings { * Represents the sound effect to play when an action happens */ public enum SoundEffectAction { - TELEPORTATION_COMPLETE("entity_enderman_teleport"), - TELEPORTATION_WARMUP("block_note_block_banjo"), - TELEPORTATION_CANCELLED("entity_item_break"); + TELEPORTATION_COMPLETE("entity.enderman.teleport"), + TELEPORTATION_WARMUP("block.note_block.banjo"), + TELEPORTATION_CANCELLED("entity.item.break"); private final String defaultSoundEffect; SoundEffectAction(@NotNull String defaultSoundEffect) { diff --git a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java index a8a1555f..ad2b055b 100644 --- a/common/src/main/java/net/william278/huskhomes/listener/EventListener.java +++ b/common/src/main/java/net/william278/huskhomes/listener/EventListener.java @@ -2,6 +2,7 @@ package net.william278.huskhomes.listener; import de.themoep.minedown.MineDown; import net.william278.huskhomes.HuskHomes; +import net.william278.huskhomes.config.Settings; import net.william278.huskhomes.player.OnlineUser; import net.william278.huskhomes.position.Position; import net.william278.huskhomes.teleport.TeleportType; @@ -71,6 +72,8 @@ public class EventListener { } else { plugin.getLocales().getLocale("teleporting_complete") .ifPresent(onlineUser::sendMessage); + plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_COMPLETE) + .ifPresent(onlineUser::playSound); } }).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null)) .join(); diff --git a/common/src/main/java/net/william278/huskhomes/player/OnlineUser.java b/common/src/main/java/net/william278/huskhomes/player/OnlineUser.java index 2ae749a4..c6b5e1f0 100644 --- a/common/src/main/java/net/william278/huskhomes/player/OnlineUser.java +++ b/common/src/main/java/net/william278/huskhomes/player/OnlineUser.java @@ -82,6 +82,13 @@ public abstract class OnlineUser extends User { */ public abstract void sendMinecraftMessage(@NotNull String translationKey); + /** + * Play the specified sound to this player + * + * @param soundEffect the sound effect to play. If the sound name is invalid, the sound will not play + */ + public abstract void playSound(@NotNull String soundEffect); + /** * Teleport a player to the specified {@link Location} * diff --git a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java index 576275a0..49ee7a1a 100644 --- a/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java +++ b/common/src/main/java/net/william278/huskhomes/teleport/TeleportManager.java @@ -290,8 +290,13 @@ public class TeleportManager { .ifPresent(onlineUser::sendMessage); } - // Handle economy actions + // If the result was successful if (teleportResult.successful) { + // Play sound + plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_COMPLETE) + .ifPresent(onlineUser::playSound); + + // Handle economy actions for (final Settings.EconomyAction action : economyActions) { plugin.performEconomyTransaction(onlineUser, action); } @@ -371,6 +376,8 @@ public class TeleportManager { executor.scheduleAtFixedRate(() -> { // Display countdown action bar message if (teleport.timeLeft > 0) { + plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_WARMUP) + .ifPresent(sound -> teleport.getPlayer().playSound(sound)); plugin.getLocales().getLocale("teleporting_action_bar_countdown", Integer.toString(teleport.timeLeft)) .ifPresent(message -> { switch (plugin.getSettings().teleportWarmupDisplay) { @@ -425,6 +432,8 @@ public class TeleportManager { teleport.getPlayer().sendMessage(locale)); plugin.getLocales().getLocale("teleporting_action_bar_cancelled").ifPresent(locale -> teleport.getPlayer().sendActionBar(locale)); + plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_CANCELLED) + .ifPresent(sound -> teleport.getPlayer().playSound(sound)); teleport.cancelled = true; return Optional.of(teleport); } @@ -435,6 +444,8 @@ public class TeleportManager { teleport.getPlayer().sendMessage(locale)); plugin.getLocales().getLocale("teleporting_action_bar_cancelled").ifPresent(locale -> teleport.getPlayer().sendActionBar(locale)); + plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_CANCELLED) + .ifPresent(sound -> teleport.getPlayer().playSound(sound)); teleport.cancelled = true; return Optional.of(teleport); }