koca2000 / NoteBlockAPI

https://www.spigotmc.org/resources/noteblockapi.19287/
GNU Lesser General Public License v3.0
119 stars 40 forks source link

Problems when using the API in my plugin #101

Closed AILANTEL closed 1 year ago

AILANTEL commented 1 year ago

I tried to read your official documentation to use this API, but I always encounter a null pointer error when calling the methods. I checked my code repeatedly, making sure it is consistent with the usage in the official documentation, but the problem still persists. Spigot version 1.16.5, NoteBlockAPI version 1.6.1, server version 1.16.5, every time I call the playMusic0 method, I get a null pointer error. I have attached screenshots of my code and the error below. I put the loadMusic method in the onEnable method. I have also downloaded the NoteBlockAPI jar file and put it in the plugins folder of the server. I used the sout method to print out the Song object startSong and found that it was not null, startSong got the nbs file. {F27C4C0A-51E3-44b5-AE54-93E4572E9809}

{95C5B6BA-9D7F-46b9-A2D4-99142405EAD2}

koca2000 commented 1 year ago

Hi! It looks like the NoteBlock API is not yet initialized at the time you call the playMusic0 method. Have you added it as you plugin's dependency in plugin.yml? Is there any message about NoteBlockAPI in the server's startup log?

AILANTEL commented 1 year ago

I have written the dependencies in my plugin configuration file, and the server has successfully initialized the API. {57B641F1-3531-4afc-9FF9-23137C232003} {0A73F5EA-660E-4916-AF9B-B806CBEA6B0A}

AILANTEL commented 1 year ago

Every time I try to call the method to play music it will appear {7930B3D5-23E5-47fd-994E-4EB3A17109A4}

koca2000 commented 1 year ago

Assuming you are using maven, may I see your pom.xml file?

AILANTEL commented 1 year ago

I am using gradle, this is my build file, please take a look {47170490-4D90-4492-8DA1-E104F7A43155} {0A7A1D0F-6113-4521-9536-831597791E0E}

koca2000 commented 1 year ago

I see. Please change the implementation to compileOnly. I'll update the wiki.

AILANTEL commented 1 year ago

“OK, I will try this method right away

AILANTEL commented 1 year ago

Thank you very much, the solution is very useful, my plugin can now play music normally!