91 lines
3.1 KiB
Java
91 lines
3.1 KiB
Java
package com.softwarerat.SQL;
|
|
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.util.ArrayList;
|
|
|
|
public class Homes {
|
|
|
|
|
|
public PlayerHome getHomeByName(String name){
|
|
PreparedStatement ps = null;
|
|
try {
|
|
ps = MySQL.getConnection().prepareStatement("SELECT * FROM homes WHERE Name = '" + name + "';");
|
|
} catch (SQLException ex) {
|
|
System.getLogger(Homes.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
|
|
}
|
|
ResultSet resultSet = null;
|
|
try {
|
|
resultSet = ps.executeQuery();
|
|
} catch (SQLException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
if (resultSet != null) {
|
|
try {
|
|
resultSet.next();
|
|
return new PlayerHome(resultSet.getString("Name"),resultSet.getString("UUID"),resultSet.getString("World"),resultSet.getInt("x"),resultSet.getInt("y"), resultSet.getInt("z"));
|
|
} catch (SQLException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
System.out.println("Loaded home");
|
|
return null;
|
|
}
|
|
|
|
|
|
//FIX: creation with new sql handler
|
|
public void createNewHome(PlayerHome playerHome){
|
|
PreparedStatement ps = null;
|
|
try {
|
|
ps = MySQL.getConnection().prepareStatement("INSERT INTO homes (Name, UUID, World, x, y, z) VALUES ('"+playerHome.getName()+"','"+playerHome.getUUID()+"','"+playerHome.getWorld()+"','"+playerHome.getX()+"','"+playerHome.getY()+"','"+playerHome.getZ()+"');");
|
|
} catch (SQLException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
try {
|
|
ps.executeUpdate();
|
|
} catch (SQLException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
//ToDo: DeleteHome method
|
|
public ArrayList<PlayerHome> getPlayerHomes(String UUID) {
|
|
ArrayList<PlayerHome> homes = new ArrayList<>();
|
|
ResultSet resultSet = null;
|
|
PreparedStatement ps = null;
|
|
try {
|
|
ps = MySQL.getConnection().prepareStatement("SELECT * FROM homes WHERE uuid = '" + UUID + "';");
|
|
} catch (SQLException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
try {
|
|
resultSet = ps.executeQuery();
|
|
} catch (SQLException e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
if (resultSet != null) {
|
|
try {
|
|
while (true){
|
|
resultSet.next();
|
|
homes.add(new PlayerHome(resultSet.getString("Name"),resultSet.getString("UUID"),resultSet.getString("World"),resultSet.getInt("x"),resultSet.getInt("y"), resultSet.getInt("z")));
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
System.out.println("Loaded Homes from player ");
|
|
return null;
|
|
}
|
|
}
|