Advertisement
Guest User

Deduct money

a guest
May 24th, 2014
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1.     //begin vault
  2.     public Economy econ;
  3.     //end vault
  4.    
  5.     public void onEnable() {
  6.         //begin vault
  7.         setupEconomy();
  8.         //end vault
  9.     }
  10.     public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
  11.         if(label.equalsIgnoreCase("yourcommand")) {
  12.             if(cs.hasPermission("your.permission.node")) {
  13.                 //You can change the amout of money being deducted
  14.                 EconomyResponse er = econ.withdrawPlayer(cs.getName(), 1.0);
  15.                 if(er.transactionSuccess()) {
  16.                     //The player has enough money and no errors occured
  17.                     //Do your command here
  18.                     return true;
  19.                 }
  20.                 else {
  21.                     cs.sendMessage(ChatColor.RED + "Insufficent funds!");
  22.                     return true;
  23.                 }
  24.             }
  25.             else {
  26.                 cs.sendMessage(ChatColor.RED + "You do not have permission!");
  27.                 return true;
  28.             }
  29.         }
  30.         return false;
  31.     }
  32.     //Some parts of this code are copied from Vault. You will know by the code starting with "begin vault". At the end there should be a "end vault".
  33.     //begin vault
  34.     private boolean setupEconomy() {
  35.         if (getServer().getPluginManager().getPlugin("Vault") == null) {
  36.             return false;
  37.         }
  38.         RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
  39.         if (rsp == null) {
  40.             return false;
  41.         }
  42.         econ = rsp.getProvider();
  43.         return econ != null;
  44.     }
  45.     //end vault
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement