Economy Offline Player Problems

Discussion in 'Plugin Development' started by hubeb, Jun 26, 2013.

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

    hubeb

    Ok so i have written an Economy plugin. It works fine up until trying to send money to an offline player. How would i go about doing this?

    Command(last modification may not work):
    Code:java
    1.  
    2. if(label.equalsIgnoreCase("pay")){
    3. if(args.length == 2){
    4. try{
    5. if(isOnline(args[0]) == true){
    6. String target = Bukkit.getPlayer(args[0]).getName();
    7. if(isInt(args[1])==true){
    8. try {
    9. Bank.pay(player.getName(),target,args[1]);
    10. } catch (IOException e) {System.out.println("Error With Payment between "+ player.getName()+" & "+ target + " for " + args[1]);}
    11. }
    12. }else{
    13. //String target1 = Bukkit.getOfflinePlayer(args[0]).getName();
    14. if(isInt(args[1])==true){
    15. try {
    16. Bank.pay(player.getName(), args[0], args[1]);
    17. } catch (IOException e) {System.out.println("Error With Payment between "+ player.getName()+" & "+ args[0] + " for " + args[1]);}
    18. }
    19. }
    20.  
    21. }catch(Exception e){System.out.println("Error With Payments");}
    22. }
    23.  

    Pay Method:
    Code:java
    1.  
    2. public static void pay(String player, String target, String amount) throws IOException {
    3. double paymentAmnt = Double.parseDouble(amount);
    4. double bal = 0;
    5. File playerFile = new File(plugin.getDataFolder() + File.separator + "players" + File.separator + player + ".yml");
    6. File targetFile = new File(plugin.getDataFolder() + File.separator + "players" + File.separator + target + ".yml");
    7. if(playerFile.exists()){
    8. FileConfiguration fc = YamlConfiguration.loadConfiguration(playerFile);
    9. bal = fc.getDouble("Player.Balance");
    10. if(!(paymentAmnt > bal)){
    11. if(targetFile.exists()){
    12. FileConfiguration fct = YamlConfiguration.loadConfiguration(targetFile);
    13. double targetBal = fct.getDouble("Player.Balance");
    14. fct.set("Player.Balance", targetBal+paymentAmnt);
    15. fct.save(targetFile);
    16. }
    17. fc.set("Player.Balance", bal - paymentAmnt);
    18. fc.save(playerFile);
    19. Player p = Bukkit.getPlayer(player);
    20. try{
    21. Player t = Bukkit.getPlayer(target);
    22. t.sendMessage(ChatColor.GREEN+"You have recieved "+ChatColor.AQUA+paymentAmnt+" from "+ChatColor.GRAY+p.getName()+".");
    23. }catch(Exception e){System.out.println("Player not online - no problem (Payment Still sucessful");}
    24. p.sendMessage(ChatColor.GREEN+"You have sent "+ChatColor.GRAY+target+ " "+ChatColor.AQUA+ paymentAmnt+ChatColor.GREEN+".");
    25. }else{
    26.  
    27. }
    28. }
    29.  


    I know something isnt working, because its tripping the Error with Payments Error. (Line:21 in command)

    Any help would be appreciated thanks.
     
  2. Offline

    skipperguy12

    Well, what does it do right now? What doesn't work? Errors? Simply not sending? If it's just not sending, try debugging to see where it all stops working.
     
  3. Offline

    hubeb

    The problem is getting whether the player is online or offline - Error is occurring here.
    IsOnline code:
    Code:java
    1. public boolean isOnline(String pName){
    2. if(Bukkit.getPlayer(pName).isOnline()){
    3. return true;
    4. }
    5. return false;
    6. }
    7.  
     
  4. Offline

    skipperguy12

    hubeb
    Why... why do you even have a method for that? You just put a method which does the same thing in a method...
    What's the error?
     
  5. Offline

    hubeb

    lol the error is:
    Code:
    19:50:14 [INFO] L0rdOfTheCraft issued server command: /pay Min3CraftDud3 20
    19:50:14 [INFO] Error With Payments
    >
    Which means that somewhere between line 4 and line 21 of Command there is an issue happening, give me a second ill remove the try catch and give you raw error.


    Code:
    20:08:54 [INFO] L0rdOfTheCraft[/192.168.0.7:4817] logged in with entity id 119 a
    t ([world] 670.3611203616604, 69.0, 269.8016983453719)
    20:08:58 [INFO] L0rdOfTheCraft issued server command: /pay Min3CraftDud3 20
    20:08:58 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'pay'
    in plugin EEco v1.5
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    9)
            at org.bukkit.craftbukkit.v1_5_R3.CraftServer.dispatchCommand(CraftServe
    r.java:523)
            at net.minecraft.server.v1_5_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:965)
            at net.minecraft.server.v1_5_R3.PlayerConnection.chat(PlayerConnection.j
    ava:883)
            at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java
    :840)
            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
    :109)
            at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
            at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:5
    81)
            at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:2
    26)
            at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:4
    77)
            at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java
    :410)
            at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:5
    73)
    Caused by: java.lang.NullPointerException
            at info.edenmmorpg.EEco.EEco.isOnline(EEco.java:183)
            at info.edenmmorpg.EEco.EEco.onCommand(EEco.java:45)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
            ... 15 more
    >
    Line 45 = if(isOnline(args[0]) == true){
    line 183 = if(Bukkit.getPlayer(pName).isOnline()){

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

    skipperguy12

    hubeb
    Try debugging. Make use of the logger, and just output everything.
     
  7. Offline

    hubeb

    skipperguy12
    ok ive re written the pay command, but there is a new problem.
    The args[0] is supposed to be player name. and it will auto correct it if the user only uses for example (only the first 4 letters of a name such as Min3 | full name = min3craftdud3.

    when the player is offline it wont do that, any suggestions on how to make that happen.

    Above is only error atm.

    new command:
    Code:java
    1.  
    2. if(label.equalsIgnoreCase("pay")){
    3. if(args.length == 2){
    4. try{
    5. if(isInt(args[1])==true){
    6. try {
    7. Bank.pay(player.getName(),args[0],args[1]);
    8. } catch (IOException e) {System.out.println("Error With Payment between "+ player.getName()+" & "+ args[0] + " for " + args[1]);}
    9. }
    10. }catch(Exception e){System.out.println("Error With Payments");}
    11. }
    12.  


    its tripping line 23 of the pay method:
    player not online - no problem (payment still successful)

    Thanks,
    hubeb

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
Thread Status:
Not open for further replies.

Share This Page