How to charge people money when using a command

Discussion in 'Plugin Development' started by jacklin213, Sep 8, 2012.

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

    jacklin213

    I have made my config.yml and it works fine. I just need to know how i would get commands out of the config and charge people if they use it

    config.yml
    Code:YAML
    1. #=== CmdCharger - config (made by Jacklin213) ===#
    2. No-Money-Msg: 'Sorry! You need %price% to run %cmd%'
    3. Prices:
    4. Commands:
    5. ExampleCommand: # Put your command name where ExmapleCommand is
    6. Price: 1.50
    7. Essentialsspawn:
    8. Price: 2.35
    9. CmdCharger setprice [command] [price]: #how would i get this command because it had variables in it [command] [price]
    10.  


    Command bit
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd,
    2. String commandLabel, String[] args) {
    3. if (commandLabel.equalsIgnoreCase("cmdcharge")
    4. || commandLabel.equalsIgnoreCase("cc")) {
    5. if (args.length >= 3) {
    6. if (args[0].equalsIgnoreCase("testprice")) {
    7. String command = args[1];
    8. this.getConfig().set("Prices.Commands." + command,
    9. command);
    10. this.saveConfig();
    11. try {
    12. int price = Integer.parseInt(args[2]);
    13. this.getConfig().set(
    14. "Prices.Commands." + command + ".Price",
    15. price);
    16. this.saveConfig();
    17. sender.sendMessage("The price for " + command
    18. + " has been set to:" + price);
    19. } catch (NumberFormatException e) {
    20. sender.sendMessage(ChatColor.RED
    21. + "This is not a number! Try typing a number in");
    22. }
    23. return true;
    24. } else {
    25. sender.sendMessage("testfailed");
    26. }
    27. }else if (args.length <= 1){
    28. if (args[0].equalsIgnoreCase("help")){
    29. try {
    30. int page = Integer.parseInt(args[0]);
    31.  
    32. if (page == 1) {
    33. sender.sendMessage(ChatColor.YELLOW + " ------------ " + ChatColor.WHITE + "Help: CmdCharger (Page 1)" + ChatColor.YELLOW + " ------------");
    34. sender.sendMessage(ChatColor.GOLD + "/cmdcharge" + ChatColor.GRAY + " - " + ChatColor.WHITE + "Shows info");
    35. sender.sendMessage(ChatColor.GOLD + "/cmdcharge setprice [command] [price]" + ChatColor.GRAY + " - " + ChatColor.WHITE + "Set price for command!");
    36.  
    37. } else {
    38. sender.sendMessage(ChatColor.RED + " Invalid page number specified. There is only 1 page right now.");
    39. }
    40. } catch (NumberFormatException nfe) {
    41. sender.sendMessage(ChatColor.RED + " Invalid page number specified. There is only 1 page right now.");
    42. }
    43. }
    44.  
    45. }
    46.  
    47. return info(sender);
    48. }
    49. return false;
    50. }


    anymore info can be obtained here https://github.com/jacklin213/CmdCharger
     
  2. Offline

    tommycake50

    you would use vault to take money and if the transaction is successful execute the command.
    but im not sure how to check if another plugin's command is run.
     
  3. Offline

    jacklin213

    Yeh that's what I'm looking for now
     
  4. Try:
    Code:
    player.preformCommand("eco take 10")
     
  5. Offline

    jacklin213

    k ill go try now
     
Thread Status:
Not open for further replies.

Share This Page