Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. package me.oneerlijk.economy;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.plugin.java.JavaPlugin;
  5.  
  6. public class SmallEconomy extends JavaPlugin
  7. {
  8.  
  9.  
  10.  
  11. public void onEnable()
  12. {
  13. getCommand("bal").setExecutor(new EconCommand());
  14. new EconManager(this);
  15. SLAPI.loadBalances();
  16. Bukkit.getPluginManager().registerEvents(new PlayerJoin(), this);
  17. }
  18.  
  19. public void onDisable()
  20. {
  21. SLAPI.saveBalances();
  22. }
  23.  
  24. }
  25.  
  26. -------------------------------
  27.  
  28. package me.oneerlijk.economy;
  29.  
  30. import java.util.HashMap;
  31.  
  32. public class EconManager
  33. {
  34. private static SmallEconomy plugin;
  35. public EconManager(SmallEconomy instance)
  36. {
  37. plugin = instance;
  38. }
  39. public static HashMap<String, Double> bal = new HashMap<>(); // {PlayerName, Balance}
  40.  
  41. public static void setBalance (String player, double amount)
  42. {
  43. bal.put(player, amount);
  44.  
  45. }
  46.  
  47. public static Double getBalance(String player)
  48. {
  49. return bal.get(player);
  50. }
  51.  
  52. public static boolean hasAccount(String player)
  53. {
  54. return bal.containsKey(player);
  55. }
  56.  
  57.  
  58. public static HashMap<String, Double> getBalanceMap()
  59. {
  60. return bal;
  61. }
  62.  
  63. public static SmallEconomy getPlugin()
  64. {
  65. return plugin;
  66. }
  67. }
  68.  
  69. --------------------
  70.  
  71. package me.oneerlijk.economy;
  72.  
  73. import org.bukkit.command.Command;
  74. import org.bukkit.command.CommandExecutor;
  75. import org.bukkit.command.CommandSender;
  76.  
  77. import net.md_5.bungee.api.ChatColor;
  78.  
  79. public class EconCommand implements CommandExecutor
  80. {
  81.  
  82.  
  83. @Override
  84. public boolean onCommand(CommandSender cs, Command command, String s, String[] args)
  85. {
  86. if(args.length != 3)
  87. {
  88. cs.sendMessage(ChatColor.RED+ "Hey! Je kunt dat commando niet zo gebruiken!");
  89. cs.sendMessage(ChatColor.GREEN+ "Gebruik: /bal <add/remove/set> <speler> <hoeveel>");
  90. return true;
  91.  
  92. }
  93. if(args[0].equalsIgnoreCase("add"))
  94. {
  95. if(!EconManager.hasAccount(args[1]))
  96. {
  97. cs.sendMessage(ChatColor.RED+"Fout: Deze speler heeft geen account");
  98. return true;
  99. }
  100. double amount = 0;
  101. try
  102. {
  103. amount = Double.parseDouble(args[2]);
  104. }catch (Exception e)
  105. {
  106. cs.sendMessage(ChatColor.RED+"Je moet een cijfers invoeren");
  107. return true;
  108. }
  109.  
  110. EconManager.setBalance(args[1], EconManager.getBalance(args[1]) + amount);
  111. }else if (args[0].equalsIgnoreCase("remove"))
  112. {
  113. if(!EconManager.hasAccount(args[1]))
  114. {
  115. cs.sendMessage(ChatColor.RED+"Fout: Deze speler heeft geen account");
  116. return true;
  117. }
  118. double amount = 0;
  119. try
  120. {
  121. amount = Double.parseDouble(args[2]);
  122. }catch (Exception e)
  123. {
  124. cs.sendMessage(ChatColor.RED+"Je moet een cijfers invoeren");
  125. return true;
  126. }
  127.  
  128. EconManager.setBalance(args[1], EconManager.getBalance(args[1]) - amount);
  129.  
  130. }else if (args[0].equalsIgnoreCase("set"))
  131. {
  132. if(!EconManager.hasAccount(args[1]))
  133. {
  134. cs.sendMessage(ChatColor.RED+"Fout: Deze speler heeft geen account");
  135. return true;
  136. }
  137. double amount = 0;
  138. try
  139. {
  140. amount = Double.parseDouble(args[2]);
  141. }catch (Exception e)
  142. {
  143. cs.sendMessage(ChatColor.RED+"Je moet een cijfers invoeren");
  144. return true;
  145. }
  146.  
  147. EconManager.setBalance(args[1], amount);
  148. }else
  149. {
  150. cs.sendMessage(ChatColor.RED+"Onjuist argument");
  151. }
  152.  
  153. return true;
  154. }
  155.  
  156. }
  157.  
  158.  
  159. --------------------
  160.  
  161. package me.oneerlijk.economy;
  162.  
  163. import org.bukkit.event.EventHandler;
  164. import org.bukkit.event.Listener;
  165. import org.bukkit.event.player.PlayerJoinEvent;
  166.  
  167. public class PlayerJoin implements Listener
  168. {
  169. @EventHandler
  170. public void onJoin(PlayerJoinEvent event)
  171. {
  172. if(EconManager.hasAccount(event.getPlayer().getName())) return;
  173. EconManager.setBalance(event.getPlayer().getName(), 20);
  174. }
  175.  
  176. }
  177.  
  178.  
  179. --------------
  180.  
  181. package me.oneerlijk.economy;
  182.  
  183. public class SLAPI
  184. {
  185. private static SmallEconomy plugin = EconManager.getPlugin();
  186.  
  187. public static void saveBalances()
  188. {
  189. for(String p : EconManager.getBalanceMap().keySet())
  190. {
  191. plugin.getConfig().set("balance."+p, EconManager.getBalanceMap().get(p));
  192. }
  193. plugin.saveConfig();
  194. }
  195.  
  196.  
  197. public static void loadBalances()
  198. {
  199. if(plugin.getConfig().contains("balance")) return;
  200. for(String s : plugin.getConfig().getConfigurationSection("balance").getKeys(false))
  201. {
  202. EconManager.setBalance(s, plugin.getConfig().getDouble("balance."+s));
  203. }
  204. }
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement