Economy Error

Discussion in 'Plugin Development' started by tuupkedebest, Apr 30, 2014.

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

    tuupkedebest

    Hello

    i have this error but what is the problem?
    Cannot make a static reference to the non-static method getBalance(String) from the type EconomyScoreboard.javaline 56Java Problem

    it from this code!
    Code:java
    1. package mcbobbejaan.scoreboard;
    2.  
    3. import com.bergerkiller.bukkit.common.scoreboards.CommonObjective;
    4. import com.bergerkiller.bukkit.common.scoreboards.CommonScore;
    5. import com.bergerkiller.bukkit.common.scoreboards.CommonScoreboard;
    6. import com.bergerkiller.bukkit.common.scoreboards.CommonScoreboard.Display;
    7. import net.milkbowl.vault.economy.Economy;
    8. import java.util.ArrayList;
    9. import java.util.List;
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.Location;
    12. import org.bukkit.Server;
    13. import org.bukkit.World;
    14. import org.bukkit.command.Command;
    15. import org.bukkit.command.CommandSender;
    16. import org.bukkit.entity.Entity;
    17. import org.bukkit.entity.HumanEntity;
    18. import org.bukkit.entity.Minecart;
    19. import org.bukkit.entity.Player;
    20. import org.bukkit.event.EventHandler;
    21. import org.bukkit.event.Listener;
    22. import org.bukkit.event.entity.CreatureSpawnEvent;
    23. import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    24. import org.bukkit.event.inventory.InventoryCloseEvent;
    25. import org.bukkit.event.player.PlayerJoinEvent;
    26. import org.bukkit.event.player.PlayerQuitEvent;
    27. import org.bukkit.plugin.PluginManager;
    28. import org.bukkit.plugin.java.JavaPlugin;
    29. import org.bukkit.scheduler.BukkitScheduler;
    30. import org.bukkit.util.Vector;
    31.  
    32. public class Scoreboard extends JavaPlugin
    33. implements Listener
    34. {
    35. int lines = 6;
    36. List<String> listlore = new ArrayList();
    37. List<String> members = new ArrayList();
    38.  
    39. public void onEnable()
    40. {
    41. getServer().getPluginManager().registerEvents(this, this);
    42. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    43. {
    44. public void run()
    45. {
    46. int onlinePlayers = Bukkit.getOnlinePlayers().length;
    47. int totalPlayers = Bukkit.getOfflinePlayers().length;
    48. for (Player player : Bukkit.getOnlinePlayers())
    49. {
    50. CommonObjective sidebar = CommonScoreboard.get(player).getObjective(CommonScoreboard.Display.SIDEBAR);
    51. CommonScore score = sidebar.getScore("online");
    52. CommonScore score2 = sidebar.getScore("punten");
    53. if (score == null)
    54. {
    55. score = sidebar.createScore("online", "§aOnline", onlinePlayers);
    56. score2 = sidebar.createScore("punten", "§aBobbieCoins", (int) Economy.getBalance(player.getName()));
    57. }
    58. else
    59. {
    60. score.setValue(onlinePlayers);
    61. score.update();
    62. score2.setValue((int) Economy.getBalance(player.getName()));
    63. score2.update();
    64. }
    65. }
    66. }
    67. }
    68. , 20L, 20L);
    69. }
     
  2. Offline

    mythbusterma

    You're new to Java aren't you? Basically what that error says is that "Economy.getBalance(...)" is not valid code because Economy is a class, not an object. Instantiate Economy and then use getBalance(...) on the instance.
     
  3. Offline

    tackleza

    You should put there code to new class and create timer to run that class evey x sec

    getServer().getScheduler().scheduleSyncRepeatingTask(this, new YourNewClass(),0,20);//run every 1 sec

    20 is ticks not sec, if you want this task run every 5 sec that number should be 5*20 = 200
     
  4. Offline

    tuupkedebest

    Hello,

    And thanks for the help but i'm new with java and i don't know how to code the class you said! please help me a little bit more!

    Greetz
     
  5. Offline

    mythbusterma

    You haven't told us enough about your plugin to help you out, for all we know you may not even need a scheduler or a plugin that runs every tick. Please tell us to what end you're programming this.
     
  6. Offline

    Lolmewn

    tuupkedebest Since you're using Vault, check out how to get the Economy class with their documentation. I suggest you store the object in a local (private) variable and use that to get the balance of players.
     
  7. Offline

    tuupkedebest

    @mythbusterma Its a plugin that is a scoreboard sidebar and shows the online players and the money they have but i dont know how to code that vault thing because i'm a beginner in java! but is it possible to use essentials economy instead of Vault? and if it is possible how? i think it is a little thing why it doesn't work but i have no solution

    SORRY FOR BAD ENGLISH!

    Please help me!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  8. Offline

    Minnymin3

    Don't bump within 24 hours. People have helped you. You have been told to go check out the Vault API documentation which is written ON THE MAIN PAGE of their plugin. It is very, very simple and if you have difficulty doing that then you need to go back and learn the basics of Java BEFORE asking for help.
     
  9. Offline

    tuupkedebest

    I have now this the plugin works but the coins in the sidebar doesnt update!
    Code:java
    1. package mcbobbejaan.scoreboard;
    2.  
    3. import com.bergerkiller.bukkit.common.scoreboards.CommonObjective;
    4. import com.bergerkiller.bukkit.common.scoreboards.CommonScore;
    5. import com.bergerkiller.bukkit.common.scoreboards.CommonScoreboard;
    6. import com.bergerkiller.bukkit.common.scoreboards.CommonScoreboard.Display;
    7.  
    8. import net.milkbowl.vault.economy.Economy;
    9. import net.milkbowl.vault.economy.EconomyResponse;
    10.  
    11. import java.util.ArrayList;
    12. import java.util.List;
    13.  
    14. import org.bukkit.Bukkit;
    15. import org.bukkit.Location;
    16. import org.bukkit.Server;
    17. import org.bukkit.World;
    18. import org.bukkit.command.Command;
    19. import org.bukkit.command.CommandSender;
    20. import org.bukkit.entity.Entity;
    21. import org.bukkit.entity.HumanEntity;
    22. import org.bukkit.entity.Minecart;
    23. import org.bukkit.entity.Player;
    24. import org.bukkit.event.EventHandler;
    25. import org.bukkit.event.Listener;
    26. import org.bukkit.event.entity.CreatureSpawnEvent;
    27. import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    28. import org.bukkit.event.inventory.InventoryCloseEvent;
    29. import org.bukkit.event.player.PlayerJoinEvent;
    30. import org.bukkit.event.player.PlayerQuitEvent;
    31. import org.bukkit.plugin.PluginManager;
    32. import org.bukkit.plugin.java.JavaPlugin;
    33. import org.bukkit.scheduler.BukkitScheduler;
    34. import org.bukkit.util.Vector;
    35.  
    36. public class Scoreboard extends JavaPlugin
    37. implements Listener
    38. {
    39. int lines = 6;
    40. List<String> listlore = new ArrayList();
    41. List<String> members = new ArrayList();
    42.  
    43. public void onEnable()
    44. {
    45. getServer().getPluginManager().registerEvents(this, this);
    46. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    47. {
    48. public void run()
    49. {
    50. int onlinePlayers = Bukkit.getOnlinePlayers().length;
    51. int totalPlayers = Bukkit.getOfflinePlayers().length;
    52. for (Player player : Bukkit.getOnlinePlayers())
    53. {
    54. CommonObjective sidebar = CommonScoreboard.get(player).getObjective(CommonScoreboard.Display.SIDEBAR);
    55. CommonScore score = sidebar.getScore("online");
    56. CommonScore score2 = sidebar.getScore("punten");
    57. if (score == null)
    58. {
    59. score = sidebar.createScore("online", "§aOnline", onlinePlayers);
    60. score2 = sidebar.createScore("punten", "§aBobbieCoins", (int) getBalance(player.getName()));
    61. }
    62. else
    63. {
    64. score.setValue(onlinePlayers);
    65. score.update();
    66. score2.setValue((int) getBalance(player.getName()));
    67. score2.update();
    68. }
    69. }
    70. }
    71. }
    72. , 20L, 20L);
    73. }
    74.  
    75. @EventHandler
    76. public void oninvsluit(InventoryCloseEvent event)
    77. {
    78. HumanEntity human = event.getPlayer();
    79. if ((human instanceof Player))
    80. {
    81. Player player = (Player)human;
    82. this.members.remove(player.getName());
    83. }
    84. }
    85.  
    86. @EventHandler
    87. public void onSpawn(CreatureSpawnEvent event)
    88. {
    89. event.getEntity();
    90. if (!event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.SPAWNER_EGG))
    91. event.setCancelled(true);
    92. }
    93.  
    94. @EventHandler
    95. public void onLeave(PlayerQuitEvent event)
    96. {
    97. }
    98.  
    99. @EventHandler
    100. public void onJoin(PlayerJoinEvent event)
    101. {
    102. Player speler = event.getPlayer();
    103. speler.getLocation();
    104. CommonObjective sidebar = CommonScoreboard.get(speler).getObjective(CommonScoreboard.Display.SIDEBAR);
    105. sidebar.show();
    106. sidebar.setDisplayName("§6MC§bBobbejaan");
    107. }
    108.  
    109. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    110. {
    111. if ((cmd.getName().equalsIgnoreCase("wet")) &&
    112. (args.length >= 1) && (args[0].toLowerCase().equals("launchcartcoord")) &&
    113. (args.length >= 5))
    114. {
    115. int x = getIntFromString(args[1], 0);
    116. int z = getIntFromString(args[2], 0);
    117. float speed = getFloatFromString(args[3], 0.0F);
    118. for (Entity curEntity : getServer().getWorld(args[4]).getEntities()) {
    119. if (((curEntity instanceof Minecart)) &&
    120. (curEntity.getLocation().getBlockX() == x) && (curEntity.getLocation().getBlockZ() == z))
    121. {
    122. Minecart mc = (Minecart)curEntity;
    123. sender.sendMessage("LAUNCHED!");
    124. Vector speedvec = mc.getVelocity();
    125. speedvec.setX(0);
    126. speedvec.setZ(0);
    127. speedvec.setY(speed);
    128. mc.setVelocity(speedvec);
    129.  
    130. speedvec = mc.getFlyingVelocityMod();
    131. speedvec.setX(0);
    132. speedvec.setZ(0);
    133. mc.setFlyingVelocityMod(speedvec);
    134. }
    135. }
    136. }
    137.  
    138. return false;
    139. }
    140.  
    141. public boolean isEmpty(String str)
    142. {
    143. return (str == null) || (str.length() == 0);
    144. }
    145.  
    146. public int getIntFromString(String str, int defval)
    147. {
    148. int ret = defval;
    149. if (!isEmpty(str)) {
    150. try
    151. {
    152. ret = Integer.parseInt(str);
    153. }
    154. {
    155. ret = defval;
    156. }
    157. }
    158. return ret;
    159. }
    160.  
    161. public float getFloatFromString(String str, float defval)
    162. {
    163. float ret = defval;
    164. if (!isEmpty(str)) {
    165. try
    166. {
    167. ret = Float.parseFloat(str);
    168. }
    169. {
    170. ret = defval;
    171. }
    172. }
    173. return ret;
    174. }
    175.  
    176. public String validateString(String str2)
    177. {
    178. String str = "";
    179. if (!isEmpty(str2)) {
    180. str = str2;
    181. }
    182. return str;
    183. }
    184.  
    185. public String[] getElementsFromString(String data)
    186. {
    187. return data.split("/");
    188. }
    189.  
    190. public int getIntFromStringarray(String[] strarr, int arrItem, int defval)
    191. {
    192. int ret = defval;
    193. if ((strarr.length > arrItem) &&
    194. (!isEmpty(strarr[arrItem]))) {
    195. try
    196. {
    197. ret = Math.abs(Integer.parseInt(strarr[arrItem]));
    198. }
    199. {
    200. ret = defval;
    201. }
    202. }
    203.  
    204. return ret;
    205. }
    206.  
    207. public int[] getIntarrayFromStringarray(String[] strarr, int defval)
    208. {
    209. int[] ret = new int[strarr.length];
    210. for (int i = 0; i < strarr.length; i++) {
    211. if (!isEmpty(strarr[i])) {
    212. try
    213. {
    214. ret[i] = Math.abs(Integer.parseInt(strarr[i]));
    215. }
    216. {
    217. ret[i] = defval;
    218. }
    219. }
    220. }
    221. return ret;
    222. }
    223.  
    224. public String getStringfromIntarray(int[] arr)
    225. {
    226. String lol = "";
    227. for (int i = 0; i < arr.length; i++)
    228. {
    229. lol = lol + arr[i];
    230. if (i < arr.length - 1) {
    231. lol = lol + "/";
    232. }
    233. }
    234. return lol;
    235. }
    236.  
    237. public EconomyResponse bankBalance(String arg0) {
    238. // TODO Auto-generated method stub
    239. return null;
    240. }
    241.  
    242. public EconomyResponse bankDeposit(String arg0, double arg1) {
    243. // TODO Auto-generated method stub
    244. return null;
    245. }
    246.  
    247. public EconomyResponse bankHas(String arg0, double arg1) {
    248. // TODO Auto-generated method stub
    249. return null;
    250. }
    251.  
    252. public EconomyResponse bankWithdraw(String arg0, double arg1) {
    253. // TODO Auto-generated method stub
    254. return null;
    255. }
    256.  
    257. public EconomyResponse createBank(String arg0, String arg1) {
    258. // TODO Auto-generated method stub
    259. return null;
    260. }
    261.  
    262. public boolean createPlayerAccount(String arg0) {
    263. // TODO Auto-generated method stub
    264. return false;
    265. }
    266.  
    267. public boolean createPlayerAccount(String arg0, String arg1) {
    268. // TODO Auto-generated method stub
    269. return false;
    270. }
    271.  
    272. public String currencyNamePlural() {
    273. // TODO Auto-generated method stub
    274. return null;
    275. }
    276.  
    277. public String currencyNameSingular() {
    278. // TODO Auto-generated method stub
    279. return null;
    280. }
    281.  
    282. public EconomyResponse deleteBank(String arg0) {
    283. // TODO Auto-generated method stub
    284. return null;
    285. }
    286.  
    287. public EconomyResponse depositPlayer(String arg0, double arg1) {
    288. return null;
    289. }
    290.  
    291. public EconomyResponse depositPlayer(String arg0, String arg1, double arg2) {
    292. return null;
    293. }
    294.  
    295. public String format(double arg0) {
    296. return null;
    297. }
    298.  
    299. public int fractionalDigits() {
    300. // TODO Auto-generated method stub
    301. return 0;
    302. }
    303.  
    304. public double getBalance(String arg0) {
    305. // TODO Auto-generated method stub
    306. return 0;
    307. }
    308.  
    309. public double getBalance(String arg0, String arg1) {
    310. // TODO Auto-generated method stub
    311. return 0;
    312. }
    313.  
    314. public List<String> getBanks() {
    315. return null;
    316. }
    317.  
    318. public boolean has(String arg0, double arg1) {
    319. // TODO Auto-generated method stub
    320. return false;
    321. }
    322.  
    323. public boolean has(String arg0, String arg1, double arg2) {
    324. // TODO Auto-generated method stub
    325. return false;
    326. }
    327.  
    328. public boolean hasAccount(String arg0) {
    329. // TODO Auto-generated method stub
    330. return false;
    331. }
    332.  
    333. public boolean hasAccount(String arg0, String arg1) {
    334. return false;
    335. }
    336.  
    337. public boolean hasBankSupport() {
    338. // TODO Auto-generated method stub
    339. return false;
    340. }
    341.  
    342. public EconomyResponse isBankMember(String arg0, String arg1) {
    343. // TODO Auto-generated method stub
    344. return null;
    345. }
    346.  
    347. public EconomyResponse isBankOwner(String arg0, String arg1) {
    348. return null;
    349. }
    350.  
    351. public EconomyResponse withdrawPlayer(String arg0, double arg1) {
    352. // TODO Auto-generated method stub
    353. return null;
    354. }
    355.  
    356. public EconomyResponse withdrawPlayer(String arg0, String arg1, double arg2) {
    357. // TODO Auto-generated method stub
    358. return null;
    359. }}[/i][/i][/i][/i][/i]
     
Thread Status:
Not open for further replies.

Share This Page