diff --git a/src/main/java/li/cil/oc/api/detail/FileSystemAPI.java b/src/main/java/li/cil/oc/api/detail/FileSystemAPI.java index 5efd028e2..e0a53518d 100644 --- a/src/main/java/li/cil/oc/api/detail/FileSystemAPI.java +++ b/src/main/java/li/cil/oc/api/detail/FileSystemAPI.java @@ -108,7 +108,7 @@ public interface FileSystemAPI { ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, Label label, EnvironmentHost host, String accessSound); /** - * Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, String, li.cil.oc.api.driver.EnvironmentHost)}, + * Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, li.cil.oc.api.driver.EnvironmentHost, String)}, * but creates a read-only label initialized to the specified value. * * @param fileSystem the file system to wrap. @@ -121,7 +121,7 @@ public interface FileSystemAPI { ManagedEnvironment asManagedEnvironment(FileSystem fileSystem, String label, EnvironmentHost host, String accessSound); /** - * Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, String, li.cil.oc.api.driver.EnvironmentHost)}, + * Like {@link #asManagedEnvironment(li.cil.oc.api.fs.FileSystem, Label, li.cil.oc.api.driver.EnvironmentHost, String)}, * but does not provide a container and access sound. * * @param fileSystem the file system to wrap. diff --git a/src/main/scala/li/cil/oc/common/Sound.scala b/src/main/scala/li/cil/oc/common/Sound.scala index 9f5b8496e..c192d209e 100644 --- a/src/main/scala/li/cil/oc/common/Sound.scala +++ b/src/main/scala/li/cil/oc/common/Sound.scala @@ -6,10 +6,15 @@ import li.cil.oc.api.driver.EnvironmentHost import scala.collection.mutable object Sound { - val lastPlayed = mutable.WeakHashMap.empty[EnvironmentHost, Long] + val globalTimeouts = mutable.WeakHashMap.empty[EnvironmentHost, mutable.Map[String, Long]] - def play(host: EnvironmentHost, name: String) { - host.world.playSoundEffect(host.xPosition, host.yPosition, host.zPosition, Settings.resourceDomain + ":" + name, Settings.get.soundVolume, 1) + def play(host: EnvironmentHost, name: String) = this.synchronized { + globalTimeouts.get(host) match { + case Some(hostTimeouts) if hostTimeouts.getOrElse(name, 0L) > System.currentTimeMillis() => // Cooldown. + case _ => + host.world.playSoundEffect(host.xPosition, host.yPosition, host.zPosition, Settings.resourceDomain + ":" + name, Settings.get.soundVolume, 1) + globalTimeouts.getOrElseUpdate(host, mutable.Map.empty) += name -> (System.currentTimeMillis() + 500) + } } def playDiskInsert(host: EnvironmentHost) { @@ -19,13 +24,4 @@ object Sound { def playDiskEject(host: EnvironmentHost) { play(host, "floppy_eject") } - - def playDiskActivity(host: EnvironmentHost, sound: String) = this.synchronized { - lastPlayed.get(host) match { - case Some(time) if time > System.currentTimeMillis() => // Cooldown. - case _ => - play(host, sound) - lastPlayed += host -> (System.currentTimeMillis() + 500) - } - } } diff --git a/src/main/scala/li/cil/oc/server/component/FileSystem.scala b/src/main/scala/li/cil/oc/server/component/FileSystem.scala index 1a031279f..d5719a505 100644 --- a/src/main/scala/li/cil/oc/server/component/FileSystem.scala +++ b/src/main/scala/li/cil/oc/server/component/FileSystem.scala @@ -300,7 +300,7 @@ class FileSystem(val fileSystem: IFileSystem, var label: Label, val host: Option private def makeSomeNoise() { (sound, host) match { - case (Some(s), Some(h)) => Sound.playDiskActivity(h, s) + case (Some(s), Some(h)) => Sound.play(h, s) case _ => } } diff --git a/src/main/scala/li/cil/oc/server/driver/item/Loot.scala b/src/main/scala/li/cil/oc/server/driver/item/Loot.scala index 358b9c15a..25ea10099 100644 --- a/src/main/scala/li/cil/oc/server/driver/item/Loot.scala +++ b/src/main/scala/li/cil/oc/server/driver/item/Loot.scala @@ -27,7 +27,7 @@ object Loot extends Item { dataTag(stack).getString(Settings.namespace + "fs.label") } else null - api.FileSystem.asManagedEnvironment(fs, label, host, "floppy_disk") + api.FileSystem.asManagedEnvironment(fs, label, host, "floppy_access") } else null