save entry location in database

This commit is contained in:
2024-07-14 13:50:23 +02:00
parent 4b2203e5ae
commit 89de8b6ab5
3 changed files with 79 additions and 17 deletions

View File

@@ -136,16 +136,64 @@ public class PixelBlock {
if(!uuids.contains(this.uuid)) {
try (var conn = DriverManager.getConnection(url)) {
PreparedStatement prep = conn.prepareStatement(
"INSERT INTO pixelblocks(uuid, owner, locationWorldName, locationX, locationY, locationZ)" +
" VALUES(?, ?, ?, ?, ?, ?);"
"INSERT INTO pixelblocks(uuid, owner, " +
"locationWorldName, locationX, locationY, locationZ, " +
"entryLocationWorldName, entryLocationX, entryLocationY, entryLocationZ) " +
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
);
prep.setString(1, this.uuid.toString());
prep.setString(2, this.owner.toString());
prep.setString(3, this.pixelBlockLocation.getWorld().getName());
prep.setDouble(4, this.pixelBlockLocation.getX());
prep.setDouble(5, this.pixelBlockLocation.getY());
prep.setDouble(6, this.pixelBlockLocation.getZ());
if(this.lastEntryLocation != null) {
prep.setString(7, this.lastEntryLocation.getWorld().getName());
prep.setDouble(8, this.lastEntryLocation.getX());
prep.setDouble(9, this.lastEntryLocation.getY());
prep.setDouble(10, this.lastEntryLocation.getZ());
} else {
prep.setString(7, Bukkit.getWorlds().getFirst().getName());
prep.setDouble(8, Bukkit.getWorlds().getFirst().getSpawnLocation().getX());
prep.setDouble(9, Bukkit.getWorlds().getFirst().getSpawnLocation().getY());
prep.setDouble(10, Bukkit.getWorlds().getFirst().getSpawnLocation().getZ());
}
prep.executeUpdate();
} catch (SQLException e) {
System.err.println(e.getMessage());
}
} else {
try (var conn = DriverManager.getConnection(url)) {
PreparedStatement prep = conn.prepareStatement(
"UPDATE pixelblocks " +
"SET owner=?, locationWorldName=?, locationX=?, locationY=?, locationZ=?," +
"entryLocationWorldName=?, entryLocationX=?, entryLocationY=?, entryLocationZ=? " +
"WHERE uuid=?;"
);
prep.setString(1, this.owner.toString());
prep.setString(2, this.pixelBlockLocation.getWorld().getName());
prep.setDouble(3, this.pixelBlockLocation.getX());
prep.setDouble(4, this.pixelBlockLocation.getY());
prep.setDouble(5, this.pixelBlockLocation.getZ());
if(this.lastEntryLocation != null) {
prep.setString(6, this.lastEntryLocation.getWorld().getName());
prep.setDouble(7, this.lastEntryLocation.getX());
prep.setDouble(8, this.lastEntryLocation.getY());
prep.setDouble(9, this.lastEntryLocation.getZ());
} else {
prep.setString(6, Bukkit.getWorlds().getFirst().getName());
prep.setDouble(7, Bukkit.getWorlds().getFirst().getSpawnLocation().getX());
prep.setDouble(8, Bukkit.getWorlds().getFirst().getSpawnLocation().getY());
prep.setDouble(9, Bukkit.getWorlds().getFirst().getSpawnLocation().getZ());
}
prep.setString(10, this.uuid.toString());
prep.executeUpdate();
} catch (SQLException e) {
System.err.println(e.getMessage());