Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.dr.utility.sql.impl;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import com.osrsunity.game.character.player.Player;
- import com.osrsunity.game.items.Item;
- import net.dr.utility.NameUtils;
- import net.dr.utility.sql.Connections;
- public class MarketHandler implements Runnable {
- private Connections connection;
- private Player player;
- private Player target;
- private Item[] items1;
- private Item[] items2;
- public MarketHandler(Player player, Player target, Item[] items1, Item[] items2) {
- this.connection = new Connections("divinere_market", "divinere_main", "o2kHzHLPv(u2Uk");
- this.player = player;
- this.target = target;
- this.items1 = items1;
- this.items2 = items2;
- }
- @Override
- public void run() {
- boolean test = true;
- if(test){
- return;
- }
- Connection connection = this.connection.createConnection();
- if(connection == null) {
- return;
- }
- try {
- PreparedStatement pstmt = connection.prepareStatement("INSERT INTO trade (player_1, player_2) VALUES ('"+NameUtils.formatNameForProtocol(player.getUsername())+"', '"+NameUtils.formatNameForProtocol(target.getUsername())+"')", Statement.RETURN_GENERATED_KEYS);
- pstmt.executeUpdate();
- int id = -1;
- ResultSet keys = pstmt.getGeneratedKeys();
- if(keys.next()) {
- id = keys.getInt(1);
- }
- if(id == -1) {
- return;
- }
- for(Item item : items1) {
- if(item == null || item.getDefinition() == null) {
- continue;
- }
- 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())+"')");
- }
- for(Item item : items2) {
- if(item == null || item.getDefinition() == null) {
- continue;
- }
- 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())+"')");
- }
- this.connection.destroyConnection();
- } catch(Throwable t) {
- t.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement