Development Assistance Sign EventListener Errors

Discussion in 'Plugin Help/Development/Requests' started by Shortninja66, Jan 5, 2015.

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

    Shortninja66

    I have been working on a plugin that implements custom potions and decided the best way to sell these potions to players is through a sign. I am having a few errors that I can't seem to solve. First error is that I cannot get Vault economy API working in my Listener class. I have tried pasting the "setupEconomy" code from the Vault API site like I did with my main class, but to no avail. I am not used to working with Vault API to be honest and I am completely stumped here. Below is my Listener code and the error that I receive in console when I attempt to right click a "SpeedIII" sign. I also know the method that I am using to withdraw money is deprecated, but I don't know the alternate method to take players' money and haven't Googled it because the deprecated method still works for now.


    Error:
    Code:
    [19:27:38 ERROR]: Could not pass event PlayerInteractEvent to CustomPotions v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:242) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.interact(PlayerInteractManager.java:382) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:662) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.handle(PacketPlayInBlockPlace.java:86) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    Caused by: java.lang.NullPointerException
        at me.bukkit.shortninja66.PotionListener.signInteract(PotionListener.java:122) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_65]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_65]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_65]
        at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        ... 15 more
    >
    

    Sign Listener:
    Code:
     @EventHandler
        public void signInteract(PlayerInteractEvent event)
        {
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
            {
                Block block = event.getClickedBlock();
                    if(block.getType().equals(Material.WALL_SIGN))
                    {
                              Player player = event.getPlayer();
                       
                          Sign sign = (Sign) event.getClickedBlock().getState();
                          if(sign.getLine(0).contains("SpeedIII"))
                          {
                              r = econ.withdrawPlayer(player.getName(), 400);
                              if(r.transactionSuccess())
                              {
                                  ItemStack speediii = setMeta(new ItemStack(Material.POTION), "Speed III", Arrays.asList(ChatColor.AQUA + "Grants Speed III", ChatColor.AQUA + "for 30 seconds."));
                                  player.getInventory().addItem(speediii);
                                  player.sendMessage(ChatColor.GREEN + "$300 has been taken from your account.");
                              }else
                              {
                                  player.sendMessage(ChatColor.RED + "Insufficient funds!");
                              }
                          }
                    }
            }
        }
     
  2. Offline

    nverdier

  3. Offline

    Shortninja66

    The Vault API economy method

    Code:
        @EventHandler
        public void signInteract(PlayerInteractEvent event)
        {
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK)
            {
                Block block = event.getClickedBlock();
                    if(block.getType().equals(Material.WALL_SIGN))
                    {
                              Player player = event.getPlayer();
                       
                          Sign sign = (Sign) event.getClickedBlock().getState();
                          if(sign.getLine(0).contains("SpeedIII"))
                          {
                        //Below this is line 122.
                              r = econ.withdrawPlayer(player.getName(), 400);
                              if(r.transactionSuccess())
                              {
                                  ItemStack speediii = setMeta(new ItemStack(Material.POTION), "Speed III", Arrays.asList(ChatColor.AQUA + "Grants Speed III", ChatColor.AQUA + "for 30 seconds."));
                                  player.getInventory().addItem(speediii);
                                  player.sendMessage(ChatColor.GREEN + "$300 has been taken from your account.");
                              }else
                              {
                                  player.sendMessage(ChatColor.RED + "Insufficient funds!");
                              }
                          }
                    }
            }
        }
     
  4. Offline

    nverdier

    @Shortninja66 But how do I know which line is 122? What exactly is on line 122?
     
  5. Offline

    Shortninja66

    The following code is line 122, sorry for misunderstanding.

    Code:
                              r = econ.withdrawPlayer(player.getName(), 400);
     
  6. Offline

    nverdier

    @Shortninja66 So it's possible that econ or player are null. Try debugging by doing a System.out.printlt() with the econ and player variable to see what is null.
     
  7. Offline

    Shortninja66

    I'm almost sure that it's this, but I don't get why because Vault API had said that this is needed for the setupEconomy.
    Code:
        public static Economy econ = null;
        public static EconomyResponse r;
     
  8. Offline

    nverdier

    @Shortninja66 Do you ever set econ to anything other than null?
     
  9. Offline

    Shortninja66

    Not that I know of, my main class has this set as null and the economy works fine.
     
  10. Offline

    nverdier

    @Shortninja66 Well you probably don't do anything with it in the main class? It defiantly shouldn't' be null... It's useless.
     
  11. Offline

    Shortninja66

    I did do something in it with the main class, I made a command that withdrawed $400 from the player's account and gave them a potion titled "SpeedIII". The code I used for the sign starting at line 122 is the same as the command I made because I supposed it would work the same way.
     
  12. Offline

    nverdier

    @Shortninja66 Are you sure econ isn't null? But still try debugging because if it worked before then player is null. But it shouldn't have worked the way you described it.
     
  13. Offline

    Shortninja66

    How can I debug it? I've never tried debugging before. Plus, I am very sure that the issue is what I mentioned, the signs work just fine without the economy methods.
     
  14. Offline

    nverdier

    @Shortninja66 You just use System.out.println() with some variables that might be a problem, or after if statements to see if they are passed. Stuff like that.
     
  15. Offline

    Shortninja66

    So I'd do:

    Code:
    r = econ.withdrawPlayer(player.getName(), 400);
                              if(r.transactionSuccess())
                              {
                                  System.out.println();
                                  ItemStack speediii = setMeta(new ItemStack(Material.POTION), "Speed III", Arrays.asList(ChatColor.AQUA + "Grants Speed III", ChatColor.AQUA + "for 30 seconds."));
                                  player.getInventory().addItem(speediii);
                                  player.sendMessage(ChatColor.GREEN + "$300 has been taken from your account.");
                              }else
    ????
     
  16. Offline

    nverdier

    @Shortninja66 That prints out exactly nothing. Print out something that says "Transaction Success!" or something important.
     
  17. Offline

    Shortninja66

    Code:
                                  System.out.println("Transaction successful!");
    Then what? Export it, attempt sign, then check console?
     
  18. Offline

    nverdier

  19. Offline

    Shortninja66

    Console outputs same error it appears:

    Code:
    [20:25:59] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to CustomPotions v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at org.bukkit.craftbukkit.v1_7_R4.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:242) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.interact(PlayerInteractManager.java:382) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:662) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:50) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockPlace.handle(PacketPlayInBlockPlace.java:86) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:186) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:734) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
    Caused by: java.lang.NullPointerException
        at me.bukkit.shortninja66.PotionListener.signInteract(PotionListener.java:122) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_65]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_65]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_65]
        at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[spigot.jar:git-Spigot-1.7.9-R0.2-205-g0a049fa]
        ... 15 more
     
  20. Offline

    nverdier

    @Shortninja66 Do a println of the player and econ variables before you do the econ.withdrawlPlayer() and see what's null. My guess is that as econ is null, so it's throwing an NPE.
     
  21. Offline

    Shortninja66

    Code:
    System.out.println("Transaction successful!");
                              r = econ.withdrawPlayer(player.getName(), 400);
                              if(r.transactionSuccess())
                              {
                                  ItemStack speediii = setMeta(new ItemStack(Material.POTION), "Speed III", Arrays.asList(ChatColor.AQUA + "Grants Speed III", ChatColor.AQUA + "for 30 seconds."));
                                  player.getInventory().addItem(speediii);
                                  player.sendMessage(ChatColor.GREEN + "$300 has been taken from your account.");
                              }else
                              {
    By player and economy variables, you mean to have something like getPlayer as the Println variable?
     
  22. Offline

    nverdier

    @Shortninja66 No, do System.out.println("Player: " + player + ", econ: " + econ)
     
  23. Offline

    nj2miami

    Did you even assign econ? econ cannot be set to NULL like you have it.


    Code:
    RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
         
    if (rsp != null) {     
    econ = rsp.getProvider();
    Bukkit.getLogger().log(Level.INFO, "Linked to Vault Economy.");
    }
     
  24. Offline

    Shortninja66

    Thanks for bearing with me. The economy is definitely null..

    Code:
    [20:44:34 INFO]: Player: CraftPlayer{name=Shortninja66}, econ: null
    
     
  25. Offline

    nverdier

    @Shortninja66 Then assign it!
     
  26. Offline

    nj2miami

    @Shortninja66 - There is no way this is correct. Perhaps that was the initializer he gave in an example, but you still have to assign the EconAPI to it.
     
  27. Offline

    Shortninja66

    I use that method as well? This is all the economy things I have:

    Code:
        public static Economy econ = null;
        public static EconomyResponse r;
    Code:
    @Override
        public void onEnable()
        {
            if (!setupEconomy() )
            {
                log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
    Code:
    public boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
    Okay I see.. So I'm expecting Essentials as the economy, so assign Essentials to it? In what way?

    <merged posts. Please use the edit button. ~Eya>
     
  28. Offline

    nj2miami

    @Shortninja66

    r = econ.withdrawPlayer(player.getName(), 400);

    r is not defined in this scope. r is set in your main class and would need to be referenced accordingly.

    Based on your code, reference PLUGIN.r = econ....

    but I would just remove the static r reference from your main class an create a local private variable inside your listener to handle the response.

    EconomyResponse r;
     
  29. Offline

    Shortninja66

    Code:
        private EconomyResponse r;
    ? I don't get why the null works fine in Main class, but has troubles in the listener. How can I assign economy to where null is?
     
  30. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
Thread Status:
Not open for further replies.

Share This Page