SHARE
TWEET

Untitled

a guest Oct 21st, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public interface CallBack<T> {
  2.     void onSuccess(T done);
  3.     void onFailure(Throwable cause);
  4. }
  5.  
  6. public void hasRecord(final CallBack<HashMap> callBack, final Player player) {
  7.     Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
  8.         @Override
  9.         public void run() {
  10.             final HashMap<String, Boolean> result = new HashMap<String, Boolean>();
  11.  
  12.             PreparedStatement q = connection.prepareStatement("SELECT * FROM " + tableName + " WHERE " + rowUsername + " = ? LIMIT 1");
  13.            
  14.             q.setString(1, player.getName());
  15.            
  16.             ResultSet resultat = q.executeQuery();
  17.             boolean hasRecord = resultat.next();
  18.             q.close();
  19.  
  20.             result.put("hasRecord", hasRecord);
  21.  
  22.             Bukkit.getScheduler().runTask(plugin, new Runnable() {
  23.                 @Override
  24.                 public void run() {
  25.                     @Override
  26.                     public void run() {
  27.                         callBack.onSuccess(result);
  28.                     }
  29.                 }
  30.             });
  31.         }
  32.     });
  33. }
  34.  
  35. public void test() {
  36.  
  37.     // Je veux recuperer si le hasRecord du joueur
  38.  
  39.     hasRecord(new CallBack<HashMap>() {
  40.  
  41.         @Override
  42.         public void onSuccess(HashMap done) {
  43.             boolean hasRecord = done.get("hasRecord");
  44.         }
  45.  
  46.         @Override
  47.         public void onFailure(Throwable cause) {
  48.             System.out.println("ERROR: LOADING ASYNC MYSQL DATA");
  49.         }
  50.  
  51.     }, p);
  52.  
  53. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top