Solved [HELP] Vault

Discussion in 'Plugin Development' started by rob1998@, Jun 22, 2013.

Thread Status:
Not open for further replies.
  1. I need some help with Vault.
    How can I pay every online player?
     
  2. Offline

    kreashenz

    Loop through the online players, then add the money. Simple.
     
  3. And how do I do that?
    Can you give/link me an example or tutorial?
     
  4. Offline

    kreashenz

    Code:java
    1. for(Player players : Bukkit.getOnlinePlayers()){
    2. String name = players.getName();
    3. // add the money
    4. }
     
  5. Offline

    TheBoy3

    I haven't tested this, but try stating the new BukkitRunnable() in a variable (for example, BukkitRunnable br = new BukkitRunnable(){code};) and then do br.runTaskTimer(plugin, 20, 20);
     
  6. I already figured out

    I got an error
    Show Spoiler

    Code:
     [SEVERE] Could not load 'plugins/RoPay.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NoSuchMethodException: com.bugs3.cracmac.RoPay.RoPay.<init>()
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.reload(CraftServer.java:603)
        at org.bukkit.Bukkit.reload(Bukkit.java:275)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_5_R3.PlayerConnection.handleCommand(PlayerConnection.java:971)
        at net.minecraft.server.v1_5_R3.PlayerConnection.chat(PlayerConnection.java:889)
        at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:846)
        at net.minecraft.server.v1_5_R3.Packet3Chat.handle(Packet3Chat.java:44)
        at net.minecraft.server.v1_5_R3.NetworkManager.b(NetworkManager.java:292)
        at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:115)
        at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:581)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NoSuchMethodException: com.bugs3.cracmac.RoPay.RoPay.<init>()
        at java.lang.Class.getConstructor0(Class.java:2730)
        at java.lang.Class.getConstructor(Class.java:1676)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:176)
        ... 21 more
    


    my code:
    Show Spoiler

    Code:java
    1. public RoPay plugin;
    2. public RoPay(RoPay plugin) {
    3. this.plugin = plugin;
    4. }
    5.  
    6. @Override
    7. public void onDisable() {
    8. log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
    9. }
    10.  
    11. @Override
    12. public void onEnable() {
    13. if (!setupEconomy() ) {
    14. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    15. getServer().getPluginManager().disablePlugin(this);
    16. return;
    17. }
    18. setupPermissions();
    19. setupChat();
    20. new BukkitRunnable(){
    21. public void run(){
    22. for(Player players : Bukkit.getOnlinePlayers()){
    23. String name = players.getName();
    24. EconomyResponse r = econ.depositPlayer(name, 20.00);
    25. if(r.transactionSuccess()) {
    26. players.sendMessage(String.format("You were given %s and now have %s", econ.format(r.amount), econ.format(r.balance)));
    27. } else {
    28. players.sendMessage(String.format("An error occured: %s", r.errorMessage));
    29. }
    30. }
    31. }
    32. }.runTaskTimer(plugin, 20, 24000);
    33. }



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

    CubieX

    Do you have "extends JavaPlugin" added behind your main class definition?
     
  8. Yes

    bump

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

    BeYkeRYkt

  10. no, this is my source:
    Show Spoiler

    Code:java
    1. package com.bugs3.cracmac.RoPay;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import net.milkbowl.vault.chat.Chat;
    6. import net.milkbowl.vault.economy.Economy;
    7. import net.milkbowl.vault.economy.EconomyResponse;
    8. import net.milkbowl.vault.permission.Permission;
    9.  
    10. import org.bukkit.Bukkit;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.Listener;
    13. import org.bukkit.plugin.RegisteredServiceProvider;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15. import org.bukkit.scheduler.BukkitRunnable;
    16.  
    17. public class RoPay extends JavaPlugin implements Listener{
    18.  
    19. private static final Logger log = Logger.getLogger("Minecraft");
    20. public static Economy econ = null;
    21. public static Permission perms = null;
    22. public static Chat chat = null;
    23. public RoPay plugin;
    24. public RoPay(RoPay plugin) {
    25. this.plugin = plugin;
    26. }
    27.  
    28. @Override
    29. public void onDisable() {
    30. log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
    31. }
    32.  
    33. @Override
    34. public void onEnable() {
    35. if (!setupEconomy() ) {
    36. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    37. getServer().getPluginManager().disablePlugin(this);
    38. return;
    39. }
    40. setupPermissions();
    41. setupChat();
    42. new BukkitRunnable(){
    43. public void run(){
    44. for(Player players : Bukkit.getOnlinePlayers()){
    45. String name = players.getName();
    46. EconomyResponse r = econ.depositPlayer(name, 20.00);
    47. if(r.transactionSuccess()) {
    48. players.sendMessage(String.format("You were given %s and now have %s", econ.format(r.amount), econ.format(r.balance)));
    49. } else {
    50. players.sendMessage(String.format("An error occured: %s", r.errorMessage));
    51. }
    52. }
    53. }
    54. }.runTaskTimer(plugin, 20, 24000);
    55. }
    56.  
    57.  
    58.  
    59. private boolean setupEconomy() {
    60. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    61. return false;
    62. }
    63. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    64. if (rsp == null) {
    65. return false;
    66. }
    67. econ = rsp.getProvider();
    68. return econ != null;
    69. }
    70.  
    71. private boolean setupChat() {
    72. RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
    73. chat = rsp.getProvider();
    74. return chat != null;
    75. }
    76.  
    77. private boolean setupPermissions() {
    78. RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
    79. perms = rsp.getProvider();
    80. return perms != null;
    81. }
    82.  
    83.  
    84.  
    85. }



    And this is my plugin.yml
    Show Spoiler

    Code:
    name: RoPay
    main: com.bugs3.cracmac.RoPay.RoPay
    version: 1.1
    depend: [Vault]
    authors:
      - rob1998
    
     
  11. Offline

    desht

    Your "public RoPay(RoPay plugin)" constructor is simply wrong - delete it. The "public RoPay plugin" field is also pointless.

    What is it you're trying to achieve with that? If you need access to the plugin instance anywhere within your RoPay class, simply use this.
     
  12. Thanks it works
     
Thread Status:
Not open for further replies.

Share This Page