Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import com.ventyz.server.character.Client;
- // TODO: Auto-generated Javadoc
- /**
- * The Class Store.
- */
- public class Store {
- /*
- * @author: Pax M
- */
- /** The connection. */
- private static Connection connection;
- /** The las connection. */
- private static long lasConnection = System.currentTimeMillis();
- static {
- init();
- }
- /**
- * Claim payment.
- *
- * @param p
- * the p
- * @param name
- * the name
- */
- public static void claimPayment(final Client p, final String name) {
- try {
- if (System.currentTimeMillis() - lasConnection > 10000) {
- destroyConnection();
- init();
- lasConnection = System.currentTimeMillis();
- }
- Statement s = connection.createStatement();
- String name2 = name.replaceAll(" ", "_");
- String query = "SELECT * FROM itemstore WHERE username = '" + name2
- + "'";
- ResultSet rs = s.executeQuery(query);
- boolean claimed = false;
- while (rs.next()) {
- int prod = Integer.parseInt(rs.getString("productid"));
- int price = Integer.parseInt(rs.getString("price"));
- if (prod == 1 && price == 5) {
- /*
- * RETURN WITH REWARD 1
- */
- claimed = true;
- } else if (prod == 2 && price == 20) {
- /*
- * RETURN WITH REWARD 2
- */
- claimed = true;
- } else if (prod == 3 && price == 30) {
- /*
- * RETURN WITH REWARD 3
- */
- claimed = true;
- if (claimed) {
- s.execute("DELETE FROM `itemstore` WHERE `username` = '"
- + name2 + "';");
- final String FILE_PATH = "data/logs/orders/orders.txt";
- try {
- Calendar cal = Calendar.getInstance();
- BufferedWriter writer = new BufferedWriter(
- new FileWriter(FILE_PATH, true));
- writer.write("[" + cal.getTime() + "] - $" + price);
- writer.newLine();
- writer.flush();
- writer.close();
- } catch (IOException e) {
- System.err.println(e);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * Destroy connection.
- */
- public static void destroyConnection() {
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- /**
- * Inits the.
- */
- public static void init() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- connection = DriverManager.getConnection(
- "jdbc:mysql://scape-deadman.com/scape-hs",
- "scape-hs", "p~mr4sWVu3PW");
- } catch (Exception e) {
- e.printStackTrace();
- System.err.println("Could not connect to Store SQL Database.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement