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.
This commit is contained in:
William278 committed 2021-02-06 16:16:36 +00:00
1 parent c03c44252a
commit b10856baae
3 files changed
+21 -2

No files matched your search

@@ -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;
}
}
@@ -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 {