mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +00:00
Add sound effects
This commit is contained in:
1 parent
7b1930e554
commit
7d4dc6f11d
5 files changed
+33
-4
No files matched your search
@@ -110,6 +110,11 @@ public class BukkitPlayer extends OnlineUser {
|
|||||||
player.spigot().sendMessage(new TranslatableComponent(translationKey));
|
player.spigot().sendMessage(new TranslatableComponent(translationKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playSound(@NotNull String soundEffect) {
|
||||||
|
player.playSound(player.getLocation(), soundEffect, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<TeleportResult> teleport(@NotNull Location location, boolean asynchronous) {
|
public CompletableFuture<TeleportResult> teleport(@NotNull Location location, boolean asynchronous) {
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
|||||||
@@ -129,6 +129,9 @@ public class Settings {
|
|||||||
);
|
);
|
||||||
|
|
||||||
public Optional<String> getSoundEffect(@NotNull SoundEffectAction action) {
|
public Optional<String> getSoundEffect(@NotNull SoundEffectAction action) {
|
||||||
|
if (!playSoundEffects) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
return Optional.ofNullable(soundEffects.get(action.name().toLowerCase()));
|
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
|
* Represents the sound effect to play when an action happens
|
||||||
*/
|
*/
|
||||||
public enum SoundEffectAction {
|
public enum SoundEffectAction {
|
||||||
TELEPORTATION_COMPLETE("entity_enderman_teleport"),
|
TELEPORTATION_COMPLETE("entity.enderman.teleport"),
|
||||||
TELEPORTATION_WARMUP("block_note_block_banjo"),
|
TELEPORTATION_WARMUP("block.note_block.banjo"),
|
||||||
TELEPORTATION_CANCELLED("entity_item_break");
|
TELEPORTATION_CANCELLED("entity.item.break");
|
||||||
private final String defaultSoundEffect;
|
private final String defaultSoundEffect;
|
||||||
|
|
||||||
SoundEffectAction(@NotNull String defaultSoundEffect) {
|
SoundEffectAction(@NotNull String defaultSoundEffect) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.william278.huskhomes.listener;
|
|||||||
|
|
||||||
import de.themoep.minedown.MineDown;
|
import de.themoep.minedown.MineDown;
|
||||||
import net.william278.huskhomes.HuskHomes;
|
import net.william278.huskhomes.HuskHomes;
|
||||||
|
import net.william278.huskhomes.config.Settings;
|
||||||
import net.william278.huskhomes.player.OnlineUser;
|
import net.william278.huskhomes.player.OnlineUser;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.teleport.TeleportType;
|
import net.william278.huskhomes.teleport.TeleportType;
|
||||||
@@ -71,6 +72,8 @@ public class EventListener {
|
|||||||
} else {
|
} else {
|
||||||
plugin.getLocales().getLocale("teleporting_complete")
|
plugin.getLocales().getLocale("teleporting_complete")
|
||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
|
plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_COMPLETE)
|
||||||
|
.ifPresent(onlineUser::playSound);
|
||||||
}
|
}
|
||||||
}).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null))
|
}).thenRun(() -> plugin.getDatabase().setCurrentTeleport(onlineUser, null))
|
||||||
.join();
|
.join();
|
||||||
|
|||||||
@@ -82,6 +82,13 @@ public abstract class OnlineUser extends User {
|
|||||||
*/
|
*/
|
||||||
public abstract void sendMinecraftMessage(@NotNull String translationKey);
|
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}
|
* Teleport a player to the specified {@link Location}
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -290,8 +290,13 @@ public class TeleportManager {
|
|||||||
.ifPresent(onlineUser::sendMessage);
|
.ifPresent(onlineUser::sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle economy actions
|
// If the result was successful
|
||||||
if (teleportResult.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) {
|
for (final Settings.EconomyAction action : economyActions) {
|
||||||
plugin.performEconomyTransaction(onlineUser, action);
|
plugin.performEconomyTransaction(onlineUser, action);
|
||||||
}
|
}
|
||||||
@@ -371,6 +376,8 @@ public class TeleportManager {
|
|||||||
executor.scheduleAtFixedRate(() -> {
|
executor.scheduleAtFixedRate(() -> {
|
||||||
// Display countdown action bar message
|
// Display countdown action bar message
|
||||||
if (teleport.timeLeft > 0) {
|
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))
|
plugin.getLocales().getLocale("teleporting_action_bar_countdown", Integer.toString(teleport.timeLeft))
|
||||||
.ifPresent(message -> {
|
.ifPresent(message -> {
|
||||||
switch (plugin.getSettings().teleportWarmupDisplay) {
|
switch (plugin.getSettings().teleportWarmupDisplay) {
|
||||||
@@ -425,6 +432,8 @@ public class TeleportManager {
|
|||||||
teleport.getPlayer().sendMessage(locale));
|
teleport.getPlayer().sendMessage(locale));
|
||||||
plugin.getLocales().getLocale("teleporting_action_bar_cancelled").ifPresent(locale ->
|
plugin.getLocales().getLocale("teleporting_action_bar_cancelled").ifPresent(locale ->
|
||||||
teleport.getPlayer().sendActionBar(locale));
|
teleport.getPlayer().sendActionBar(locale));
|
||||||
|
plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_CANCELLED)
|
||||||
|
.ifPresent(sound -> teleport.getPlayer().playSound(sound));
|
||||||
teleport.cancelled = true;
|
teleport.cancelled = true;
|
||||||
return Optional.of(teleport);
|
return Optional.of(teleport);
|
||||||
}
|
}
|
||||||
@@ -435,6 +444,8 @@ public class TeleportManager {
|
|||||||
teleport.getPlayer().sendMessage(locale));
|
teleport.getPlayer().sendMessage(locale));
|
||||||
plugin.getLocales().getLocale("teleporting_action_bar_cancelled").ifPresent(locale ->
|
plugin.getLocales().getLocale("teleporting_action_bar_cancelled").ifPresent(locale ->
|
||||||
teleport.getPlayer().sendActionBar(locale));
|
teleport.getPlayer().sendActionBar(locale));
|
||||||
|
plugin.getSettings().getSoundEffect(Settings.SoundEffectAction.TELEPORTATION_CANCELLED)
|
||||||
|
.ifPresent(sound -> teleport.getPlayer().playSound(sound));
|
||||||
teleport.cancelled = true;
|
teleport.cancelled = true;
|
||||||
return Optional.of(teleport);
|
return Optional.of(teleport);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user