Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.47 KB | None | 0 0
  1. package pl.foxi.justhard.data.base.user;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.OfflinePlayer;
  6. import org.bukkit.entity.Player;
  7. import pl.foxi.justhard.data.base.guild.Guild;
  8. import pl.foxi.justhard.managers.GuildManager;
  9. import pl.foxi.justhard.GuildPlugin;
  10. import pl.foxi.justhard.utils.ChatUtil;
  11.  
  12. import java.sql.ResultSet;
  13. import java.sql.SQLException;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16.  
  17. public class User
  18. {
  19. private String name;
  20. private int points;
  21. private int kills;
  22. private int deaths;
  23. private int asyst;
  24. private int logout;
  25.  
  26. private long lastChat;
  27.  
  28. private String firstIP;
  29. private String lastIP;
  30.  
  31. private long firstJoin;
  32.  
  33. //KIT SYSTEM
  34. private long kit_mieso;
  35. private long kit_start;
  36. private long kit_tw;
  37. private long kit_yt;
  38. private long kit_vip;
  39. private long kit_svip;
  40. private long turboDrop;
  41. private long turboExp;
  42. private List<Player> tpa;
  43. private List<Player> tpahere;
  44. private String home;
  45. private boolean helpop;
  46. private long lastHelpop;
  47. private long lastPearl;
  48.  
  49. private String lastKill;
  50. private long lastKillTime;
  51. private boolean god;
  52. private int lvl;
  53. private int exp;
  54.  
  55.  
  56. private Guild guild;
  57.  
  58. public User(final Player p) {
  59. this.name = p.getName();
  60. this.points = 1000;
  61. this.kills = 0;
  62. this.deaths = 0;
  63. this.asyst = 0;
  64. this.logout = 0;
  65. this.firstIP = p.getAddress().getAddress().getHostAddress();
  66. this.lastIP = p.getAddress().getAddress().getHostAddress();
  67. this.firstJoin = System.currentTimeMillis();
  68. this.kit_mieso = 0L;
  69. this.kit_start = 0L;
  70. this.kit_tw = 0L;
  71. this.kit_yt = 0L;
  72. this.kit_vip = 0L;
  73. this.kit_svip = 0L;
  74. this.home = ChatUtil.locToString(0.0, 0.0, 0.0);
  75. this.lastKill = "-";
  76. this.lastKillTime = 0L;
  77. this.lastChat = 0L;
  78. this.god = false;
  79. this.lvl = 1;
  80. this.exp = 0;
  81. this.turboDrop = 0L;
  82. this.turboExp = 0L;
  83. this.tpa = new ArrayList<>();
  84. this.tpahere = new ArrayList<>();
  85. this.helpop = true;
  86. this.lastHelpop = 0L;
  87. this.lastPearl = 0L;
  88. this.insert();
  89. }
  90.  
  91. public User(final String p) {
  92. this.name = p;
  93. this.points = 1000;
  94. this.kills = 0;
  95. this.deaths = 0;
  96. this.asyst = 0;
  97. this.logout = 0;
  98. this.firstIP = "-";
  99. this.lastIP = "-";
  100. this.firstJoin = 0L;
  101. this.kit_mieso = 0L;
  102. this.kit_start = 0L;
  103. this.kit_tw = 0L;
  104. this.kit_yt = 0L;
  105. this.kit_vip = 0L;
  106. this.kit_svip = 0L;
  107. this.home = ChatUtil.locToString(0.0, 0.0, 0.0);
  108. this.lastKill = "-";
  109. this.lastKillTime = 0L;
  110. this.lastChat = 0L;
  111. this.god = false;
  112. this.lvl = 1;
  113. this.exp = 0;
  114. this.turboDrop = 0L;
  115. this.turboExp = 0L;
  116. this.tpa = new ArrayList<>();
  117. this.tpahere = new ArrayList<>();
  118. this.helpop = true;
  119. this.lastHelpop = 0L;
  120. this.lastPearl = 0L;
  121. this.insert();
  122. }
  123.  
  124. public User(final ResultSet rs) throws SQLException{
  125. this.name = rs.getString("name");
  126. this.points = rs.getInt("points");
  127. this.kills = rs.getInt("kills");
  128. this.deaths = rs.getInt("deaths");
  129. this.asyst = rs.getInt("asyst");
  130. this.logout = rs.getInt("logout");
  131. this.firstIP = rs.getString("firstIP");
  132. this.lastIP = rs.getString("lastIP");
  133. this.firstJoin = rs.getLong("firstJoin");
  134. this.kit_mieso = 0L;
  135. this.kit_start = rs.getLong("kit_start");
  136. this.kit_tw = rs.getLong("kit_tw");
  137. this.kit_yt = rs.getLong("kit_yt");
  138. this.kit_vip = rs.getLong("kit_vip");
  139. this.kit_svip = rs.getLong("kit_svip");
  140. this.turboDrop = rs.getLong("turboDrop");
  141. this.turboExp = rs.getLong("turboExp");
  142. this.home = rs.getString("home");
  143. this.lastKill = rs.getString("lastKill");
  144. this.lastKillTime = rs.getLong("lastKillTime");
  145. this.lastChat = 0L;
  146. this.god = (rs.getInt("god") == 1);
  147. this.lvl = rs.getInt("lvl");
  148. this.exp = rs.getInt("exp");
  149. this.tpa = new ArrayList<>();
  150. this.tpahere = new ArrayList<>();
  151. this.helpop = true;
  152. this.lastHelpop = 0L;
  153. this.lastPearl = 0L;
  154. }
  155.  
  156. public boolean isLastHelpop() {
  157. return this.getLastHelpop() > System.currentTimeMillis();
  158. }
  159.  
  160. public boolean isLastPearl() {
  161. return this.getLastPearl() > System.currentTimeMillis();
  162. }
  163. public long getLastHelpop() {
  164. return lastHelpop;
  165. }
  166.  
  167. public void setLastHelpop(long lastHelpop) {
  168. this.lastHelpop = lastHelpop;
  169. }
  170.  
  171. public long getLastPearl() {
  172. return lastPearl;
  173. }
  174.  
  175. public void setLastPearl(long lastPearl) {
  176. this.lastPearl = lastPearl;
  177. }
  178.  
  179. public boolean isHelpop() {
  180. return helpop;
  181. }
  182.  
  183. public void setHelpop(boolean helpop) {
  184. this.helpop = helpop;
  185. }
  186.  
  187. public List<Player> getTpahere() {
  188. return tpahere;
  189. }
  190.  
  191. public void setTpahere(List<Player> tpahere) {
  192. this.tpahere = tpahere;
  193. }
  194.  
  195. public List<Player> getTpa() {
  196. return tpa;
  197. }
  198.  
  199. public void setTpa(List<Player> tpa) {
  200. this.tpa = tpa;
  201. }
  202.  
  203. public String getName() {
  204. return name;
  205. }
  206.  
  207. public void setName(String name) {
  208. this.name = name;
  209. }
  210.  
  211. public int getPoints() {
  212. return points;
  213. }
  214.  
  215. public void setPoints(int points) {
  216. this.points = points;
  217. }
  218.  
  219. public int getKills() {
  220. return kills;
  221. }
  222.  
  223. public void setKills(int kills) {
  224. this.kills = kills;
  225. }
  226.  
  227. public int getDeaths() {
  228. return deaths;
  229. }
  230.  
  231. public void setDeaths(int deaths) {
  232. this.deaths = deaths;
  233. }
  234.  
  235. public int getAsyst() {
  236. return asyst;
  237. }
  238.  
  239. public void setAsyst(int asyst) {
  240. this.asyst = asyst;
  241. }
  242.  
  243. public int getLogout() {
  244. return logout;
  245. }
  246.  
  247. public void setLogout(int logout) {
  248. this.logout = logout;
  249. }
  250.  
  251. public String getFirstIP() {
  252. return firstIP;
  253. }
  254.  
  255. public void setFirstIP(String firstIP) {
  256. this.firstIP = firstIP;
  257. }
  258.  
  259. public String getLastIP() {
  260. return lastIP;
  261. }
  262.  
  263. public void setLastIP(String lastIP) {
  264. this.lastIP = lastIP;
  265. }
  266.  
  267. public long getFirstJoin() {
  268. return firstJoin;
  269. }
  270.  
  271. public void setFirstJoin(long firstJoin) {
  272. this.firstJoin = firstJoin;
  273. }
  274.  
  275. public long getKit_mieso() {
  276. return kit_mieso;
  277. }
  278.  
  279. public void setKit_mieso(long kit_mieso) {
  280. this.kit_mieso = kit_mieso;
  281. }
  282.  
  283. public long getKit_start() {
  284. return kit_start;
  285. }
  286.  
  287. public void setKit_start(long kit_start) {
  288. this.kit_start = kit_start;
  289. GuildPlugin.getStore().update(false, "UPDATE `{P}users` SET `kit_start`='" + this.getKit_start() + "' WHERE `name`='" + this.getName() + "'");
  290. }
  291.  
  292. public long getKit_tw() {
  293. return kit_tw;
  294. }
  295.  
  296. public void setKit_tw(long kit_tw) {
  297. this.kit_tw = kit_tw;
  298. GuildPlugin.getStore().update(false, "UPDATE `{P}users` SET `kit_tw` ='" + this.getKit_tw() + "' WHERE `name` ='" + this.getName() + "'");
  299. }
  300.  
  301. public long getKit_yt() {
  302. return kit_yt;
  303. }
  304.  
  305. public void setKit_yt(long kit_yt) {
  306. this.kit_yt = kit_yt;
  307. GuildPlugin.getStore().update(false, "UPDATE `{P}users` SET `kit_yt` ='" + this.getKit_yt() + "' WHERE `name` ='" + this.getName() + "'");
  308. }
  309.  
  310. public boolean isKit_yt() {
  311. return this.getKit_yt() > System.currentTimeMillis();
  312. }
  313.  
  314. public boolean isKit_tw() {
  315. return this.getKit_tw() > System.currentTimeMillis();
  316. }
  317. public long getKit_vip() {
  318. return kit_vip;
  319. }
  320.  
  321. public void setKit_vip(long kit_vip) {
  322. this.kit_vip = kit_vip;
  323. GuildPlugin.getStore().update(false, "UPDATE `{P}users` SET `kit_vip`='" + this.getKit_vip() + "' WHERE `name`='" + this.getName() + "'");
  324. }
  325.  
  326. public long getKit_svip() {
  327. return kit_svip;
  328. }
  329.  
  330. public void setKit_svip(long kit_svip) {
  331. this.kit_svip = kit_svip;
  332. GuildPlugin.getStore().update(false, "UPDATE `{P}users` SET `kit_svip`='" + this.getKit_svip() + "' WHERE `name`='" + this.getName() + "'");
  333. }
  334.  
  335. public String getHome() {
  336. return home;
  337. }
  338.  
  339. public Location getHomeLocation() {
  340. return ChatUtil.locFromString(this.getHome());
  341. }
  342.  
  343. public void setHome(Location home) {
  344. this.home = ChatUtil.locToString(home);
  345. GuildPlugin.getStore().update(false, "UPDATE `{P}users` SET `home` ='" + this.getHome() + "' WHERE `name` ='" + this.getName() + "'");
  346. }
  347.  
  348. public Player getPlayer() {
  349. return Bukkit.getPlayer(this.getName());
  350. }
  351.  
  352. public boolean isOnline() {
  353. return this.getPlayer() != null;
  354. }
  355.  
  356. public String getLastKill() {
  357. return lastKill;
  358. }
  359.  
  360. public void setLastKill(String lastKill) {
  361. this.lastKill = lastKill;
  362. }
  363.  
  364. public long getLastKillTime() {
  365. return lastKillTime;
  366. }
  367.  
  368. public void setLastKillTime(long lastKillTime) {
  369. this.lastKillTime = lastKillTime;
  370. }
  371.  
  372. public boolean isChat() {
  373. return System.currentTimeMillis() > this.lastChat;
  374. }
  375.  
  376. public void setLastChat(long lastChat) {
  377. this.lastChat = lastChat;
  378. }
  379.  
  380. public long getLastChat() {
  381. return lastChat;
  382. }
  383.  
  384. public void addPoints(int index) {
  385. this.points += index;
  386. }
  387.  
  388. public void addKills(int index) {
  389. this.kills += index;
  390. }
  391.  
  392. public void addDeaths(int index) {
  393. this.deaths += index;
  394. }
  395.  
  396. public void addAsyst(int index) {
  397. this.asyst += index;
  398. }
  399.  
  400. public void addLogouts(int index) {
  401. this.logout += index;
  402. }
  403.  
  404. public void removePoints(int index) {
  405. this.points -= index;
  406. }
  407.  
  408. public void removeKills(int index) {
  409. this.kills -= index;
  410. }
  411.  
  412. public void removeDeaths(int index) {
  413. this.deaths -= index;
  414. }
  415.  
  416. public void removeAsyst(int index) {
  417. this.asyst -= index;
  418. }
  419.  
  420. public boolean isGod() {
  421. return god;
  422. }
  423.  
  424. public void setGod(boolean god) {
  425. this.god = god;
  426. }
  427.  
  428. public int getLvl() {
  429. return lvl;
  430. }
  431.  
  432. public void setLvl(int lvl) {
  433. this.lvl = lvl;
  434. GuildPlugin.getStore().update(false, "UPDATE `{P}users` SET `lvl` ='" + this.getLvl() + "', `exp` ='" + this.getExp() + "' WHERE `name` ='" + this.getName() + "'");
  435. }
  436.  
  437. public int getExp() {
  438. return exp;
  439. }
  440.  
  441. public long getTurboDrop() {
  442. return turboDrop;
  443. }
  444.  
  445. public void setTurboDrop(long turboDrop) {
  446. this.turboDrop = turboDrop;
  447. }
  448.  
  449. public long getTurboExp() {
  450. return turboExp;
  451. }
  452.  
  453. public void setTurboExp(long turboExp) {
  454. this.turboExp = turboExp;
  455. }
  456.  
  457. public void setExp(int exp) {
  458. this.exp = exp;
  459. }
  460.  
  461. public void removeLogouts(int index) {
  462. this.logout -= index;
  463. }
  464.  
  465. public Guild getGuild() {
  466. return GuildManager.getGuild(this.getPlayer());
  467. }
  468.  
  469. private void insert() {
  470. GuildPlugin.getStore().update(false, "INSERT INTO `{P}users`(`id`, `name`, `points`, `kills`, `deaths`, `asyst`, `logout`, `firstIP`, `lastIP`, `firstJoin`, `kit_start`, `kit_yt`, `kit_tw`, `kit_vip`, `kit_svip`, `turboDrop`, `turboExp`, `home`, `lastKill`, `lastKillTime`, `god`, `lvl`, `exp`) VALUES (NULL, '" + this.getName() + "','" + this.getPoints() + "','" + this.getKills() + "','" + this.getDeaths() + "','" + this.getAsyst() + "','" + this.getLogout() + "','" + this.getFirstIP() + "','" + this.getLastIP() + "','" + this.getFirstJoin() + "','" + this.getKit_start() + "','" + this.getKit_yt() + "','" + this.getKit_tw() + "','" + this.getKit_vip() + "','" + this.getKit_svip() + "','" + this.getTurboDrop() + "','" + this.getTurboExp() + "','" + User.this.getHome() + "','" + User.this.getLastKill() + "','" + User.this.getLastKillTime() + "','" + (User.this.isGod() ? 1 : 0) + "','" + User.this.getLvl() + "','" + User.this.getExp() + "');");
  471. }
  472.  
  473. public void save() {
  474. GuildPlugin.getStore().update(false, "UPDATE `{P}users` SET `points` = '" + this.getPoints() + "', `kills` = '" + this.getKills() + "', `deaths` = '" + this.getDeaths() + "', `asyst` = '" + this.getAsyst() + "', `logout` = '" + this.getLogout() + "', `firstIP` = '" + this.getFirstIP() + "', `lastIP` =' " + this.getLastIP() + "', `firstJoin` = '" + this.getFirstJoin() + "', `kit_start` =' " + this.getKit_start() + "', `kit_yt` = '" + this.getKit_yt() + "', `kit_tw` = '" + this.getKit_tw() + "', `kit_svip` = '" + this.getKit_svip() + "', `turboDrop` = '" + this.getTurboDrop() + "', `turboExp` = '" + this.getTurboExp() + "', `home` = '" + this.getHome() + "', `lastKill` = '" + this.getLastKill() + "', `lastKillTime` = '" + this.getLastKillTime() + "', `god` = '" + (this.isGod() ? 1 : 0) + "', `lvl` = '" + this.getLvl() + "', `exp` = '" + this.getExp() + "' WHERE `name` ='" + this.getName() + "';");
  475. }
  476.  
  477. public double getKd() {
  478. if (this.getKills() == 0 && this.getDeaths() == 0) {
  479. return 0;
  480. }
  481. else if (this.getKills() > 0 && this.getDeaths() == 0) {
  482. return this.getKills();
  483. }
  484. else if (this.getDeaths() > 0 && this.getKills() == 0) {
  485. return -this.getDeaths();
  486. }
  487. else {
  488. return ChatUtil.round(this.getKills() / (double) this.getDeaths(), 2);
  489. }
  490. }
  491.  
  492. public OfflinePlayer getOfflinePlayer() {
  493. return Bukkit.getOfflinePlayer(this.getName());
  494. }
  495.  
  496. public boolean isKitMieso() {
  497. return this.getKit_mieso() > System.currentTimeMillis();
  498. }
  499.  
  500. public boolean isKitStart() {
  501. return this.getKit_start() > System.currentTimeMillis();
  502. }
  503.  
  504. public boolean isKitVip() {
  505. return this.getKit_vip() > System.currentTimeMillis();
  506. }
  507.  
  508. public boolean isKitSvip() {
  509. return this.getKit_svip() > System.currentTimeMillis();
  510. }
  511. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement