Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. package lobby.coinsystem;
  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 lobby.main.Main;
  14.  
  15. public class EconomySystem implements CommandExecutor{
  16.  
  17.  
  18. @Override
  19. public boolean onCommand(CommandSender sender, Command command, String lable, String[] args) {
  20. Player p = (Player)sender;
  21.  
  22. if(args.length == 0) {
  23. p.sendMessage(Main.prefix + "§c§l Du hast §f§l[" + getMoney(p.getName()) + "]§c§l Coins");
  24. } else if(args.length == 3) {
  25. if(p.hasPermission("example.coins")) {
  26. if(args[0].equalsIgnoreCase("add")) {
  27. String target = args[1];
  28. Integer amount = Integer.valueOf(args[2]);
  29. addMoney(target, amount);
  30. p.sendMessage(Main.prefix + "§c§l Du hast dem Spieler "+target+" §f§l[" +amount+"]§c§l Coins zu seinem Guthaben hinzugefügt , Der Spieler hat jetzt "+getMoney(target)+ " Coins !" );
  31. } else if(args[0].equalsIgnoreCase("remove")) {
  32. String target = args[1];
  33. Integer amount = Integer.valueOf(args[2]);
  34. removeMoney(target, amount);
  35. p.sendMessage(Main.prefix + "§c§l Du hast dem Spieler "+target+" §f§l[" +amount+"]§c§l Coins vom Guthaben entfernt , Der Spieler hat jetzt §f§l["+getMoney(target)+ "§c§L Coins !" );
  36. } else if(args[0].equalsIgnoreCase("set")) {
  37. String target = args[1];
  38. Integer amount = Integer.valueOf(args[2]);
  39. setMoney(target, amount);
  40. p.sendMessage(Main.prefix + "§c§l Du hast dem Spieler "+target+" Das Guthaben auf §f§l[" +amount+"]§c§l gesetzt !" );
  41. }
  42. } else {
  43. p.sendMessage(Main.prefix + "§c§l Dazu hast du keine Rechte ! ");
  44. }
  45. }else {
  46. p.sendMessage(Main.prefix + "§c§l Falsche verwendung! Bitte benutze /coins add/remove/set (SpielerName) (zahl) ");
  47. }
  48. return true;
  49. }
  50.  
  51. public Integer getMoney(String name) {
  52. File file = new File("plugins/baastizockt", "money.yml");
  53. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  54.  
  55. int money = cfg.getInt(name + ".money");
  56. return money;
  57. }
  58. public static void addMoney(String name, int amount) {
  59. File file = new File("plugins/baastizockt", "money.yml");
  60. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  61.  
  62. int money = cfg.getInt(name + ".money");
  63. money=money+amount;
  64. cfg.set(name + ".money" , money);
  65. try {
  66. cfg.save(file);
  67. } catch (IOException e) {
  68. e.printStackTrace();
  69. }
  70.  
  71. }
  72. public void removeMoney(String name, int amount) {
  73. File file = new File("plugins/baastizockt", "money.yml");
  74. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  75.  
  76. int money = cfg.getInt(name + ".money");
  77. money=money-amount;
  78. cfg.set(name + ".money" , money);
  79. try {
  80. cfg.save(file);
  81. } catch (IOException e) {
  82. e.printStackTrace();
  83. }
  84.  
  85. }
  86. public void setMoney(String name, int amount) {
  87. File file = new File("plugins/baastizockt", "money.yml");
  88. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  89. cfg.set(name + ".money" , amount);
  90. try {
  91. cfg.save(file);
  92. } catch (IOException e) {
  93. e.printStackTrace();
  94. }
  95. }
  96. public boolean hasEnoughMoney(String name, int amount) {
  97. File file = new File("plugins/baastizockt", "money.yml");
  98. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
  99. int money = cfg.getInt(name + ".money");
  100. if(money >=amount) {
  101. return true;
  102. } else
  103. return false;
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement