Advertisement
Guest User

CreditsAPI

a guest
Apr 20th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. package me.WingedMLGPro.API;
  2.  
  3. import org.bukkit.entity.Player;
  4.  
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. /**
  9. * © This Document and Code is STRICTLY copyrited(©) to Ben.
  10. * © If anyone takes any part of this code and uses it for
  11. * © Something public, Share with someone, uses it for API's,
  12. * © implementing it to their code and taking the rights for
  13. * © it is NOT allowed unless you get permission from me!
  14. * © This project SwiftyCredits was created by 35047
  15. * © at 21/04/15 at 10:04 AM
  16. */
  17. public class CreditsAPI {
  18.  
  19. public Integer getCredits(Player p){
  20. ResultSet rs = mySQL.getResult("SELECT Credits FROM SwiftyCredits WHERE UUID='" + p.getUniqueId() + "'");
  21. try {
  22. if (rs.next()){
  23. rs.getInt("Credits");
  24. }
  25. return null;
  26. } catch (SQLException e){
  27. e.printStackTrace();
  28. }
  29. return 0;
  30. }
  31. public void setCredits(Player p, int credits){
  32. if (getCredits(p) == null){
  33. mySQL.update("INSERT INTO `SwiftyCredits`(`UUID`, `PlayerName`, `Credits`) VALUES ('"+p.getUniqueId()+"','"+p.getName()+"','"+credits+"')");
  34. }
  35. else if (getCredits(p) != null){
  36. mySQL.update("UPDATE `SwiftyCredits` SET `UUID`='"+p.getUniqueId()+"',`PlayerName`='"+p.getName()+"',`Credits`='"+credits+"' WHERE UUID='"+p.getUniqueId()+"'");
  37. }
  38. }
  39. public void addCredits(Player p, int credits){
  40. if (getCredits(p) == null){
  41. mySQL.update("INSERT INTO `SwiftyCredits`(`UUID`, `PlayerName`, `Credits`) VALUES ('"+p.getUniqueId()+"','"+p.getName()+"','"+credits+"')");
  42. }
  43. else if (getCredits(p) != null){
  44. int num = getCredits(p) + credits;
  45. mySQL.update("UPDATE `SwiftyCredits` SET `UUID`='"+p.getUniqueId()+"',`PlayerName`='"+p.getName()+"',`Credits`='"+num+"' WHERE UUID='"+p.getUniqueId()+"'");
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement