Merge pull request #136 from smooone/master

Make invalid sounds not play any sound
This commit is contained in:
William authored and GitHub committed 2022-02-13 13:29:47 +00:00
commit f138e39a95
3 files changed
+31 -11

No files matched your search

@@ -7,6 +7,8 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import javax.annotation.Nullable;
public class Settings { public class Settings {
private final Plugin plugin; private final Plugin plugin;
@@ -228,13 +230,23 @@ public class Settings {
// Retrieve sounds used in plugin; if invalid, use defaults. // Retrieve sounds used in plugin; if invalid, use defaults.
try { try {
this.teleportationCompleteSound = Sound.valueOf(config.getString("general.sounds.teleportation_complete", "ENTITY_ENDERMAN_TELEPORT")); this.teleportationCompleteSound = Sound.valueOf(config.getString("general.sounds.teleportation_complete", "ENTITY_ENDERMAN_TELEPORT"));
} catch (IllegalArgumentException exception) {
Bukkit.getLogger().severe("Invalid sound specified for teleportation_complete, using no sound instead");
this.teleportationCompleteSound = null;
}
try {
this.teleportWarmupSound = Sound.valueOf(config.getString("general.sounds.teleportation_warmup", "BLOCK_NOTE_BLOCK_BANJO")); this.teleportWarmupSound = Sound.valueOf(config.getString("general.sounds.teleportation_warmup", "BLOCK_NOTE_BLOCK_BANJO"));
} catch (IllegalArgumentException exception) {
Bukkit.getLogger().severe("Invalid sound specified for teleportation_warmup, using no sound instead");
this.teleportWarmupSound = null;
}
try {
this.teleportCancelledSound = Sound.valueOf(config.getString("general.sounds.teleportation_cancelled", "ENTITY_ITEM_BREAK")); this.teleportCancelledSound = Sound.valueOf(config.getString("general.sounds.teleportation_cancelled", "ENTITY_ITEM_BREAK"));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
Bukkit.getLogger().severe("Invalid sound specified in config.yml; using default sounds instead."); Bukkit.getLogger().severe("Invalid sound specified for teleportation_cancelled, using no sound instead");
this.teleportationCompleteSound = Sound.ENTITY_ENDERMAN_TELEPORT; this.teleportCancelledSound = null;
this.teleportWarmupSound = Sound.BLOCK_NOTE_BLOCK_BANJO;
this.teleportCancelledSound = Sound.ENTITY_ITEM_BREAK;
} }
this.allowUnicodeInDescriptions = config.getBoolean("allow_unicode_descriptions", true); this.allowUnicodeInDescriptions = config.getBoolean("allow_unicode_descriptions", true);
@@ -442,15 +454,15 @@ public class Settings {
public int getWarpsPerPage() { public int getWarpsPerPage() {
return warpsPerPage; return warpsPerPage;
} }
@Nullable
public Sound getTeleportationCompleteSound() { public Sound getTeleportationCompleteSound() {
return teleportationCompleteSound; return teleportationCompleteSound;
} }
@Nullable
public Sound getTeleportWarmupSound() { public Sound getTeleportWarmupSound() {
return teleportWarmupSound; return teleportWarmupSound;
} }
@Nullable
public Sound getTeleportCancelledSound() { public Sound getTeleportCancelledSound() {
return teleportCancelledSound; return teleportCancelledSound;
} }
@@ -105,7 +105,9 @@ public class TeleportManager {
player.eject(); // Eject passengers before teleporting player.eject(); // Eject passengers before teleporting
} }
PaperLib.teleportAsync(player, targetLocation).thenRun(() -> { PaperLib.teleportAsync(player, targetLocation).thenRun(() -> {
player.playSound(targetLocation, HuskHomes.getSettings().getTeleportationCompleteSound(), 1, 1); if (HuskHomes.getSettings().getTeleportationCompleteSound() != null) {
player.playSound(targetLocation, HuskHomes.getSettings().getTeleportationCompleteSound(), 1, 1);
}
MessageManager.sendMessage(player, "teleporting_complete"); MessageManager.sendMessage(player, "teleporting_complete");
}); });
}); });
@@ -76,14 +76,18 @@ public class TimedTeleport {
} }
if (hasMoved(executablePlayer)) { if (hasMoved(executablePlayer)) {
cancel(); cancel();
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1); if (HuskHomes.getSettings().getTeleportCancelledSound() != null) {
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1);
}
MessageManager.sendMessage(player, "teleporting_cancelled_movement"); MessageManager.sendMessage(player, "teleporting_cancelled_movement");
sendWarmupMessage(player, "teleporting_action_bar_cancelled"); sendWarmupMessage(player, "teleporting_action_bar_cancelled");
return; return;
} }
if (hasLostHealth(executablePlayer)) { if (hasLostHealth(executablePlayer)) {
cancel(); cancel();
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1); if (HuskHomes.getSettings().getTeleportCancelledSound() != null) {
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportCancelledSound(), 1, 1);
}
MessageManager.sendMessage(player, "teleporting_cancelled_damage"); MessageManager.sendMessage(player, "teleporting_cancelled_damage");
sendWarmupMessage(player, "teleporting_action_bar_cancelled"); sendWarmupMessage(player, "teleporting_action_bar_cancelled");
return; return;
@@ -138,7 +142,9 @@ public class TimedTeleport {
return; return;
} }
sendWarmupMessage(executablePlayer, "teleporting_action_bar_countdown", Integer.toString(i[0])); sendWarmupMessage(executablePlayer, "teleporting_action_bar_countdown", Integer.toString(i[0]));
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportWarmupSound(), 1, 1); if (HuskHomes.getSettings().getTeleportWarmupSound() != null) {
executablePlayer.playSound(executablePlayer.getLocation(), HuskHomes.getSettings().getTeleportWarmupSound(), 1, 1);
}
} }
}.runTaskTimer(plugin, 0, 20L); }.runTaskTimer(plugin, 0, 20L);
} }