Advertisement
Guest User

Code

a guest
Dec 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. package eu.penguinpiz.slenderman.commands;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5.  
  6. import org.bukkit.command.Command;
  7. import org.bukkit.command.CommandExecutor;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10. import org.bukkit.configuration.file.YamlConfiguration;
  11. import org.bukkit.entity.Player;
  12.  
  13. import eu.penguinpiz.slenderman.main.Main;
  14.  
  15. public class CoinSystem implements CommandExecutor{
  16.  
  17. @Override
  18. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  19. Player p = (Player) sender;
  20. if(args.length == 0) {
  21. p.sendMessage(Main.PREFIX + "§7You Have §a" + getCoins(p.getName()));
  22. } else if(args.length == 3) {
  23. if(args[0].equalsIgnoreCase("add")) {
  24. if(p.hasPermission("sm.coind.add")) {
  25. String target = args[1];
  26. Integer amount = Integer.valueOf(args[2]);
  27. addCoins(target, amount);
  28. p.sendMessage(Main.PREFIX + "§7The Player §f" + target + " §aGot " + amount + " §f§lCoins");
  29. } else {
  30. p.sendMessage(Main.NO_PERMISSION);
  31. }
  32. }else if(args[0].equalsIgnoreCase("remove")) {
  33. if(p.hasPermission("sm.coind.remove")) {
  34. String target = args[1];
  35. Integer amount = Integer.valueOf(args[2]);
  36. removeCoins(target, amount);
  37. p.sendMessage(Main.PREFIX + "§7The Player §f" + target + " §cLost " + amount + " §f§lCoins");
  38. } else {
  39. p.sendMessage(Main.NO_PERMISSION);
  40. }
  41. } else if(args[0].equalsIgnoreCase("set")) {
  42. if(p.hasPermission("sm.coind.set")) {
  43. String target = args[1];
  44. Integer amount = Integer.valueOf(args[2]);
  45. setCoins(target, amount);
  46. p.sendMessage(Main.PREFIX + "§7The §f§lCoins §7of " + target + " §7were §aSet §7to " + amount);
  47. } else {
  48. p.sendMessage(Main.NO_PERMISSION);
  49. }
  50. } else {
  51. p.sendMessage(Main.PREFIX + "§7System §aOutDated§7! §7:D");
  52. }
  53. } else {
  54. p.sendMessage(Main.PREFIX + "§7System §aOutDated§7! §7:D");
  55. }
  56. return false;
  57. }
  58.  
  59. public Integer getCoins(String name) {
  60. File file = new File("plugins/SlenderMan", "coins.yml");
  61. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  62.  
  63. int coins = cfg.getInt(name + ".coins");
  64. return coins;
  65. }
  66.  
  67. public void addCoins(String name, int amount) {
  68. File file = new File("plugins/SlenderMan", "coins.yml");
  69. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  70.  
  71. int coins = cfg.getInt(name + ".coins");
  72. coins=coins+amount;
  73. cfg.set(name + ".coins", coins);
  74. try {
  75. cfg.save(file);
  76. } catch (IOException e) {
  77. e.printStackTrace();
  78. }
  79. }
  80.  
  81. public void removeCoins(String name, int amount) {
  82. File file = new File("plugins/SlenderMan", "coins.yml");
  83. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  84.  
  85. int coins = cfg.getInt(name + ".coins");
  86. coins=coins-amount;
  87. cfg.set(name + ".coins", coins);
  88. try {
  89. cfg.save(file);
  90. } catch (IOException e) {
  91. e.printStackTrace();
  92. }
  93.  
  94. }
  95.  
  96. public void setCoins(String name, int amount) {
  97. File file = new File("plugins/SlenderMan", "coins.yml");
  98. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  99.  
  100. cfg.set(name + ".coins", amount);
  101. try {
  102. cfg.save(file);
  103. } catch (IOException e) {
  104. e.printStackTrace();
  105. }
  106. }
  107.  
  108. public boolean hasCoins(String name, int amount) {
  109. File file = new File("plugins/SlenderMan", "coins.yml");
  110. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  111.  
  112. int coins = cfg.getInt(name + ".coins");
  113. if(coins >= amount) {
  114. removeCoins(name, amount);
  115. return true;
  116. } else
  117. return false;
  118.  
  119. }
  120.  
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement