Kewilleen

Untitled

Nov 18th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. public static void setSpawn(Player p) {
  2.         Location loc = p.getLocation();
  3.         double x, y, z;
  4.         float pitch, yaw;
  5.         x = loc.getX();
  6.         y = loc.getY();
  7.         z = loc.getZ();
  8.         pitch = loc.getPitch();
  9.         yaw = loc.getYaw();
  10.         String w = loc.getWorld().getName();
  11.         if (!getMySQL()) {
  12.             try {
  13.                 PreparedStatement ps = sql.getConnection()
  14.                         .prepareStatement("INSERT INTO kw_spawn (mundo, x, y, z, pitch, yaw) VALUES(?,?,?,?,?,?);");
  15.                 ps.setString(1, w);
  16.                 ps.setString(2, Double.toString(x));
  17.                 ps.setString(3, Double.toString(y));
  18.                 ps.setString(4, Double.toString(z));
  19.                 ps.setString(5, Float.toString(pitch));
  20.                 ps.setString(6, Float.toString(yaw));
  21.                 ps.executeUpdate();
  22.             } catch (SQLException e) {
  23.                 e.printStackTrace();
  24.             }
  25.         } else {
  26.             try {
  27.                 PreparedStatement ps = sql.getConnection().prepareStatement("SELECT * FROM kw_spawn");
  28.                 ResultSet rs = ps.executeQuery();
  29.                 while (rs.next()) {
  30.                     ps = sql.getConnection().prepareStatement("UPDATE kw_spawn");
  31.                     ps.setString(1, w);
  32.                     ps.setString(2, Double.toString(x));
  33.                     ps.setString(3, Double.toString(y));
  34.                     ps.setString(4, Double.toString(z));
  35.                     ps.setString(5, Float.toString(pitch));
  36.                     ps.setString(6, Float.toString(yaw));
  37.                     ps.executeUpdate();
  38.                 }
  39.             } catch (SQLException e) {
  40.                 e.printStackTrace();
  41.             }
  42.         }
  43.         p.sendMessage(KwMetodos.getReplaced("Setado"));
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment