From b10856baaeb16f10961593de891b0fadbb5493c5 Mon Sep 17 00:00:00 2001 From: William278 Date: Sat, 6 Feb 2021 16:16:36 +0000 Subject: [PATCH] Add sound for teleport cancelled; is possible to specify in config.yml Added handling if an invalid sound is set in config.yml; plugin will use defaults instead. --- .../huskhomes2/Objects/Settings.java | 19 +++++++++++++++++-- .../william278/huskhomes2/runEverySecond.java | 3 +++ src/main/resources/config.yml | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/Objects/Settings.java b/src/main/java/me/william278/huskhomes2/Objects/Settings.java index 9f8c68c7..e6aa5caf 100644 --- a/src/main/java/me/william278/huskhomes2/Objects/Settings.java +++ b/src/main/java/me/william278/huskhomes2/Objects/Settings.java @@ -57,6 +57,7 @@ public class Settings { // Sounds Sound teleportationCompleteSound; Sound teleportWarmupSound; + Sound teleportCancelledSound; // Number of items per page on lists int privateHomesPerPage; @@ -135,8 +136,18 @@ public class Settings { this.publicHomeCost = configFile.getDouble("economy_integration.costs.make_home_public"); this.rtpCost = configFile.getDouble("economy_integration.costs.random_teleport"); - this.teleportationCompleteSound = Sound.valueOf(configFile.getString("general.sounds.teleportation_complete")); - this.teleportWarmupSound = Sound.valueOf(configFile.getString("general.sounds.teleportation_warmup")); + // Retrieve sounds used in plugin; if invalid, use defaults. + try { + this.teleportationCompleteSound = Sound.valueOf(configFile.getString("general.sounds.teleportation_complete")); + this.teleportWarmupSound = Sound.valueOf(configFile.getString("general.sounds.teleportation_warmup")); + this.teleportCancelledSound = Sound.valueOf(configFile.getString("general.sounds.teleportation_cancelled")); + } catch (IllegalArgumentException exception) { + Bukkit.getLogger().severe("Invalid sound specified in config.yml; using default sounds instead."); + this.teleportationCompleteSound = Sound.ENTITY_ENDERMAN_TELEPORT; + this.teleportWarmupSound = Sound.BLOCK_NOTE_BLOCK_BANJO; + this.teleportCancelledSound = Sound.ENTITY_ITEM_BREAK; + } + this.checkVanishedPlayers = configFile.getBoolean("handle_vanished_players"); @@ -324,4 +335,8 @@ public class Settings { public Sound getTeleportWarmupSound() { return teleportWarmupSound; } + + public Sound getTeleportCancelledSound() { + return teleportCancelledSound; + } } diff --git a/src/main/java/me/william278/huskhomes2/runEverySecond.java b/src/main/java/me/william278/huskhomes2/runEverySecond.java index d6b2a167..42665f5b 100644 --- a/src/main/java/me/william278/huskhomes2/runEverySecond.java +++ b/src/main/java/me/william278/huskhomes2/runEverySecond.java @@ -5,6 +5,7 @@ import me.william278.huskhomes2.Objects.RandomPoint; import me.william278.huskhomes2.Objects.TimedTeleport; import org.bukkit.Bukkit; import org.bukkit.Sound; +import org.bukkit.entity.Husk; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitScheduler; @@ -60,11 +61,13 @@ public class runEverySecond { } else { messageManager.sendActionBarMessage(teleporter, "teleporting_action_bar_cancelled"); messageManager.sendMessage(teleporter, "teleporting_cancelled_damage"); + teleporter.playSound(teleporter.getLocation(), HuskHomes.settings.getTeleportCancelledSound(), 1, 1); completedTeleports.add(timedTeleport); } } else { messageManager.sendActionBarMessage(teleporter, "teleporting_action_bar_cancelled"); messageManager.sendMessage(teleporter, "teleporting_cancelled_movement"); + teleporter.playSound(teleporter.getLocation(), HuskHomes.settings.getTeleportCancelledSound(), 1, 1); completedTeleports.add(timedTeleport); } } else { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1a6e2acc..6f4b8091 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -19,6 +19,7 @@ general: sounds: teleportation_complete: 'ENTITY_ENDERMAN_TELEPORT' teleportation_warmup: 'BLOCK_NOTE_BLOCK_BANJO' + teleportation_cancelled: 'ENTITY_ITEM_BREAK' lists: private_homes_per_page: 10 public_homes_per_page: 10