Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. package net.dr.utility.sql.impl;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.Statement;
  7.  
  8. import com.osrsunity.game.character.player.Player;
  9. import com.osrsunity.game.items.Item;
  10.  
  11. import net.dr.utility.NameUtils;
  12. import net.dr.utility.sql.Connections;
  13.  
  14. public class MarketHandler implements Runnable {
  15.  
  16. private Connections connection;
  17.  
  18. private Player player;
  19.  
  20. private Player target;
  21.  
  22. private Item[] items1;
  23.  
  24. private Item[] items2;
  25.  
  26. public MarketHandler(Player player, Player target, Item[] items1, Item[] items2) {
  27. this.connection = new Connections("divinere_market", "divinere_main", "o2kHzHLPv(u2Uk");
  28. this.player = player;
  29. this.target = target;
  30. this.items1 = items1;
  31. this.items2 = items2;
  32. }
  33.  
  34. @Override
  35. public void run() {
  36. boolean test = true;
  37. if(test){
  38. return;
  39. }
  40. Connection connection = this.connection.createConnection();
  41. if(connection == null) {
  42. return;
  43. }
  44. try {
  45. PreparedStatement pstmt = connection.prepareStatement("INSERT INTO trade (player_1, player_2) VALUES ('"+NameUtils.formatNameForProtocol(player.getUsername())+"', '"+NameUtils.formatNameForProtocol(target.getUsername())+"')", Statement.RETURN_GENERATED_KEYS);
  46. pstmt.executeUpdate();
  47. int id = -1;
  48. ResultSet keys = pstmt.getGeneratedKeys();
  49. if(keys.next()) {
  50. id = keys.getInt(1);
  51. }
  52. if(id == -1) {
  53. return;
  54. }
  55. for(Item item : items1) {
  56. if(item == null || item.getDefinition() == null) {
  57. continue;
  58. }
  59. this.connection.query("INSERT INTO items (item_id, item_amount, item_name, trade_id, player) VALUES ('"+item.getId()+"', '"+item.getCount()+"', '"+item.getDefinition().getName().replaceAll("'", "\\\\'")+"', '"+id+"', '"+NameUtils.formatNameForProtocol(player.getUsername())+"')");
  60. }
  61. for(Item item : items2) {
  62. if(item == null || item.getDefinition() == null) {
  63. continue;
  64. }
  65. this.connection.query("INSERT INTO items (item_id, item_amount, item_name, trade_id, player) VALUES ('"+item.getId()+"', '"+item.getCount()+"', '"+item.getDefinition().getName().replaceAll("'", "\\\\'")+"', '"+id+"', '"+NameUtils.formatNameForProtocol(target.getUsername())+"')");
  66.  
  67. }
  68. this.connection.destroyConnection();
  69. } catch(Throwable t) {
  70. t.printStackTrace();
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement