Skip to content

Commit

Permalink
Modern and legacy sound keys support
Browse files Browse the repository at this point in the history
This change requires modifying the Mars API join sounds configuration. Refer to this list for updated sound keys: https://minecraft.wiki/w/Sounds.json/Java_Edition_values
  • Loading branch information
jorgeberrex committed Sep 22, 2024
1 parent 76d4ce2 commit d6d6f29
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package network.warzone.mars.match.tracker

import net.kyori.adventure.key.Key
import net.kyori.adventure.sound.Sound
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.Component.text
Expand All @@ -16,6 +15,7 @@ import network.warzone.mars.player.PlayerManager
import network.warzone.mars.player.feature.PlayerFeature
import network.warzone.mars.utils.AUDIENCE_PROVIDER
import network.warzone.mars.utils.KEvent
import network.warzone.mars.utils.Sounds
import network.warzone.mars.utils.simple
import org.bukkit.ChatColor.*
import org.bukkit.entity.Player
Expand All @@ -34,8 +34,8 @@ import java.util.*
class PlayerTracker : Listener {

companion object {
val ORB_SOUND = Sound.sound(Key.key("random.orb"), Sound.Source.MASTER, 0.05f, 1f)
val LEVEL_UP_SOUND = Sound.sound(Key.key("entity.player.levelup"), Sound.Source.MASTER, 1000f, 1f)
val ORB_SOUND = Sound.sound(Sounds.RANDOM_ORB, Sound.Source.MASTER, 0.05f, 1f)
val LEVEL_UP_SOUND = Sound.sound(Sounds.RANDOM_LEVELUP, Sound.Source.MASTER, 1000f, 1f)
}

private var pendingFirstBlood = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package network.warzone.mars.player.achievements

import net.kyori.adventure.key.Key.key
import net.kyori.adventure.sound.Sound
import net.kyori.adventure.sound.Sound.sound
import net.kyori.adventure.text.Component
Expand All @@ -15,6 +14,7 @@ import network.warzone.mars.api.socket.models.SimplePlayer
import network.warzone.mars.player.feature.PlayerFeature
import network.warzone.mars.player.models.PlayerProfile
import network.warzone.mars.utils.AUDIENCE_PROVIDER
import network.warzone.mars.utils.Sounds
import org.bukkit.Bukkit
import java.util.*

Expand All @@ -23,7 +23,7 @@ import java.util.*
class AchievementEmitter(private val achievement: Achievement) {

companion object {
val LEVEL_UP_SOUND = sound(key("entity.player.levelup"), Sound.Source.MASTER, 1f, 1f)
val LEVEL_UP_SOUND = sound(Sounds.RANDOM_LEVELUP, Sound.Source.MASTER, 1f, 1f)
}

// Add an achievement to the specified profile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package network.warzone.mars.player.listeners

import github.scarsz.discordsrv.DiscordSRV
import kotlinx.coroutines.runBlocking
import net.kyori.adventure.key.Key.key
import net.kyori.adventure.sound.Sound
import net.kyori.adventure.sound.Sound.sound
import net.kyori.adventure.text.Component
Expand Down Expand Up @@ -78,7 +77,8 @@ class ChatListener : Listener {
val message = translateAlternateColorCodes('&', rawMessage)
if (soundName != null) {
try {
val sound = sound(key(soundName), Sound.Source.MASTER, 1000f, 1f)
val key = Sounds.resolve(soundName)
val sound = sound(key, Sound.Source.MASTER, 1000f, 1f)
playerIds.mapNotNull { Bukkit.getPlayer(it) }
.map(AUDIENCE_PROVIDER::player)
.forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ package network.warzone.mars.player.perks
import com.github.kittinunf.result.getOrNull
import com.github.kittinunf.result.onFailure
import kotlinx.coroutines.runBlocking
import net.kyori.adventure.key.Key
import net.kyori.adventure.sound.Sound
import network.warzone.mars.Mars
import network.warzone.mars.api.ApiClient
import network.warzone.mars.api.http.ApiExceptionType
import network.warzone.mars.player.PlayerContext
import network.warzone.mars.player.feature.exceptions.PlayerMissingException
import network.warzone.mars.player.models.PlayerProfile
import network.warzone.mars.utils.AUDIENCE_PROVIDER
import network.warzone.mars.utils.ItemUtils
import network.warzone.mars.utils.color
import network.warzone.mars.utils.*
import network.warzone.mars.utils.menu.GUI
import network.warzone.mars.utils.menu.gui
import network.warzone.mars.utils.menu.item
import network.warzone.mars.utils.parseHttpException
import org.bukkit.Bukkit
import org.bukkit.ChatColor
import org.bukkit.Material
Expand All @@ -27,15 +23,16 @@ import tc.oc.pgm.util.material.Materials

object JoinSoundService {

private val ORB_SOUND = Sound.sound(Key.key("random.orb"), Sound.Source.MASTER, 0.05f, 1f)
private val NO_SOUND = Sound.sound(Key.key("entity.villager.no"), Sound.Source.MASTER, 0.25f, 1f)
private val ORB_SOUND = Sound.sound(Sounds.RANDOM_ORB, Sound.Source.MASTER, 0.05f, 1f)
private val NO_SOUND = Sound.sound(Sounds.MOB_VILLAGER_NO, Sound.Source.MASTER, 0.25f, 1f)

private var joinSounds: List<JoinSound>? = null

init {
runBlocking {
joinSounds = ApiClient.get<List<JoinSoundData>>("/mc/perks/join_sounds").mapNotNull { sound ->
val bukkitSound = Sound.sound(Key.key(sound.sound), Sound.Source.MASTER, sound.volume, sound.pitch)
val key = Sounds.resolve(sound.sound)
val bukkitSound = Sound.sound(key, Sound.Source.MASTER, sound.volume, sound.pitch)
val material = ItemUtils.getMaterialByName(sound.guiIcon) ?: Materials.SIGN
val item = ItemStack(material)
return@mapNotNull JoinSound(sound.id, sound.name, sound.description, bukkitSound, sound.permission, item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import app.ashcon.intake.parametric.annotation.Switch
import app.ashcon.intake.parametric.annotation.Text
import com.google.common.cache.Cache
import com.google.common.cache.CacheBuilder
import net.kyori.adventure.key.Key.key
import net.kyori.adventure.sound.Sound
import net.kyori.adventure.sound.Sound.sound
import net.kyori.adventure.text.Component
Expand All @@ -18,6 +17,7 @@ import net.kyori.adventure.text.format.NamedTextColor
import net.kyori.adventure.text.format.TextDecoration
import network.warzone.mars.report.PlayerReportEvent
import network.warzone.mars.report.Report
import network.warzone.mars.utils.Sounds
import network.warzone.mars.utils.matchPlayer
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
Expand All @@ -44,7 +44,7 @@ import java.util.stream.Collectors
class ReportCommands {

companion object {
private val REPORT_NOTIFY_SOUND: Sound = sound(key("random.pop"), Sound.Source.MASTER, 1f, 1.2f)
private val REPORT_NOTIFY_SOUND: Sound = sound(Sounds.RANDOM_POP, Sound.Source.MASTER, 1f, 1.2f)

private const val REPORT_COOLDOWN_SECONDS: Long = 15
private const val REPORT_EXPIRE_HOURS: Long = 1
Expand Down
Loading

0 comments on commit d6d6f29

Please sign in to comment.