inital commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package com.softwarerat.SQL;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class Homes {
|
||||
AsyncSQLHandler sqlHandler;
|
||||
|
||||
public Homes(AsyncSQLHandler sqlHandler) {
|
||||
this.sqlHandler = sqlHandler;
|
||||
}
|
||||
|
||||
public PlayerHome getHomeByName(String name){
|
||||
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
resultSet = sqlHandler.executeQuery("SELECT * FROM homes WHERE Name = '" + name + "';");
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public void createNewHome(PlayerHome playerHome){
|
||||
try {
|
||||
sqlHandler.executeUpdate("INSERT INTO homes (Name, UUID, World, x, y, z) VALUES ('"+playerHome.getName()+"','"+playerHome.getUUID()+"','"+playerHome.getWorld()+"','"+playerHome.getX()+"','"+playerHome.getY()+"','"+playerHome.getZ()+"');");
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
//ToDo: DeleteHome method
|
||||
public ArrayList<PlayerHome> getPlayerHomes(String UUID) {
|
||||
ArrayList<PlayerHome> homes = new ArrayList<>();
|
||||
ResultSet resultSet = null;
|
||||
try {
|
||||
resultSet = sqlHandler.executeQuery("SELECT * FROM homes WHERE uuid = '" + UUID + "';");
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user