Solved Vault testing error :L

Discussion in 'Plugin Development' started by TheLovelySlothMan, Oct 20, 2016.

Thread Status:
Not open for further replies.
  1. So this day went quite smoothly, and nothing went wrong. I thought to myself, "why not try out vault?" After setting it all up, I was hyped and excited to try some things. Nothing could break my day I thought to myself; until, I got some errors.

    Here are the two classes
    Main:
    Code:java
    1. public class Main extends JavaPlugin {
    2.  
    3. static public Permission permission = null;
    4. public Economy econ = null;
    5.  
    6. @Override
    7. public void onEnable() {
    8. getCommand("msg").setExecutor(new Msg());
    9. Bukkit.getPluginManager().registerEvents(new Prefix(), this);
    10. enableVault();
    11. }
    12.  
    13. @Override
    14. public void onDisable() {
    15.  
    16. }
    17.  
    18. private void enableVault() {
    19. if (!setupEconomy()) {
    20. System.out.println("No economy found");
    21. return;
    22. }
    23. if (!setupPermissions()) {
    24. System.out.println("No economy found");
    25. return;
    26. }
    27. }
    28.  
    29. private boolean setupEconomy() {
    30. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    31. return false;
    32. }
    33. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    34. if (rsp == null) {
    35. return false;
    36. }
    37. econ = rsp.getProvider();
    38. return econ != null;
    39. }
    40.  
    41. private boolean setupPermissions()
    42. {
    43. RegisteredServiceProvider<Permission> permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
    44. if (permissionProvider != null) {
    45. permission = permissionProvider.getProvider();
    46. }
    47. return (permission != null);
    48. }
    49. }
    50.  

    The reason for I have setupPermissions and setupEconomy, was to try both things. But the error was still the same :L


    Prefix:
    Code:java
    1. public class Prefix implements Listener{
    2.  
    3. private Main main;
    4.  
    5. //Test
    6. @EventHandler
    7. public void onPlayerChat(AsyncPlayerChatEvent e) {
    8. Player p = e.getPlayer();
    9. double money = main.econ.getBalance(p);
    10. p.sendMessage("Test: "+money);
    11. }
    12. }
    13.  

    At main.econ.getBalance(), I tried both p and p.getName()
    I wanted to send the player a message when he writes something. I wanted the string to be the player's balance. But instead of recieving the balance, I got an error.

    Stacktrace
    Code:
    19:32:55 [SEVERE] Could not pass event AsyncPlayerChatEvent to YangFu_Chat v1.0.0
    19:32:55 org.bukkit.event.EventException
    19:32:55     at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.10.2-R0.1-SNAPSHOT-latest.jar:git-Spigot-5391d73-0ebb9c7]
    19:32:55     at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.10.2-R0.1-SNAPSHOT-latest.jar:git-Spigot-5391d73-0ebb9c7]
    19:32:55     at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.10.2-R0.1-SNAPSHOT-latest.jar:git-Spigot-5391d73-0ebb9c7]
    19:32:55     at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot-1.10.2-R0.1-SNAPSHOT-latest.jar:git-Spigot-5391d73-0ebb9c7]
    19:32:55     at net.minecraft.server.v1_10_R1.PlayerConnection.chat(PlayerConnection.java:1273) [spigot-1.10.2-R0.1-SNAPSHOT-latest.jar:git-Spigot-5391d73-0ebb9c7]
    19:32:55     at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:1211) [spigot-1.10.2-R0.1-SNAPSHOT-latest.jar:git-Spigot-5391d73-0ebb9c7]
    19:32:55     at net.minecraft.server.v1_10_R1.PacketPlayInChat$1.run(PacketPlayInChat.java:39) [spigot-1.10.2-R0.1-SNAPSHOT-latest.jar:git-Spigot-5391d73-0ebb9c7]
    19:32:55     at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_102]
    19:32:55     at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_102]
    19:32:55     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_102]
    19:32:55     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_102]
    19:32:55     at java.lang.Thread.run(Unknown Source) [?:1.8.0_102]
    19:32:55 Caused by: java.lang.NullPointerException
    19:32:55     at com.MunchMallow.chat.Prefix.onPlayerChat(Prefix.java:17) ~[?:?]
    19:32:55     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_102]
    19:32:55     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_102]
    19:32:55     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_102]
    19:32:55     at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_102]
    19:32:55     at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.10.2-R0.1-SNAPSHOT-latest.jar:git-Spigot-5391d73-0ebb9c7]
    19:32:55     ... 11 more
    
    Thank you in advance, dearly TheLovelySloth.. Remember the sloths..
     
    Last edited: Oct 20, 2016
  2. Offline

    Zombie_Striker

    This is the line that is causing the error. Notice how you never set "main" equal to anything? That means that main is null, and that is why you are getting an NPE.

    Create a constructor for that class, and pass the instance of Main through the constructor.
     
    TheLovelySlothMan likes this.
  3. Ahh, thanks man. It works like a charm now :3
     
Thread Status:
Not open for further replies.

Share This Page