Solved Playsounds

Discussion in 'Spigot Plugin Development' started by Nico12, Jan 25, 2020.

  1. Hi, I was trying to reproduce the sound BLOCK_ENDER_CHEST_CLOSE when a player joins the server but when he joins he throws me this error:
    Code (Text):

    org.bukkit.event.EventException: null
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:235) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:202) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:198) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:991) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:26) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_231]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_231]
            at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
    Caused by: java.lang.NoSuchFieldError: BLOCK_ENDER_CHEST_CLOSE
            at me.LobbyBrain.Events.PlayerJoinEvents.skere(PlayerJoinEvents.java:180) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_231]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_231]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_231]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            ... 18 more
     
    My Code:
    Code (Text):

        @EventHandler
        public void skere(PlayerJoinEvent e) {
            Player p = e.getPlayer();
                    World world = p.getWorld();
                    Location loc = p.getLocation();
                    p.playSound(loc, Sound.BLOCK_ENDER_CHEST_CLOSE, 1, 1);
        }
     
    But when trying other sounds like GHAST_SCREAM it works.
    Could you help me?
    Thanks in advance
     
  2. What is the API-version of your plugin
     
  3. It's likely the version of the server you're running on is a different version from what your plugin uses. Your server seems to be running on 1.12 - make sure that your plugin also depends on the 1.12 version of the API.
     
  4. But I need my complement to be compatible with multiple versions, if I do it with nms could it work?
     
  5. NMS isn't going to help you any; really, it'll make your life 10x tougher.
    Firstly though, are you trying to make your own server support multiple versions for players? Or do you want to make your plugin work with different server versions?
    If you want your server to be compatible with players on multiple versions, all you need is ViaVersion or some plugin of that nature.
    If you're making a plugin for other people and want it to work on multiple server versions, you have a couple of options.

    The simple way: Use Sound.valueOf, check the server version to know what sound name to use.
    The roundabout (maybe-even-slightly-overkill way): Abstraction with a multi-module project. If you're not familiar with the idea or at least multi-module projects though, I wouldn't suggest it.
     
    • Agree Agree x 1
  6. And solve it, I apologize for not having notified and resolved this, I'm sorry.