sReward not working? Economy problem.

Discussion in 'Plugin Development' started by SenseTheGod, Jan 26, 2014.

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

    SenseTheGod

    Okay im not sure what the problem is.... Ive had friends help me but i still can't get it..
    here is my code for sRewards
    Code:java
    1.  
    2.  
    3. package me.sensethegod;
    4.  
    5. import java.util.logging.Logger;
    6.  
    7. import net.milkbowl.vault.economy.Economy;
    8.  
    9. import org.bukkit.Bukkit;
    10. import org.bukkit.Server;
    11. import org.bukkit.plugin.RegisteredServiceProvider;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14.  
    15. public class sReward extends JavaPlugin {
    16.  
    17. public static Economy econ = null;
    18.  
    19. public static Economy getEconomy() {
    20. Economy ecoVault = null;
    21. boolean vaultLoaded = false;
    22. if (!vaultLoaded) {
    23. vaultLoaded = true;
    24. Server theServer = Bukkit.getServer();
    25. if (theServer.getPluginManager().getPlugin("Vault") != null) {
    26. RegisteredServiceProvider<Economy> rsp = theServer.getServicesManager().getRegistration(Economy.class);
    27. if (rsp != null) {
    28. ecoVault = (Economy)rsp.getProvider();
    29. }
    30. }
    31. }
    32.  
    33. return ecoVault;
    34. }
    35.  
    36. public final Logger logger = Logger.getLogger("Minecraft");
    37.  
    38. public void onEnable()
    39. {
    40. if (!setupEconomy() ) {
    41. getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    42. getServer().getPluginManager().disablePlugin(this);
    43. return;
    44. }
    45. }
    46.  
    47. boolean setupEconomy() {
    48. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    49. return false;
    50. }
    51. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    52. if (rsp == null) {
    53. return false;
    54. }
    55. econ = rsp.getProvider();
    56. return econ != null;
    57. }
    58.  
    59.  
    60. public void onDisable()
    61. {
    62. getLogger().info("sReward disabled for some reason! Please fix soon!");
    63. }
    64.  
    65.  
    66.  
    67.  
    68.  
    69. }
    70.  
    71.  



    and here is my listener..

    Code:java
    1.  
    2.  
    3. package me.sensethegod;
    4.  
    5.  
    6. import net.milkbowl.vault.economy.Economy;
    7.  
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.entity.PlayerDeathEvent;
    13.  
    14. public class listener implements Listener {
    15.  
    16. public static Economy econ = null;
    17. public listener(sReward plugin) {
    18. }
    19.  
    20. public boolean PlayerListener(sReward plugin) {
    21. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    22. return false;
    23. }
    24.  
    25. @EventHandler
    26. public void onPlayerKill(PlayerDeathEvent event) {
    27.  
    28. Economy econ = sReward.getEconomy();
    29. if ((event.getEntity() instanceof Player) && (event.getEntity().getKiller() instanceof Player) && event.getEntity().getKiller() != null)
    30. {
    31. econ.depositPlayer(event.getEntity().getKiller().getName(), 25);
    32. event.getEntity().getKiller().sendMessage(ChatColor.GREEN + "You have recieved " + ChatColor.RED + "$25 " + ChatColor.GREEN + "for killing " + ChatColor.AQUA + event.getEntity().getName());
    33.  
    34. }
    35.  
    36. }
    37. }
    38.  
    39.  
    40.  
    41.  


    Please help me with my problem, all help is appreciated! Thank you
     
  2. Offline

    foldagerdk

    Do you have a stack trace SenseTheGod ?
    And can you explain what it should do compared to what it actually does?
     
  3. Offline

    L33m4n123

  4. Offline

    SenseTheGod

    Well when you kill a player you should be getting $25 and a message saying you got $25, it doesnt do either. I changed the way i added vault into it too and it didn't make a difference..
     
  5. Offline

    L33m4n123

    ah why not saying earlier that? I thought it simply does not find your economy plugin. Next time please state in the OP what your issue is ;)

    Getting any stacktrace?
     
  6. Offline

    SenseTheGod

    What do you mean stacktrace? and i dont know 100% what the problem is.. Just it isnt working?
    i just changed some shit.. idk if it is good though..
    listener:
    Code:java
    1.  
    2. package me.sensethegod;
    3.  
    4.  
    5. import net.milkbowl.vault.economy.Economy;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.PlayerDeathEvent;
    12.  
    13. public class listener implements Listener {
    14.  
    15. public static Economy econ = null;
    16. public listener(sReward plugin) {
    17. }
    18.  
    19. public boolean PlayerListener(sReward plugin) {
    20. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    21. return false;
    22. }
    23.  
    24. @EventHandler
    25. public void onPlayerKill(PlayerDeathEvent event) {
    26.  
    27. if ((event.getEntity() instanceof Player) && (event.getEntity().getKiller() instanceof Player) && event.getEntity().getKiller() != null)
    28. {
    29. econ.depositPlayer(event.getEntity().getKiller().getName(), 25);
    30. event.getEntity().getKiller().sendMessage(ChatColor.GREEN + "You have recieved " + ChatColor.RED + "$25 " + ChatColor.GREEN + "for killing " + ChatColor.AQUA + event.getEntity().getName());
    31.  
    32. }
    33.  
    34. }
    35. }
    36.  
    37.  
    38.  


    sReward
    Code:java
    1.  
    2. package me.sensethegod;
    3.  
    4. import java.util.logging.Logger;
    5.  
    6. import net.milkbowl.vault.chat.Chat;
    7. import net.milkbowl.vault.economy.Economy;
    8.  
    9.  
    10. import org.bukkit.plugin.RegisteredServiceProvider;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13.  
    14. public class sReward extends JavaPlugin {
    15.  
    16. public static Economy econ = null;
    17. public static Economy economy = null;
    18. public static Chat chat = null;
    19.  
    20.  
    21.  
    22. public final Logger logger = Logger.getLogger("Minecraft");
    23.  
    24. public void onEnable()
    25. {
    26. if (!setupEconomy() ) {
    27. getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    28. getServer().getPluginManager().disablePlugin(this);
    29. return;
    30. }
    31. }
    32.  
    33. public boolean setupEconomy()
    34. {
    35. RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
    36. if (economyProvider != null) {
    37. economy = economyProvider.getProvider();
    38. }
    39.  
    40. return (economy != null);
    41. }
    42.  
    43.  
    44. public void onDisable()
    45. {
    46. getLogger().info("Nigga why did you disable meh? sReward disabled!");
    47. }
    48.  
    49.  
    50. }
    51.  

    Thanks for the help. Please help me fix this.
     
  7. Offline

    L33m4n123

  8. Offline

    SenseTheGod

    No im not getting that at all.
     
  9. Offline

    L33m4n123

    you did not registered the event correctly and at the same time you have in your listener class econ = null so you will get a nullpointerexception oce the event is registered correctly and do not fix that

    http://wiki.bukkit.org/Plugin_Tutorial
     
  10. Offline

    SenseTheGod

    [​IMG]
    Well that link doesn't work. What do you mean its not registed correctly? What part? and what would i changed the econ = null to? Please be more specific
     
  11. Offline

    L33m4n123

    Messed up with that link, my bad

    wiki.bukkit.org/Plugin_Tutorial

    #
    As in - It is not registered correctly. See the link on how to register events

    Well to what ever you got via Vault obviously
     
  12. Offline

    SenseTheGod

    okay. i registed the event better i think now i am getting a stacktrace error i think. and i still have no fucking idea what you mean with
     
  13. Offline

    L33m4n123

  14. Offline

    SenseTheGod

    its actually not that... i have no idea what it is... what do you think it is?
     
  15. Offline

    L33m4n123

    you set the eco to null and then work with it.. it cannot work. And aslong as you do not post the stacktrace here I stick with it.. It's due to the fact that you did eco = null instead of getting the economy you got via vault in your main class
     
  16. Offline

    SenseTheGod

    so instead of eco = null what can i do? im using essentials? eco = essentials dafuq?
     
  17. Offline

    L33m4n123

    for or the 4th time

    You set up your economy already in the main-class with Vault. use THAT
     
  18. Offline

    SenseTheGod

  19. Offline

    L33m4n123

  20. Offline

    Wizehh

    Learn the basic concepts behind Java before attempting to make a plugin; if you don't know how to reference variables from another class, you're not ready to use the Bukkit API.
    TheNewBoston Java Tutorials
     
    L33m4n123 likes this.
Thread Status:
Not open for further replies.

Share This Page