Advertisement
mattibijnens

Untitled

Aug 29th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. public static void addCoins(Player p, int coins){
  2.         openConnection();
  3.         int previousCoins = 0;
  4.         try{
  5.             if(playerDataContainsPlayer(p)){
  6.         PreparedStatement sqlC = connection
  7.                 .prepareStatement("SELECT coins FROM `player_data` WHERE player =?;");
  8.         sqlC.setString(1, p.getName());
  9.         ResultSet resultC = sqlC.executeQuery();
  10.         resultC.next();
  11.        
  12.         previousCoins = resultC.getInt("coins");
  13.  
  14.         PreparedStatement CoinsUpdate = connection
  15.                 .prepareStatement("UPDATE `player_data` SET coins=? WHERE player=?;");
  16.         CoinsUpdate.setInt(1, previousCoins + coins);
  17.         CoinsUpdate.setString(2, p.getName());
  18.         if(coins <= 1 ){
  19.             p.sendMessage(ChatColor.GOLD + "+ 1 coin");
  20.         } else {
  21.             p.sendMessage(ChatColor.GOLD + "+ " + coins + " coins");   
  22.         }
  23.         SQLHandler.coins.put(p, coins + previousCoins);
  24.         CoinsUpdate.executeUpdate();
  25.        
  26.  
  27.         CoinsUpdate.close();
  28.         sqlC.close();
  29.         resultC.close();
  30.             }
  31.        
  32.     }   catch (Exception e) {
  33.         e.printStackTrace();
  34.     } finally {
  35.         closeConnection();
  36.     }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement