Exemple #1
0
 /**
  * This is called AsyncPlayerLoginEvent so no need to make it Async
  *
  * @param p_name
  */
 public void loadData(String p_name) {
   try (PreparedStatement pst =
       ConnectionPool.getConnection()
           .prepareStatement("SELECT * FROM hearthstone WHERE p_name = ?")) {
     pst.setString(1, p_name);
     ResultSet rst = pst.executeQuery();
     if (!rst.first()) {
       tp_loc = HearthstoneMechanics.spawn_map.get("Cyrennica");
       tp_name = "Cyrennica";
       sendInsertQuery();
       return;
     }
     tp_name = rst.getString("location_name");
     if (tp_name == null) {
       System.out.print("Location name was null for " + p_name);
     }
     tp_loc = HearthstoneMechanics.spawn_map.get(rst.getString("location_name"));
     setTimer(rst.getInt("timer"));
     // TODO: Download the data from tables and set their spawns
     System.out.print("[HearthstoneMechanics] Set " + p_name + " location to " + tp_name);
     pst.close();
   } catch (SQLException sqlE) {
     sqlE.printStackTrace();
   }
 }
Exemple #2
0
 /** This saves all their data in an Async task */
 public void sendInsertQuery() {
   try (PreparedStatement pst =
       ConnectionPool.getConnection()
           .prepareStatement(
               "INSERT IGNORE INTO hearthstone (p_name, location_name, timer) VALUES (?, ?, 0) ON DUPLICATE KEY UPDATE location_name = ?")) {
     pst.setString(1, tp_name);
     pst.setString(2, "Cyrennica");
     pst.setString(3, tp_name);
     pst.executeUpdate();
     System.out.print(
         "[HeartstoneMechanics] Saved " + p_name + "s Hearthstone data for the first time.");
     pst.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }