[Tutorial] Adding custom sounds to your plugin (well… sort of)

Discussion in 'Resources' started by Quantum64, Mar 26, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    Thank you very much for taking the effort to help me out.

    I am sorry for your dissapointment. I have tried something similiar as you did already, but I didn't succeed.

    EDIT: Looking back at my code, I created an apart function to stop the sound, wherein the sound var might not have been initialized. I didn't know you could do it your way.
    Thank you.
  2. Hi Quantum64
    made everything working, but for some people it won't work.
    1) I know 1 persen that won't be received by the websocket package, when i play music there is an error in the console. And I know another person who can't hear the playing music. How can i fix this?

    2) When you reload, the webserver and websocketserver are rerunning, so the port is already bind. Then the the site don't work.
  3. Offline


    There are known compatibility issues with mac computers... don't ask me why. Could that be the issue? The simplest way to fix errors in the console would be to add a try and catch statement that catches and ignores a general exceptions, as these connections are not always perfect.

    As for issue two, try stopping both servers in the onDisable method.
  4. He has a Windows computer, maybe something with his firewall.
    But how can i stop the servers in the onDisable? I already tried it before. ;)
  5. Offline


    Might be. Make sure he's using a modern browser. (Not Internet Explorer)

    You clearly didn't try very hard ;) The Jetty server has a .stop() method and jWebSocket has a .stopServer() method.
  6. Offline


    And how can i change my volume?
  7. Offline


    I would just implement an HTML slider on the page, then link it to the Howler volume control value in the Javascript.
  8. Offline


    Can you explain me? I'm not the best with javascript
  9. Offline


    Hello guys... I have make your plugin and it working but there is a problem...
    The music not be playing at same time for all players...
  10. Offline


    What do you mean by "at the same time" there could be a delay of several seconds depending on the internet speed of your players, but everything after that is likely a code issue.
  11. Offline


    ThePenspinneur if you write a buffer to buffer the song that is gonna play in like 3 seconds to the webclient knows that he needs to start buffering the song but setting it on pause and play after the 3 seconds by a reply from you socket server in bukkit
  12. Offline


    Ok, I know this can be considered old by now but it is the only source for a project like this I can find...

    I have the exact same problem as @CMG had. The sessions's username is null. Everytime I connect to the website I get the message "Connected to websocket server! Sent data: name:Ziron5" like it should be but the minecraft server console tells that the session is closed immediatly:

    log (open)
    [13:29:43] [WebSocketWorker-37/INFO]: process(518): {GET HTTP/1.1
    -AgentMozilla/5.0 (Windows NT 6.1WOW64rv:40.0Gecko/20100101 Firefox/40.0
    Accept-Language: de,en-US;q=0.7,en;q=0.3
    Accept-Encoding: gzip, deflate
    Sec-WebSocket-Version: 13
    Origin: http://localhost:8080
    Sec-WebSocket-Extensions: permessage-deflate
    Sec-WebSocket-Key: kA+ovDwmkpBO6nZpB/Z7RA==
    Connection: keep-alive, Upgrade
    Pragma: no-cache
    Cache-Control: no-cache
    Upgrade: websocket

    [13:29:43] [WebSocketWorker-37/INFO]: write(141): {HTTP/1.1 101 Switching Protocols
    Connection: keep-alive, Upgrade
    Sec-WebSocket-Accept: D8PvnA+LO4xg/rOJ0U2T/oGVx/E=
    Upgrade: websocket

    [13:29:43] [WebSocketWorker-37/INFO]: open using draft: Draft_17
    [13:29:43] [WebSocketWorker-37/INFO]: Opened Websocket session: WebsocketSession.java - Host: 0:0:0:0:0:0:0:1 Name: null
    [13:29:43] [WebSocketWorker-37/INFO]: 0:0:0:0:0:0:0:1 has connected to the Websocket server!
    [13:29:43] [WebSocketWorker-37/INFO]: process(8): {ˆ‚ÔƒÂ
    [13:29:43] [WebSocketWorker-37/INFO]: matched frame: Framedata{ optcode:CLOSING, fin:true, payloadlength:2, payload:[3, -61, -87]}code: 1001
    [13:29:43] [WebSocketWorker-37/INFO]: send frame: Framedata{ optcode:CLOSING, fin:true, payloadlength:2, payload:[3, -61, -87]}code: 1001
    [13:29:43] [WebSocketWorker-37/INFO]: write(4): {ˆé}
    [13:29:43] [WebsocketSelector41/INFO]: Ended Websocket session: null
    [13:29:43] [WebsocketSelector41/INFO]: org.java_websocket.WebSocketImpl@738b0b has disconnected form the Websocket server
    [13:37:52] [WebSocketWorker-38/INFO]: process(518): {GET / HTTP/1.1
    Host: localhost:8887
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/

    13:37:52] [WebSocketWorker-38/INFO]: write(141): {HTTP/1.1 101 Switching Protocols

    13:37:52] [WebSocketWorker-38/INFO]: open using draftDraft_17
    [13:37:52] [WebSocketWorker-38/INFO]: Opened Websocket sessionWebsocketSession.java Host0:0:0:0:0:0:0:1 Namenull
    [13:37:52] [WebSocketWorker-38/INFO]: 0:0:0:0:0:0:0:1 has connected to the Websocket server!
    13:37:52] [WebSocketWorker-38/INFO]: process(8): {ˆ‚ÍØÄÎí}
    13:37:52] [WebSocketWorker-38/INFO]: matched frameFramedataoptcode:CLOSINGfin:truepayloadlength:2payload:[3, -61, -87]}code1001
    [13:37:52] [WebSocketWorker-38/INFO]: send frameFramedataoptcode:CLOSINGfin:truepayloadlength:2payload:[3, -61, -87]}code1001
    [13:37:52] [WebSocketWorker-38/INFO]: write(4): {ˆé}
    13:37:52] [WebsocketSelector41/INFO]: Ended Websocket sessionnull
    [13:37:52] [WebsocketSelector41/INFO]: org.java_websocket.WebSocketImpl@1daa75f has disconnected form the Websocket server

    Notice the line that says ended websocket Session. I added that before the session actually gets removed from the session ArrayList but it still says null meaning there has never been a session for that host appearently.

    When I try to play a sound with the SoundEffectManager this is the outcome:

    [13:38:16] [Server thread/INFO]: Ziron5 issued server command: /pw test
    [13:38:16] [Server thread/INFO]: Session gotten:WebsocketSession.java Host0:0:0:0:0:0:0:1 Namenull
    [13:38:16] [Server thread/INFO]: Session gotten:WebsocketSession.java Host0:0:0:0:0:0:0:1 Namenull
    What could be the reason that every attempted connection gets closed right on opening? I really hope for an answer or help!

    Thanks in advance!

  13. As stated above, I know this is old but its the only place for it. I have everything set up and it all launches and the server load. but when I go to the IP it doesn't show anything in console. I have a feeling something isn't configured right somewhere meaning that it isn't parsing the connection to the plugin.
  14. Offline


    First of all: Is this tutorial outdated?
    i get this strange error:

    Log (open)

    [19:57:19 INFO]: [BP] Enabling BP v1.0
    [19:57:19 ERROR]: Error occurred while enabling BP v1.0 (Is it up to date?)
    java.lang.Error: Unresolved compilation problems:
            SGApi cannot be resolved
            The method setHandlers(org.eclipse.jetty.server.Handler[]) in the type HandlerCollection is not applicable for the arguments (java.util.logging.Handler[])
            Type mismatch: cannot convert from ResourceHandler to Handler
            Type mismatch: cannot convert from DefaultHandler to Handler
            at me.the_red_freak.bptf.web.server.WebServer.runServer(WebServer.java:21) ~[?:?]
            at me.the_red_freak.bptf.main.main.onEnable(main.java:10) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292) ~[bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugin(CraftServer.java:361) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.craftbukkit.v1_9_R1.CraftServer.enablePlugins(CraftServer.java:321) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.MinecraftServer.t(MinecraftServer.java:411) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.MinecraftServer.l(MinecraftServer.java:376) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.MinecraftServer.a(MinecraftServer.java:331) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.DedicatedServer.init(DedicatedServer.java:269) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:527) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]

    EDIT #1

    I know that this is an compilation error but how schould i resolve them?

    EDIT #2

    SGApi have to replaced with your plugin's main class
    Last edited: Apr 26, 2016
  15. Online

    timtower Ninja on the waves Moderator

    @The_Red_Freak Chances are indeed that it is outdated as it is from 2 years ago.
    And looks like it that your server and build path use different files.
  16. Offline


    @timtower thx for dat fast response but seriously how can i fix that?
  17. Offline


    @The_Red_Freak You're either using a version of Jetty that is newer or older than the one in the tutorial. It might be better to look into a more modern Java web framework like http://sparkjava.com/

    Edit: Or possibly you're importing the ResourceHander from somewhere that isn't Jetty
  18. Offline


    i was importing it wrong but now i get this error:
    log (open)

    [14:01:52 ERROR]: Error occurred while enabling BP v1.0 (Is it up to date?)
    java.lang.NoClassDefFoundError: org/eclipse/jetty/server/Handler
            at me.the_red_freak.bptf.main.main.onEnable(main.java:10) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292) ~[bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugin(CraftServer.java:361) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.craftbukkit.v1_9_R1.CraftServer.enablePlugins(CraftServer.java:321) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.craftbukkit.v1_9_R1.CraftServer.reload(CraftServer.java:745) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.Bukkit.reload(Bukkit.java:539) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServer.java:645) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchServerCommand(CraftServer.java:631) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.DedicatedServer.aL(DedicatedServer.java:438) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:401) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [bukkit.jar:git-Spigot-2038f4a-44216f1]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.server.Handler
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_91]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[bukkit.jar:git-Spigot-2038f4a-44216f1]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[bukkit.jar:git-Spigot-2038f4a-44216f1]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_91]
            ... 17 more

    Fixed it myself, just had to export it as Runnable Jar File not just as Jar file. :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.

    Edit #1:
    I don't know why but
    log (open)

    41699, 242.74795214286942)
    [16:39:49 INFO]: The_Red_Freak issued server command: /test
    [16:39:49 INFO]: Session gotten:WebsocketSession.java - Host: 0:0:0:0:0:0:0:1 Name: The_Red_Freak
    [16:39:49 INFO]: Session gotten:WebsocketSession.java - Host: 0:0:0:0:0:0:0:1 Name: The_Red_Freak
    [16:39:49 INFO]: Send data packet: 1
    [16:39:49 INFO]: send frame: Framedata{ optcode:TEXT, fin:true, payloadlength:1, payload:[49]}
    [16:39:49 INFO]: write(3): {?1}

    it says: " write (3): {?*1} "
    * = Some strange Unicode or something



    In the Websocket.js file i use ".ogg" instead of ".mp3" so it could not find the sound file ._. derp xD
    Last edited: May 13, 2016
  19. Offline


    first of all: thank you for this great tutorial.
    Currently I use your variant with an apache2 server and it worked with http very well.
    Now I had the idea to change this to https. I created a Let´s Encrypt certificate and changed the "ws://..." to "wss://...".
    Also i changed something in the WebsocketServer.class to accept ssl certificates. Currently it looks like this:
                String STORETYPE = "JKS";
                String KEYSTORE = Main.getPlugin().getDataFolder() + "/keystore.jks";
                String STOREPASSWORD = "secret";
                String KEYPASSWORD = "secret";
                KeyStore ks = KeyStore.getInstance(STORETYPE);
                File kf = new File(KEYSTORE);
                ks.load(new FileInputStream(kf), STOREPASSWORD.toCharArray());
                KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
                kmf.init(ks, KEYPASSWORD.toCharArray());
                TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
                String[] tlsCipherSuite = { "TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
                        "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256",
                        "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256",
                        "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA", "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
                        "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
                        "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
                        "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256",
                        "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256", "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256",
                        "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
                        "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" };
                SSLContext sslContext = null;
                sslContext = SSLContext.getInstance("TLSv1.2");
                sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
                websocketServer.setWebSocketFactory(new DefaultSSLWebSocketServerFactory(sslContext));
    Now i have the problem that the server doesn't accept the client certificates. My server printed this error message:
    Caused by: javax.net.ssl.SSLHandshakeException: no cipher suites in common
    Do you have any idea how to fix this?

    Thanks in advance,
Thread Status:
Not open for further replies.

Share This Page