Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.81 KB | None | 0 0
  1. package me.acemen.core.Object;
  2.  
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.ArrayList;
  6. import java.util.Date;
  7. import java.util.GregorianCalendar;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.UUID;
  11.  
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.permissions.PermissionAttachment;
  14.  
  15. import me.acemen.core.Main;
  16. import me.acemen.core.API.CMySQL;
  17. import me.acemen.core.API.Eco;
  18. import me.acemen.core.Data.DataManager;
  19. import me.acemen.core.Enums.DataBase;
  20. import me.acemen.core.Object.Utils.UtilsCUser;
  21. import me.acemen.core.Object.Utils.UtilsGroup;
  22. import me.acemen.core.Tools.Utils;
  23.  
  24. public class CUser {
  25.  
  26. private int id;
  27. private String name, displayNick, password, email, ctag, chat;
  28. private UUID uuid;
  29. private Player player;
  30. private double money, multiple, zlotowki;
  31. private Group group, xpgroup;
  32. private Date expire;
  33. private List<String> colors;
  34.  
  35. public CUser(Player p) {
  36. this.player = p;
  37. this.name = p.getName();
  38. this.uuid = p.getUniqueId();
  39. List<HashMap<String, String>> r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM auth WHERE uuid='" + p.getUniqueId() + "'");
  40. if (!r.isEmpty()) {
  41. HashMap<String, String> rs = r.get(0);
  42. this.password = rs.get("password");
  43. this.email = rs.get("email");
  44. this.id = Integer.valueOf(rs.get("id"));
  45. }else {
  46. CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO auth(id, name, uuid, password, email, ip) VALUES (NULL,'" + p.getName() + "','" + p.getUniqueId() + "',NULL,NULL,NULL)");
  47. List<HashMap<String, String>> r2 = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM auth WHERE uuid='" + p.getUniqueId() + "'");
  48. HashMap<String, String> rs = r2.get(0);
  49. this.password = rs.get("password");
  50. this.email = rs.get("email");
  51. this.id = Integer.valueOf(rs.get("id"));
  52. }
  53. r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM users_colors WHERE user='" + id + "'");
  54. if (!r.isEmpty()) {
  55. HashMap<String, String> rs = r.get(0);
  56. this.displayNick = rs.get("nick");
  57. this.chat = rs.get("chat");
  58. this.colors = new ArrayList<String>();
  59. p.setDisplayName(Utils.colored("&" + this.displayNick + name));
  60. p.setPlayerListName(this.group.getPrefix() + " " + Utils.colored("&" + this.displayNick + name + "§r"));
  61. for(String s : rs.get("hasColors").split(":")) {
  62. colors.add(s);
  63. }
  64. }
  65. r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM users_ranks WHERE user='" + id + "'");
  66. if (!r.isEmpty()) {
  67. HashMap<String, String> rs = r.get(0);
  68. this.group = UtilsGroup.getGroup(Integer.valueOf(rs.get("rank")));
  69. }else {
  70. this.group = UtilsGroup.getGroup(0);
  71. }
  72. DownloadZlotowki();
  73. r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM users_xprank WHERE user='" + id + "'");
  74. if (!r.isEmpty()) {
  75. HashMap<String, String> rs = r.get(0);
  76. if (!CMySQL.NullDetector(rs.get("expire")).equalsIgnoreCase("null")) {
  77. this.xpgroup = UtilsGroup.getGroup(Integer.valueOf(rs.get("rank")));
  78. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  79. try {
  80. this.expire = formatter.parse(rs.get("expire").substring(0, 19));
  81. } catch (ParseException e) {
  82. e.printStackTrace();
  83. }
  84. }else if(Integer.valueOf(rs.get("rank")) != 0) {
  85. this.xpgroup = UtilsGroup.getGroup(Integer.valueOf(rs.get("rank")));
  86. this.expire = null;
  87. }
  88. }
  89. recalculateMultiple();
  90. refreshName();
  91. UtilsCUser.addCUser(this);
  92. recalculatePerms();
  93. }
  94.  
  95. public void DownloadZlotowki() {
  96. List<HashMap<String, String>> r = CMySQL.QueryResult(DataBase.CROSS.toString(), "SELECT * FROM users_money WHERE id='" + id + "'");
  97. if (!r.isEmpty()) {
  98. HashMap<String, String> rs = r.get(0);
  99. this.zlotowki = Double.valueOf(rs.get("money"));
  100. }
  101. }
  102.  
  103. public void recalculateMultiple() {
  104. multiple = group.getXppercent();
  105. if (xpgroup != null) multiple += xpgroup.getXppercent();
  106. }
  107.  
  108. public void remove() {
  109. if (CMySQL.NullDetector(password).equalsIgnoreCase("NULL")) {
  110. UtilsCUser.removeCUser(this);
  111. return;
  112. }
  113. String expiree = "";
  114. if (expire == null) {
  115. expiree = "NULL";
  116. } else {
  117. GregorianCalendar calendar = new GregorianCalendar();
  118. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  119. calendar.setTime(expire);
  120. expiree = "'" + format.format(calendar.getTime()) + "'";
  121. }
  122. CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO auth(id, name, uuid, password, email, ip) VALUES ('" + id + "','" + name + "','" + uuid + "','" + password + "','" + email + "','" + player.getAddress().getHostString() + "') ON DUPLICATE KEY UPDATE password='" + password + "', email='" + email + "', ip='" + player.getAddress().getHostString() + "'");
  123. if(group.getId() != 0) CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO users_ranks(user, rank) VALUES ('" + id + "','" + group.getId() + "') ON DUPLICATE KEY UPDATE rank='" + group.getId()+"';");
  124. if(xpgroup != null) {
  125. CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO users_xprank(user, rank, expire) VALUES ('" + id + "','" + xpgroup.getId() + "'," + expiree + ") ON DUPLICATE KEY UPDATE rank='" + xpgroup.getId()+"', expire=" + expiree);
  126. }
  127. UtilsCUser.removeCUser(this);
  128. }
  129.  
  130. public void refreshName() {
  131. if(player == null) return;
  132. if(this.displayNick != null && !this.displayNick.equalsIgnoreCase("")) {
  133. player.setDisplayName(Utils.colored("&" + this.displayNick + name + "§r"));
  134. player.setPlayerListName(this.group.getPrefix() + " " + Utils.colored("&" + this.displayNick + name + "§r"));
  135. }else {
  136. player.setPlayerListName(this.group.getPrefix() + " §r" + player.getName());
  137. }
  138. }
  139.  
  140. public void takeCoins(double i) {
  141. Eco.takeMoney(this, i);
  142. }
  143.  
  144. public void addCoins(double i) {
  145. Eco.addMoney(this, i);
  146. }
  147.  
  148. public void addGameCoins(double i) {
  149. Eco.addGameCoins(this, i);
  150. }
  151.  
  152. public double getCoins() {
  153. return Eco.getMoney(this);
  154. }
  155.  
  156. public void sendMessage(String message) {
  157. player.sendMessage(message);
  158. }
  159.  
  160. public int getId() {
  161. return id;
  162. }
  163.  
  164. public void setId(int id) {
  165. this.id = id;
  166. }
  167.  
  168. public String getName() {
  169. return name;
  170. }
  171.  
  172. public void setName(String name) {
  173. this.name = name;
  174. }
  175.  
  176. public UUID getUuid() {
  177. return uuid;
  178. }
  179.  
  180. public void setUuid(UUID uuid) {
  181. this.uuid = uuid;
  182. }
  183.  
  184. public Player getPlayer() {
  185. return player;
  186. }
  187.  
  188. public void setPlayer(Player player) {
  189. this.player = player;
  190. }
  191.  
  192. public double getMoney() {
  193. return money;
  194. }
  195.  
  196. public void setMoney(double money) {
  197. this.money = money;
  198. }
  199.  
  200. public String getDisplayNick() {
  201. if(this.displayNick != null) return Utils.colored("&" + this.displayNick + name + "&r");
  202. return name;
  203. }
  204.  
  205. public void setDisplayNick(String displayNick) {
  206. this.displayNick = displayNick;
  207. refreshName();
  208. }
  209.  
  210. public Group getGroup() {
  211. return group;
  212. }
  213.  
  214. public void setGroup(Group group) {
  215. this.group = group;
  216. refreshName();
  217. recalculatePerms();
  218. }
  219.  
  220. public void recalculatePerms() {
  221. PermissionAttachment attachment = this.player.addAttachment(Main.getInst());
  222. for (String s : this.group.getPerms()) {
  223. attachment.setPermission(s, true);
  224. }
  225. DataManager.perms.put(this.player.getUniqueId(), attachment);
  226. }
  227.  
  228. public Group getXpgroup() {
  229. return xpgroup;
  230. }
  231.  
  232. public void setXpgroup(Group xpgroup) {
  233. this.xpgroup = xpgroup;
  234. refreshName();
  235. recalculatePerms();
  236. }
  237.  
  238. public Date getExpire() {
  239. return expire;
  240. }
  241.  
  242. public void setExpire(Date expire) {
  243. this.expire = expire;
  244. }
  245.  
  246. public double getMultiple() {
  247. return multiple;
  248. }
  249.  
  250. public void setMultiple(double multiple) {
  251. this.multiple = multiple;
  252. }
  253.  
  254. public String getPassword() {
  255. return password;
  256. }
  257.  
  258. public void setPassword(String password) {
  259. this.password = password;
  260. }
  261.  
  262. public String getEmail() {
  263. return email;
  264. }
  265.  
  266. public void setEmail(String email) {
  267. this.email = email;
  268. }
  269.  
  270. public String getCtag() {
  271. return ctag;
  272. }
  273.  
  274. public void setCtag(String ctag) {
  275. this.ctag = ctag;
  276. }
  277.  
  278. public String getChat() {
  279. return chat;
  280. }
  281.  
  282. public void setChat(String chat) {
  283. this.chat = chat;
  284. }
  285.  
  286. public List<String> getColors() {
  287. return colors;
  288. }
  289.  
  290. public void setColors(List<String> colors) {
  291. this.colors = colors;
  292. }
  293.  
  294. public double getZlotowki() {
  295. return zlotowki;
  296. }
  297.  
  298. public void addZlotowki(double zl) {
  299. CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO users_money(id, money) VALUES ('" + id + "','" + zl + "') ON DUPLICATE KEY UPDATE money=money+" + zl + ";");
  300. DownloadZlotowki();
  301. }
  302.  
  303. public void takeZlotowki(double zl) {
  304. CMySQL.QueryUpLoad(DataBase.CROSS.toString(), "INSERT INTO users_money(id, money) VALUES ('" + id + "','" + (-zl) + "') ON DUPLICATE KEY UPDATE money=money-" + zl + ";");
  305. DownloadZlotowki();
  306. }
  307.  
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement