How?

Discussion in 'Plugin Development' started by ElCreeperHD, Jul 1, 2015.

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

    ElCreeperHD

    Im making a plugin that subtracts money of the executor of the command (using essentials API), but i have a problem. I don t know to put the player to substract the money! I tried but i can t use in the method subtract , (Player, double)in essentials API! Here its the code:

    Code:
    public boolean onCommand(CommandSender sender, Command command,
            String commandLabel, String[] args)
    {
    if (command.getName().equalsIgnoreCase("test"))
    return test(sender, args);
    
    return true;
    }
    
    private boolean test(CommandSender sender, String[] args)
    {
    // comandos
        Player p = sender.getPlayer();
        subtract(p,1000000);
       
        return true;
        }   
       
    
    
             
     
  2. Offline

    terturl890

    Why dont you just pit it all into the same method?

    Code:
    public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
    
        if(label.equalsIgnoreCase("test")) {
    
            if((cs instanceof Player)) {
    
                Player p = (Player)cs;
                subtract(p, Integer.valueOf(args[0]));
    
            }
    
        }
    
        return false;
    }
    
    This will do the exact thing you want but more compact and able to accept the argument after /test

    EXAMPLE: /test 1000

    will take $1,000 away from you.
     
    ElCreeperHD likes this.
  3. Offline

    Ruptur

    @ElCreeperHD
    Did you static import the method subtract else then it wouldnt work because the method subtract doesnt exist
     
  4. Offline

    terturl890

    I believe he is just not showing it but it does exist somewhere in the plugin
     
  5. Offline

    BagduFagdu

  6. Offline

    ElCreeperHD

Thread Status:
Not open for further replies.

Share This Page